# chaos-genius/chaos_genius architecture

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

- Interactive diagram: https://gitdiagram.com/chaos-genius/chaos_genius
- Repository: https://github.com/chaos-genius/chaos_genius

## Overview

##### Main System Components
The system architecture should be divided into these key components:

a. Frontend Layer:
- React-based web application (frontend directory)
- Key modules: Analytics, Anomaly Detection, Alerts, Dashboard
- UI components for data visualization and user interaction

b. Backend Layer:
- Flask-based API server (chaos_genius directory)
- Core analytics engine
- Data processing pipeline
- Authentication and authorization

c. Data Processing Components:
- Anomaly detection engine (chaos_genius/core/anomaly)
- Root cause analysis engine (chaos_genius/core/rca)
- Data connectors (chaos_genius/connectors)

d. Job Processing:
- Celery workers for async tasks
- Task scheduling and monitoring
- Alert processing system

e. Storage Layer:
- Database for application data
- Cache layer for performance optimization

##### Component Relationships and Data Flow

a. External Integrations:
- Data source connectors (MySQL, Postgres, Snowflake, etc.)
- Alert destinations (Email, Slack)
- Authentication systems

b. Internal Data Flow:
- User requests → Frontend → Backend API
- Data ingestion → Processing pipeline → Storage
- Scheduled jobs → Analytics engine → Results storage
- Alert triggers → Alert processing → External notifications

##### Specific Architectural Elements

Key architectural patterns:

a. Service Architecture:
- RESTful API endpoints (chaos_genius/views)
- Modular connector system (chaos_genius/connectors)
- Pluggable ML models (chaos_genius/core/anomaly/models)

b. Data Processing Pipeline:
- Data ingestion
- Preprocessing
- Analysis (anomaly detection, RCA)
- Results storage and caching

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        DS[Data Sources]
        AD[Alert Destinations]
        AS[Auth Systems]
    end

    subgraph Frontend
        FA["Main App"]:::frontend
        AM["Analytics Module"]:::frontend
        ADU["Anomaly Detection UI"]:::frontend
        AU["Alerts UI"]:::frontend
        DU["Dashboard UI"]:::frontend
        click FA "https://github.com/chaos-genius/chaos_genius/blob/main/frontend/src/App.js"
        click AM "https://github.com/chaos-genius/chaos_genius/tree/main/frontend/src/components/Analystics/"
        click ADU "https://github.com/chaos-genius/chaos_genius/tree/main/frontend/src/components/Anomaly/"
        click AU "https://github.com/chaos-genius/chaos_genius/tree/main/frontend/src/components/AlertsForm/"
        click DU "https://github.com/chaos-genius/chaos_genius/tree/main/frontend/src/components/DashboardForm/"
    end

    subgraph Backend
        API["Flask API Server"]:::backend
        AV["API Views"]:::backend
        CT["Controllers"]:::backend
        click API "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/app.py"
        click AV "https://github.com/chaos-genius/chaos_genius/tree/main/chaos_genius/views/"
        click CT "https://github.com/chaos-genius/chaos_genius/tree/main/chaos_genius/controllers/"
    end

    subgraph "Data Processing"
        ADE["Anomaly Detection Engine"]:::processing
        RCA["Root Cause Analysis"]:::processing
        DC["Data Connectors"]:::processing
        MLM["ML Models"]:::processing
        click ADE "https://github.com/chaos-genius/chaos_genius/tree/main/chaos_genius/core/anomaly/"
        click RCA "https://github.com/chaos-genius/chaos_genius/tree/main/chaos_genius/core/rca/"
        click DC "https://github.com/chaos-genius/chaos_genius/tree/main/chaos_genius/connectors/"
        click MLM "https://github.com/chaos-genius/chaos_genius/tree/main/chaos_genius/core/anomaly/models/"
    end

    subgraph "Job Processing"
        CC["Celery Config"]:::job
        AT["Alert Tasks"]:::job
        ANT["Analytics Tasks"]:::job
        AMT["Anomaly Tasks"]:::job
        click CC "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/celery_config.py"
        click AT "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/jobs/alert_tasks.py"
        click ANT "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/jobs/analytics_scheduler.py"
        click AMT "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/jobs/anomaly_tasks.py"
    end

    subgraph Storage
        DM["Database Models"]:::storage
        BM["Base Model"]:::storage
        DBU["Database Utils"]:::storage
        click DM "https://github.com/chaos-genius/chaos_genius/tree/main/chaos_genius/databases/models/"
        click BM "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/databases/base_model.py"
        click DBU "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/databases/db_utils.py"
    end

    subgraph "Alert System"
        AC["Alert Core"]:::alert
        EA["Email Alerts"]:::alert
        SA["Slack Alerts"]:::alert
        AT["Alert Templates"]:::alert
        click AC "https://github.com/chaos-genius/chaos_genius/tree/main/chaos_genius/alerts/"
        click EA "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/alerts/email.py"
        click SA "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/alerts/slack.py"
        click AT "https://github.com/chaos-genius/chaos_genius/tree/main/chaos_genius/alerts/email_templates/"
    end

    subgraph "Core Utils"
        DL["Data Loading"]:::util
        KV["KPI Validation"]:::util
        GU["General Utils"]:::util
        click DL "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/core/utils/data_loader.py"
        click KV "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/core/utils/kpi_validation.py"
        click GU "https://github.com/chaos-genius/chaos_genius/blob/main/chaos_genius/core/utils/utils.py"
    end

    %% Connections
    DS --> DC
    Frontend --> API
    API --> AV
    AV --> CT
    DC --> ADE
    DC --> RCA
    ADE --> MLM
    CT --> DM
    AT --> EA
    AT --> SA
    EA --> AD
    SA --> AD
    AS --> API

    %% Styles
    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef backend fill:#4CAF50,stroke:#2E7D32,color:white
    classDef processing fill:#FF9800,stroke:#EF6C00,color:white
    classDef job fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef storage fill:#FFC107,stroke:#FF8F00,color:black
    classDef alert fill:#F44336,stroke:#C62828,color:white
    classDef util fill:#607D8B,stroke:#37474F,color:white
    classDef external fill:#9E9E9E,stroke:#424242,color:white
```
