# zxlawdx/nextfit architecture

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

- Interactive diagram: https://gitdiagram.com/zxlawdx/nextfit
- Repository: https://github.com/zxlawdx/nextfit

## Overview

##### Project type and purpose
- NextFit is a hybrid desktop + microservice application:
– Desktop client: JavaFX-based UI (src/main/java & FXML/CSS in src/main/resources).
– Back-end microservice: Python FastAPI (main.py + requirements.txt).
– Local persistence: SQLite database (src/main/database/database_system.db).
– Container orchestration: Dockerfiles (nextfit.dockerfile, integration.dockerfile) and docker-compose.yml.

##### File structure
- Top-level directories:
– src/main/java/dbsystem & src/main/java/system → Java packages for persistence and UI/controllers/business logic.
– src/main/resources/system/layouts & css → JavaFX view definitions.
– src/main/database → SQLite files and DB schema.
– src/main/appplayer (optional Python modules).
– main.py + requirements.txt → Python FastAPI entrypoint and dependencies.
– Dockerfiles & docker-compose.yml → container build and service orchestration.
- Build scripts:
– build.gradle, settings.gradle, gradlew scripts → Java build.
– requirements.txt → Python dependencies.

##### Key insights from README
- Core features: AI interaction, meal management, user auth, data viz.
- Technology stack: JavaFX, SQLite, FastAPI, Docker.
- Two containers: a JavaFX client image & a Python API service.

##### Main components & relationships
a. JavaFX Client
– Layers:
- Presentation: FXML + controllers (DashboardController, Chat, etc.).
- Business logic: system.Session, ScreenManager, LocalAIClient.
- Persistence: dbsystem.DatabaseConnector + DAOs.
– Interaction:
- JDBC → SQLite (database_system.db).
- HTTP/REST → FastAPI microservice for AI inference.
b. Python FastAPI Service
– main.py defines API endpoints (e.g., /recommend, /chat).
– Loads AI model (via Ollama or local engine).
– Returns JSON responses to Java client.
c. Database
– SQLite file stored under src/main/database.
– Accessed directly by Java via JDBC.
d. AI Model
– Hosted in the Python container (or external Ollama process).
– Communicated over HTTP.
e. Containerization & Orchestration
– nextfit.dockerfile → builds JavaFX image.
– integration.dockerfile → builds Python API image.
– docker-compose.yml → brings up both services.

##### Architectural patterns & principles
- Desktop MVC: FXML views + JavaFX controllers → separation of concerns.
- Layered architecture: UI → service layer → data access layer → database.
- Microservice: Python FastAPI as separate service for AI logic.
- Containerization: isolates Java and Python runtimes, simplifies deployment.

##### Essential elements checklist
– Clear, distinct labels for each component.
- Desktop UI
- Business/Service layer
- Database
- AI microservice
- External AI engine
– Docker Compose boundary.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actor
    User(("User")):::user

    %% Docker Compose Boundary
    subgraph "Docker Compose" 
        direction TB

        %% JavaFX Client Container
        subgraph "JavaFX Client"
            direction TB
            FXML["FXML Layouts"]:::ui
            CSS["CSS Styles"]:::ui
            Controllers["Controllers"]:::bl
            Services["Service Layer\n(Session, ScreenManager,\nLocalAIClient)"]:::bl
            Persistence["Persistence Layer\n(DatabaseConnector,\nDAOs)"]:::pl
            DB["SQLite Database\n(database_system.db)"]:::db
            DF1["nextfit.dockerfile"]:::file
        end

        %% Python API Service Container
        subgraph "Python API Service"
            direction TB
            API["FastAPI Service\n(main.py + requirements.txt)"]:::api
            ExtModel["External AI Model\n(Ollama/local)"]:::ext
            DF2["integration.dockerfile"]:::file
        end

        %% Orchestration File
        DC["docker-compose.yml"]:::file
    end

    %% Connections
    User --> FXML
    User --> CSS
    FXML --> Controllers
    CSS --> Controllers
    Controllers --> Services
    Services --> Persistence
    Persistence --> DB
    Services -->|HTTP/REST| API
    API -->|HTTP/REST| ExtModel

    %% Click Events
    click FXML "https://github.com/zxlawdx/nextfit/tree/main/src/main/resources/system/layouts"
    click CSS "https://github.com/zxlawdx/nextfit/tree/main/src/main/resources/system/layouts/css"
    click Controllers "https://github.com/zxlawdx/nextfit/tree/main/src/main/java/system"
    click Services "https://github.com/zxlawdx/nextfit/tree/main/src/main/java/system"
    click Persistence "https://github.com/zxlawdx/nextfit/tree/main/src/main/java/dbsystem"
    click DB "https://github.com/zxlawdx/nextfit/blob/main/src/main/database/database_system.db"
    click API "https://github.com/zxlawdx/nextfit/blob/main/main.py"
    click DF1 "https://github.com/zxlawdx/nextfit/blob/main/nextfit.dockerfile"
    click DF2 "https://github.com/zxlawdx/nextfit/blob/main/integration.dockerfile"
    click DC "https://github.com/zxlawdx/nextfit/blob/main/docker-compose.yml"

    %% Styles
    classDef user fill:#f0f0f0,stroke:#333,stroke-width:1px
    classDef ui fill:#add8e6,stroke:#333,stroke-width:1px,rx:5,ry:5
    classDef bl fill:#87cefa,stroke:#333,stroke-width:1px,rx:5,ry:5
    classDef pl fill:#98fb98,stroke:#333,stroke-width:1px,rx:5,ry:5
    classDef db fill:#228B22,stroke:#333,stroke-width:1px
    classDef api fill:#ffa500,stroke:#333,stroke-width:1px,rx:5,ry:5
    classDef ext fill:#ffff99,stroke:#333,stroke-width:1px,rx:5,ry:5
    classDef file fill:#d3d3d3,stroke:#333,stroke-width:1px,rx:3,ry:3
```
