# charlesdedampierre/bunkatopics architecture

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

- Interactive diagram: https://gitdiagram.com/charlesdedampierre/bunkatopics
- Repository: https://github.com/charlesdedampierre/bunkatopics

## Overview

##### Project Type and Purpose
- This is a full-stack, multi-component data-science platform for topic modeling, data cleaning, visualization, and frame analysis.
- Core library (“bunkatopics”) provides embedding, projection, clustering, Bourdieu mapping and manual cleaning functions.
- An optional HTTP API (Flask + Celery) exposes the functionality as services (REST endpoints + background tasks).
- Two UIs:
- A React-based web front-end (in `/web`) for interactive topic exploration.
- A Streamlit app (`/streamlit/app.py`) as an alternative lightweight UI.
- Documentation is generated with MkDocs (`/docs`, `mkdocs.yml`).

##### File Structure Analysis
- Top level:
- `bunkatopics/` – core Python library (data model, cleaning, modeling, visualization).
- `api/` – Flask app (`bunka_api/app.py`), Celery config, deployment assets, notebooks, tests.
- `web/` – React single-page app (package.json, Dockerfile, nginx config).
- `streamlit/` – Streamlit entry point.
- `docs/` & `site/` – docs source and generated site.
- Root config: Dockerfiles (API & worker), Makefile, GitHub Actions workflows.
- Key patterns:
- MVC–style separation in the Flask service (`routes.py` → `jobs.py` → `processing_functions.py`).
- Asynchronous task processing via Celery.
- Containerized deployment with Docker + Nginx.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    subgraph "Clients"
        React["React SPA<br/>(web/)"]:::frontend
        Streamlit["Streamlit App<br/>(streamlit/app.py)"]:::frontend
        SDK["Python SDK & Notebooks"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        Nginx["Nginx Reverse Proxy<br/>(api/deployment/nginx-configuration-prod.conf)"]:::api
        Flask["Flask API Server<br/>(api/bunka_api/app.py)"]:::api
    end

    %% Task Queue
    subgraph "Task Queue"
        Broker["Message Broker<br/>(Redis/RabbitMQ)"]:::external
        Celery["Celery Worker(s)"]:::api
    end

    %% Core Library
    subgraph "Core Library<br/>(bunkatopics/)"
        DM1["datamodel.py"]:::core
        DM2["utils.py"]:::core
        DM3["logging.py"]:::core
        Clean["cleaning/outlier_detection.py"]:::core
        TM["topic_modeling/"]:::core
        Bour["bourdieu/"]:::core
        Viz["visualization/"]:::core
        Serve["serveur/server_utils.py"]:::core
    end

    %% External ML Services
    subgraph "External ML Services"
        HF["Hugging Face / OpenAI"]:::external
        STModel["SentenceTransformers"]:::external
        UMAP["UMAP / sklearn"]:::external
    end

    %% Documentation
    Mkdocs["MkDocs Site<br/>(docs/, mkdocs.yml)"]:::docs

    %% Interactions
    React -->|"HTTP Requests"| Nginx
    Nginx --> Flask
    Flask -->|"Submit Task"| Broker
    Broker --> Celery
    Celery -->|"Invokes Core Functions"| DM1
    Celery --> DM2
    Celery --> DM3
    Celery --> Clean
    Celery --> TM
    Celery --> Bour
    Celery --> Viz
    Celery --> Serve
    Flask -->|"Direct Import"| DM1
    SDK -->|"Direct Import"| DM1
    Streamlit -->|"Direct Import"| DM1
    Flask -->|"Calls LLM APIs"| HF
    Celery -->|"Embeddings & Summaries"| HF
    Celery -->|"Embeddings"| STModel
    Celery -->|"Projection/Clustering"| UMAP

    %% Click Events
    click React "https://github.com/charlesdedampierre/bunkatopics/tree/main/web/"
    click Streamlit "https://github.com/charlesdedampierre/bunkatopics/blob/main/streamlit/app.py"
    click DM1 "https://github.com/charlesdedampierre/bunkatopics/blob/main/bunkatopics/datamodel.py"
    click DM2 "https://github.com/charlesdedampierre/bunkatopics/blob/main/bunkatopics/utils.py"
    click DM3 "https://github.com/charlesdedampierre/bunkatopics/blob/main/bunkatopics/logging.py"
    click Clean "https://github.com/charlesdedampierre/bunkatopics/blob/main/bunkatopics/cleaning/outlier_detection.py"
    click TM "https://github.com/charlesdedampierre/bunkatopics/tree/main/bunkatopics/topic_modeling/"
    click Bour "https://github.com/charlesdedampierre/bunkatopics/tree/main/bunkatopics/bourdieu/"
    click Viz "https://github.com/charlesdedampierre/bunkatopics/tree/main/bunkatopics/visualization/"
    click Serve "https://github.com/charlesdedampierre/bunkatopics/blob/main/bunkatopics/serveur/server_utils.py"
    click Flask "https://github.com/charlesdedampierre/bunkatopics/blob/main/api/bunka_api/app.py"
    click Nginx "https://github.com/charlesdedampierre/bunkatopics/blob/main/api/deployment/nginx-configuration-prod.conf"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#21618C,color:#1B4F72
    classDef api fill:#D5F5E3,stroke:#27AE60,color:#196F3D
    classDef core fill:#E8DAEF,stroke:#8E44AD,color:#512E5F
    classDef external fill:#FDEBD0,stroke:#E67E22,color:#873600
    classDef docs fill:#FEF9E7,stroke:#F1C40F,color:#7D6608
```
