# gabrielchasukjin/conceptbottleneck-gui-experiment architecture

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

- Interactive diagram: https://gitdiagram.com/gabrielchasukjin/conceptbottleneck-gui-experiment
- Repository: https://github.com/gabrielchasukjin/conceptbottleneck-gui-experiment

## Overview

##### Main Components

A. Frontend Layer:
- React Application (src/App.js, src/index.js)
- User Interface Components
- Visualization Components (for concept activations)

B. Backend Layer:
- Flask Server (src/app.py)
- Model Training Components
- Concept Processing Pipeline

C. Machine Learning Components:
- CBL (Concept Bottleneck Layer) Module
- RoBERTa Model Integration
- Training Pipeline Components

D. Data Layer:
- Dataset Management (SetFit SST2)
- Model Weights Storage
- Configuration Storage

##### Component Relationships

**[Frontend Layer]**
- ↕ HTTP/API
**[Backend Layer]**
- ↕ Internal Communication
**[ML Components]**
- ↕ Data Flow
**[Data Layer]**

##### Specific Implementation Details

- Rectangles: Main components (Frontend, Backend, ML Pipeline)
- Hexagons: Processing units

- Blue: Frontend components
- Green: Backend services
- Purple: ML components
- Yellow: Data storage
- Red: Critical system paths

##### Component Breakdown

Frontend (Blue):
**[React App]**
- ↓
**[Component Layer]**
- Model Configuration UI
- Training Interface
- Visualization Dashboard
- Results Display

Backend (Green):
**[Flask Server]**
- ↓
**[API Endpoints]**
- ↓
**[Service Layer]**
- Training Orchestrator
- Concept Processor
- Model Manager

ML Pipeline (Purple):
**[CBL Training Module]**
- ↓
**[RoBERTa Integration]**
- ↓
**[Concept Extraction]**
- ↓
**[Model Evaluation]**

Data Layer (Yellow):
**[Configuration Store]**
**[Model Weights]**
**[Training Data]**
**[Results Cache]**

##### Key Flows to Highlight

A. Training Flow:
**User Input → Frontend → Backend → ML Pipeline → Data Storage → Results → Frontend**

B. Inference Flow:
**Text Input → Frontend → Backend → Model → Concept Analysis → Visualization → Frontend**

##### Additional Elements

- Version information for key components
- External service integrations (DSMPL UCSD server option)
- Scaling points and potential bottlenecks
- Security boundaries and data validation points

##### Implementation Notes

- Maintain consistent spacing and alignment
- Clear labels for all components
- Brief descriptions for complex interactions
- Both synchronous and asynchronous communication paths

This system design should effectively communicate the architecture while highlighting the unique aspects of the Concept Bottleneck Layer integration and the GUI's role in making it accessible to users.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef ml fill:#9b59b6,stroke:#8e44ad,color:white
    classDef data fill:#f1c40f,stroke:#f39c12,color:black
    classDef critical fill:#e74c3c,stroke:#c0392b,color:white

    %% Frontend Layer
    subgraph Frontend
        ReactApp["React Application"]
        CompLayer["Component Layer"]
        ModelConfigUI["Model Configuration UI"]
        TrainingUI["Training Interface"]
        VisDash["Visualization Dashboard"]
        ResultsDisplay["Results Display"]
    end
    
    %% Backend Layer
    subgraph Backend
        FlaskServer["Flask Server"]
        APIEndpoints["API Endpoints"]
        ServiceLayer["Service Layer"]
        TrainingOrch["Training Orchestrator"]
        ConceptProc["Concept Processor"]
        ModelMgr["Model Manager"]
    end
    
    %% ML Pipeline
    subgraph MLPipeline
        CBLModule["CBL Training Module"]
        RoBERTaInt["RoBERTa Integration"]
        ConceptExt["Concept Extraction"]
        ModelEval["Model Evaluation"]
        FeatureLearning["Feature Learning"]
        ModelDef["Model Definition"]
    end
    
    %% Data Layer
    subgraph DataLayer
        ConfigStore[("Configuration Store")]
        ModelWeights[("Model Weights")]
        TrainingData[("Training Data")]
        ResultsCache[("Results Cache")]
    end
    
    %% Relationships
    ReactApp --> CompLayer
    CompLayer --> ModelConfigUI & TrainingUI & VisDash & ResultsDisplay
    
    ModelConfigUI & TrainingUI & VisDash & ResultsDisplay --> FlaskServer
    
    FlaskServer --> APIEndpoints
    APIEndpoints --> ServiceLayer
    ServiceLayer --> TrainingOrch & ConceptProc & ModelMgr
    
    TrainingOrch --> CBLModule
    ConceptProc --> ConceptExt
    ModelMgr --> ModelDef
    
    CBLModule --> RoBERTaInt
    RoBERTaInt --> ConceptExt
    ConceptExt --> ModelEval
    ModelEval --> ResultsCache
    
    ModelDef --> ModelWeights
    FeatureLearning --> ModelWeights
    
    ConfigStore --> ServiceLayer
    TrainingData --> CBLModule
    ModelWeights --> ModelEval
    ResultsCache --> ResultsDisplay

    %% Click Events
    click ReactApp "https://github.com/gabrielchasukjin/ConceptBottleneck-GUI-Experiment/blob/main/src/App.js"
    click FlaskServer "https://github.com/gabrielchasukjin/ConceptBottleneck-GUI-Experiment/blob/main/src/app.py"
    click ConceptProc "https://github.com/gabrielchasukjin/ConceptBottleneck-GUI-Experiment/blob/main/src/concepts.py"
    click CBLModule "https://github.com/gabrielchasukjin/ConceptBottleneck-GUI-Experiment/blob/main/src/train_CBL.py"
    click FeatureLearning "https://github.com/gabrielchasukjin/ConceptBottleneck-GUI-Experiment/blob/main/src/train_FL.py"
    click ModelDef "https://github.com/gabrielchasukjin/ConceptBottleneck-GUI-Experiment/blob/main/src/model.py"
    click ModelEval "https://github.com/gabrielchasukjin/ConceptBottleneck-GUI-Experiment/blob/main/src/test_model.py"
    click ConfigStore "https://github.com/gabrielchasukjin/ConceptBottleneck-GUI-Experiment/blob/main/config/config.json"
    click TrainingData "https://github.com/gabrielchasukjin/ConceptBottleneck-GUI-Experiment/tree/main/data/MNIST/"
    click VisDash "https://github.com/gabrielchasukjin/ConceptBottleneck-GUI-Experiment/blob/main/src/visualization.py"
    
    %% Legend
    subgraph Legend
        Frontend_L["Frontend Component"]:::frontend
        Backend_L["Backend Component"]:::backend
        ML_L["ML Component"]:::ml
        Data_L["Data Storage"]:::data
        Critical_L["Critical Path"]:::critical
    end

    %% Apply styles
    class ReactApp,CompLayer,ModelConfigUI,TrainingUI,VisDash,ResultsDisplay frontend
    class FlaskServer,APIEndpoints,ServiceLayer,TrainingOrch,ConceptProc,ModelMgr backend
    class CBLModule,RoBERTaInt,ConceptExt,ModelEval,FeatureLearning,ModelDef ml
    class ConfigStore,ModelWeights,TrainingData,ResultsCache data
    class TrainingOrch,ConceptProc critical
```
