# sebiche09/app-anti-gaspillage architecture

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

- Interactive diagram: https://gitdiagram.com/sebiche09/app-anti-gaspillage
- Repository: https://github.com/sebiche09/app-anti-gaspillage

## Overview

##### Main High-Level Components
- Frontend:
- Flutter-based client with separate sub-components for mobile (iOS and Android) and web.
- That the frontend code is organized under a "frontend" directory with separate configurations for Android and iOS.
- Backend:
- A Go-based API server containing distinct layers:
▪ API Handlers (in the “backend/api/handlers” folder) – this is where HTTP endpoints are implemented (for baskets, invitations, merchants, restaurants, and users).
▪ Request/Response structs (in “backend/api/requests” and “backend/api/responses”) – defining the data exchanged between client and server.
▪ Middlewares (authentication and others under “backend/middlewares”) – intercept requests for security and other cross-cutting concerns.
▪ Domain Models (in “backend/models”) – representing the core data entities such as basket, merchant, restaurant, user, etc.
▪ Repositories (in “backend/repositories”) – for data persistence operations with the PostgreSQL database.
▪ Business Services (in “backend/services”) – containing the core business logic (e.g., basket_service, email_service) that orchestrate the domain operations.
▪ Routing (set up in “backend/routes”) – where HTTP routing and endpoint linking take place.
- Database:
- PostgreSQL is mentioned explicitly in the README as the database used.
- It as a relational database connected to the backend, handling persistence for merchants, users, orders, etc.
- Containerization & Deployment:
- Dockerfiles exist for both the backend and frontend (and a separate one for the database in “db/Dockerfile”).
- A “docker-compose.yml” file orchestrates the multi-container setup.
- Devcontainer configuration for developer-specific environments.

##### Relationships and Data Flow between the Components
- Frontend to Backend:
- Backend Internal Layers:
- That error handling, authentication middleware, and model validation layers are also noted where relevant.
- Backend to Database:
- Docker Containerization:
- A container boundary for each major service (backend container, frontend container, and database container) to show deployment separation.

##### Architectural Patterns and Key Design Principles
- Layered Architecture:
- Separation of concerns in the backend through distinct packages (API, models, repositories, services, middlewares, tests).
- Microservices vs. Monolith:
- Although the code structure in the backend is modular, the project appears to be built as a single service rather than many independent microservices.
- API-first and RESTful Design:
- That API Handlers facilitate REST endpoints for client communications.
- Testability:
- Briefly note the presence of tests (unit, integration, repository tests) which support continuous quality assurance.

##### Important Technologies, Frameworks, and Libraries
- Backend: Go (version specified, e.g., 1.23.4), along with modules for JWT handling, documentation (Swagger in “backend/docs”), and likely a PostgreSQL driver.
- Frontend: Flutter (with the standard structure for mobile and web), along with Dart files for UI, models, providers, and services.
- Database: PostgreSQL, managed and orchestrated with Docker.

- Clear Labels: Identify each component clearly (e.g., “Flutter Mobile Client”, “Flutter Web App”, “Go API Server”, “PostgreSQL Database”).
▪ From frontend to backend,
▪ Within the backend: Handlers → Services → Repositories,
▪ From repositories to the database.
▪ Rectangles for application components (frontend and backend),
- Annotations: Optionally include configuration files and test modules as side components to indicate development and CI/CD integrations.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Frontend"
        subgraph "Mobile Clients"
            Android("Flutter Android Client"):::frontend
            iOS("Flutter iOS Client"):::frontend
        end
        Web("Flutter Web App"):::frontend
    end

    subgraph "Backend"
        Server("Go API Server"):::backend
        subgraph "Application Layers"
            Routing("Routing"):::backend
            Handlers("API Handlers"):::backend
            Req("Request Structs"):::backend
            Resp("Response Structs"):::backend
            Middleware("Middlewares"):::backend
            Models("Domain Models"):::backend
            Services("Business Services"):::backend
            Repos("Repositories"):::backend
            Docs("API Documentation (Swagger)"):::backend
        end
    end

    subgraph "Database"
        DB("PostgreSQL Database"):::database
    end

    subgraph "Deployment & Containerization"
        Compose("docker-compose"):::container
        BE_Docker("Backend Dockerfile"):::container
        FE_Docker("Frontend Dockerfile"):::container
        DevCont("Devcontainer"):::container
        DB_Docker("DB Dockerfile"):::container
    end

    %% Frontend to Backend
    Android -->|"API_call"| Server
    iOS -->|"API_call"| Server
    Web -->|"API_call"| Server

    %% Backend Internal Flow
    Server -->|"routes"| Routing
    Routing -->|"directs"| Handlers
    Handlers -->|"delegates"| Services
    Services -->|"persists"| Repos
    Repos -->|"queries"| DB

    %% Additional Backend Dependencies
    Handlers -.->|"uses"| Req
    Handlers -.->|"uses"| Resp
    Middleware -.->|"applies to"| Handlers
    Server ---|"provides"| Docs

    %% Container orchestration (Deployment)
    Compose -->|"orchestrates"| Android
    Compose -->|"orchestrates"| iOS
    Compose -->|"orchestrates"| Web
    Compose -->|"orchestrates"| Server
    Compose -->|"orchestrates"| DB

    %% Classes for styling
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef database fill:#F4A460,stroke:#000,stroke-width:1px;
    classDef container fill:#D3D3D3,stroke:#000,stroke-width:1px;

    %% Click Events
    click Android "https://github.com/sebiche09/app-anti-gaspillage/tree/main/frontend/android"
    click iOS "https://github.com/sebiche09/app-anti-gaspillage/tree/main/frontend/ios"
    click Web "https://github.com/sebiche09/app-anti-gaspillage/tree/main/frontend/web"
    click Server "https://github.com/sebiche09/app-anti-gaspillage/blob/main/backend/main.go"
    click Handlers "https://github.com/sebiche09/app-anti-gaspillage/tree/main/backend/api/handlers"
    click Req "https://github.com/sebiche09/app-anti-gaspillage/tree/main/backend/api/requests"
    click Resp "https://github.com/sebiche09/app-anti-gaspillage/tree/main/backend/api/responses"
    click Middleware "https://github.com/sebiche09/app-anti-gaspillage/tree/main/backend/middlewares"
    click Models "https://github.com/sebiche09/app-anti-gaspillage/tree/main/backend/models"
    click Repos "https://github.com/sebiche09/app-anti-gaspillage/tree/main/backend/repositories"
    click Services "https://github.com/sebiche09/app-anti-gaspillage/tree/main/backend/services"
    click Routing "https://github.com/sebiche09/app-anti-gaspillage/tree/main/backend/routes"
    click DB "https://github.com/sebiche09/app-anti-gaspillage/tree/main/db/Dockerfile"
    click Compose "https://github.com/sebiche09/app-anti-gaspillage/blob/main/docker-compose.yml"
    click BE_Docker "https://github.com/sebiche09/app-anti-gaspillage/tree/main/backend/Dockerfile"
    click FE_Docker "https://github.com/sebiche09/app-anti-gaspillage/tree/main/frontend/Dockerfile"
    click DevCont "https://github.com/sebiche09/app-anti-gaspillage/blob/main/.devcontainer.json"
    click Docs "https://github.com/sebiche09/app-anti-gaspillage/tree/main/backend/docs"
```
