# coopjr/redash architecture

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

- Interactive diagram: https://gitdiagram.com/coopjr/redash
- Repository: https://github.com/coopjr/redash

## Overview

##### Project type and purpose
- This is a full-stack, open-source data analytics and visualization platform (Redash).
- Frontend: Single-Page Application (React, Redux, LESS, Webpack) in `client/` and shared viz components in `viz-lib/`.
- Backend: Python Flask app with REST API, authentication, scheduled tasks, and a plugin architecture for data-source connectors.
- Background workers: RQ-driven jobs for query execution, scheduling, and alerts.
- Persistence: Relational database (PostgreSQL via SQLAlchemy/Alembic migrations) and Redis as broker/cache.
- External integrations: SMTP/email, OAuth providers, third-party messaging/webhooks, and 35+ data sources via pluggable query runners.

##### File structure
- Top-level:
- `client/` – React UI, Cypress tests, build configs.
- `viz-lib/` – Shared visualization library.
- `redash/` – Flask app (handlers, models, query runners, tasks, serializers, settings).
- `migrations/` – Alembic scripts for DB schema evolution.
- `manage.py`, `wsgi.py` – CLI entrypoint and WSGI server loader.
- `Dockerfile`, `docker-compose.yml`, `.ci/` – Containerization and CI pipeline.
- Patterns & Components:
- MVC/API pattern in Flask: `handlers/` (controllers) → `models/` → DB.
- Plugin architecture: `redash/query_runner/` modules loaded dynamically.
- Task queue: `redash/tasks/` invoked by RQ workers (`redash/worker.py`).
- Configuration-driven: `redash/settings/` and dynamic settings loader.

##### README for additional insights
- Confirms browser-based SPA, REST API covering all UI actions, scheduling, alerts, pluggable data sources.
- Highlights ease of setup, supported data sources, and use cases (visualizations, dashboards, sharing, alerts).

##### Elements
– Labels: each component (e.g., “Flask API”, “RQ Worker”, “PostgreSQL”)
- Blue for user-facing components (Browser, SPA)
- Green for data stores (Postgres, Redis)
- Orange for compute/processing (API server, Workers)

##### Detail
– Capture every essential piece: static asset build → served by web server → API → queue → worker → external DS → DB → API → SPA.
– Don’t overthink—split into as many logical components as needed to reflect real deployment.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend"
        Browser["User Browser\n(SPA)"]:::frontend
        client["Frontend SPA\n(client/)"]:::frontend
        vizlib["Shared Visualization Library\n(viz-lib/)"]:::frontend
    end

    %% Web Server
    NGINX["Load Balancer / Web Server\n(NGINX)"]:::compute

    %% Backend API Layer
    subgraph "Backend API"
        manage["CLI Entrypoint\nmanage.py"]:::compute
        app["Flask App Bootstrap\nredash/app.py"]:::compute
        wsgi["WSGI Loader\nredash/wsgi.py"]:::compute
        handlers["REST API Layer\n(redash/handlers/)"]:::compute
        models["Data Models\n(redash/models/)"]:::compute
        serializers["Serialization Layer\n(redash/serializers/)"]:::compute
        settings["Configuration & Settings\n(redash/settings/)"]:::compute
        auth["Authentication Providers\n(redash/authentication/)"]:::compute
        destinations["Alert Destinations\n(redash/destinations/)"]:::compute
        templates["Templating\n(redash/templates/)"]:::compute
        utils["Utility Functions\n(redash/utils/)"]:::compute
        migrations["DB Migrations\n(migrations/)"]:::compute
        queryrunners["Query Runners\n(redash/query_runner/)"]:::compute
    end

    %% Workers & Tasks
    subgraph "Workers"
        tasks["Task Definitions\n(redash/tasks/)"]:::compute
        worker["Worker Entrypoint\nredash/worker.py"]:::compute
    end

    %% Data Stores
    subgraph "Data Stores"
        db["PostgreSQL"]:::data
        redis["Redis"]:::data
    end

    %% External Integrations
    subgraph "External Services"
        smtp["SMTP / Email"]:::external
        oauth["OAuth Providers"]:::external
        webhooks["Webhooks"]:::external
        extdb["External Data Sources"]:::external
    end

    %% CI/CD & Containerization
    subgraph "CI/CD & Containerization"
        dockerfile["Dockerfile"]:::compute
        compose["docker-compose.yml"]:::compute
        ci["CI Configs\n(.ci/)"]:::compute
    end

    %% Connections
    Browser --> client
    client --> vizlib
    client --> NGINX
    NGINX --> app
    app --> handlers
    handlers --> models
    handlers --> serializers
    handlers --> settings
    handlers --> auth
    handlers --> utils
    handlers --> queryrunners
    handlers --> db
    handlers --> redis
    handlers --> destinations
    handlers --> templates
    handlers --> migrations

    handlers -->|Enqueue jobs| redis
    redis --> worker
    worker --> tasks
    tasks --> queryrunners
    queryrunners --> extdb
    tasks --> db
    tasks --> smtp
    tasks --> webhooks
    tasks --> destinations

    %% CI/CD connections
    ci --> dockerfile
    ci --> compose
    ci --> client
    ci --> app
    ci --> worker

    %% Click Events
    click client "https://github.com/coopjr/redash/tree/master/client/"
    click vizlib "https://github.com/coopjr/redash/tree/master/viz-lib/"
    click manage "https://github.com/coopjr/redash/blob/master/manage.py"
    click app "https://github.com/coopjr/redash/blob/master/redash/app.py"
    click wsgi "https://github.com/coopjr/redash/blob/master/redash/wsgi.py"
    click handlers "https://github.com/coopjr/redash/tree/master/redash/handlers/"
    click models "https://github.com/coopjr/redash/tree/master/redash/models/"
    click serializers "https://github.com/coopjr/redash/tree/master/redash/serializers/"
    click settings "https://github.com/coopjr/redash/tree/master/redash/settings/"
    click auth "https://github.com/coopjr/redash/tree/master/redash/authentication/"
    click destinations "https://github.com/coopjr/redash/tree/master/redash/destinations/"
    click templates "https://github.com/coopjr/redash/tree/master/redash/templates/"
    click utils "https://github.com/coopjr/redash/tree/master/redash/utils/"
    click migrations "https://github.com/coopjr/redash/tree/master/migrations/"
    click queryrunners "https://github.com/coopjr/redash/tree/master/redash/query_runner/"
    click tasks "https://github.com/coopjr/redash/tree/master/redash/tasks/"
    click worker "https://github.com/coopjr/redash/blob/master/redash/worker.py"
    click dockerfile "https://github.com/coopjr/redash/tree/master/Dockerfile"
    click compose "https://github.com/coopjr/redash/blob/master/docker-compose.yml"
    click ci "https://github.com/coopjr/redash/tree/master/.ci/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef compute fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef data fill:#C8E6C9,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
```
