# tuandat1601/food_delivery_backend_go architecture

> Architecture diagram of the GitHub repository tuandat1601/food_delivery_backend_go, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tuandat1601/food_delivery_backend_go
- Repository: https://github.com/tuandat1601/food_delivery_backend_go

## Overview

##### Main Components
- API/Transport Layer: Represented by the “internal/transport/gin” directory, which includes handlers for various endpoints (menus, restaurants, users). Also include “internal/routes” where the routing logic is defined. This layer receives HTTP requests, performs parameter validation, and delegates processing to business logic.
- Business Logic Layer: Located in “internal/biz,” this is where core functions for handling menu creation, restaurant management, and user authentication reside. This layer encapsulates business rules and processing.
- Data Model & Repository Layer: Indicated by the “internal/model” (domain objects like food, order, restaurant, user) and “internal/repositories” (actual data access operations) directories. This layer handles interactions with the database.
- Middleware: The “internal/middleware” component (e.g., authentication) ensures that security and access control are enforced before reaching the business logic.
- Database: External to the codebase but integral – represented by the “database” directory containing migrations (schema and initial data) and then your Postgres database.
- Configuration and Environment: The “config”, “app.env”, and related files provide environment-specific settings which configure how the application runs.
- Documentation: The “docs” folder (with Swagger JSON/YAML) provides API documentation that informs how clients should interact with the service.
- Orchestration/Deployment: Files like the Dockerfile and docker-compose.yml define containerization details and how the service is deployed.
- External Clients: Although not a direct code component, include clients like restaurant managers (web/mobile apps) and customers (web/mobile interfaces) as external actors interacting via HTTP.

- Middleware (authentication) as an inline security check that intercepts requests before reaching the business layer.
- Also, note configuration services that feed environment and runtime settings into the system.
- Optionally, show a side component for documentation (Swagger) which clients can refer to for API details.

##### Architectural Patterns and Technologies
- Layered Architecture: Separate concerns clearly into transport (Gin handlers), business logic (biz), and data access (repositories/models).
- RESTful API Design: Represented through clearly defined routers in “internal/routes” and handlers in “internal/transport/gin”.
- Middleware Pattern: Authentication is applied globally or on selected routes.
- Database Migrations: Show that a migration process exists (database/migrations) to update the schema in the Postgres database.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External Clients"
        RM["Restaurant Manager"]:::client
        C["Customer"]:::client
    end

    %% API/Transport Layer
    subgraph "API/Transport Layer"
        G["Gin Handlers"]:::transport
        R["Routes"]:::transport
    end

    %% Middleware
    subgraph "Middleware"
        M["Authentication Middleware"]:::middleware
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        B["Business Logic"]:::biz
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        D["Data Model"]:::data
        Repo["Repositories"]:::data
    end

    %% Database
    subgraph "Database"
        P["Postgres Database"]:::database
        DM["Database Migrations"]:::database
    end

    %% Configuration and Environment
    subgraph "Configuration and Environment"
        CFG["Config"]:::config
        ENV["Environment Settings"]:::config
    end

    %% Documentation
    subgraph "Documentation"
        DOC["Documentation (Swagger)"]:::documentation
    end

    %% Deployment
    subgraph "Deployment"
        DF["Dockerfile"]:::deployment
        DC["docker-compose.yml"]:::deployment
    end

    %% Connections
    RM -->|"sendsRequest"| G
    RM -->|"sendsRequest"| R
    C  -->|"sendsRequest"| G
    C  -->|"sendsRequest"| R

    G -->|"passesTo"| M
    R -->|"routesThrough"| M

    M -->|"invokes"| B

    B -->|"callsRepo"| Repo
    B -->|"usesModel"| D

    Repo -->|"persistsTo"| P

    DM -->|"updates"| P

    CFG ---|"configures"| G
    CFG ---|"configures"| B
    ENV ---|"sets"| G
    ENV ---|"sets"| B

    DOC ---|"references"| RM
    DOC ---|"references"| C

    DF ---|"buildsService"| G
    DF ---|"buildsService"| B
    DC ---|"orchestrates"| DF
    DC ---|"orchestrates"| P

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef transport fill:#6495ED,stroke:#000,stroke-width:2px,color:#fff;
    classDef middleware fill:#F08080,stroke:#000,stroke-width:2px;
    classDef biz fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef data fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef database fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef config fill:#C0C0C0,stroke:#000,stroke-width:2px;
    classDef documentation fill:#40E0D0,stroke:#000,stroke-width:2px;
    classDef deployment fill:#DA70D6,stroke:#000,stroke-width:2px;

    %% Click Events
    click G "https://github.com/tuandat1601/food_delivery_backend_go/tree/main/internal/transport/gin"
    click R "https://github.com/tuandat1601/food_delivery_backend_go/tree/main/internal/routes"
    click B "https://github.com/tuandat1601/food_delivery_backend_go/tree/main/internal/biz"
    click D "https://github.com/tuandat1601/food_delivery_backend_go/tree/main/internal/model"
    click Repo "https://github.com/tuandat1601/food_delivery_backend_go/tree/main/internal/repositories"
    click M "https://github.com/tuandat1601/food_delivery_backend_go/tree/main/internal/middleware"
    click DM "https://github.com/tuandat1601/food_delivery_backend_go/tree/main/database/migrations"
    click CFG "https://github.com/tuandat1601/food_delivery_backend_go/tree/main/config"
    click ENV "https://github.com/tuandat1601/food_delivery_backend_go/blob/main/app.env"
    click DOC "https://github.com/tuandat1601/food_delivery_backend_go/tree/main/docs"
    click DF "https://github.com/tuandat1601/food_delivery_backend_go/tree/main/Dockerfile"
    click DC "https://github.com/tuandat1601/food_delivery_backend_go/blob/main/docker-compose.yml"
```
