How nsaltun/bitirici works
Main components of the system
• Entry Point: The "cmd" directory, specifically the main.go file, acts as the application's starting point.
• Controllers: Located in the "internal/controller" package, these handle the incoming requests and determine which business processes to trigger.
• Middleware: Found in the "internal/middleware" directory (e.g., auth_middleware.go), these components manage request authentication and other cross-cutting concerns.
• Models: The "internal/model" package defines the core data structures (e.g., user.go) that are used throughout the application.
• Services: The "internal/service" package contains the business logic (e.g., service.go, user_service.go) which orchestrates operations using the model and repository layers.
• Repositories: Under "internal/repository" and supplemented by "lib/db", these components abstract the data persistence layer (e.g., postgres integration via postgre.go and pg_repository.go).
• Library Components: The "lib/logging" package is used for application-wide logging, while other "lib" segments provide important infrastructure integrations.
• Shared/Utility Resources: The "pkg" directory houses utility functions or shared resources (here, for instance, resource.go) that may be consumed across other layers.
• Deployment & Configuration: Files like Dockerfile, docker-compose.yml, and the environment configuration files in "cmd/local_config.env" along with deployment yaml files indicate the project’s readiness for containerized deployment. The "deploy" directory organizes environment-specific configurations.
• Build and Dependency Management: Presence of go.mod, go.sum, and Makefile indicate dependency management and build automation.
Relationships and interactions
• The application initialization in "cmd/main.go" is responsible for bootstrapping and wiring the different components (e.g., router initialization from "internal/router/router.go").
• The router directs incoming HTTP requests to the appropriate controllers. The controllers perform any necessary request validation and then delegate the business logic to service layers.
• The services process business rules and then utilize the repository layer to interact with the database. This data interaction is abstracted further in the "lib/db" package where actual Postgres queries are executed.
• Middleware (e.g., authentication middleware) is integrated within the request pipeline to secure endpoints, ensuring that requests reach the controller only after passing the necessary checks.
• Abstract logging is handled by components in "lib/logging", ensuring that operations across the entire stack are properly logged for debugging and monitoring.
Important architectural patterns and design principles
• Layered/MVC architecture: Clear separation exists between request handling, business logic, data persistence, and cross-cutting concerns.
• Dependency Injection & Modular Design: Although not explicitly detailed, the structure implies that dependency injection is used to pass repositories into services, and services into controllers.
• Containerization: Through Dockerfile and docker-compose.yml, the project is designed to be containerized for consistent deployment across environments.