# twilight2368/itss-web-exercise architecture

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

- Interactive diagram: https://gitdiagram.com/twilight2368/itss-web-exercise
- Repository: https://github.com/twilight2368/itss-web-exercise

## Overview

##### Project Type and Purpose
- The project is a full-stack web application, branded as “Smart Exercise Plan” (deployed via Render), with a clear division between a React+Vite frontend and an Express-based backend.
- The frontend manages user interfaces such as authentication (login, registration), dashboards, scheduling, nutrition, and other interactive components, while the backend handles REST API endpoints, user and schedule models, external API integrations (e.g., using Hugging Face APIs), and data mocking.
- Additional supporting directories like “data” (with Excel files) may be used for importing or processing data.

##### Main Components
a. Frontend:
- Built with React and Vite; note the use of several libraries – Material UI (@mui), React-Redux, i18next for internationalization, and more.
- Modular structure: Pages (auth, dashboard, nutrition, schedule, etc.), Layouts, Components (header, footer, sidebar, modals, breadcrumbs, notifications, etc.), and utility contexts for state management (e.g., LoginContext, Redux store).
- Internationalization asset connectors (i18next and locale JSON files may be found both in frontend and backend).

b. Backend:
- The Express server (in backend/index.js) acts as the API server with routes defined in app.routes.js and the application logic in app.js.
- Models (User.js and Schedule.js) following an MVC-like pattern.
- Integrations such as “robots” (i.e., external API interaction modules: huggingFaceApi.js and huggingFaceApi2.js) which interact with third-party services.
- “mock” folder which contains static JSON files for food and review data – possibly used for testing or demonstration.
- The backend integration with environment variables (via .env configuration) and dependency tools (JWT, bcrypt for security, Mongoose for database interaction) clearly indicate the server’s responsibilities.

c. Data Layer:
- Although not explicitly a database file in the tree, note the usage of Mongoose in the backend dependencies implies a MongoDB database connection.
- Optionally, include the “data” folder with Excel files as a component that might be used for batch data import or reporting.

d. External and Supporting Services:
- External API modules (i.e., interactions with Hugging Face) and any external services used by the frontend (possibly for API calls handled via Axios, with proxy settings in Vite).
- Reverse proxy setup if the server is hosted on port 3000 and the frontend uses Vite’s proxy configuration.

##### Relationships and Interactions
- Server handling business logic, data processing (auth, scheduling, etc.), and then interacting with the database (via Mongoose).
- Communication between the backend “robots” modules and external APIs (e.g., Hugging Face) to highlight integration points.
- How internationalization is handled with locale JSON files provided on both sides (frontend and backend) to support multiple languages.

##### Architectural Patterns and Technologies
- Frontend: Component-based architecture (React) with routing (react-router-dom), state management (React-Redux), and theming (MUI). Highlight the use of Vite for building the front-end bundle.
- Backend: Express-based REST API utilizing middleware for security (JWT, cookie-parser, bcrypt, CORS), dependency injection (dotenv for environment configuration), and logging (morgan). The structure reflects a separation of concerns (routes, models, controllers/services).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE1["React Frontend (React/Vite)"]:::frontend
        FE2["Pages (auth, dashboard, nutrition, schedule)"]:::frontend
        FE3["Components (header, footer, sidebar, modals, notifications)"]:::frontend
        FE4["LoginContext (Context)"]:::frontend
        FE4a["Redux Store"]:::frontend
        FE5A["Locales (i18n assets)"]:::frontend
        FE5B["i18n Config"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE1["Express Server (Express/Mongoose)"]:::backend
        BE2["API Routes"]:::backend
        BE3["Application Logic"]:::backend
        subgraph "Models"
            BE4a["User Model"]:::backend
            BE4b["Schedule Model"]:::backend
        end
        subgraph "External Integrations"
            BE5a["HuggingFace API 1"]:::backend
            BE5b["HuggingFace API 2"]:::backend
        end
        BE6["Mock Data"]:::backend
        BE7["Backend i18n Assets"]:::backend
    end

    %% Data Layer & External Services
    subgraph "Data Layer & External Services"
        DB["MongoDB Database"]:::database
        DI["Data Import (Excel Files)"]:::database
        EX["Hugging Face External Service"]:::external
    end

    %% Connections between Frontend and Backend
    FE1 -->|"API-call"| BE1
    BE1 -->|"routes to"| BE2
    BE2 -->|"processes"| BE3
    FE1 -->|"loads"| FE5A
    BE1 -->|"loads"| BE7

    %% Backend Business Logic Connections
    BE3 -->|"uses"| BE4a
    BE3 -->|"uses"| BE4b
    BE3 -->|"fetches"| BE6
    BE3 -->|"queries"| DB
    BE3 -->|"imports data"| DI
    BE3 -->|"calls"| BE5a
    BE3 -->|"calls"| BE5b

    %% External Integrations Connection
    BE5a -->|"integration"| EX
    BE5b -->|"integration"| EX

    %% Styling Classes
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef database fill:#FFC107,stroke:#333,stroke-width:2px;
    classDef external fill:#FFE082,stroke:#333,stroke-width:2px;

    %% Click Events for Frontend
    click FE1 "https://github.com/twilight2368/itss-web-exercise/tree/main/frontend/"
    click FE2 "https://github.com/twilight2368/itss-web-exercise/tree/main/frontend/src/pages/"
    click FE3 "https://github.com/twilight2368/itss-web-exercise/tree/main/frontend/src/components/"
    click FE4 "https://github.com/twilight2368/itss-web-exercise/tree/main/frontend/src/context/"
    click FE4a "https://github.com/twilight2368/itss-web-exercise/tree/main/frontend/src/store/"
    click FE5A "https://github.com/twilight2368/itss-web-exercise/tree/main/frontend/public/locales/"
    click FE5B "https://github.com/twilight2368/itss-web-exercise/blob/main/frontend/src/i18.js"

    %% Click Events for Backend
    click BE1 "https://github.com/twilight2368/itss-web-exercise/blob/main/backend/index.js"
    click BE2 "https://github.com/twilight2368/itss-web-exercise/blob/main/backend/src/app.routes.js"
    click BE3 "https://github.com/twilight2368/itss-web-exercise/blob/main/backend/src/app.js"
    click BE4a "https://github.com/twilight2368/itss-web-exercise/blob/main/backend/src/models/User.js"
    click BE4b "https://github.com/twilight2368/itss-web-exercise/blob/main/backend/src/models/Schedule.js"
    click BE5a "https://github.com/twilight2368/itss-web-exercise/blob/main/backend/src/robots/huggingFaceApi.js"
    click BE5b "https://github.com/twilight2368/itss-web-exercise/blob/main/backend/src/robots/huggingFaceApi2.js"
    click BE6 "https://github.com/twilight2368/itss-web-exercise/tree/main/backend/src/mock/"
    click BE7 "https://github.com/twilight2368/itss-web-exercise/tree/main/backend/src/dist/locales/"

    %% Click Event for Data Import
    click DI "https://github.com/twilight2368/itss-web-exercise/tree/main/data/"
```
