# percona/orchestrator architecture

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

- Interactive diagram: https://gitdiagram.com/percona/orchestrator
- Repository: https://github.com/percona/orchestrator

## Overview

##### Project Overview and Type
- This is a backend service written in Go. Its primary purpose is to monitor, map, and manage MySQL replication topologies. It provides three interfaces: a command-line interface (CLI), an HTTP API, and a Web interface.
- Key functional areas include discovery (crawling MySQL topologies), refactoring (restructuring replication relationships), and recovery (handling failovers and automated/manual recovery).

##### Analyzing the File Structure
- The “go” directory contains the core business logic. Look at subdirectories like:
– go/app and go/cmd/orchestrator for entry points (CLI and main execution).
– go/agent and go/inst for interacting with MySQL instances and maintaining topology information.
– go/discovery for modules that probe and discover replication status.
– go/logic for recovery and refactoring algorithms.
– go/http for HTTP API endpoints and web server functionality.
– go/raft, which suggests a Raft implementation is used for leader election and state replication.
- There are additional directories for configuration (conf), templates (resources/templates), public resources for the Web UI (resources/public), and extensive tests (tests/*), which indicate robust integration and system testing.
- Dockerfiles and Vagrant files point to containerized and virtualized environments used for deployment/testing.

##### Key Components to Represent (Main Components and Their Interactions)
a. Orchestrator Service Core
– State Management & Coordination: The Raft module that handles internal coordination and leader election.
– Business Logic: Modules under “go/logic”, “go/inst”, “go/attributes”, etc., which manage topology evaluation and replication state.
b. API and Interface Layers
– HTTP API Component: Handles incoming RESTful API calls and serves JSON responses.
– Web Interface: Uses resources from “resources/public” and “resources/templates” to render the UI.
– CLI Tool: Represented by the command-line interface as well as “go/app/cli.go”.
c. Data Access Layer
– Database Interaction: The “go/db” modules, which support migration, patch generation, and TLS configuration when interacting with MySQL.
d. External Dependencies
– MySQL Servers: External MySQL instances that the Orchestrator monitors, discovers, and upon which it occasionally executes change commands during disaster recovery, refactoring, or troubleshooting tasks.
– Configuration Files: Shown as an external “conf” source of configurations for different deployment scenarios (e.g., sample configs provided for different modes such as “raft”, “system”, “simple”).
– Logging/Metrics: Modules under “go/golib/log” and “go/metrics” indicate integration with external monitoring or logging systems.
– Integration with CI tools and container orchestration (Docker and Vagrant). These may be depicted as the deployment and testing envelopes.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Interface Layer
    subgraph "Interface Layer"
        HTTP["HTTP API Endpoints<br/>(Handles RESTful calls)"]:::interface
        CLI["CLI Interface<br/>(Command-line operations)"]:::interface
        WEB["Web User Interface<br/>(Renders pages using templates & static assets)"]:::interface
    end

    %% Orchestrator Service Core
    subgraph "Orchestrator Service Core"
        DISCOVERY["Discovery<br/>(Crawls MySQL topologies)"]:::core
        REF_REC["Refactoring & Recovery<br/>(Automated/manual failover and topology restructuring)"]:::core
        MYSQL_BL["MySQL Interaction<br/>(Manages replication state & instance communications)"]:::core
        RAFT["Raft Coordination<br/>(Leader election & state replication)"]:::core
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        DB["Database Interaction<br/>(Handles migrations, patch generation, TLS settings)"]:::datalayer
    end

    %% External Dependencies
    subgraph "External Dependencies"
        MYSQLS["MySQL Instances<br/>(External MySQL servers)"]:::external
        CONFIG["Configuration Files<br/>(Orchestrator deployment configs)"]:::external
        LOG_METRICS["Logging & Metrics<br/>(External monitoring systems)"]:::external
    end

    %% Connections from Interface Layer to Orchestrator Core
    HTTP -->|"calls"| DISCOVERY
    CLI -->|"commands"| REF_REC
    WEB -->|"queries"| DISCOVERY

    %% Internal Orchestrator Core interactions
    RAFT -->|"syncs"| DISCOVERY
    RAFT -->|"syncs"| REF_REC
    DISCOVERY -->|"monitors"| MYSQLS
    REF_REC -->|"executes recovery on"| MYSQLS
    MYSQL_BL -->|"issues DB operations to"| DB

    %% External Configuration and Logging
    CONFIG -->|"configures"| DISCOVERY
    LOG_METRICS -->|"logs/metrics"| DISCOVERY

    %% Styles
    classDef interface fill:#f9e79f,stroke:#f39c12,stroke-width:2px;
    classDef core fill:#aed6f1,stroke:#3498db,stroke-width:2px;
    classDef datalayer fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;

    %% Click Events
    click DISCOVERY "https://github.com/percona/orchestrator/tree/master/go/discovery/"
    click REF_REC "https://github.com/percona/orchestrator/tree/master/go/logic/"
    click MYSQL_BL "https://github.com/percona/orchestrator/tree/master/go/inst/"
    click RAFT "https://github.com/percona/orchestrator/tree/master/go/raft/"
    click HTTP "https://github.com/percona/orchestrator/tree/master/go/http/"
    click CLI "https://github.com/percona/orchestrator/blob/master/go/app/cli.go"
    click WEB "https://github.com/percona/orchestrator/tree/master/resources/templates"
    click DB "https://github.com/percona/orchestrator/tree/master/go/db/"
    click CONFIG "https://github.com/percona/orchestrator/tree/master/conf/"
    click LOG_METRICS "https://github.com/percona/orchestrator/tree/master/go/golib/log/"
```
