# it-at-m/mucgpt architecture

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

- Interactive diagram: https://gitdiagram.com/it-at-m/mucgpt
- Repository: https://github.com/it-at-m/mucgpt

## Overview

##### Project type and purpose
- MUCGPT is a full-stack, web-based interface for large language models (LLMs).
- The frontend is built in React/TypeScript; the backend is a FastAPI (Python) service integrating LangChain to call OpenAI-compatible endpoints.
- The system supports chatting, summarizing, brainstorming (mind-maps), simplified language translation, and custom “GPT” generation.

##### File structure
- Top-level “app/frontend” houses the React UI, static assets, API client code, pages and reusable components.
- “app/backend” contains FastAPI entrypoints (app.py, init_app.py), business modules (chat, summarize, brainstorm, simply, create_bot), core helpers, type definitions, configuration and logging.
- “config/.env.empty” hints at environment-driven settings (LLM endpoints, database URL).
- Dockerfile, uv workflows and CI configs signal containerized deployment using Uvicorn, Docker, GitHub Actions.
- Tests/ folder holds unit/integration tests for backend logic.

##### Extract insights from the README
- Deployed on Azure App Service with a PostgreSQL database and an Azure OpenAI resource (or any OpenAI-compatible endpoint).
- Frontend communicates via REST (FastAPI) to backend.
- Backend uses LangChain for LLM orchestration.
- Local browser storage (IndexedDB) is used for chat history and custom GPT persistence.

##### Main components & interactions
a. User’s Browser / Client:
- Renders React app (HTML/CSS/JS).
- Reads/writes chat history & custom bots to IndexedDB.
- Calls backend REST endpoints (/chat, /summarize, /brainstorm, /simply, /create_bot).
b. Frontend App:
- Hosts pages & components, API client (api.ts), state/context providers (LLMSelector, LanguageSelector).
- Static assets (images, CSS modules).
c. Backend Service (FastAPI + Uvicorn):
- API layer (app.py, backend.py) defines endpoints.
- Business modules handle each feature (chat/chat.py, summarize/summarize.py, brainstorm/brainstorm.py, simply/simply.py, create_bot/…).
- Core helpers manage authentication, config loading, data persistence, model/LLM calls, text splitting, logging.
d. LLM Endpoint(s):
- Azure OpenAI or any OpenAI-compatible API URL configured via .env.
- LangChain orchestrates prompt templates, streaming, vector stores (if used).
e. Persistent Storage:
- PostgreSQL (for user-defined bots, usage statistics, if implemented).
- (Local) IndexedDB in browser for chat history and custom GPT definitions.
f. Container & Deployment:
- Docker container runs Uvicorn server exposing port 8000.
- CI/CD via GitHub/GitLab workflows, uv, Docker Hub or Azure Container Registry.

##### Architectural patterns & principles
- Client-Server separation (React UI vs. REST API).
- Modular backend: one module per feature (SRP).
- Environment-driven config (12-factor principles).
- Dependency injection via FastAPI’s startup events (init_app.py).
- Typed Python (pydantic models in core/types) for request/response validation.
- CI/CD and containerization for reproducibility.

##### Detail is key—capture
- Each feature path (chat, summarize, brainstorm, simply, create_bot) as its own module in the backend layer.
- Core helpers (auth, config, llmhelper, datahelper, textsplit) as a shared service block.
- Persistence layers separated by scope (browser vs. server).
- Deployment environment—Docker container on Azure, managed via uv and GitHub Actions—so ops can see end-to-end flow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Browser (Frontend)"
        direction TB
        ReactApp["React App"]:::frontend
        subgraph "API Client" 
            direction TB
            APIClient_TS["api.ts"]:::apiClient
            APIClient_IDX["index.ts"]:::apiClient
            APIClient_MOD["models.ts"]:::apiClient
        end
        subgraph "Context Providers"
            direction TB
            LLMContext["LLMContextProvider"]:::provider
            LLMSelector["LLMSelector"]:::provider
            LanguageContext["LanguageContextProvider"]:::provider
            LanguageSelector["LanguageSelector"]:::provider
        end
        subgraph "Pages"
            direction TB
            ChatPage["Chat Page"]:::page
            BrainstormPage["Brainstorm Page"]:::page
            SummarizePage["Summarize Page"]:::page
            SimplyPage["Simplified Language Page"]:::page
            BotPage["Create Bot Page"]:::page
        end
        IndexedDB["IndexedDB / LocalStorage"]:::storage
    end

    %% Backend Layer
    subgraph "Backend Service (FastAPI)" 
        direction TB
        APILayer["FastAPI Entrypoints"]:::backend
        subgraph "Feature Modules"
            direction TB
            ChatModule["Chat Module"]:::backend
            SummarizeModule["Summarize Module"]:::backend
            BrainstormModule["Brainstorm Module"]:::backend
            SimplyModule["Simplified Language Module"]:::backend
            CreateBotModule["Create Bot Module"]:::backend
        end
        CoreHelpers["Core Helpers"]:::backend
        Types["Pydantic Types"]:::backend
    end

    %% External Services and Infrastructure
    LLM["LLM Endpoint (Azure/OpenAI)"]:::external
    Postgres["PostgreSQL DB"]:::database
    Container["Docker Container / Azure App Service"]:::deployment
    CI["CI/CD (GitHub Actions)"]:::ops
    Tests["Backend Tests"]:::ops

    %% Connections
    ReactApp -->|renders UI| APIClient_TS
    ReactApp --> IndexedDB
    APIClient_TS --> APILayer
    APIClient_IDX --> APILayer
    APIClient_MOD --> APILayer

    APILayer --> ChatModule
    APILayer --> SummarizeModule
    APILayer --> BrainstormModule
    APILayer --> SimplyModule
    APILayer --> CreateBotModule

    ChatModule --> CoreHelpers
    SummarizeModule --> CoreHelpers
    BrainstormModule --> CoreHelpers
    SimplyModule --> CoreHelpers
    CreateBotModule --> CoreHelpers

    CoreHelpers --> LLM
    ChatModule --> Postgres
    CreateBotModule --> Postgres

    Container --> APILayer
    CI --> Container
    Tests --> APILayer

    %% Click Events
    click ReactApp "https://github.com/it-at-m/mucgpt/tree/main/app/frontend"
    click APIClient_TS "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/api/api.ts"
    click APIClient_IDX "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/api/index.ts"
    click APIClient_MOD "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/api/models.ts"
    click LLMContext "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/components/LLMSelector/LLMContextProvider.tsx"
    click LLMSelector "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/components/LLMSelector/LLMSelector.tsx"
    click LanguageContext "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/components/LanguageSelector/LanguageContextProvider.tsx"
    click LanguageSelector "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/components/LanguageSelector/LanguageSelector.tsx"
    click ChatPage "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/pages/chat/Chat.tsx"
    click BrainstormPage "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/pages/brainstorm/Brainstorm.tsx"
    click SummarizePage "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/pages/summarize/Summarize.tsx"
    click SimplyPage "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/pages/simplyfied-language/Simply.tsx"
    click BotPage "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/pages/bot/Bot.tsx"
    click IndexedDB "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/service/indexedDBStorage.ts"
    click IndexedDB "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/service/botstorage.ts"
    click IndexedDB "https://github.com/it-at-m/mucgpt/blob/main/app/frontend/src/service/storage.ts"
    click APILayer "https://github.com/it-at-m/mucgpt/blob/main/app/backend/app.py"
    click ChatModule "https://github.com/it-at-m/mucgpt/blob/main/app/backend/chat/chat.py"
    click SummarizeModule "https://github.com/it-at-m/mucgpt/blob/main/app/backend/summarize/summarize.py"
    click BrainstormModule "https://github.com/it-at-m/mucgpt/blob/main/app/backend/brainstorm/brainstorm.py"
    click SimplyModule "https://github.com/it-at-m/mucgpt/blob/main/app/backend/simply/simply.py"
    click CreateBotModule "https://github.com/it-at-m/mucgpt/blob/main/app/backend/create_bot/prompt_for_title.md"
    click CoreHelpers "https://github.com/it-at-m/mucgpt/tree/main/app/backend/core"
    click Types "https://github.com/it-at-m/mucgpt/tree/main/app/backend/core/types"
    click Container "https://github.com/it-at-m/mucgpt/tree/main/Dockerfile"
    click CI "https://github.com/it-at-m/mucgpt/blob/main/.github/workflows/python-test.yaml"
    click Tests "https://github.com/it-at-m/mucgpt/blob/main/tests/integration/test_backend.py"

    %% Styles
    classDef frontend fill:#E8F4FC,stroke:#0366D6,color:#0366D6;
    classDef apiClient fill:#F0FFF4,stroke:#22863A,color:#22863A;
    classDef provider fill:#FFF5E5,stroke:#D15704,color:#D15704;
    classDef page fill:#F5F5F5,stroke:#6A737D,color:#6A737D;
    classDef storage fill:#FFF0F6,stroke:#D73A49,color:#D73A49;
    classDef backend fill:#EFF8FF,stroke:#1F6FEB,color:#1F6FEB;
    classDef external fill:#F0F5FF,stroke:#0A3069,color:#0A3069;
    classDef database fill:#FFF5B1,stroke:#735C0F,color:#735C0F;
    classDef deployment fill:#E6FFFA,stroke:#057D74,color:#057D74;
    classDef ops fill:#F6FFED,stroke:#238636,color:#238636;
```
