Backend

module
v0.0.0-...-73c8273 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2025 License: Apache-2.0

README

TrinityKnights Backend

TrinityKnights Backend is a service that provides backend functionalities for the TrinityKnights application.

Go GitHub code size in bytes Go Report Card License

Table of Contents

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

Deploy to Koyeb

  • Railway

Deploy on Railway

  • Vercel

Deploy with Vercel

  • Render

Deploy to Render

Requirements

  • Go 1.23+
  • Docker
  • PostgreSQL
  • Redis
  • Make

Installation

  1. Clone the repository:

    git clone https://github.com/savioruz/TrinityKnights.Backend.git
    cd TrinityKnights.Backend
    
  2. Environment Variables:

    Create a .env file in the root directory and add the following:

    cp .env.example .env
    
  3. 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:

  1. Clean build artifacts
  2. Run code critics
  3. Perform security checks
  4. Execute tests with coverage
  5. 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

  1. Run redis:

    make docker.redis
    
  2. Run the application:

    make docker.run
    

For production, you need to secure redis on Makefile with a password.

Make

  1. Run the application:

    make run
    

You need to have Redis running on your machine.

ERD Schema

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

Acknowledgements

Directories

Path Synopsis
cmd
app command
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
internal
pkg
jwt
test
mock/delivery/graph
Package mock_graph is a generated GoMock package.
Package mock_graph is a generated GoMock package.
mock/delivery/http/handler/event
Package mock_event is a generated GoMock package.
Package mock_event is a generated GoMock package.
mock/delivery/http/handler/order
Package mock_order is a generated GoMock package.
Package mock_order is a generated GoMock package.
mock/delivery/http/handler/payment
Package mock_payment is a generated GoMock package.
Package mock_payment is a generated GoMock package.
mock/delivery/http/handler/ticket
Package mock_ticket is a generated GoMock package.
Package mock_ticket is a generated GoMock package.
mock/delivery/http/handler/user
Package mock_user is a generated GoMock package.
Package mock_user is a generated GoMock package.
mock/delivery/http/handler/venue
Package mock_venue is a generated GoMock package.
Package mock_venue is a generated GoMock package.
mock/delivery/http/route
Package mock_route is a generated GoMock package.
Package mock_route is a generated GoMock package.
mock/pkg/cache
Package mock_cache is a generated GoMock package.
Package mock_cache is a generated GoMock package.
mock/pkg/gomail
Package mock_gomail is a generated GoMock package.
Package mock_gomail is a generated GoMock package.
mock/pkg/jwt
Package mock_jwt is a generated GoMock package.
Package mock_jwt is a generated GoMock package.
mock/repository
Package mock_repository is a generated GoMock package.
Package mock_repository is a generated GoMock package.
mock/repository/event
Package mock_event is a generated GoMock package.
Package mock_event is a generated GoMock package.
mock/repository/order
Package mock_order is a generated GoMock package.
Package mock_order is a generated GoMock package.
mock/repository/payment
Package mock_payment is a generated GoMock package.
Package mock_payment is a generated GoMock package.
mock/repository/ticket
Package mock_ticket is a generated GoMock package.
Package mock_ticket is a generated GoMock package.
mock/repository/user
Package mock_user is a generated GoMock package.
Package mock_user is a generated GoMock package.
mock/repository/venue
Package mock_venue is a generated GoMock package.
Package mock_venue is a generated GoMock package.
mock/service/event
Package mock_event is a generated GoMock package.
Package mock_event is a generated GoMock package.
mock/service/order
Package mock_order is a generated GoMock package.
Package mock_order is a generated GoMock package.
mock/service/payment
Package mock_payment is a generated GoMock package.
Package mock_payment is a generated GoMock package.
mock/service/ticket
Package mock_ticket is a generated GoMock package.
Package mock_ticket is a generated GoMock package.
mock/service/user
Package mock_user is a generated GoMock package.
Package mock_user is a generated GoMock package.
mock/service/venue
Package mock_venue is a generated GoMock package.
Package mock_venue is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL