# README
TrinityKnights Backend
TrinityKnights Backend is a service that provides backend functionalities for the TrinityKnights application.
Table of Contents
- Features
- Deployment
- Requirements
- Installation
- Usage
- Project Structure
- Contributing
- License
- Reference
- Acknowledgements
Features
-
Authentication & Authorization
- JWT-based authentication
- Role-based access control (Admin/Public)
- Token refresh mechanism
-
Payment Processing
- Xendit payment gateway integration
- Payment status tracking
- Invoice generation
- Payment search and filtering
-
API Interfaces
- RESTful HTTP API
- GraphQL API with playground
- Swagger/OpenAPI documentation
-
Data Management
- PostgreSQL database integration
- Redis caching
- GORM ORM implementation
-
Development Features
- Docker and Docker Compose support
- Comprehensive test coverage
- Mock generation for testing
- Code quality checks (critic, security)
- Hot reload in development
Deployment
-
Koyeb
-
Railway
-
Vercel
-
Render
Requirements
- Go 1.23+
- Docker
- PostgreSQL
- Redis
- Make
Installation
-
Clone the repository:
git clone https://github.com/savioruz/TrinityKnights.Backend.git cd TrinityKnights.Backend
-
Environment Variables:
Create a
.env
file in the root directory and add the following:cp .env.example .env
-
Edit the
.env
file with your configuration:APP_PORT=3000 APP_LOG_LEVEL=6 APP_ENV=development DB_HOST= DB_PORT=5432 DB_USER= DB_PASSWORD= DB_NAME= DB_SSL_MODE=require DB_TIMEZONE= REDIS_HOST= REDIS_PORT= REDIS_PASSWORD= REDIS_DB=0 SMTP_HOST= SMTP_PORT= SMTP_USERNAME= SMTP_PASSWORD= JWT_SECRET= JWT_ACCESS_EXPIRY=1h JWT_REFRESH_EXPIRY=168h XENDIT_API_KEY= XENDIT_CALLBACK_TOKEN=
Usage
Development Commands
# Generate Swagger documentation
make swag
# Generate mocks for testing
make mockgen
# Run code critics (static analysis)
make critic
# Run security checks
make security
# Run tests with coverage
make test
Docker Commands
Single Container
# Build Docker image
make docker.build
# Run container
make docker.run
# Stop and remove container
make docker.stop
Docker Compose
# Build services
make dc.build
# Start services
make dc.up
# Stop services
make dc.down
Testing
Run the full test suite with coverage:
make test
This will:
- Clean build artifacts
- Run code critics
- Perform security checks
- Execute tests with coverage
- Display coverage report
Code Generation
Generate mock implementations for testing:
make mockgen
Generate Swagger documentation:
make swag
Running the API
You can run the API using Docker or directly with Make.
Docker
-
Run redis:
make docker.redis
-
Run the application:
make docker.run
For production, you need to secure redis on Makefile with a password.
Make
-
Run the application:
make run
You need to have Redis running on your machine.
ERD Schema
API Documentation
Swagger documentation is available at: http://localhost:3000/swagger.
GraphQL Playground
GraphQL playground is available at: http://localhost:3000/playground.
Project Structure
.
├── cmd/
│ └── app/main.go
├── config/
├── docs/
├── internal/
│ ├── builder/
│ ├── delivery/
│ │ ├── graph/
│ │ │ ├── handler/
│ │ │ ├── model/
│ │ │ ├── resolver/
│ │ │ └── schema.graphqls
│ │ └── http/
│ │ │ ├── handler/
│ │ │ ├── middleware/
│ │ │ └── route/
│ ├── domain/
│ │ ├── entity/
│ │ └── model/
│ │ └── converter/
│ ├── repository/
│ └── service/
├── pkg/
│ ├── cache/
│ ├── errors/
│ ├── helper/
│ └── route/
├── test/mock
├── .env
├── .env.example
├── .gitignore
├── Dockerfile
├── docker-compose.yml
├── tools.go
├── go.mod
├── go.sum
├── Makefile
├── README.md
├── vercel.json
└── LICENSE
Contributing
Feel free to open issues or submit pull requests with improvements.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Reference
- Go Programming Language
- GORM Documentation
- GraphQL
- Xendit API Documentation
- Redis Documentation
- Docker Documentation
- Swagger/OpenAPI