# betagouv/comparia architecture

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

- Interactive diagram: https://gitdiagram.com/betagouv/comparia
- Repository: https://github.com/betagouv/comparia

## Overview

##### Main Components

a. Frontend Layer:
- Custom Gradio Components (customchatbot, customradiocard, frinput)
- Templates (HTML/Svelte components)
- Static Assets (DSFR design system)

b. Backend Layer:
- FastAPI Application (main.py)
- Controller Layer (controller.py)
- Languia Core Module
- API Provider
- Block Arena
- Conversation Handler
- Theme Management

c. External Services:
- LLM API Services (multiple providers)
- Database (for storing conversations and reactions)

##### Component Relationships

**User Interface**
- ↓↑
**Frontend Components (Gradio)**
- ↓↑
**FastAPI Application**
- ↓↑
**Languia Core**
- ↓↑
**External LLM APIs**
- ↓↑
**Database Storage**

##### Specific Implementation Details

a. Frontend Components:
- Custom Chat Interface (customchatbot)
- Radio Card Selection (customradiocard)
- French Input Component (frinput)
- DSFR Design System Integration

b. Backend Services:
- FastAPI Routes
- Conversation Management
- Model Selection & Comparison
- Response Processing
- Analytics & Logging

c. Data Flow:
- User Question Input
- Parallel LLM API Calls
- Response Aggregation
- User Feedback Collection
- Analytics Storage

##### Additional Elements

- Authentication Flow
- Error Handling Paths
- Monitoring Points
- Scaling Components

##### The theme management system

Use standardized symbols:
- Rectangles for services
- Double lines for API boundaries

This system design should reflect the project's focus on comparing LLM responses while maintaining a user-friendly, government-standard compliant interface through the DSFR design system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        UI_CHAT["Custom Chat Interface"]
        UI_RADIO["Radio Card Selection"]
        UI_INPUT["French Input Component"]
    end

    subgraph FE["Frontend Components"]
        CHAT["Custom Chatbot"]:::frontend
        RADIO["Custom Radio Card"]:::frontend
        FINPUT["French Input"]:::frontend
        TEMPLATES["HTML Templates"]:::frontend
        DSFR["DSFR Design System"]:::frontend
        CSS["Custom CSS"]:::frontend
    end

    subgraph BE["Backend Layer"]
        MAIN["FastAPI Application"]:::backend
        CTRL["Controller Layer"]:::backend
    end

    subgraph CORE["Languia Core"]
        API_PROV["API Provider"]:::core
        ARENA["Block Arena"]:::core
        CONV["Conversation Handler"]:::core
        THEME["Theme Management"]:::core
        CONFIG["Configuration"]:::core
    end

    subgraph EXT["External Services"]
        LLM_API["LLM APIs"]:::external
        DB["Database"]:::storage
    end

    %% UI to Frontend
    UI_CHAT --> CHAT
    UI_RADIO --> RADIO
    UI_INPUT --> FINPUT

    %% Frontend to Backend
    CHAT & RADIO & FINPUT --> MAIN
    TEMPLATES --> MAIN
    DSFR --> TEMPLATES
    CSS --> TEMPLATES

    %% Backend to Core
    MAIN --> CTRL
    CTRL --> API_PROV
    CTRL --> ARENA
    CTRL --> CONV
    CTRL --> THEME

    %% Core to External
    API_PROV --> LLM_API
    CONV --> DB
    CONFIG --> API_PROV

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:#fff
    classDef backend fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef core fill:#e67e22,stroke:#d35400,color:#fff
    classDef external fill:#f1c40f,stroke:#f39c12,color:#fff
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:#fff

    %% Click Events
    click CHAT "https://github.com/betagouv/comparia/tree/develop/custom_components/customchatbot/"
    click RADIO "https://github.com/betagouv/comparia/tree/develop/custom_components/customradiocard/"
    click FINPUT "https://github.com/betagouv/comparia/tree/develop/custom_components/frinput/"
    click TEMPLATES "https://github.com/betagouv/comparia/tree/develop/templates/"
    click DSFR "https://github.com/betagouv/comparia/tree/develop/assets/dsfr/"
    click CSS "https://github.com/betagouv/comparia/blob/develop/assets/custom-arena.css"
    click MAIN "https://github.com/betagouv/comparia/blob/develop/main.py"
    click CTRL "https://github.com/betagouv/comparia/blob/develop/controller.py"
    click API_PROV "https://github.com/betagouv/comparia/blob/develop/languia/api_provider.py"
    click ARENA "https://github.com/betagouv/comparia/blob/develop/languia/block_arena.py"
    click CONV "https://github.com/betagouv/comparia/blob/develop/languia/conversation.py"
    click THEME "https://github.com/betagouv/comparia/tree/develop/languia/themes/"
    click CONFIG "https://github.com/betagouv/comparia/blob/develop/languia/config.py"
```
