How dzungtran/echo-rest-api works
Main Components
• API Service: This is located in the cmd/api directory. It serves as the entry point of the application.
• Business/Domain Modules: The project is organized into separate modules found in the "modules" directory (e.g., “core”, “projects”, and “shared”). These are responsible for core domain logic like handling users, organizations, and projects.
• Configuration and Dependency Injection: The "config" directory manages application settings, and dependency injection is implemented via uber-go/dig (see cmd/api/di).
• Infrastructure and Persistence:
• The “infrastructure” folder, along with the “migrations” directory, includes components for data access and database migrations.
• Under “infrastructure/datastore” you have SQL and Redis integrations.
• Shared Libraries and Utils: The “pkg” directory contains utilities, middleware, authorization (Rego files), constants, and helper functions that are used across the application.
• Tools: Tools for module generation (tools/mod) and route generation (tools/routes) assist in scaffolding and managing the project structure.
• External Services:
• Firebase is used for authentication.
• The Open Policy Agent is used to enforce role-based access control (RBAC) as seen in “pkg/authz”.
Relationships and Interactions
• The API service (cmd/api) accepts HTTP requests, which are routed to specific handlers in the modules (e.g., modules/core/handlers, modules/projects/handlers).
• Handlers then invoke usecases and business logic that reside within their respective module directories.
• These usecases interact with repository layers to perform database operations, as outlined in both the infrastructure and modules sections.
• The dependency injection mechanism (in cmd/api/di) wires the components together at startup.
• External integrations are encapsulated:
• Authentication flows interact with Firebase.
• RBAC is enforced through OPA policies (present in pkg/authz).
• Tools and migration frameworks link the development/deployment pipelines with the core application code.
Architectural Patterns and Technologies
• Clear Separation of Concerns: The project is organized into layers (API, business logic, data access) typical in an MVC/MVP architectural style even if not strictly following MVC.
• Module-Based Architecture: Using separate modules for different domains (core, projects, shared) enhances maintainability and scalability.
• Dependency Injection: Managed by uber-go/dig, ensuring loose coupling and easier testing.
• Use of External Services: Integration with Firebase for user authentication and OPA for authorization.
• Containerization: With Docker and docker-compose for local development and environment consistency.
• CLI-based code generation: Simplifies creating new modules or routes using tools in the “tools” directory.
Instructing the Principal Software Engineer
• Clear Labels: Ensure each component (API layer, modules, infrastructure, external services, etc.) is clearly labeled.
• Rectangles for service components (API server, modules).
• Cloud symbols for external services like Firebase and OPA.
Detailed Component Breakdown
• Top Layer: Client applications interacting via HTTP.
• Middle Layer: The API Gateway/Server represented by cmd/api.
• Handlers (request processing)
• Use Cases (business logic)
• Repositories (data access)
• Data & Infrastructure Layer: Containers for SQL/Redis (infrastructure/datastore, migrations) and shared utilities (pkg).