# sae0-3/healthtone architecture

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

- Interactive diagram: https://gitdiagram.com/sae0-3/healthtone
- Repository: https://github.com/sae0-3/healthtone

## Overview

##### Main Components
- Frontend: A React-based application (notice the use of components, hooks, routes, layouts, and API utility modules). It is built with Vite, uses Tailwind CSS, and communicates with the backend through REST endpoints.
- Backend: A Node.js service structured with versioned controllers (v0 and v1), corresponding models, configuration files (e.g., database, Firebase, passport for authentication), and clearly defined routes. It encapsulates the business logic that drives authentication, book management, progress tracking, and user-related functionalities.
- Database: The “db” folder with SQL initialization script(s) and a Docker Compose file indicates a relational database setup (possibly PostgreSQL) used to persist data.
- External Services: Firebase is integrated (as seen in both backend and frontend firebase configuration files) and may represent external authentication or real-time database functionality.

##### Relationships and Interactions
- The Backend receives these API calls through its defined routes, processes the request via the controllers and models, and accesses the Database for persistent storage.
- Authentication middleware (using Passport and Firebase as seen in the configuration) helps secure routes, so highlight that interaction between “Auth components” in the backend and the Firebase external service.
- Docker orchestration: Include containerization as an infrastructure layer. The Docker Compose file builds separate containers for the frontend, backend, and the database.

##### Architectural Patterns and Design Principles
- Versioning: The backend has versioned routes and controllers (v0 and v1), allowing evolutionary changes in the API.
- Separation of Concerns: Frontend, backend, and database components are clearly separated. Within the backend, responsibilities are divided between controllers (request handling/response), models (data access/logic), and routes (URL mapping).
- API Aggregation: Consider showing that the frontend accesses multiple REST endpoints (for authentication, books, progress, etc.) provided by the backend.
- External Service Integration: Firebase integration points should be clearly illustrated (e.g., user authentication, real-time push updates, or notifications).

##### Incorporate Relevant Technologies, Frameworks, and Tools
- Frontend Libraries: React, Vite, Tailwind CSS.
- Backend: Node.js with Express-like routing (given the controllers and middleware architecture), and Passport for authentication.
- Database: The SQL scripts and structure initializations indicate a relational database (such as PostgreSQL).
- Docker: Containerization for consistent development and deployment environments.
- Firebase: As an external service for configuration and probably authentication or data management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Docker Compose Containers
    subgraph "Docker Compose"
        %% Frontend Container
        subgraph "Frontend Container"
            F1["React Frontend"]:::frontend
            F2["Main JSX"]:::frontend
            F3["Vite Config"]:::frontend
            F4["Tailwind Config"]:::frontend
            subgraph "React Modules"
                F5["API Utils"]:::frontend
                F6["Pages"]:::frontend
                F7["Components"]:::frontend
                F8["Hooks"]:::frontend
            end
            F1 --> F2
            F1 --> F3
            F1 --> F4
            F1 --> F5
            F1 --> F6
            F1 --> F7
            F1 --> F8
        end

        %% Backend Container
        subgraph "Backend Container"
            B1["Node.js Backend"]:::backend
            B2["Main JS"]:::backend
            B3["Backend Config"]:::backend
            B4["Controllers"]:::backend
            B5["Models"]:::backend
            B6["Routes"]:::backend
            B1 --> B2
            B1 --> B3
            B1 --> B4
            B1 --> B5
            B1 --> B6
            B3 --> B7["Firebase Config (Backend)"]:::backend
        end

        %% Database Container
        subgraph "Database Container"
            D1["Relational Database (SQL)"]:::database
            D2["Compose File"]:::database
            D3["SQL Init"]:::database
            D1 --> D2
            D1 --> D3
        end
    end

    %% External Service
    E1["Firebase Service"]:::external
    E2["Firebase Config (Frontend)"]:::external

    %% Inter-component Interactions
    F1 -->|"API_calls"| B1
    B1 -->|"SQL_query"| D1
    B1 -->|"Auth"| E1
    F1 -->|"Firebase"| E1
    F1 -->|"FrontendFirebaseConfig"| E2

    %% Click Events for Frontend
    click F1 "https://github.com/sae0-3/healthtone/tree/main/frontend/"
    click F2 "https://github.com/sae0-3/healthtone/blob/main/frontend/src/main.jsx"
    click F3 "https://github.com/sae0-3/healthtone/blob/main/frontend/vite.config.js"
    click F4 "https://github.com/sae0-3/healthtone/blob/main/frontend/tailwind.config.js"
    click F5 "https://github.com/sae0-3/healthtone/tree/main/frontend/src/api"
    click F6 "https://github.com/sae0-3/healthtone/tree/main/frontend/src/pages"
    click F7 "https://github.com/sae0-3/healthtone/tree/main/frontend/src/components"
    click F8 "https://github.com/sae0-3/healthtone/tree/main/frontend/src/hooks"

    %% Click Events for Backend
    click B1 "https://github.com/sae0-3/healthtone/tree/main/backend/"
    click B2 "https://github.com/sae0-3/healthtone/blob/main/backend/src/main.js"
    click B3 "https://github.com/sae0-3/healthtone/tree/main/backend/src/config/"
    click B4 "https://github.com/sae0-3/healthtone/tree/main/backend/src/controllers/"
    click B5 "https://github.com/sae0-3/healthtone/tree/main/backend/src/models/"
    click B6 "https://github.com/sae0-3/healthtone/tree/main/backend/src/routes/"
    click B7 "https://github.com/sae0-3/healthtone/blob/main/backend/src/config/firebase-config.js"

    %% Click Events for Database
    click D1 "https://github.com/sae0-3/healthtone/tree/main/db/"
    click D2 "https://github.com/sae0-3/healthtone/blob/main/db/compose.yaml"
    click D3 "https://github.com/sae0-3/healthtone/blob/main/db/structure/init.sql"

    %% Click Event for Frontend Firebase Config
    click E2 "https://github.com/sae0-3/healthtone/blob/main/frontend/src/firebase/config.js"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef database fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
```
