# mathis-lambert/personal_website architecture

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

- Interactive diagram: https://gitdiagram.com/mathis-lambert/personal_website
- Repository: https://github.com/mathis-lambert/personal_website

## Overview

##### Project Type and Purpose
- This is a full‑stack personal website with an interactive LLM‑powered chat feature and RAG (Retrieval‑Augmented Generation) knowledge layer.
- Frontend: React + ViteJS + Redux + Chakra UI
- Backend: FastAPI (Python) exposing REST endpoints
- Database: MongoDB for storing content collections and RAG knowledge
- External Service: LLM API (e.g., OpenAI via `api_client`)

##### Main Architectural Components
a. Frontend Application
- Browser-based React SPA
- UI layer (Chakra UI components)
- State management (Redux + Context)
- API client module (calls backend REST endpoints)
b. Backend Application
- FastAPI server hosting multiple routes (chat, UI endpoints)
- Service layer (`api/services`) implementing core logic (e.g., `get_classes`)
- RAG module (`prompts` + retrieval against MongoDB)
- Database connector (`mongo_db_connector.py`)
- Utility modules (logging, file utils, startup checks)
c. Data Storage
- MongoDB instance (Docker container)
- Collections loaded from JSON files under `backend/datasets`
d. External LLM Service
- Hosted LLM endpoint (via `api_client` pointing at `api.mathislambert.fr`)
e. Deployment & Integration
- Docker Compose orchestrating three containers: Frontend, Backend, MongoDB
- Build scripts (`Dockerfile` in each folder) and `docker‐compose.yml`

##### Relationships and Data Flows
1. User interacts with Browser → React UI
2. React dispatches actions → Redux store → UI updates
3. Chat input triggers REST call → FastAPI `/chat` endpoint
4. FastAPI endpoint → Service layer invokes:
– MongoDB connector to fetch relevant docs (RAG retrieval)
– External LLM API (prompts+rtrv docs)
5. LLM generates response → Backend assembles and returns JSON → Frontend
6. Frontend displays chat response in UI

##### Architectural Patterns & Design Principles
- Layered architecture (Presentation → API → Services → Data)
- Separation of concerns: UI vs. business logic vs. persistence
- Modular code organization (routes, services, utils, prompts)
- Infrastructure as code via Docker Compose

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Docker Compose"
        direction TB
        subgraph "Frontend Service"
            direction TB
            Browser["Browser"]:::frontend
            Main["main.tsx"]:::frontend
            UI["Chakra UI Components"]:::frontend
            State["ChatContext"]:::frontend
            Hook["useChatCompletion Hook"]:::frontend
            Pages["Pages"]:::frontend

            Browser --> Main
            Main --> UI
            Main --> State
            Main --> Pages
            UI --> State
            State --> Hook
            Hook -->|"POST /chat"| API
        end

        subgraph "Backend Service"
            direction TB
            API["FastAPI Server"]:::backend
            EndpointsChat["chat.py Endpoints"]:::backend
            EndpointsUI["ui.py Endpoints"]:::backend
            Services["get_classes Service"]:::backend
            Prompts["Prompt Templates"]:::backend
            Connector["MongoDB Connector"]:::backend
            Utils["Utility Modules"]:::backend

            API --> EndpointsChat
            API --> EndpointsUI
            EndpointsChat --> Services
            EndpointsChat --> Connector
            EndpointsChat --> Prompts
            EndpointsUI --> Utils
            Services --> Connector
            Prompts --> Connector
        end

        subgraph "MongoDB Container"
            DB["MongoDB"]:::db
        end

        External["LLM API Service"]:::external

        Connector -->|"Retrieve Docs"| DB
        Prompts -->|"Augmented Prompt"| External
        External -->|"LLM Response"| API
        API -->|"JSON Response"| Hook

        DCfile["docker-compose.yml"]:::infra
        Ffile["frontend/Dockerfile"]:::infra
        Bfile["backend/Dockerfile"]:::infra
    end

    click UI "https://github.com/mathis-lambert/personal_website/tree/main/frontend/src/components/ui"
    click State "https://github.com/mathis-lambert/personal_website/blob/main/frontend/src/contexts/ChatContext.tsx"
    click Hook "https://github.com/mathis-lambert/personal_website/blob/main/frontend/src/hooks/useChatCompletion.ts"
    click Main "https://github.com/mathis-lambert/personal_website/blob/main/frontend/src/main.tsx"
    click Pages "https://github.com/mathis-lambert/personal_website/tree/main/frontend/src/pages"
    click API "https://github.com/mathis-lambert/personal_website/blob/main/backend/src/ml_backend/main.py"
    click EndpointsChat "https://github.com/mathis-lambert/personal_website/blob/main/backend/src/ml_backend/api/routes/chat.py"
    click EndpointsUI "https://github.com/mathis-lambert/personal_website/blob/main/backend/src/ml_backend/api/routes/ui.py"
    click Services "https://github.com/mathis-lambert/personal_website/blob/main/backend/src/ml_backend/api/services/get_classes.py"
    click Prompts "https://github.com/mathis-lambert/personal_website/tree/main/backend/src/ml_backend/prompts"
    click Connector "https://github.com/mathis-lambert/personal_website/blob/main/backend/src/ml_backend/databases/mongo_db_connector.py"
    click Utils "https://github.com/mathis-lambert/personal_website/blob/main/backend/src/ml_backend/utils/ensure_starting.py"
    click Utils "https://github.com/mathis-lambert/personal_website/blob/main/backend/src/ml_backend/utils/file_utils.py"
    click Utils "https://github.com/mathis-lambert/personal_website/blob/main/backend/src/ml_backend/utils/logger.py"
    click DB "https://github.com/mathis-lambert/personal_website/blob/main/backend/datasets/*.json"
    click DCfile "https://github.com/mathis-lambert/personal_website/blob/main/docker-compose.yml"
    click Ffile "https://github.com/mathis-lambert/personal_website/tree/main/frontend/Dockerfile"
    click Bfile "https://github.com/mathis-lambert/personal_website/tree/main/backend/Dockerfile"

    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef backend fill:#E6FFED,stroke:#22863A,color:#22863A
    classDef db fill:#FFF5E6,stroke:#E36209,color:#E36209
    classDef external fill:#F3E5FF,stroke:#6F42C1,color:#6F42C1
    classDef infra fill:#F0F0F0,stroke:#666666,color:#333333
```
