How hcsouza/fiap-tech-fast-food works
Project Type & Purpose
• This is a backend API service built using Golang to manage a fast food system. It supports user registration, product management, order creation, and payment/checkout flows.
• The service is designed with resilience, scalability, and containerized deployment in mind (using Docker and Kubernetes).
Analyzing the File Structure
• Top-level directories:
• cmd: Contains the entry point (go-command.go) for starting the application.
• docker & kubernetes: Provide containerization (Dockerfile, docker-compose) and orchestration (Kubernetes manifests) files.
• docs: Contains Swagger/openAPI documentation.
• src/common: Shared constants, DTOs, error definitions, and interfaces.
• src/core: Houses core business logic with domain entities, use cases, and value objects.
• src/external: Contains the API layer implementation (using Gin), configuration setups, handlers for API endpoints, middlewares, route definitions, integration with MongoDB through adapters, and third-party dependencies.
• src/operation: Provides controllers and gateway implementations that likely adapt core business use cases to infrastructure concerns.
• test: Contains unit tests and mock implementations.
Key Architectural Components
a. API Layer (Presentation/External Interface):
• Located in src/external/api and its subfolders (v1/handlers, middlewares, routes).
• This is where HTTP requests are processed using the Gin framework. It also includes Swagger documentation generation.
b. Business Logic / Domain Layer:
• Found in src/core, includes:
• Entity definitions (e.g., customer, order, product).
• Business rules via use cases (e.g., checkout, order processing).
• Value objects for domain-specific data (e.g., category, CPF, order status).
• This layer encapsulates the core logic independent of external concerns.
c. Data Access / Infrastructure Layer:
• Implemented in src/external/datasource (e.g., mongoAdapter) and configuration files under src/external/api/infra/config.
• This layer interacts with MongoDB using the mongo-driver.
d. Integration and Controller Layer:
• Located under src/operation, this layer adapts external API calls to invoke the appropriate use cases and bridges to external gateways.
e. Containerization & Deployment:
• Dockerfile and docker-compose (in the docker folder) enable local container deployment.
• Kubernetes manifests (in the kubernetes folder) illustrate how to deploy and scale both the application and the database (MongoDB) in a cloud-native environment.
Recommended Architectural Patterns and Design Principles
• Separation of concerns between presentation (API endpoints), domain business logic (use cases and entities), and data persistence (MongoDB interactions).
• Use layered architecture (or hexagonal/ports and adapters) pattern as evident by the clear separation via directories (src/core vs. src/external vs. src/operation).
• Dependency inversion by showing how the core business logic (domain layer) relies on interfaces defined under src/common/interfaces and is then concretely implemented by components in src/external and src/operation.