# czerny40/fitness-web-app architecture

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

- Interactive diagram: https://gitdiagram.com/czerny40/fitness-web-app
- Repository: https://github.com/czerny40/fitness-web-app

## Overview

##### Project Type and Purpose
- This is a full-stack web application aimed at providing a comprehensive health and fitness management platform. It includes user management, Q&A, workout routines, partner matching, diet recommendation, real-time chat, and several other features.
- The README makes it clear that the project integrates a Spring Boot main backend with additional Python-based FastAPI and Flask servers for specialized functionality (partner matching and diet recommendation, respectively).

##### Analyzing the File Structure
- The top-level directories and files (e.g., src/main/java, src/main/resources) show that the project follows a standard Spring Boot (Java) structure.
- Inside the Java package (com.mysite.sbb), there are several domain-specific packages such as answer, chat, food, question, user, workout_tab, and custom modules like FitnessSearch and UserMatching. This indicates an MVC pattern usage with controllers, services, repositories, and domain models.
- The presence of configuration files (SecurityConfig, WebSocketConfig) and the Gradle build files reinforces the use of Spring Boot and its modular nature.
- The additional folders for static resources (CSS, JS, images, fonts) and templates (Thymeleaf HTML files) indicate a rich client-side layer integrated with server-side rendering.

##### Key Components in the System
a. Client (Web):
- Web UI built with HTML/CSS/JavaScript and Thymeleaf templates, providing pages for login, signup, Q&A, workout routines, diet recommendations, and live chat.
b. Main Backend – Spring Boot Server:
- Handles core business logic, user authentication (including OAuth2), and serves as the REST API for the client.
- Contains separate modules for handling answers, questions, messaging, chat (WebSocket), workout management, and more.
- Uses Spring Data JPA for persistence with a MySQL database.
c. External/Additional Servers:
- FastAPI Server: Dedicated to the exercise partner matching functionality.
- Flask Server: Manages customized diet recommendations integrating with an external nutrition database.
d. Database:
- MySQL is used by the main Spring Boot application and likely by the additional servers as well.
e. Security and Communication:
- Spring Security with OAuth2.0 for authentication.
- WebSocket configured via STOMP for real-time chat.
- Data encryption (AES) is handled in messaging, and BCrypt is used for password encoding.

##### Relationships and Interactions
- The client communicates with the Spring Boot backend using HTTP/REST for standard page rendering, CRUD operations, and API calls.
- The Spring Boot server interacts with:
– A MySQL database (persistence layer) to store various data (users, Q&A posts, workout routines, etc.).
– FastAPI server via HTTP/REST for partner matching requests.
– Flask server via HTTP/REST to get dietary recommendations.
- WebSocket connections are used to establish real-time chat sessions between clients and the server.
- Security components (filters and OAuth2 integrations) interact with the main backend to ensure secure access.

##### Architectural Patterns and Technologies Highlight
- MVC (Model-View-Controller) is adopted in many modules (e.g., question, answer, user modules).
- Microservices/Distributed integration pattern where the main Spring Boot server acts as an orchestrator that communicates with specialized Python-based services.
- Use of RESTful API design between components.
- Security is enforced using Spring Security and OAuth2.
- Real-time functionality provided by WebSocket with STOMP.

##### Final Detailed Steps for the Principal Software Engineer
- Branch out from the Spring Boot backend to the separate FastAPI and Flask servers to indicate inter-service communication.
– How the client makes REST calls and WebSocket connections,
– How the backend communicates with both the database and external services.
- Connections (e.g., API calls to FastAPI/Flask, security modules, and data encryption utilities) are annotated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Client (Web UI)"]:::frontend
        FE1["Templates"]:::frontend
        FE2["Static Assets"]:::frontend
    end

    %% Backend Layer
    subgraph "Spring Boot Backend"
        BE1["Application Entry Point"]:::backend
        BE2["Security Configuration"]:::backend
        BE3["WebSocket Configuration"]:::backend
        BE4["Questions Module"]:::backend
        BE5["Answers Module"]:::backend
        BE6["Chat Module"]:::backend
        BE7["User Management Module"]:::backend
        BE8["Workout Routine Module"]:::backend
        BE9["Food Recommendation Integration"]:::backend
        BE10["Fitness Search Module"]:::backend
        BE11["User Matching Module"]:::backend
        BE12["REST Client Utility"]:::backend
        BE13["Encryption Utility"]:::backend
    end

    %% External Services
    subgraph "External Services"
        EX1["FastAPI - Partner Matching"]:::external
        EX2["Flask - Diet Recommendation"]:::external
    end

    %% Database Layer
    DB["MySQL Database"]:::database

    %% Connections
    FE -->|"HTTP/REST"| BE1
    FE -->|"WebSocket"| BE6
    BE1 -->|"JPA Persistence"| DB
    BE1 -->|"REST_call"| EX1
    BE1 -->|"REST_call"| EX2
    BE1 -->|"Calls"| BE12
    BE1 -->|"Uses"| BE13

    %% Click Events - Frontend
    click FE1 "https://github.com/czerny40/fitness-web-app/tree/master/src/main/resources/templates"
    click FE2 "https://github.com/czerny40/fitness-web-app/tree/master/src/main/resources/static"

    %% Click Events - Backend
    click BE1 "https://github.com/czerny40/fitness-web-app/blob/master/src/main/java/com/mysite/sbb/SbbApplication.java"
    click BE2 "https://github.com/czerny40/fitness-web-app/blob/master/src/main/java/com/mysite/sbb/SecurityConfig.java"
    click BE3 "https://github.com/czerny40/fitness-web-app/blob/master/src/main/java/com/mysite/sbb/chat/WebSocketConfig.java"
    click BE4 "https://github.com/czerny40/fitness-web-app/tree/master/src/main/java/com/mysite/sbb/question"
    click BE5 "https://github.com/czerny40/fitness-web-app/tree/master/src/main/java/com/mysite/sbb/answer"
    click BE6 "https://github.com/czerny40/fitness-web-app/tree/master/src/main/java/com/mysite/sbb/chat"
    click BE7 "https://github.com/czerny40/fitness-web-app/tree/master/src/main/java/com/mysite/sbb/user"
    click BE8 "https://github.com/czerny40/fitness-web-app/tree/master/src/main/java/com/mysite/sbb/workout_tab"
    click BE9 "https://github.com/czerny40/fitness-web-app/tree/master/src/main/java/com/mysite/sbb/food"
    click BE10 "https://github.com/czerny40/fitness-web-app/tree/master/src/main/java/com/mysite/sbb/FitnessSearch"
    click BE11 "https://github.com/czerny40/fitness-web-app/tree/master/src/main/java/com/mysite/sbb/UserMatching"
    click BE12 "https://github.com/czerny40/fitness-web-app/blob/master/src/main/java/com/mysite/sbb/service/RestClientService.java"
    click BE13 "https://github.com/czerny40/fitness-web-app/blob/master/src/main/java/com/mysite/sbb/util/EncryptionUtil.java"

    %% Click Event - Database
    click DB "https://github.com/czerny40/fitness-web-app/blob/master/src/main/resources/application.properties"

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