# childax/stadvdb-mco2-ddb architecture

> Architecture diagram of the GitHub repository childax/stadvdb-mco2-ddb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/childax/stadvdb-mco2-ddb
- Repository: https://github.com/childax/stadvdb-mco2-ddb

## Overview

This is a three-node distributed database transaction-management application. Users inspect cluster health and train services through a React frontend and Express API; service reads are resolved transparently across nodes, while writes are routed to the central copy and the owning date fragment. Internally, sharding, SQL transactions, replication, and pending-replication logging support that workflow. The README also describes concurrency and crash-recovery capabilities, but sampled code shows recovery logging hooks rather than complete replay, and the frontend is explicitly a scaffold. Links reflect shown calls or documented capabilities; unsampled recovery behavior is not inferred.

Main entry points: [`backend/src/config/db.js`](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/config/db.js) (MySQL Pools), [`backend/src/services/replication.js`](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/services/replication.js) (Distributed Writes), [`backend/src/utils/sharding.js`](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/utils/sharding.js) (Fragment Routing), [`backend/src/routes/cluster.js`](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/routes/cluster.js) (Cluster Status API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application Entry"]
  node_frontend["React UI<br/>[App.jsx]"]
  node_frontend_entry["UI Bootstrap<br/>[main.jsx]"]
  node_api["Express Server<br/>[index.js]"]
end

subgraph group_routing["API And Routing"]
  node_cluster_routes["Cluster Status API<br/>[cluster.js]"]
  node_service_routes["Service CRUD API<br/>[services.js]"]
end

subgraph group_transactions["Transaction Management"]
  node_sharding["Fragment Routing<br/>[sharding.js]"]
  node_replication["Distributed Writes<br/>[replication.js]"]
  node_concurrency["SQL Transactions<br/>[concurrency.js]"]
  node_recovery["Pending Write Log<br/>[recovery.js]"]
end

subgraph group_storage["Distributed Storage"]
  node_node_config["Node Configuration<br/>[nodes.js]"]
  node_db_pools["MySQL Pools<br/>[db.js]"]
  node_mysql_cluster[("Three MySQL Nodes<br/>[schema.sql]")]
end

node_user(("User"))

node_user -->|"uses"| node_frontend
node_frontend_entry -->|"renders"| node_frontend
node_api -->|"mounts"| node_cluster_routes
node_api -->|"mounts"| node_service_routes
node_db_pools -->|"loads settings"| node_node_config
node_db_pools -->|"connects"| node_mysql_cluster
node_cluster_routes -->|"checks nodes"| node_db_pools
node_cluster_routes -->|"reports rule"| node_sharding
node_service_routes -->|"routes reads"| node_sharding
node_service_routes -->|"dispatches writes"| node_replication
node_sharding -->|"queries nodes"| node_db_pools
node_replication -->|"selects targets"| node_sharding
node_replication -->|"runs transactions"| node_concurrency
node_replication -->|"logs failures"| node_recovery
node_concurrency -->|"opens connections"| node_db_pools
node_recovery -->|"stores log entries"| node_db_pools
node_replication -->|"writes replicas"| node_mysql_cluster

click node_frontend "https://github.com/childax/stadvdb-mco2-ddb/blob/main/frontend/src/App.jsx"
click node_frontend_entry "https://github.com/childax/stadvdb-mco2-ddb/blob/main/frontend/src/main.jsx"
click node_api "https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/index.js"
click node_node_config "https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/config/nodes.js"
click node_db_pools "https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/config/db.js"
click node_cluster_routes "https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/routes/cluster.js"
click node_service_routes "https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/routes/services.js"
click node_sharding "https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/utils/sharding.js"
click node_replication "https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/services/replication.js"
click node_concurrency "https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/services/concurrency.js"
click node_recovery "https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/services/recovery.js"
click node_mysql_cluster "https://github.com/childax/stadvdb-mco2-ddb/blob/main/db/schema.sql"

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_frontend,node_frontend_entry,node_api,node_user toneBlue
class node_cluster_routes,node_service_routes toneAmber
class node_sharding,node_replication,node_concurrency,node_recovery toneMint
class node_node_config,node_db_pools,node_mysql_cluster toneRose
```

## Components

### Application Entry

- [React UI](https://github.com/childax/stadvdb-mco2-ddb/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [UI Bootstrap](https://github.com/childax/stadvdb-mco2-ddb/blob/main/frontend/src/main.jsx): `frontend/src/main.jsx`
- [Express Server](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/index.js): `backend/src/index.js`

### API And Routing

- [Cluster Status API](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/routes/cluster.js): `backend/src/routes/cluster.js`
- [Service CRUD API](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/routes/services.js): `backend/src/routes/services.js`

### Transaction Management

- [Fragment Routing](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/utils/sharding.js): `backend/src/utils/sharding.js`
- [Distributed Writes](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/services/replication.js): `backend/src/services/replication.js`
- [SQL Transactions](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/services/concurrency.js): `backend/src/services/concurrency.js`
- [Pending Write Log](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/services/recovery.js): `backend/src/services/recovery.js`

### Distributed Storage

- [Node Configuration](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/config/nodes.js): `backend/src/config/nodes.js`
- [MySQL Pools](https://github.com/childax/stadvdb-mco2-ddb/blob/main/backend/src/config/db.js): `backend/src/config/db.js`
- [Three MySQL Nodes](https://github.com/childax/stadvdb-mco2-ddb/blob/main/db/schema.sql): `db/schema.sql`

### Other components

- **User**

## Connections

- User → React UI: uses (evidence: `README.md`)
- UI Bootstrap → React UI: renders (evidence: `frontend/src/main.jsx`)
- Express Server → Cluster Status API: mounts (evidence: `backend/src/index.js`)
- Express Server → Service CRUD API: mounts (evidence: `backend/src/index.js`)
- MySQL Pools → Node Configuration: loads settings (evidence: `backend/src/config/db.js`)
- MySQL Pools → Three MySQL Nodes: connects (evidence: `backend/src/config/db.js`)
- Cluster Status API → MySQL Pools: checks nodes (evidence: `backend/src/routes/cluster.js`)
- Cluster Status API → Fragment Routing: reports rule (evidence: `backend/src/routes/cluster.js`)
- Service CRUD API → Fragment Routing: routes reads (evidence: `backend/src/routes/services.js`)
- Service CRUD API → Distributed Writes: dispatches writes (evidence: `backend/src/routes/services.js`)
- Fragment Routing → MySQL Pools: queries nodes (evidence: `backend/src/utils/sharding.js`)
- Distributed Writes → Fragment Routing: selects targets (evidence: `backend/src/services/replication.js`)
- Distributed Writes → SQL Transactions: runs transactions (evidence: `backend/src/services/replication.js`)
- Distributed Writes → Pending Write Log: logs failures (evidence: `backend/src/services/replication.js`)
- SQL Transactions → MySQL Pools: opens connections (evidence: `backend/src/services/concurrency.js`)
- Pending Write Log → MySQL Pools: stores log entries (evidence: `backend/src/services/recovery.js`)
- Distributed Writes → Three MySQL Nodes: writes replicas (evidence: `backend/src/services/replication.js`)
