# azaroth-01/opspilot architecture

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

- Interactive diagram: https://gitdiagram.com/azaroth-01/opspilot
- Repository: https://github.com/azaroth-01/opspilot

## Overview

OpsPilot is a backend for incident investigation and simulated recovery. Its main workflow accepts an incident, records it, uses a Gemini-driven agent and diagnostic tools to produce an assessment and optional approval, then allows an operator to approve or reject recovery and verifies service health. Incident simulation is a separate capability that creates sample health and log conditions. The excerpts show route ownership and service calls; the agent's full internal orchestration is only partially excerpted, so its link to Gemini is documented by its source rather than inferred beyond that.

Main entry points: [`backend/routes/agentRoutes.js`](https://github.com/azaroth-01/opspilot/blob/main/backend/routes/agentRoutes.js) (Agent routes), [`backend/agent/agent.js`](https://github.com/azaroth-01/opspilot/blob/main/backend/agent/agent.js) (Incident agent), [`backend/agent/tools.js`](https://github.com/azaroth-01/opspilot/blob/main/backend/agent/tools.js) (Tool dispatch), [`backend/services/healthService.js`](https://github.com/azaroth-01/opspilot/blob/main/backend/services/healthService.js) (Health diagnostics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and workflow"]
  node_server["HTTP server<br/>[server.js]"]
  node_routes["Agent routes<br/>[agentRoutes.js]"]
end

subgraph group_investigation["Agent investigation"]
  node_agent["Incident agent<br/>[agent.js]"]
  node_prompts["Agent prompts<br/>[prompts.js]"]
  node_tools["Tool dispatch<br/>[tools.js]"]
end

subgraph group_operations["Diagnostics and simulation"]
  node_health["Health diagnostics<br/>[healthService.js]"]
  node_logs["Log analysis<br/>[logService.js]"]
  node_simulation["Incident simulation"]
end

subgraph group_lifecycle["Incident and recovery"]
  node_incidents[("Incident lifecycle<br/>[incidentService.js]")]
  node_approvals[("Approval lifecycle<br/>[approvalService.js]")]
  node_recovery["Recovery action<br/>[recoveryService.js]"]
end

node_operator(("Operator"))
node_gemini{{"Gemini API"}}

node_operator -->|"sends requests"| node_server
node_server -->|"routes API"| node_routes
node_routes -->|"creates and updates"| node_incidents
node_routes -->|"starts investigation"| node_agent
node_agent -->|"executes tools"| node_tools
node_agent -.->|"requests assessments"| node_gemini
node_agent -.->|"uses prompt"| node_prompts
node_tools -->|"checks health"| node_health
node_tools -->|"analyzes logs"| node_logs
node_tools -->|"requests approval"| node_approvals
node_routes -->|"triggers simulation"| node_simulation
node_simulation -->|"changes health state"| node_health
node_simulation -->|"resets and adds logs"| node_logs
node_routes -->|"manages approval"| node_approvals
node_routes -->|"executes approved action"| node_recovery
node_routes -->|"verifies recovery"| node_health
node_recovery -->|"restores service"| node_health
node_routes -->|"records recovery state"| node_incidents

click node_server "https://github.com/azaroth-01/opspilot/blob/main/backend/server.js"
click node_routes "https://github.com/azaroth-01/opspilot/blob/main/backend/routes/agentRoutes.js"
click node_agent "https://github.com/azaroth-01/opspilot/blob/main/backend/agent/agent.js"
click node_prompts "https://github.com/azaroth-01/opspilot/blob/main/backend/agent/prompts.js"
click node_tools "https://github.com/azaroth-01/opspilot/blob/main/backend/agent/tools.js"
click node_health "https://github.com/azaroth-01/opspilot/blob/main/backend/services/healthService.js"
click node_logs "https://github.com/azaroth-01/opspilot/blob/main/backend/services/logService.js"
click node_simulation "https://github.com/azaroth-01/opspilot/blob/main/backend/services/incidentSimulationService.js"
click node_incidents "https://github.com/azaroth-01/opspilot/blob/main/backend/services/incidentService.js"
click node_approvals "https://github.com/azaroth-01/opspilot/blob/main/backend/services/approvalService.js"
click node_recovery "https://github.com/azaroth-01/opspilot/blob/main/backend/services/recoveryService.js"

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_server,node_routes toneBlue
class node_agent,node_prompts,node_tools toneAmber
class node_health,node_logs,node_simulation,node_gemini toneMint
class node_incidents,node_approvals,node_recovery toneRose
class node_operator toneIndigo
```

## Components

### API and workflow

- [HTTP server](https://github.com/azaroth-01/opspilot/blob/main/backend/server.js): `backend/server.js`
- [Agent routes](https://github.com/azaroth-01/opspilot/blob/main/backend/routes/agentRoutes.js): `backend/routes/agentRoutes.js`

### Agent investigation

- [Incident agent](https://github.com/azaroth-01/opspilot/blob/main/backend/agent/agent.js): `backend/agent/agent.js`
- [Agent prompts](https://github.com/azaroth-01/opspilot/blob/main/backend/agent/prompts.js): `backend/agent/prompts.js`
- [Tool dispatch](https://github.com/azaroth-01/opspilot/blob/main/backend/agent/tools.js): `backend/agent/tools.js`

### Diagnostics and simulation

- [Health diagnostics](https://github.com/azaroth-01/opspilot/blob/main/backend/services/healthService.js): `backend/services/healthService.js`
- [Log analysis](https://github.com/azaroth-01/opspilot/blob/main/backend/services/logService.js): `backend/services/logService.js`
- [Incident simulation](https://github.com/azaroth-01/opspilot/blob/main/backend/services/incidentSimulationService.js): `backend/services/incidentSimulationService.js`

### Incident and recovery

- [Incident lifecycle](https://github.com/azaroth-01/opspilot/blob/main/backend/services/incidentService.js): `backend/services/incidentService.js`
- [Approval lifecycle](https://github.com/azaroth-01/opspilot/blob/main/backend/services/approvalService.js): `backend/services/approvalService.js`
- [Recovery action](https://github.com/azaroth-01/opspilot/blob/main/backend/services/recoveryService.js): `backend/services/recoveryService.js`

### Other components

- **Operator**
- **Gemini API**

## Connections

- Operator → HTTP server: sends requests (evidence: `backend/server.js`)
- HTTP server → Agent routes: routes API (evidence: `backend/server.js`)
- Agent routes → Incident lifecycle: creates and updates (evidence: `backend/routes/agentRoutes.js`)
- Agent routes → Incident agent: starts investigation (evidence: `backend/routes/agentRoutes.js`)
- Incident agent → Tool dispatch: executes tools (evidence: `backend/agent/agent.js`)
- Incident agent → Gemini API: requests assessments
- Incident agent → Agent prompts: uses prompt
- Tool dispatch → Health diagnostics: checks health (evidence: `backend/agent/tools.js`)
- Tool dispatch → Log analysis: analyzes logs (evidence: `backend/agent/tools.js`)
- Tool dispatch → Approval lifecycle: requests approval (evidence: `backend/agent/tools.js`)
- Agent routes → Incident simulation: triggers simulation (evidence: `backend/routes/agentRoutes.js`)
- Incident simulation → Health diagnostics: changes health state (evidence: `backend/services/incidentSimulationService.js`)
- Incident simulation → Log analysis: resets and adds logs (evidence: `backend/services/incidentSimulationService.js`)
- Agent routes → Approval lifecycle: manages approval (evidence: `backend/routes/agentRoutes.js`)
- Agent routes → Recovery action: executes approved action (evidence: `backend/routes/agentRoutes.js`)
- Agent routes → Health diagnostics: verifies recovery (evidence: `backend/routes/agentRoutes.js`)
- Recovery action → Health diagnostics: restores service (evidence: `backend/services/recoveryService.js`)
- Agent routes → Incident lifecycle: records recovery state (evidence: `backend/routes/agentRoutes.js`)
