# vishnuvardhanbr/serenity-harbor architecture

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

- Interactive diagram: https://gitdiagram.com/vishnuvardhanbr/serenity-harbor
- Repository: https://github.com/vishnuvardhanbr/serenity-harbor

## Overview

##### Main Components
- Frontend:
- This is the client-facing React application (located in the “frontend” folder) that manages user interaction and presentation.
- Key elements include React components (e.g., HomePage, LoginPage, ChatPage, AdminPage) and static assets (images, CSS, etc.).
- It communicates with the backend API, and has its own configuration (e.g., staticwebapp.config.json, tailwind.config.js).

- Backend:
- Contained in the “backend” directory, this is a Python-based server (likely a Flask or similar lightweight framework judging by the app.py file).
- It handles API requests, configurations (from backend/config), database operations (using dbutils.py and the MONGODB_URI from the .env file), and interactions with external APIs like OpenAI (see openaiapi.py).
- A Dockerfile is provided for containerization, indicating deployment via Docker.

- External Services & Environment:
- OpenAI API: Configured via an API key in the .env file, it provides AI functionalities as indicated by the presence of openaiapi.py.
- Database: MongoDB, given the “MONGODB_URI” parameter provided in the .env file.
- Authentication/Authorization: Use of JWT (JWT_SECRET_KEY in .env) for secure communications.
- Additionally, there may be some speech processing capabilities (referenced by the “backend/speech” folder) though details are minimal.

- Model Finetuning:
- Found under “model_finetuning”, this area contains Jupyter notebooks and JSONL data files used for finetuning machine learning models.
- Although not part of the live serving architecture, it’s an essential component in the iterative development of the backend’s AI functionalities.

##### Relationships and Interactions
- The Frontend sends HTTP requests (via REST APIs) to the Backend. The .env file in the frontend indicates that the backend is hosted at http://127.0.0.1:8080.
- The Backend processes these requests, potentially interacting with the database (MongoDB) for persistence.
- For AI-related operations, the Backend calls the OpenAI API, possibly taking advantage of the finetuned models (managed in model_finetuning).
- CI/CD pipelines and automation via GitHub workflows (as seen in the .github/workflows directory) can be noted as part of the development and deployment lifecycle.

##### Architectural Patterns & Design Principles
- Separation of concerns: Clear division between frontend and backend functionalities.
- RESTful API interactions: The frontend consumes data and services via defined endpoints from the backend.
- Containerization: The backend is set up for Docker-based deployment.
- Environment-based configuration: Use of .env files in both the frontend and backend to manage secrets and operational parameters.
- Model Training Pipeline: A separate module (model_finetuning) to experiment and finetune models independently of the core API service.

##### Final Touches

This level of detail will provide a comprehensive architectural view that accurately represents Serenity Harbor’s structure, making it easy for stakeholders and new team members to understand the system’s components and their interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Block
    subgraph "Frontend"
        FE1["React Application (frontend)"]:::frontend
        FE2["Static Assets (Images, CSS)"]:::frontend
        FE3["Configuration (staticwebapp.config.json, tailwind.config.js)"]:::frontend
    end

    %% Backend Block
    subgraph "Backend"
        BE1["API Server (app.py)"]:::backend
        BE2["Configuration (backend/config)"]:::backend
        BE3["Database Utilities (dbutils.py)"]:::backend
        BE4["OpenAI API Integration (openaiapi.py)"]:::backend
        BE5["Speech Processing Module (backend/speech)"]:::backend
    end

    %% External Services Block
    subgraph "External Services"
        EX1["MongoDB Database"]:::external
        EX2["OpenAI API"]:::external
    end

    %% Model Finetuning Block
    subgraph "Model Finetuning"
        MF1["Finetuning Notebooks & Data"]:::finetuning
    end

    %% Deployment / CI-CD Block
    subgraph "Deployment / CI-CD"
        DP1["Docker Containerization (Dockerfile)"]:::deployment
        DP2["CI/CD Pipelines (.github/workflows)"]:::deployment
    end

    %% Connections
    FE1 -->|"calls_API"| BE1
    BE1 -->|"uses"| BE3
    BE3 -->|"queries"| EX1
    BE1 -->|"calls"| BE4
    BE4 -->|"communicates"| EX2
    BE1 -->|"utilizes"| BE5
    MF1 -->|"integrates_model"| BE1
    DP1 -->|"containerizes"| BE1
    DP2 -->|"triggers_deployment"| BE1

    %% Click Events
    click FE1 "https://github.com/vishnuvardhanbr/serenity-harbor/tree/main/frontend/"
    click BE1 "https://github.com/vishnuvardhanbr/serenity-harbor/blob/main/backend/app.py"
    click BE4 "https://github.com/vishnuvardhanbr/serenity-harbor/blob/main/backend/openaiapi.py"
    click BE5 "https://github.com/vishnuvardhanbr/serenity-harbor/tree/main/backend/speech/"
    click DP1 "https://github.com/vishnuvardhanbr/serenity-harbor/tree/main/backend/Dockerfile"
    click MF1 "https://github.com/vishnuvardhanbr/serenity-harbor/tree/main/model_finetuning/"
    click DP2 "https://github.com/vishnuvardhanbr/serenity-harbor/tree/main/.github/workflows/"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1D6FA3,stroke-width:2px;
    classDef backend fill:#D5F5E3,stroke:#229954,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#D4AC0D,stroke-width:2px;
    classDef finetuning fill:#E8DAEF,stroke:#AF7AC5,stroke-width:2px;
    classDef deployment fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;
```
