Skip to content

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! πŸ’»βš‘

Notifications You must be signed in to change notification settings

nanda03dev/go-ms-clean-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Golang Microservice Template πŸš€

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 Structure

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        

Layers Explained

  • 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.

Getting Started

Prerequisites

  • Go 1.XX or higher
  • Dependencies specified in go.mod

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd project
  2. Install dependencies:

    go mod tidy

Running the Application

To start the application, run:

go run main.go

Testing

To run tests, execute:

go test ./...

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

About

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! πŸ’»βš‘

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published