# hcsouza/fiap-tech-fast-food architecture

> Architecture diagram of the GitHub repository hcsouza/fiap-tech-fast-food, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hcsouza/fiap-tech-fast-food
- Repository: https://github.com/hcsouza/fiap-tech-fast-food

## Overview

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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        direction TB
        A1["Routes"]:::api
        A2["Handlers"]:::api
        A3["Middlewares"]:::api
        A1 --> A2
        A2 --> A3
    end

    %% Integration Layer
    subgraph "Integration Layer"
        direction TB
        I1["Controller"]:::integration
        I2["Gateway"]:::integration
        I1 --> I2
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        D1["Entity"]:::domain
        D2["Use Case"]:::domain
        D3["Value Object"]:::domain
        D1 --> D2
        D2 --> D3
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        INF1["Mongo Adapter"]:::infra
        INF2["Config"]:::infra
        INF1 --- INF2
    end

    %% Database
    DB["MongoDB"]:::db

    %% Deployment Environment
    subgraph "Deployment Environment"
        direction TB
        DEP1["Docker Container"]:::deployment
        DEP2["Kubernetes Deployment"]:::deployment
        DEP1 --> DEP2
    end

    %% Tools & Automation
    subgraph "Tools & Automation"
        direction TB
        T1["Swagger"]:::tools
        T2["Viper"]:::tools
        T3["Make/Mockery"]:::tools
    end

    %% Connections between layers
    A3 --> I1
    I2 --> D2
    D3 --> INF1
    INF1 --> DB
    DB --> DEP1

    %% Dashed connections to Tools
    A1 ---|docs| T1
    INF2 ---|config| T2
    D2 ---|testing| T3

    %% Click Events for API Layer
    click A1 "https://github.com/hcsouza/fiap-tech-fast-food/tree/main/src/external/api/v1/routes"
    click A2 "https://github.com/hcsouza/fiap-tech-fast-food/tree/main/src/external/api/v1/handlers"
    click A3 "https://github.com/hcsouza/fiap-tech-fast-food/tree/main/src/external/api/v1/middlewares"

    %% Click Events for Integration Layer
    click I1 "https://github.com/hcsouza/fiap-tech-fast-food/tree/main/src/operation/controller"
    click I2 "https://github.com/hcsouza/fiap-tech-fast-food/tree/main/src/operation/gateway"

    %% Click Events for Business Logic Layer
    click D1 "https://github.com/hcsouza/fiap-tech-fast-food/tree/main/src/core/entity"
    click D2 "https://github.com/hcsouza/fiap-tech-fast-food/tree/main/src/core/usecase"
    click D3 "https://github.com/hcsouza/fiap-tech-fast-food/tree/main/src/core/valueObject"

    %% Click Events for Infrastructure Layer
    click INF1 "https://github.com/hcsouza/fiap-tech-fast-food/blob/main/src/external/datasource/mongoAdapter.go"
    click INF2 "https://github.com/hcsouza/fiap-tech-fast-food/tree/main/src/external/api/infra/config"

    %% Click Events for Deployment Environment
    click DEP1 "https://github.com/hcsouza/fiap-tech-fast-food/tree/main/docker"
    click DEP2 "https://github.com/hcsouza/fiap-tech-fast-food/tree/main/kubernetes"

    %% Styles
    classDef api fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef integration fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef domain fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef infra fill:#FFC0CB,stroke:#000,stroke-width:2px;
    classDef db fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef deployment fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef tools fill:#EEE8AA,stroke:#000,stroke-width:2px;
```
