# mlldzi/coffee-corner-sp architecture

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

- Interactive diagram: https://gitdiagram.com/mlldzi/coffee-corner-sp
- Repository: https://github.com/mlldzi/coffee-corner-sp

## Overview

##### Main Components
a. Client (Browser)
- The user’s browser running the React/Next.js UI.
b. Frontend Service
- Next.js app (React) in a Node.js container.
- Renders pages (menu, checkout, history, etc.) and serves static assets (images, videos).
- Contains a client-side “services/api.js” for communicating with the backend and “services/store.js” for state management.
c. Backend Service
- Flask/Python application in its own container.
- Exposes RESTful endpoints under `/auth`, `/menu`, `/orders`, `/user`.
- Layers:
- Routes (in `backend/app/routes/`)
- Business logic (in `backend/app/services/`)
- Data models (SQLAlchemy models in `backend/app/models.py`)
- Utilities (decorators, helpers)
d. Database
- PostgreSQL container managed via Docker Compose.
- Stores users, orders, menu items. Credentials loaded from `backend/secrets`.
e. Docker Compose
- Orchestrates the three containers (frontend, backend, database) and defines networking.
f. Optional/Test Components
- Frontend ESLint config, but not a runtime component.

##### Relationships & Data Flows
- User → (HTTP) → Next.js frontend
- Next.js frontend → (HTTP/REST) → Flask backend
- Flask backend → (SQL) → PostgreSQL
- PostgreSQL → (SQL results) → Flask backend → (JSON) → Frontend → Browser
- Docker Compose networks all three via an internal bridge
- Secrets fed into the backend container at runtime

##### Architectural Patterns
- Separation of Concerns:
- Presentation (Next.js) vs. API (Flask) vs. Persistence (Postgres)
- Layered Backend:
- Controllers (routes) → Services → Models → DB
- Component-Based Frontend:
- React components under `src/app/components`
- CSS Modules for styling
- Containerization:
- Each service in its own Docker container
- Single `docker-compose.yaml` for dev/local orchestration

##### Technologies/Frameworks
- Frontend: Next.js, React, CSS Modules, ESLint
- Backend: Flask, SQLAlchemy, Pytest
- Database: PostgreSQL
- DevOps: Docker, Docker Compose

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Docker Compose boundary
    subgraph "Docker Compose" 
        direction TB
        ComposeFile["docker-compose.yaml"]:::compose

        subgraph "Next.js Frontend"
            direction TB
            FE_Docker["Dockerfile"]:::frontend
            FE_UI["UI/SSR Components\nsrc/app"]:::frontend
            FE_Static["Static Assets\npublic/"]:::frontend
            FE_API["Services/api.js"]:::frontend
            FE_Store["Services/store.js"]:::frontend
            FE_ESLINT[".eslintrc.json"]:::frontend
        end

        subgraph "Flask Backend"
            direction TB
            BE_Docker["Dockerfile"]:::backend
            BE_Entrypoint["run.py"]:::backend
            BE_Config["config.py"]:::backend
            BE_Routes["Routes\napp/routes"]:::backend
            BE_Services["Services\napp/services"]:::backend
            BE_Models["Models\napp/models.py"]:::backend
            BE_Utils["Utils\napp/utils"]:::backend
            BE_Reqs["requirements.txt"]:::backend
        end

        subgraph "PostgreSQL DB"
            direction TB
            DB["PostgreSQL"]:::db
        end

        Secrets["Secrets\n(secrets/)"]:::compose
    end

    subgraph "Backend Tests"
        direction TB
        BE_Tests["Pytest Suite\nbackend/tests/"]:::backend
    end

    %% User interactions
    User["User Browser"]:::external

    %% Flows
    User -->|"HTTP Request"| FE_UI
    FE_UI -->|"calls API()"| FE_API
    FE_API -->|"HTTP/REST"| BE_Routes
    BE_Routes -->|"invoke"| BE_Services
    BE_Services -->|"CRUD via SQLAlchemy"| BE_Models
    BE_Models -->|"SQL"| DB
    DB -->|"Query Results"| BE_Models
    BE_Models -->|"JSON Response"| BE_Routes
    BE_Routes -->|"HTTP Response"| FE_API
    FE_API -->|"update UI"| FE_UI

    %% Orchestration & secrets
    ComposeFile --> FE_Docker
    ComposeFile --> BE_Docker
    ComposeFile --> DB
    Secrets --> BE_Config

    %% Tests
    BE_Tests -->|"tests API endpoints"| BE_Routes

    %% Click Events
    click ComposeFile "https://github.com/mlldzi/coffee-corner-sp/blob/main/docker-compose.yaml"
    click FE_Docker "https://github.com/mlldzi/coffee-corner-sp/tree/main/frontend/Dockerfile"
    click FE_UI "https://github.com/mlldzi/coffee-corner-sp/tree/main/frontend/src/app/"
    click FE_Static "https://github.com/mlldzi/coffee-corner-sp/tree/main/frontend/public/"
    click FE_API "https://github.com/mlldzi/coffee-corner-sp/blob/main/frontend/src/app/services/api.js"
    click FE_Store "https://github.com/mlldzi/coffee-corner-sp/blob/main/frontend/src/app/services/store.js"
    click FE_ESLINT "https://github.com/mlldzi/coffee-corner-sp/blob/main/frontend/.eslintrc.json"
    click BE_Docker "https://github.com/mlldzi/coffee-corner-sp/tree/main/backend/Dockerfile"
    click BE_Entrypoint "https://github.com/mlldzi/coffee-corner-sp/blob/main/backend/run.py"
    click BE_Config "https://github.com/mlldzi/coffee-corner-sp/blob/main/backend/app/config.py"
    click BE_Routes "https://github.com/mlldzi/coffee-corner-sp/tree/main/backend/app/routes/"
    click BE_Services "https://github.com/mlldzi/coffee-corner-sp/tree/main/backend/app/services/"
    click BE_Models "https://github.com/mlldzi/coffee-corner-sp/blob/main/backend/app/models.py"
    click BE_Utils "https://github.com/mlldzi/coffee-corner-sp/tree/main/backend/app/utils/"
    click BE_Reqs "https://github.com/mlldzi/coffee-corner-sp/blob/main/backend/requirements.txt"
    click BE_Tests "https://github.com/mlldzi/coffee-corner-sp/tree/main/backend/tests/"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1;
    classDef backend fill:#C8E6C9,stroke:#1B5E20;
    classDef db fill:#FFE0B2,stroke:#E65100,shape:cylinder;
    classDef compose fill:#E0E0E0,stroke:#424242,stroke-dasharray:5 5;
    classDef external fill:#FFF9C4,stroke:#F57F17;
```
