# grafana/oncall architecture

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

- Interactive diagram: https://gitdiagram.com/grafana/oncall
- Repository: https://github.com/grafana/oncall

## Overview

##### Overall Structure and Key Components
- Frontend/Integration with Grafana:
– Show a “Grafana Plugin” component (under grafana-plugin) that runs inside Grafana.
– It communicates with the on‑call engine through secure REST API calls and serves as the UI for end‑users.
- Backend – OnCall Engine:
– Highlight that the engine includes a “manage.py” entry point for administrative and migration tasks.
- Background Processing:
– Include a separate component representing “Celery Workers” that handle asynchronous tasks such as sending notifications, processing alerts, and executing periodic jobs.
– Show the communication between the Engine and the Celery Task Queue.
- Data Storage:
– Represent a “Database” (or multiple persistence stores) that stores alert data, on‑call schedules, user settings, and migration history. This is typically configured as part of the Docker Compose/Helm setup.
- Deployment and Orchestration:
– Incorporate deployment artifacts like Docker Compose (docker-compose.yml), Helm charts (helm/), and Terraform (terraform/) that orchestrate containers and services.
- External Integration Services:
– Indicate that the engine’s “config_integrations” and various “apps” (like apps/slack, apps/email, etc.) interface with these external systems.
- CI/CD and Developer Tools (Optional):
– Mention the “tools/migrators” and “tools/scripts,” which assist with data migration and administrative tasks.

##### Depicting Relationships and Data Flow
– From end‑users interacting via Grafana (and its plugin) to the OnCall Engine’s API.
– Between the engine’s API endpoint and the Celery Workers for scheduling and heavy‐weight tasks.
– From the engine to external integration services to send notifications (via HTTP, SMS gateway, or telephony APIs).
– From the engine to the database for data persistence.

##### Architectural Patterns & Design Principles
- Modularization: The engine is partitioned into “apps” (e.g., alerts, api, integrations, user management, schedules) – show these as modular building blocks.
- Separation of concerns: Clearly separate the UI (Grafana Plugin), API/backend (Engine), asynchronous processing (Celery), and infrastructure/deployment (Docker, Helm, Terraform).
- Integration and Extensibility: Highlight how third‑party integrations and notification channels are isolated via dedicated modules and config files.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction Layer
    U("End User"):::user
    FP("Grafana Plugin UI"):::frontend
    U -->|"Interacts_via_Dashboard"| FP

    %% Backend Services
    BE("OnCall Engine"):::backend
    FP -->|"REST_API_call"| BE

    ME("Modular Engine Apps"):::backend
    BE -->|"Handles_Modules"| ME

    CW("Celery Workers"):::worker
    BE -->|"Queues_Tasks"| CW

    DB["Database"]:::database
    BE -->|"Database_Query"| DB

    EI("External Integrations (Slack,Telegram,Twilio,Email,Prometheus)"):::external
    BE -->|"Sends_Notifications"| EI
    ME -->|"Configures"| EI

    %% Deployment and Orchestration
    subgraph "Deployment & Orchestration"
        DC("Deployment: Docker Compose"):::deployment
        HC("Deployment: Helm Charts"):::deployment
        TF("Deployment: Terraform"):::deployment
    end

    DC -->|"Deploys"| FP
    DC -->|"Deploys"| BE
    DC -->|"Deploys"| DB
    HC -->|"Deploys"| FP
    HC -->|"Deploys"| BE
    TF -->|"Deploys"| BE

    %% CI/CD and Developer Tools
    subgraph "CI/CD & Developer Tools"
        CICD("CI/CD Tools"):::deployment
    end
    CICD -->|"CI_CD_Pipeline"| FP
    CICD -->|"CI_CD_Pipeline"| BE

    %% Click Events
    click FP "https://github.com/grafana/oncall/tree/dev/grafana-plugin/"
    click BE "https://github.com/grafana/oncall/tree/dev/engine/"
    click ME "https://github.com/grafana/oncall/tree/dev/engine/apps/"
    click CW "https://github.com/grafana/oncall/blob/dev/engine/engine/celery.py"
    click DC "https://github.com/grafana/oncall/blob/dev/docker-compose.yml"
    click HC "https://github.com/grafana/oncall/tree/dev/helm/oncall/"
    click TF "https://github.com/grafana/oncall/tree/dev/terraform/"
    click EI "https://github.com/grafana/oncall/tree/dev/engine/config_integrations/"
    click CICD "https://github.com/grafana/oncall/tree/dev/.github/"

    %% Styles
    classDef user fill:#fadbd8,stroke:#e74c3c,stroke-width:2px;
    classDef frontend fill:#a2d5f2,stroke:#1b6ca8,stroke-width:2px;
    classDef backend fill:#c1e1c5,stroke:#3a7d44,stroke-width:2px;
    classDef worker fill:#f9e79f,stroke:#d4ac0d,stroke-width:2px;
    classDef database fill:#f0e68c,stroke:#b8860b,stroke-width:2px;
    classDef external fill:#d7bde2,stroke:#af7ac5,stroke-width:2px;
    classDef deployment fill:#f5b7b1,stroke:#cd6155,stroke-width:2px;
```
