# namanyakeren/replicator architecture

> Architecture diagram of the GitHub repository namanyakeren/replicator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/namanyakeren/replicator
- Repository: https://github.com/namanyakeren/replicator

## Overview

Replicator runs a Windows agent at each site to copy MySQL data from master to backup, record replication health, and optionally reverse-sync during failback. A PHP dashboard polls site backups for agent status and database sizes. The installer configures the agent and MySQL access. The agent workflow and installer links are supported by sampled source; dashboard behavior and several agent capabilities are documented in the README, but dashboard source excerpts were not provided.

Main entry points: [`agent/src/main.rs`](https://github.com/namanyakeren/replicator/blob/main/agent/src/main.rs) (Agent runner), [`agent/src/sync.rs`](https://github.com/namanyakeren/replicator/blob/main/agent/src/sync.rs) (Table synchronization), [`dashboard/api.php`](https://github.com/namanyakeren/replicator/blob/main/dashboard/api.php) (Site status API), [`agent/src/status.rs`](https://github.com/namanyakeren/replicator/blob/main/agent/src/status.rs) (Cycle and status records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent["Replication agent"]
  node_agent_main["Agent runner<br/>[main.rs]"]
  node_config["Config validation<br/>[config.rs]"]
  node_db["MySQL connections<br/>[db.rs]"]
  node_sync["Table synchronization<br/>[sync.rs]"]
  node_util["Shared utilities<br/>[util.rs]"]
end

subgraph group_state["Status and operations"]
  node_failback["Failback state<br/>[failback.rs]"]
  node_status["Cycle and status records<br/>[status.rs]"]
  node_logger["Rotating logs<br/>[logger.rs]"]
  node_tray["Tray and monitor<br/>[tray.rs]"]
end

subgraph group_dashboard["Monitoring dashboard"]
  node_dashboard_page["Dashboard page<br/>[index.php]"]
  node_dashboard_api["Site status API<br/>[api.php]"]
  node_site_registry["Site configuration<br/>[config.php]"]
end

subgraph group_setup["Agent installation"]
  node_installer_entry["Installer entry<br/>[main.rs]"]
  node_installer_ui["Installer form<br/>[ui.rs]"]
  node_installer_work["Installation tasks<br/>[install.rs]"]
end

node_operator(("Site operator"))
node_master[("Site master MySQL")]
node_backup[("Site backup MySQL")]
node_dashboard_user(("Dashboard user"))

node_operator -->|"starts agent"| node_agent_main
node_agent_main -->|"loads settings"| node_config
node_agent_main -->|"checks connections"| node_db
node_agent_main -->|"runs cycles"| node_sync
node_agent_main -->|"publishes status"| node_status
node_agent_main -->|"checks failback"| node_failback
node_agent_main -->|"logs events"| node_logger
node_agent_main -->|"runs tray"| node_tray
node_config -->|"validates identifiers"| node_util
node_sync -->|"reads and writes"| node_db
node_sync -->|"reports progress"| node_status
node_sync -->|"reads tables"| node_master
node_sync -->|"writes replica"| node_backup
node_status -->|"writes records"| node_db
node_status -->|"stores status"| node_backup
node_tray -->|"requests mode"| node_failback
node_dashboard_user -->|"opens dashboard"| node_dashboard_page
node_dashboard_page -->|"polls status"| node_dashboard_api
node_dashboard_api -.->|"loads sites"| node_site_registry
node_dashboard_api -->|"reads agent status"| node_backup
node_dashboard_api -->|"measures database"| node_master
node_operator -->|"runs installer"| node_installer_entry
node_installer_entry -->|"opens form"| node_installer_ui
node_installer_entry -->|"performs setup"| node_installer_work
node_installer_ui -.->|"submits settings"| node_installer_work
node_installer_work -->|"prepares database"| node_backup

click node_agent_main "https://github.com/namanyakeren/replicator/blob/main/agent/src/main.rs"
click node_config "https://github.com/namanyakeren/replicator/blob/main/agent/src/config.rs"
click node_db "https://github.com/namanyakeren/replicator/blob/main/agent/src/db.rs"
click node_sync "https://github.com/namanyakeren/replicator/blob/main/agent/src/sync.rs"
click node_failback "https://github.com/namanyakeren/replicator/blob/main/agent/src/failback.rs"
click node_status "https://github.com/namanyakeren/replicator/blob/main/agent/src/status.rs"
click node_logger "https://github.com/namanyakeren/replicator/blob/main/agent/src/logger.rs"
click node_tray "https://github.com/namanyakeren/replicator/blob/main/agent/src/tray.rs"
click node_util "https://github.com/namanyakeren/replicator/blob/main/agent/src/util.rs"
click node_dashboard_page "https://github.com/namanyakeren/replicator/blob/main/dashboard/index.php"
click node_dashboard_api "https://github.com/namanyakeren/replicator/blob/main/dashboard/api.php"
click node_site_registry "https://github.com/namanyakeren/replicator/blob/main/config/config.php"
click node_installer_entry "https://github.com/namanyakeren/replicator/blob/main/installer/src/main.rs"
click node_installer_ui "https://github.com/namanyakeren/replicator/blob/main/installer/src/ui.rs"
click node_installer_work "https://github.com/namanyakeren/replicator/blob/main/installer/src/install.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_agent_main,node_config,node_db,node_sync,node_util,node_dashboard_user toneBlue
class node_failback,node_status,node_logger,node_tray,node_master,node_backup toneAmber
class node_dashboard_page,node_dashboard_api,node_site_registry toneMint
class node_installer_entry,node_installer_ui,node_installer_work toneRose
class node_operator toneIndigo
```

## Components

### Replication agent

- [Agent runner](https://github.com/namanyakeren/replicator/blob/main/agent/src/main.rs): `agent/src/main.rs`
- [Config validation](https://github.com/namanyakeren/replicator/blob/main/agent/src/config.rs): `agent/src/config.rs`
- [MySQL connections](https://github.com/namanyakeren/replicator/blob/main/agent/src/db.rs): `agent/src/db.rs`
- [Table synchronization](https://github.com/namanyakeren/replicator/blob/main/agent/src/sync.rs): `agent/src/sync.rs`
- [Shared utilities](https://github.com/namanyakeren/replicator/blob/main/agent/src/util.rs): `agent/src/util.rs`

### Status and operations

- [Failback state](https://github.com/namanyakeren/replicator/blob/main/agent/src/failback.rs): `agent/src/failback.rs`
- [Cycle and status records](https://github.com/namanyakeren/replicator/blob/main/agent/src/status.rs): `agent/src/status.rs`
- [Rotating logs](https://github.com/namanyakeren/replicator/blob/main/agent/src/logger.rs): `agent/src/logger.rs`
- [Tray and monitor](https://github.com/namanyakeren/replicator/blob/main/agent/src/tray.rs): `agent/src/tray.rs`

### Monitoring dashboard

- [Dashboard page](https://github.com/namanyakeren/replicator/blob/main/dashboard/index.php): `dashboard/index.php`
- [Site status API](https://github.com/namanyakeren/replicator/blob/main/dashboard/api.php): `dashboard/api.php`
- [Site configuration](https://github.com/namanyakeren/replicator/blob/main/config/config.php): `config/config.php`

### Agent installation

- [Installer entry](https://github.com/namanyakeren/replicator/blob/main/installer/src/main.rs): `installer/src/main.rs`
- [Installer form](https://github.com/namanyakeren/replicator/blob/main/installer/src/ui.rs): `installer/src/ui.rs`
- [Installation tasks](https://github.com/namanyakeren/replicator/blob/main/installer/src/install.rs): `installer/src/install.rs`

### Other components

- **Site operator**
- **Site master MySQL**
- **Site backup MySQL**
- **Dashboard user**

## Connections

- Site operator → Agent runner: starts agent (evidence: `README.md`)
- Agent runner → Config validation: loads settings (evidence: `agent/src/main.rs`)
- Agent runner → MySQL connections: checks connections (evidence: `agent/src/main.rs`)
- Agent runner → Table synchronization: runs cycles (evidence: `agent/src/main.rs`)
- Agent runner → Cycle and status records: publishes status (evidence: `agent/src/main.rs`)
- Agent runner → Failback state: checks failback (evidence: `agent/src/main.rs`)
- Agent runner → Rotating logs: logs events (evidence: `agent/src/main.rs`)
- Agent runner → Tray and monitor: runs tray (evidence: `agent/src/main.rs`)
- Config validation → Shared utilities: validates identifiers (evidence: `agent/src/config.rs`)
- Table synchronization → MySQL connections: reads and writes (evidence: `agent/src/sync.rs`)
- Table synchronization → Cycle and status records: reports progress (evidence: `agent/src/sync.rs`)
- Table synchronization → Site master MySQL: reads tables (evidence: `README.md`)
- Table synchronization → Site backup MySQL: writes replica (evidence: `README.md`)
- Cycle and status records → MySQL connections: writes records (evidence: `agent/src/status.rs`)
- Cycle and status records → Site backup MySQL: stores status (evidence: `README.md`)
- Tray and monitor → Failback state: requests mode (evidence: `agent/src/tray.rs`)
- Dashboard user → Dashboard page: opens dashboard (evidence: `README.md`)
- Dashboard page → Site status API: polls status (evidence: `README.md`)
- Site status API → Site configuration: loads sites
- Site status API → Site backup MySQL: reads agent status (evidence: `README.md`)
- Site status API → Site master MySQL: measures database (evidence: `README.md`)
- Site operator → Installer entry: runs installer (evidence: `README.md`)
- Installer entry → Installer form: opens form (evidence: `installer/src/main.rs`)
- Installer entry → Installation tasks: performs setup (evidence: `installer/src/main.rs`)
- Installer form → Installation tasks: submits settings (evidence: `installer/src/ui.rs`)
- Installation tasks → Site backup MySQL: prepares database (evidence: `installer/src/install.rs`)
