# myousafmalik/fettler-be architecture

> Architecture diagram of the GitHub repository myousafmalik/fettler-be, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/myousafmalik/fettler-be
- Repository: https://github.com/myousafmalik/fettler-be

## Overview

##### Project Type and Purpose
- Project Type: Backend API service built with Django and Django REST Framework.
- Purpose: Serve account management, diet/exercise request processing, and personalized recommendations (including an ML inference component using a YOLOv8 model).

##### High-Level Architecture Components
a. API Gateway / Reverse Proxy
- Nginx or similar handling SSL, static files, request routing.
b. WSGI Server
- Gunicorn/Uvicorn hosting Django’s ASGI/WSGI application.
c. Django Application
- Core config module (`config/`)
- Three Django apps:
– account (authentication, user profiles, serializers & views under account/)
– requests (end-user diet/exercise requests workflow)
– recommend (recommendation engine, includes ML model inference)
- Utilities:
– `utils/misc.py`, `utils/views/Misc.py`
– Excel asset (`utils/diets.xlsx`)
d. ML Inference Subsystem
- `recommend/utils/predict_type.py` loading `assets/yolov8n.pt`
- Could be represented as a separate microservice or internal library.
e. Database
- SQLite (`db.sqlite3`) in development; can be replaced by PostgreSQL/MySQL in production.
f. External Interfaces
- Frontend client or mobile app (consuming REST endpoints)
- Postman collection (`Fettler++.postman_collection.json`)
- Potential third-party services (email/SMS, cloud storage)

##### Relationships & Data Flow
- The client sends HTTP requests → Nginx → Gunicorn/Uvicorn → Django entry point (`config/asgi.py` or `wsgi.py`).
- URL routing (`config/urls.py`) dispatches to app-specific `urls.py`.
- View logic (in account/views, requests/views, recommend/views) invokes:
- Serializers (validate/transform input)
- Models (ORM reads/writes to database)
- ML inference (recommend/utils) when generating recommendations.
- Responses flow back up the chain to the client.

##### Architectural Patterns & Principles
- MTV (Model-Template-View) pattern, adapted as API (templates unused).
- Separation of concerns per app:
- account → auth & user data
- requests → business workflow
- recommend → ML & domain logic
- Single database backing all apps.
- Potential to extract ML inference into a microservice for scalability.

##### Final Checklist
– Green for user-facing components.
– Orange for core Django apps.
– Purple for ML inference.
– Blue for data stores.
- Version note: “DB = SQLite (dev) → PostgreSQL (prod)”.
- Filename of Postman collection as “API contract”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (Browser/Mobile)"]:::external
    Postman["Fettler++.postman_collection.json"]:::external
    ExtEmail["Email/SMS Service"]:::external

    Client -->|HTTP Requests| Nginx["Nginx (API Gateway)"]:::backend
    Postman -->|API Contract| Nginx
    Nginx -->|Proxied Requests| Gunicorn["Gunicorn/Uvicorn"]:::backend
    Gunicorn -->|Load ASGI/WGS| UrlsConfig["urls.py"]:::backend

    subgraph "Core Config Module"
        Settings["settings.py"]:::backend
        UrlsConfig
        Asgi["asgi.py"]:::backend
        Wsgi["wsgi.py"]:::backend
    end

    subgraph "Account App"
        AcUrls["urls.py"]:::backend
        AcAuth["auth.py"]:::backend
        AcUser["user.py"]:::backend
        AcModels["models.py"]:::backend
        AcSerializers["serializers.py"]:::backend
        AcUtils["helper_functions.py"]:::backend
    end

    subgraph "Requests App"
        ReqUrls["urls.py"]:::backend
        ReqViews["views.py"]:::backend
        ReqModels["models.py"]:::backend
        ReqSerial["serializers.py"]:::backend
    end

    subgraph "Recommend App"
        RecUrls["urls.py"]:::backend
        RecViews["views.py"]:::backend
        RecModels["models.py"]:::backend
        RecSerial["serializers.py"]:::backend
        RecPredict["predict_type.py"]:::ml
        RecAsset["yolov8n.pt"]:::ml
    end

    subgraph "Utilities Module"
        UtilsMisc["misc.py"]:::backend
        UtilsViews["Misc.py"]:::backend
        UtilsAsset["diets.xlsx"]:::backend
    end

    Manage["manage.py"]:::backend
    DB["db.sqlite3"]:::db

    %% Routing
    UrlsConfig --> AcUrls
    UrlsConfig --> ReqUrls
    UrlsConfig --> RecUrls

    %% Account flow
    AcUrls -->|calls| AcAuth
    AcUrls -->|calls| AcUser
    AcAuth -->|uses| AcSerializers
    AcUser -->|uses| AcSerializers
    AcAuth -->|DB ops| AcModels
    AcUser -->|DB ops| AcModels
    AcAuth -->|helper| AcUtils

    %% Requests flow
    ReqUrls -->|calls| ReqViews
    ReqViews -->|uses| ReqSerial
    ReqViews -->|DB ops| ReqModels
    ReqViews -->|helper| UtilsMisc

    %% Recommend flow
    RecUrls -->|calls| RecViews
    RecViews -->|uses| RecSerial
    RecViews -->|DB ops| RecModels
    RecViews -->|inference| RecPredict
    RecPredict -->|loads| RecAsset
    RecPredict -->|DB ops| RecModels

    %% Utilities
    UtilsViews -->|helper| UtilsMisc

    %% Server commands and DB
    Manage -->|runs| Gunicorn
    AcModels -->|reads/writes| DB
    ReqModels -->|reads/writes| DB
    RecModels -->|reads/writes| DB

    %% External
    Nginx --> ExtEmail
    RecPredict --> ExtEmail

    %% Click Events
    click Config "https://github.com/myousafmalik/fettler-be/tree/main/config/"
    click Settings "https://github.com/myousafmalik/fettler-be/blob/main/config/settings.py"
    click UrlsConfig "https://github.com/myousafmalik/fettler-be/blob/main/config/urls.py"
    click Asgi "https://github.com/myousafmalik/fettler-be/blob/main/config/asgi.py"
    click Wsgi "https://github.com/myousafmalik/fettler-be/blob/main/config/wsgi.py"
    click AcModels "https://github.com/myousafmalik/fettler-be/blob/main/account/models.py"
    click AcSerializers "https://github.com/myousafmalik/fettler-be/blob/main/account/serializers.py"
    click AcAuth "https://github.com/myousafmalik/fettler-be/blob/main/account/views/auth.py"
    click AcUser "https://github.com/myousafmalik/fettler-be/blob/main/account/views/user.py"
    click AcUrls "https://github.com/myousafmalik/fettler-be/blob/main/account/urls.py"
    click AcUtils "https://github.com/myousafmalik/fettler-be/blob/main/account/utils/helper_functions.py"
    click ReqModels "https://github.com/myousafmalik/fettler-be/blob/main/requests/models.py"
    click ReqSerial "https://github.com/myousafmalik/fettler-be/blob/main/requests/serializers.py"
    click ReqViews "https://github.com/myousafmalik/fettler-be/blob/main/requests/views.py"
    click ReqUrls "https://github.com/myousafmalik/fettler-be/blob/main/requests/urls.py"
    click RecModels "https://github.com/myousafmalik/fettler-be/blob/main/recommend/models.py"
    click RecSerial "https://github.com/myousafmalik/fettler-be/blob/main/recommend/serializers.py"
    click RecViews "https://github.com/myousafmalik/fettler-be/blob/main/recommend/views.py"
    click RecUrls "https://github.com/myousafmalik/fettler-be/blob/main/recommend/urls.py"
    click RecPredict "https://github.com/myousafmalik/fettler-be/blob/main/recommend/utils/predict_type.py"
    click RecAsset "https://github.com/myousafmalik/fettler-be/blob/main/recommend/utils/assets/yolov8n.pt"
    click UtilsMisc "https://github.com/myousafmalik/fettler-be/blob/main/utils/misc.py"
    click UtilsViews "https://github.com/myousafmalik/fettler-be/blob/main/utils/views/Misc.py"
    click UtilsAsset "https://github.com/myousafmalik/fettler-be/blob/main/utils/diets.xlsx"
    click Manage "https://github.com/myousafmalik/fettler-be/blob/main/manage.py"
    click DB "https://github.com/myousafmalik/fettler-be/blob/main/db.sqlite3"
    click Postman "https://github.com/myousafmalik/fettler-be/blob/main/Fettler++.postman_collection.json"

    classDef external fill:#d3d3d3,stroke:#000,stroke-width:1px
    classDef backend fill:#ffcc80,stroke:#e65100,stroke-width:1px
    classDef ml fill:#ce93d8,stroke:#6a1b9a,stroke-width:1px
    classDef db fill:#90caf9,stroke:#0d47a1,stroke-width:1px
```
