A scalable and maintainable microservice template in Go, inspired by the NestJS framework and built on Clean Architecture principles. Perfect for handling complex domain-driven projects with robust design and separation of concerns. Ready for both MongoDB and PostgreSQL out of the box! π»β‘
project/
βββ migrations/ # Migration scripts for PostgreSQL
β βββ user_migration.sql
β βββ order_migration.sql
βββ main.go # Application entry point
βββ go.mod
βββ src/ # Source code folder (contains all the layers)
β βββ domain/
β β βββ aggregates/
β β βββ user.go # Business logic for User (Domain model)
β β βββ order.go # Business logic for Order (Domain model)
β βββ application/
β β βββ service/
β β βββ user_service.go # Business logic for User
β β βββ order_service.go # Business logic for Order
β βββ infrastructure/
β β βββ db/
β β β βββ db.go # General Database connection
β β β βββ mongo-db.go # MongoDB connection logic
β β β βββ postgres-db.go # PostgreSQL connection logic
β β βββ entity/
β β β βββ user.go # MongoDB User entity
β β β βββ order.go # PostgreSQL Order entity
β β βββ repository/
β β β βββ user_repository_impl.go # MongoDB UserRepository implementation
β β β βββ order_repository_impl.go # PostgreSQL OrderRepository implementation
β βββ interfaces/
β β βββ handlers/
β β βββ user_handler.go # HTTP handler for User
β β βββ order_handler.go # HTTP handler for Order
β βββ app_module/ # Central module initialization
β β βββ app_module.go # Initializes repositories and services
β βββ helpers/ # Common utility functions
β β βββ uuid_helper.go # Common UUID generator
β β βββ string_helpers.go # String manipulation helpers
-
Domain Layer: Contains the core business models and domain logic. It defines entities and their relationships, encapsulating the business rules.
-
Application Layer: Holds the business logic and use cases. It coordinates the flow of data between the domain and infrastructure layers, processing requests and responses.
-
Infrastructure Layer: Manages data access and external integrations (e.g., database interactions, third-party APIs). It provides concrete implementations for the repository interfaces defined in the domain layer.
-
Interface Layer: Contains HTTP handlers for routing incoming requests and managing responses. It may also include Data Transfer Objects (DTOs) for structured data interchange between client and server.
- Go 1.XX or higher
- Dependencies specified in
go.mod
-
Clone the repository:
git clone <repository-url> cd project
-
Install dependencies:
go mod tidy
To start the application, run:
go run main.goTo run tests, execute:
go test ./...Contributions are welcome! Please open an issue or submit a pull request for any improvements.
This project is licensed under the MIT License. See the LICENSE file for details.