# dashaisoftware/dashai architecture

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

- Interactive diagram: https://gitdiagram.com/dashaisoftware/dashai
- Repository: https://github.com/dashaisoftware/dashai

## Overview

##### Project Type and Purpose
- DashAI is a full-stack web application combining a React-based Single-Page Application (SPA) frontend and a Python backend that exposes RESTful APIs. Its purpose is to provide a graphical toolbox for training, evaluating, explaining, and deploying AI/ML models.

##### High-Level Architecture Overview
- Frontend: DashAI/front (React + TypeScript, Yarn)
- Backend: DashAI/back (Python 3.8+, FastAPI-style / Pydantic schemas, SQLAlchemy, Alembic)
- Database: SQLite by default (configurable), managed via SQLAlchemy and Alembic migrations
- Job Queue: simple_job_queue or pluggable queues for async tasks (training, conversion, explanation)
- File Storage / Local Path: for datasets, experiments, runs, plugin artifacts

##### System Components
a. Client Layer (Browser)
- React SPA served by yarn start or static build
- UI Components: pages, modals, forms for datasets, experiments, explainers, explorers, predictions, results, plugins
- API Client Modules: src/api/*.ts (datasets.ts, experiment.ts, predict.ts, etc.)
b. API Gateway Layer
- DashAI/back/app.py or __main__.py launching FastAPI
- front_api.py (if any unified gateway)
- api_v0 and api_v1 routers mounted under /api/v0 and /api/v1
c. Business Logic Layer (Backend)
- Dataloaders: DashAI/back/dataloaders (CSV, JSON, Excel, audio, etc.)
- Converters: standardized ML preprocessing converters (scikit-learn, SMOTE, HuggingFace wrappers)
- Models: factory pattern producing BaseModel or wrappers (scikit-learn, transformers)
- Tasks & Jobs: BaseTask, BaseJob classes; converter_job, dataset_job, explainer_job, explorer_job, model_job, predict_job
- Exploration & Explainability: explorers (statistics, plots), explainers (SHAP, PDP, permutation importance)
- Optimizers: OptunaOptimizer, HyperoptOptimizer
- Plugins & Registry: dynamic component registration, tag-based discovery
d. Persistence and Async
- Database: SQLAlchemy models in dependencies/database/models.py
- Alembic migrations for schema evolution
- Job Queue: enqueued background tasks, can be in-process or external like Celery via abstraction
- Local Filesystem: storing raw datasets, intermediate artifacts, results

##### Relationships & Data Flows
1. User interacts with React SPA → invokes REST calls (HTTP/JSON)
2. API Gateway dispatches to appropriate router → Pydantic schema validation
3. Endpoints call into service layer modules (dataloaders, converters, jobs)
4. For synchronous endpoints (list datasets, retrieve results) → direct DB queries (SQLAlchemy)
5. For asynchronous operations (train model, convert dataset) → request enqueued in Job Queue → Worker processes job invoking Job classes → update database and file storage → status polled via endpoint
6. Explainability & Exploration jobs follow same async pattern
7. Frontend polls or subscribes to job status, then fetches results (graphs, tables)

##### Architectural Patterns & Design Principles
- Layered Architecture: Presentation (UI) → API Gateway → Service/Domain → Persistence
- Dependency Injection / Container Pattern: container.py builds config, registry, DB sessions
- Plug-in & Registry Pattern: components/plugins discovered and registered at runtime
- Versioned API: api_v0 vs api_v1 for backward compatibility
- Job Abstraction: uniform Job interface, pluggable job queue implementations

##### Technologies & Frameworks
- Frontend: React, Yarn, TypeScript, ESLint, Prettier, json-server for mock API
- Backend: Python, FastAPI (or Starlette), Pydantic, SQLAlchemy, Alembic, pytest, ruff, black
- Machine Learning: scikit-learn, imbalanced-learn, HuggingFace transformers, Optuna/Hyperopt
- Data Versioning: DVC integration at project root

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        BrowserSPA["Browser / React SPA"]:::front
    end

    subgraph "API Gateway Layer"
        AppPy["app.py"]:::api
        MainPy["__main__.py"]:::api
        FrontAPI["front_api.py"]:::api
        V0Router["api_v0 Router"]:::api
        V1Router["api_v1 Router"]:::api
        Schemas["Pydantic Schemas"]:::api
    end

    subgraph "Service Layer"
        DIContainer["Container (dependency injection)"]:::service
        ConfigLoader["config.py"]:::service
        ConfigObj["config_object.py"]:::service
        ConfigBuilder["config_builder.py"]:::service
        Dataloaders["Dataloaders"]:::service
        Converters["Converters"]:::service
        ModelFactory["Model Factory"]:::service
        BaseModel["BaseModel"]:::service
        ModelImpl["Model Implementations"]:::service
        Tasks["Task Abstractions"]:::service
        Jobs["Job Abstractions"]:::service
        Explainability["Explainability"]:::service
        Exploration["Exploration"]:::service
        Optimizers["Optimizers"]:::service
        PluginRegistry["Plugin Registry"]:::service
    end

    subgraph "Persistence & Storage"
        DB["Database (SQLite)"]:::persistence
        DBModels["SQLAlchemy Models"]:::persistence
        SqliteDB["sqlite_database.py"]:::persistence
        Alembic["Alembic Migrations"]:::persistence
        FS["File Storage"]:::persistence
    end

    subgraph "Infrastructure & External"
        JobQueue["Job Queue"]:::infra
        Worker["Worker"]:::infra
        HFHub["HuggingFace Hub"]:::external
    end

    %% Connections
    BrowserSPA -->|"HTTP/JSON"| AppPy
    BrowserSPA -->|"HTTP/JSON"| MainPy
    AppPy --> V0Router
    AppPy --> V1Router
    MainPy --> FrontAPI
    FrontAPI --> V0Router
    FrontAPI --> V1Router
    V0Router --> Schemas
    V1Router --> Schemas

    V0Router --> DIContainer
    V1Router --> DIContainer
    Schemas --> DIContainer

    DIContainer --> ConfigLoader
    DIContainer --> ConfigObj
    DIContainer --> ConfigBuilder

    V0Router --> Dataloaders
    V1Router --> Dataloaders
    V0Router --> Converters
    V1Router --> Converters
    V0Router --> ModelFactory
    V1Router --> ModelFactory
    V0Router --> Tasks
    V1Router --> Tasks
    V0Router --> Jobs
    V1Router --> Jobs
    V0Router --> Explainability
    V1Router --> Explainability
    V0Router --> Exploration
    V1Router --> Exploration
    V0Router --> Optimizers
    V1Router --> Optimizers
    V0Router --> PluginRegistry
    V1Router --> PluginRegistry

    Dataloaders --> DB
    Converters --> DB
    ModelFactory --> DB
    Tasks --> DBModels
    Jobs --> DBModels
    Explainability --> DB
    Exploration --> DB
    Optimizers --> DB

    Dataloaders --> FS
    Converters --> FS
    ModelFactory --> FS
    Explainability --> FS
    Exploration --> FS

    Converters --> JobQueue
    ModelFactory --> JobQueue
    Explainability --> JobQueue
    Exploration --> JobQueue
    Tasks --> JobQueue
    Jobs --> JobQueue

    JobQueue --> Worker
    Worker --> DB
    Worker --> FS

    HFHub --> Converters
    HFHub --> ModelFactory

    PluginRegistry --> Converters
    PluginRegistry --> ModelFactory
    PluginRegistry --> Explainability
    PluginRegistry --> Exploration

    %% Click Events
    click BrowserSPA "https://github.com/dashaisoftware/dashai/tree/develop/DashAI/front"
    click AppPy "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/app.py"
    click MainPy "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/__main__.py"
    click FrontAPI "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/api/front_api.py"
    click V0Router "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/api/api_v0/api.py"
    click V1Router "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/api/api_v1/api.py"
    click Schemas "https://github.com/dashaisoftware/dashai/tree/develop/DashAI/back/api/api_v1/schemas"
    click DBModels "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/dependencies/database/models.py"
    click SqliteDB "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/dependencies/database/sqlite_database.py"
    click Alembic "https://github.com/dashaisoftware/dashai/tree/develop/alembic/versions"
    click DIContainer "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/container.py"
    click ConfigLoader "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/config.py"
    click ConfigObj "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/config_object.py"
    click ConfigBuilder "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/dependencies/config_builder.py"
    click Dataloaders "https://github.com/dashaisoftware/dashai/tree/develop/DashAI/back/dataloaders/classes"
    click Converters "https://github.com/dashaisoftware/dashai/tree/develop/DashAI/back/converters"
    click ModelFactory "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/models/model_factory.py"
    click BaseModel "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/models/base_model.py"
    click ModelImpl "https://github.com/dashaisoftware/dashai/tree/develop/DashAI/back/models/scikit_learn"
    click Tasks "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/tasks/base_task.py"
    click Jobs "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/job/base_job.py"
    click Explainability "https://github.com/dashaisoftware/dashai/tree/develop/DashAI/back/explainability"
    click Exploration "https://github.com/dashaisoftware/dashai/tree/develop/DashAI/back/exploration"
    click Optimizers "https://github.com/dashaisoftware/dashai/tree/develop/DashAI/back/optimizers"
    click PluginRegistry "https://github.com/dashaisoftware/dashai/tree/develop/DashAI/back/plugins"
    click JobQueue "https://github.com/dashaisoftware/dashai/blob/develop/DashAI/back/dependencies/job_queues/simple_job_queue.py"

    %% Styles
    classDef front fill:#ADD8E6,stroke:#000;
    classDef api fill:#90EE90,stroke:#000;
    classDef service fill:#FFA500,stroke:#000;
    classDef persistence fill:#9370DB,stroke:#000;
    classDef infra fill:#D3D3D3,stroke:#000;
    classDef external fill:#D3D3D3,stroke:#000;
```
