# swapnildahiphale/opensre architecture

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

- Interactive diagram: https://gitdiagram.com/swapnildahiphale/opensre
- Repository: https://github.com/swapnildahiphale/opensre

## Overview

1. **Repository shape**
   - This is a multi-service platform for AI-assisted incident investigation, not a single app.
   - The core runtime is split into three application services: `config_service` (backend control plane), `sre-agent` (the investigation agent), and `web_ui` (operator console).
   - Around those are infrastructure modules for PostgreSQL, Neo4j, Kubernetes/EKS, and end-to-end test environments.

2. **High-level request flow**
   - Humans interact through the Next.js web UI or Slack.
   - The UI talks mostly to `config_service` for org/team configuration, templates, auth, audits, tokens, and knowledge management.
   - For live investigations, the UI streams to `sre-agent`, which orchestrates the investigation and returns results incrementally.
   - The agent reads configuration and stores/retrieves state from PostgreSQL, while consulting Neo4j for topology and dependency context.

3. **`config_service`: control plane and source of truth**
   - This FastAPI service is the administrative backend.
   - It owns configuration models, templates, team/org hierarchy, integrations, security policies, scheduled jobs, visitor sessions, audit logs, and token management.
   - Alembic migrations show the service is the canonical owner of persistent schema evolution.
   - It also includes encryption support, YAML config handling, dependency validation, and seeded “golden templates” for common incident workflows.

4. **`sre-agent`: autonomous investigation runtime**
   - This is the LangGraph-based agent runtime.
   - Its node graph is organized around `init_context`, `planner`, `subagent_executor`, `synthesizer`, `writeup`, plus memory and knowledge-graph enrichment nodes.
   - The agent is the execution engine that turns an incident prompt into a plan, tool calls, reasoning steps, evidence synthesis, and a final report.
   - It is designed around streamed execution, which is why the UI exposes agent-stream and trace endpoints.

5. **Agent memory subsystem**
   - The agent has a dedicated memory layer under `sre-agent/memory`.
   - This captures episodic memory, strategy generation, lookup, and storage so prior investigations influence future ones.
   - Conceptually, this is the “learn from every incident” layer: past incidents, hints, and patterns are retained and surfaced during new runs.
   - The web UI also exposes memory browsing/search pages, indicating memory is user-visible, not just internal state.

6. **Knowledge graph / topology subsystem**
   - Neo4j is a first-class architectural dependency, used to model service relationships and blast radius.
   - The agent has dedicated graph-related code and a semantic layer for querying service dependencies.
   - The web UI exposes topology and knowledge tree views, so topology is not just for agent reasoning; it is also an operational admin surface.
   - In diagram terms, Neo4j sits alongside Postgres, with the agent reading both for complementary context.

7. **Tooling and integrations boundary**
   - The platform is integration-heavy: Datadog, Grafana, PagerDuty, Elasticsearch, Kubernetes, AWS, Slack, GitHub, and others are reflected in route names, templates, and tool catalogs.
   - `config_service` manages integration schemas and metadata; `sre-agent` contains the actual skill/tool execution layer.
   - The “golden templates” and templates JSON files define reusable playbooks for specific workflows like Slack incident triage, CI auto-fix, AWS cost reduction, and observability review.
   - This separation matters: configuration lives in the control plane, while operational API calls happen inside the agent runtime.

8. **UI as a thin product shell**
   - `web_ui` is a Next.js application with app-router pages for team, admin, incidents, memory, integrations, settings, learning, and investigation review.
   - It includes many route handlers under `src/app/api`, which act as a BFF/proxy layer to the backend services rather than holding core business logic.
   - The UI contains auth/session handling, role/permission gates, visitor flows, and streamed agent interaction components.
   - It is the user-facing orchestration layer, but not the system of record.

9. **Authentication, roles, and audit**
   - Auth is multi-mode: admin/token-based access, SSO/OIDC, visitor sessions, and team tokens.
   - The backend includes explicit RBAC/admin permission logic and audit logging, which suggests strong governance around configuration changes and sensitive operations.
   - The UI mirrors these boundaries with `RequireRole`, `RequirePermission`, and sign-in/session components.
   - Token audit, revocation, extension, and admin endpoints indicate that access control is a core product concern.

10. **Persistence and schema ownership**
   - PostgreSQL is the durable store for config, tokens, audit records, scheduled jobs, and agent-related state.
   - The `config_service` repository owns the DB models, repositories, and Alembic migrations.
   - Encryption support and SQLAlchemy custom types suggest some fields are protected at rest.
   - This makes Postgres the operational system of record, while Neo4j is the relationship model.

11. **Deployment and infrastructure**
   - `config_service` and `web_ui` each have Dockerfiles and Terraform/Kubernetes deployment assets, showing they are independently deployable services.
   - There is Terraform for both application infrastructure and database infrastructure, plus Kubernetes manifests and scripts for EKS setup.
   - `make`-based workflows and scripts indicate local development and production deployment are both first-class.
   - The repo supports Docker Compose for local multi-service startup and Kubernetes/EKS for real cluster validation.

12. **Test and demo environments**
   - There are dedicated E2E and fault-injection scripts for Kind and EKS using the OpenTelemetry demo application.
   - The `test-infra` directory contains cluster setup, port-forwarding, SSE parsing, and teardown helpers.
   - This is important architecturally because the agent is validated against live service telemetry, not just unit tests.
   - The test harness is part of the product story: it exercises the full loop from fault injection to investigation output.

13. **What an architecture diagram should emphasize**
   - Show three primary application boxes: control plane (`config_service`), reasoning engine (`sre-agent`), and operator UI (`web_ui`).
   - Put PostgreSQL and Neo4j as the two central data stores with different responsibilities.
   - Show external integrations/tool providers on the agent side, and auth/identity providers on the control-plane/UI side.
   - Add Slack and EKS/OpenTelemetry demo as important external entry points for real incident workflows and end-to-end validation.

Main entry points: [`sre-agent/graph.py`](https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/graph.py) (Agent graph), [`config_service/src/api/main.py`](https://github.com/swapnildahiphale/opensre/blob/main/config_service/src/api/main.py) (config_service), [`web_ui/src/app/api/team/agent/stream/route.ts`](https://github.com/swapnildahiphale/opensre/blob/main/web_ui/src/app/api/team/agent/stream/route.ts) (BFF routes), [`sre-agent/server.py`](https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/server.py) (sre-agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_control_plane["Control Plane"]
  node_config_service_api["config_service<br/>FastAPI backend<br/>[main.py]"]
  node_config_service_core["Core config<br/>policy/config layer<br/>[config_models.py]"]
  node_config_service_db[("DB layer<br/>SQLAlchemy repos")]
  node_config_service_migrations["Migrations<br/>Alembic schema"]
  node_config_service_templates["Golden templates<br/>playbooks<br/>[planner.md]"]
end

subgraph group_group_agent["Agent Runtime"]
  node_agent_server["sre-agent<br/>LangGraph runtime<br/>[server.py]"]
  node_agent_graph{{"Agent graph<br/>workflow graph<br/>[graph.py]"}}
  node_agent_init["Init context<br/>graph node<br/>[init_context.py]"]
  node_agent_planner["Planner<br/>graph node<br/>[planner.py]"]
  node_agent_executor["Subagent exec<br/>graph node"]
  node_agent_memory[("Memory layer<br/>episodic memory<br/>[integration.py]")]
  node_agent_kg{{"KG context<br/>topology context<br/>[kg_context.py]"}}
  node_agent_writeup["Writeup<br/>report node<br/>[writeup.py]"]
end

subgraph group_group_ui["Operator UI"]
  node_web_ui_app["web_ui<br/>Next.js app<br/>[page.tsx]"]
  node_web_ui_api["BFF routes<br/>route handlers<br/>[route.ts]"]
  node_web_ui_auth["Auth gates<br/>session/rbac UI<br/>[RequireRole.tsx]"]
  node_web_ui_memory["Memory views<br/>UI pages<br/>[page.tsx]"]
  node_web_ui_topology["Topology views<br/>UI pages<br/>[route.ts]"]
end

subgraph group_group_data["Data Stores"]
  node_postgres[("PostgreSQL<br/>durable store<br/>[main.tf]")]
  node_neo4j[("Neo4j<br/>graph store<br/>[populate_neo4j.py]")]
end

subgraph group_group_infra["Infra & Validation"]
  node_eks_demo["EKS demo<br/>validation env<br/>[setup.sh]"]
  node_slack(("Slack<br/>incident entrypoint<br/>[aws.md]"))
  node_deploy_infra{{"Deploy infra<br/>terraform/k8s<br/>[main.tf]"}}
end

node_web_ui_app -->|"uses"| node_web_ui_api
node_web_ui_api -->|"admin/config"| node_config_service_api
node_web_ui_api -->|"stream/run"| node_agent_server
node_web_ui_api -->|"session/state"| node_postgres
node_web_ui_auth -->|"gates"| node_web_ui_app
node_web_ui_memory -->|"browse"| node_agent_memory
node_web_ui_topology -->|"explore"| node_neo4j
node_agent_server -->|"executes"| node_agent_graph
node_agent_graph -->|"starts"| node_agent_init
node_agent_graph -->|"plans"| node_agent_planner
node_agent_graph -->|"calls tools"| node_agent_executor
node_agent_graph -->|"consults"| node_agent_memory
node_agent_graph -->|"enriches"| node_agent_kg
node_agent_graph -->|"finishes"| node_agent_writeup
node_agent_memory -->|"stores/loads"| node_postgres
node_agent_kg -->|"queries"| node_neo4j
node_config_service_api -->|"uses"| node_config_service_core
node_config_service_api -->|"persists"| node_config_service_db
node_config_service_db -->|"stores"| node_postgres
node_config_service_migrations -->|"evolves"| node_postgres
node_config_service_templates -->|"seeds"| node_config_service_core
node_slack -.->|"intake"| node_web_ui_app
node_slack -->|"workspace config"| node_config_service_api
node_eks_demo -->|"validates"| node_agent_server
node_deploy_infra -->|"deploys"| node_config_service_api
node_deploy_infra -->|"deploys"| node_web_ui_app
node_deploy_infra -->|"deploys"| node_agent_server

click node_config_service_api "https://github.com/swapnildahiphale/opensre/blob/main/config_service/src/api/main.py"
click node_config_service_core "https://github.com/swapnildahiphale/opensre/blob/main/config_service/src/core/config_models.py"
click node_config_service_db "https://github.com/swapnildahiphale/opensre/blob/main/config_service/src/db/config_repository.py"
click node_config_service_migrations "https://github.com/swapnildahiphale/opensre/blob/main/config_service/alembic/versions/20260312_agent_run_thoughts.py"
click node_config_service_templates "https://github.com/swapnildahiphale/opensre/blob/main/config_service/golden_templates/01_slack_incident_triage/planner.md"
click node_agent_server "https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/server.py"
click node_agent_graph "https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/graph.py"
click node_agent_init "https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/nodes/init_context.py"
click node_agent_planner "https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/nodes/planner.py"
click node_agent_executor "https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/nodes/subagent_executor.py"
click node_agent_memory "https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/memory/integration.py"
click node_agent_kg "https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/nodes/kg_context.py"
click node_agent_writeup "https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/nodes/writeup.py"
click node_web_ui_app "https://github.com/swapnildahiphale/opensre/blob/main/web_ui/src/app/page.tsx"
click node_web_ui_api "https://github.com/swapnildahiphale/opensre/blob/main/web_ui/src/app/api/team/agent/stream/route.ts"
click node_web_ui_auth "https://github.com/swapnildahiphale/opensre/blob/main/web_ui/src/components/RequireRole.tsx"
click node_web_ui_memory "https://github.com/swapnildahiphale/opensre/blob/main/web_ui/src/app/team/memory/page.tsx"
click node_web_ui_topology "https://github.com/swapnildahiphale/opensre/blob/main/web_ui/src/app/api/topology/nodes/route.ts"
click node_postgres "https://github.com/swapnildahiphale/opensre/blob/main/database/infra/terraform/main.tf"
click node_neo4j "https://github.com/swapnildahiphale/opensre/blob/main/scripts/populate_neo4j.py"
click node_eks_demo "https://github.com/swapnildahiphale/opensre/blob/main/test-infra/eks/setup.sh"
click node_slack "https://github.com/swapnildahiphale/opensre/blob/main/config_service/golden_templates/01_slack_incident_triage/aws.md"
click node_deploy_infra "https://github.com/swapnildahiphale/opensre/blob/main/web_ui/infra/terraform/main.tf"

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_config_service_api,node_config_service_core,node_config_service_db,node_config_service_migrations,node_config_service_templates toneBlue
class node_agent_server,node_agent_graph,node_agent_init,node_agent_planner,node_agent_executor,node_agent_memory,node_agent_kg,node_agent_writeup toneAmber
class node_web_ui_app,node_web_ui_api,node_web_ui_auth,node_web_ui_memory,node_web_ui_topology toneMint
class node_postgres,node_neo4j toneRose
class node_eks_demo,node_slack,node_deploy_infra toneIndigo
```

## Components

### Control Plane

Administrative backend and source of truth

- [config_service](https://github.com/swapnildahiphale/opensre/blob/main/config_service/src/api/main.py): FastAPI backend · Administrative service for configuration, auth, templates, audits, tokens, and workflows · `config_service/src/api/main.py`
- [Core config](https://github.com/swapnildahiphale/opensre/blob/main/config_service/src/core/config_models.py): policy/config layer · Configuration models, RBAC, validation, YAML handling, and dependency rules · `config_service/src/core/config_models.py`
- [DB layer](https://github.com/swapnildahiphale/opensre/blob/main/config_service/src/db/config_repository.py): SQLAlchemy repos · Repository and model layer for persistent config and operational records · `config_service/src/db/config_repository.py`
- [Migrations](https://github.com/swapnildahiphale/opensre/blob/main/config_service/alembic/versions/20260312_agent_run_thoughts.py): Alembic schema · Canonical schema evolution for the control-plane database · `config_service/alembic/versions/20260312_agent_run_thoughts.py`
- [Golden templates](https://github.com/swapnildahiphale/opensre/blob/main/config_service/golden_templates/01_slack_incident_triage/planner.md): playbooks · Seeded incident workflows and reusable agent prompt templates · `config_service/golden_templates/01_slack_incident_triage/planner.md`

### Agent Runtime

Investigation execution, memory, and knowledge-graph context

- [sre-agent](https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/server.py): LangGraph runtime · Streaming investigation engine that plans, calls tools, synthesizes evidence, and writes reports · `sre-agent/server.py`
- [Agent graph](https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/graph.py): workflow graph · Orchestrates init, planning, subagent execution, synthesis, memory, and writeup · `sre-agent/graph.py`
- [Init context](https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/nodes/init_context.py): graph node · Builds the investigation context before execution · `sre-agent/nodes/init_context.py`
- [Planner](https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/nodes/planner.py): graph node · Converts the incident prompt into an investigation plan · `sre-agent/nodes/planner.py`
- [Subagent exec](https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/nodes/subagent_executor.py): graph node · Runs investigative tool calls and parallel substeps · `sre-agent/nodes/subagent_executor.py`
- [Memory layer](https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/memory/integration.py): episodic memory · Lookup, strategy generation, hinting, and storage across incidents · `sre-agent/memory/integration.py`
- [KG context](https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/nodes/kg_context.py): topology context · Queries service relationships and blast-radius context from Neo4j · `sre-agent/nodes/kg_context.py`
- [Writeup](https://github.com/swapnildahiphale/opensre/blob/main/sre-agent/nodes/writeup.py): report node · Produces the final incident narrative and structured findings · `sre-agent/nodes/writeup.py`

### Operator UI

Next.js console and BFF routes

- [web_ui](https://github.com/swapnildahiphale/opensre/blob/main/web_ui/src/app/page.tsx): Next.js app · Operator console with app-router pages, auth, memory, topology, and investigation review · `web_ui/src/app/page.tsx`
- [BFF routes](https://github.com/swapnildahiphale/opensre/blob/main/web_ui/src/app/api/team/agent/stream/route.ts): route handlers · Proxy and orchestration layer that forwards UI actions to backend services · `web_ui/src/app/api/team/agent/stream/route.ts`
- [Auth gates](https://github.com/swapnildahiphale/opensre/blob/main/web_ui/src/components/RequireRole.tsx): session/rbac UI · Sign-in, visitor sessions, role checks, and permission guards · `web_ui/src/components/RequireRole.tsx`
- [Memory views](https://github.com/swapnildahiphale/opensre/blob/main/web_ui/src/app/team/memory/page.tsx): UI pages · Browsing, search, and stats for incident memory and strategies · `web_ui/src/app/team/memory/page.tsx`
- [Topology views](https://github.com/swapnildahiphale/opensre/blob/main/web_ui/src/app/api/topology/nodes/route.ts): UI pages · Operational views for service graph and knowledge tree exploration · `web_ui/src/app/api/topology/nodes/route.ts`

### Data Stores

Persistent stores for configuration and topology

- [PostgreSQL](https://github.com/swapnildahiphale/opensre/blob/main/database/infra/terraform/main.tf): durable store · System of record for configuration, tokens, audits, jobs, and agent state · `database/infra/terraform/main.tf`
- [Neo4j](https://github.com/swapnildahiphale/opensre/blob/main/scripts/populate_neo4j.py): graph store · Dependency and topology model for service relationships and blast radius · `scripts/populate_neo4j.py`

### Infra & Validation

Deployment, local startup, and end-to-end environments

- [EKS demo](https://github.com/swapnildahiphale/opensre/blob/main/test-infra/eks/setup.sh): validation env · Kind/EKS OpenTelemetry demo environment used for live incident validation · `test-infra/eks/setup.sh`
- [Slack](https://github.com/swapnildahiphale/opensre/blob/main/config_service/golden_templates/01_slack_incident_triage/aws.md): incident entrypoint · Human-facing incident intake and workflow surface · `config_service/golden_templates/01_slack_incident_triage/aws.md`
- [Deploy infra](https://github.com/swapnildahiphale/opensre/blob/main/web_ui/infra/terraform/main.tf): terraform/k8s · Docker, Kubernetes, and Terraform assets for service deployment and local startup · `web_ui/infra/terraform/main.tf`

## Connections

- web_ui → BFF routes: uses · UI actions and page data flow through BFF route handlers
- BFF routes → config_service: admin/config · Admin pages and config views proxy to the control plane
- BFF routes → sre-agent: stream/run · Investigation pages stream live runs from the agent runtime
- BFF routes → PostgreSQL: session/state · UI-backed session and team data are persisted through backend services
- Auth gates → web_ui: gates · Role and permission components guard sensitive pages
- Memory views → Memory layer: browse · Memory pages expose investigation memory for operators
- Topology views → Neo4j: explore · Topology and knowledge tree views surface relationship data
- sre-agent → Agent graph: executes · The server hosts the LangGraph workflow runtime
- Agent graph → Init context: starts · Investigation runs begin by constructing context
- Agent graph → Planner: plans · Planning node derives investigation steps
- Agent graph → Subagent exec: calls tools · Executor runs subagents and operational tool calls
- Agent graph → Memory layer: consults · Graph uses memory for recall and strategy reuse
- Agent graph → KG context: enriches · Graph pulls topology context for dependency reasoning
- Agent graph → Writeup: finishes · Final synthesis becomes the incident report
- Memory layer → PostgreSQL: stores/loads · Memory state and investigation artifacts are persisted in Postgres
- KG context → Neo4j: queries · Knowledge-graph context comes from Neo4j
- config_service → Core config: uses · API routes are backed by validation, RBAC, encryption, and YAML logic
- config_service → DB layer: persists · Control-plane resources are written through repository abstractions
- DB layer → PostgreSQL: stores · Canonical configuration and audit data live in PostgreSQL
- Migrations → PostgreSQL: evolves · Alembic migrations define the database schema owned by the control plane
- Golden templates → Core config: seeds · Golden templates feed the template/config management layer
- Slack → web_ui: intake · Slack is a primary external incident entrypoint surfaced through the product
- Slack → config_service: workspace config · Slack app and token metadata are managed in the control plane
- EKS demo → sre-agent: validates · End-to-end validation exercises the agent against live telemetry
- Deploy infra → config_service: deploys · Service deployment assets package the control-plane runtime
- Deploy infra → web_ui: deploys · Infra assets package the UI runtime
- Deploy infra → sre-agent: deploys · Infra assets package the agent runtime
