# praneeth-nyc/distributed_database_system architecture

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

- Interactive diagram: https://gitdiagram.com/praneeth-nyc/distributed_database_system
- Repository: https://github.com/praneeth-nyc/distributed_database_system

## Overview

This repository implements a small distributed employee database: clients submit employee operations to a FastAPI node, leaders append changes to a Raft log, and applied entries update the employee table. Nodes also expose Raft state and protocol endpoints, coordinate elections and replication over HTTP, and persist Raft state, logs, and snapshots in MySQL. The graph follows shown calls and documented module references; snapshot internals and some runtime wiring are not excerpted, so uncertain links are omitted.

Main entry points: [`services/dependencies.py`](https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/dependencies.py) (Service wiring), [`services/raft_services.py`](https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/raft_services.py) (Raft state machine), [`node/main.py`](https://github.com/praneeth-nyc/distributed_database_system/blob/main/node/main.py) (FastAPI app), [`database/database.py`](https://github.com/praneeth-nyc/distributed_database_system/blob/main/database/database.py) (Database adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and models"]
  node_app["FastAPI app<br/>[main.py]"]
  node_employee_routes["Employee routes<br/>[employee.py]"]
  node_raft_routes["Raft routes<br/>[raft.py]"]
  node_health_routes["Health route<br/>[health.py]"]
  node_models["API and log models<br/>[models.py]"]
  node_employee_service["Employee operations"]
end

subgraph group_raft["Raft coordination"]
  node_raft_service["Raft state machine<br/>[raft_services.py]"]
  node_cluster_service["Peer transport"]
  node_replication_service["Log application"]
  node_snapshot_service["Snapshot management"]
end

subgraph group_storage["Persistence and data"]
  node_persistence["Raft persistence"]
  node_database["Database adapter<br/>[database.py]"]
end

subgraph group_setup["Node setup"]
  node_dependencies["Service wiring<br/>[dependencies.py]"]
  node_config["Node configuration<br/>[config.py]"]
  node_run["Process entry<br/>[run.py]"]
end

node_client(("API client"))
node_mysql[("MySQL")]
node_peer_nodes(("Peer nodes"))

node_run -->|"loads configuration"| node_config
node_run -->|"creates app"| node_app
node_app -->|"initializes services"| node_dependencies
node_app -->|"registers route"| node_health_routes
node_app -->|"registers route"| node_employee_routes
node_app -->|"registers route"| node_raft_routes
node_client -->|"requests"| node_employee_routes
node_client -->|"requests"| node_raft_routes
node_client -->|"checks health"| node_health_routes
node_employee_routes -->|"dispatches"| node_employee_service
node_employee_routes -->|"validates payloads"| node_models
node_raft_routes -->|"dispatches"| node_raft_service
node_raft_routes -->|"validates payloads"| node_models
node_employee_service -->|"appends operations"| node_raft_service
node_employee_service -->|"reads employee data"| node_database
node_raft_service -->|"loads and saves state"| node_persistence
node_raft_service -->|"dispatches replication"| node_cluster_service
node_raft_service -->|"applies committed logs"| node_replication_service
node_raft_service -->|"creates snapshots"| node_snapshot_service
node_cluster_service -->|"sends Raft messages"| node_peer_nodes
node_replication_service -->|"updates employees"| node_database
node_persistence -->|"executes queries"| node_database
node_database -->|"connects and queries"| node_mysql
node_dependencies -->|"constructs adapter"| node_database
node_dependencies -->|"constructs service"| node_persistence
node_dependencies -->|"constructs service"| node_raft_service
node_dependencies -->|"constructs service"| node_cluster_service
node_dependencies -->|"constructs service"| node_snapshot_service
node_dependencies -->|"loads settings"| node_config

click node_app "https://github.com/praneeth-nyc/distributed_database_system/blob/main/node/main.py"
click node_employee_routes "https://github.com/praneeth-nyc/distributed_database_system/blob/main/node/routes/employee.py"
click node_raft_routes "https://github.com/praneeth-nyc/distributed_database_system/blob/main/node/routes/raft.py"
click node_health_routes "https://github.com/praneeth-nyc/distributed_database_system/blob/main/node/routes/health.py"
click node_models "https://github.com/praneeth-nyc/distributed_database_system/blob/main/node/models.py"
click node_employee_service "https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/employee_services.py"
click node_raft_service "https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/raft_services.py"
click node_cluster_service "https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/cluster_services.py"
click node_replication_service "https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/replication_services.py"
click node_snapshot_service "https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/snapshot_services.py"
click node_dependencies "https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/dependencies.py"
click node_config "https://github.com/praneeth-nyc/distributed_database_system/blob/main/config/config.py"
click node_run "https://github.com/praneeth-nyc/distributed_database_system/blob/main/run.py"
click node_persistence "https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/persistence_services.py"
click node_database "https://github.com/praneeth-nyc/distributed_database_system/blob/main/database/database.py"

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_app,node_employee_routes,node_raft_routes,node_health_routes,node_models,node_employee_service,node_client toneBlue
class node_raft_service,node_cluster_service,node_replication_service,node_snapshot_service,node_mysql toneAmber
class node_persistence,node_database toneMint
class node_dependencies,node_config,node_run toneRose
class node_peer_nodes toneIndigo
```

## Components

### API and models

- [FastAPI app](https://github.com/praneeth-nyc/distributed_database_system/blob/main/node/main.py): `node/main.py`
- [Employee routes](https://github.com/praneeth-nyc/distributed_database_system/blob/main/node/routes/employee.py): `node/routes/employee.py`
- [Raft routes](https://github.com/praneeth-nyc/distributed_database_system/blob/main/node/routes/raft.py): `node/routes/raft.py`
- [Health route](https://github.com/praneeth-nyc/distributed_database_system/blob/main/node/routes/health.py): `node/routes/health.py`
- [API and log models](https://github.com/praneeth-nyc/distributed_database_system/blob/main/node/models.py): `node/models.py`
- [Employee operations](https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/employee_services.py): `services/employee_services.py`

### Raft coordination

- [Raft state machine](https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/raft_services.py): `services/raft_services.py`
- [Peer transport](https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/cluster_services.py): `services/cluster_services.py`
- [Log application](https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/replication_services.py): `services/replication_services.py`
- [Snapshot management](https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/snapshot_services.py): `services/snapshot_services.py`

### Persistence and data

- [Raft persistence](https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/persistence_services.py): `services/persistence_services.py`
- [Database adapter](https://github.com/praneeth-nyc/distributed_database_system/blob/main/database/database.py): `database/database.py`

### Node setup

- [Service wiring](https://github.com/praneeth-nyc/distributed_database_system/blob/main/services/dependencies.py): `services/dependencies.py`
- [Node configuration](https://github.com/praneeth-nyc/distributed_database_system/blob/main/config/config.py): `config/config.py`
- [Process entry](https://github.com/praneeth-nyc/distributed_database_system/blob/main/run.py): `run.py`

### Other components

- **API client**
- **MySQL**
- **Peer nodes**

## Connections

- Process entry → Node configuration: loads configuration (evidence: `run.py`)
- Process entry → FastAPI app: creates app (evidence: `run.py`)
- FastAPI app → Service wiring: initializes services (evidence: `node/main.py`)
- FastAPI app → Health route: registers route (evidence: `node/main.py`)
- FastAPI app → Employee routes: registers route (evidence: `node/main.py`)
- FastAPI app → Raft routes: registers route (evidence: `node/main.py`)
- API client → Employee routes: requests (evidence: `node/routes/employee.py`)
- API client → Raft routes: requests (evidence: `node/routes/raft.py`)
- API client → Health route: checks health (evidence: `node/routes/health.py`)
- Employee routes → Employee operations: dispatches (evidence: `node/routes/employee.py`)
- Employee routes → API and log models: validates payloads (evidence: `node/routes/employee.py`)
- Raft routes → Raft state machine: dispatches (evidence: `node/routes/raft.py`)
- Raft routes → API and log models: validates payloads (evidence: `node/routes/raft.py`)
- Employee operations → Raft state machine: appends operations (evidence: `services/employee_services.py`)
- Employee operations → Database adapter: reads employee data (evidence: `services/employee_services.py`)
- Raft state machine → Raft persistence: loads and saves state (evidence: `services/raft_services.py`)
- Raft state machine → Peer transport: dispatches replication (evidence: `services/raft_services.py`)
- Raft state machine → Log application: applies committed logs (evidence: `services/raft_services.py`)
- Raft state machine → Snapshot management: creates snapshots (evidence: `services/raft_services.py`)
- Peer transport → Peer nodes: sends Raft messages (evidence: `services/cluster_services.py`)
- Log application → Database adapter: updates employees (evidence: `services/replication_services.py`)
- Raft persistence → Database adapter: executes queries (evidence: `services/persistence_services.py`)
- Database adapter → MySQL: connects and queries (evidence: `database/database.py`)
- Service wiring → Database adapter: constructs adapter (evidence: `services/dependencies.py`)
- Service wiring → Raft persistence: constructs service (evidence: `services/dependencies.py`)
- Service wiring → Raft state machine: constructs service (evidence: `services/dependencies.py`)
- Service wiring → Peer transport: constructs service (evidence: `services/dependencies.py`)
- Service wiring → Snapshot management: constructs service (evidence: `services/dependencies.py`)
- Service wiring → Node configuration: loads settings (evidence: `services/dependencies.py`)
