How gbrayhan/microservices-go works
Main Components
• Core components:
• Domain Layer – Found under src/domain, this contains core business models (e.g., “Medicine”, “User”) and error handling.
• Application Layer – Located under src/application/usecases, which includes the use-cases (e.g., auth, medicine, user) that orchestrate business logic and application rules.
• Infrastructure Layer – Includes several sub-components:
• Repository: Implements data persistence (src/infrastructure/repository) and contains database initialization and mappings.
• REST Interface: Found in src/infrastructure/rest where adapters, controllers, routes, and middlewares (including logging, error handling, and JWT-based security) are defined.
• Security: The JWT implementation within src/infrastructure/security.
• External Components:
• Database – The stack uses a MySQL/MariaDB instance as indicated by the README and the SQL scripts in docker/scripts/schema.sql.
• API Documentation – Provided via Swagger (docs/swagger.json and docs/swagger.yaml) and supported by swaggo in the routes.
• Docker & Deployment – Dockerfile, docker-compose file, and docker scripts indicate container-based deployment.
Relationships and Interactions
• The main entry point (main.go) initializes and wires up the components. It likely sets up the REST server, routes, middlewares, and configures dependency injection between layers.
• The Infrastructure layer provides external adapters to call the underlying Application usecases. For example, incoming HTTP requests hit the REST controllers, which then call the corresponding usecases defined in the application layer.
• The Application layer encapsulates business logic and makes calls to the Infrastructure repository layer to interact with the database. The Domain layer remains at the center, holding the business rules and types.
• Security (JWT) and middlewares ensure that REST endpoints are protected and that errors and validations are managed properly across the stack.
Architectural Patterns and Design Principles
• Clean/Hexagonal Architecture: The system is divided into layers (Domain, Application, and Infrastructure). This separation ensures that business logic is decoupled from external concerns.
• Separation of Concerns: Each directory (usecases, domain, repository, adapter) plays a distinct role.
• Dependency Inversion: Higher-level modules (Application, Domain) are not directly dependent on the lower-level modules (Infrastructure). Adapters and controllers mediate the interactions.
Incorporate Technologies and Frameworks
• Golang (v1.21)
• Gin framework for building REST APIs
• JWT for token-based security
• MySQL/MariaDB for data persistence
• Swagger/Swaggo for API documentation
• Viper for managing environment configs
• Docker for containerization and deployment
• Dependency management with Go modules
Final Checklist
• Clear component labels (Domain, Application Usecases, REST Controllers, Repositories, Database, External Services)
• Indications of middleware/security layers (JWT, interceptors, etc.).
• Placement of initialization point (main.go) and configuration elements such as Docker and environment variables.