# nohithadachepalli/policy_drift_agent architecture

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

- Interactive diagram: https://gitdiagram.com/nohithadachepalli/policy_drift_agent
- Repository: https://github.com/nohithadachepalli/policy_drift_agent

## Overview

Policy Drift Agent compares submitted operational cases with written SOPs, recalls historical outcomes, and produces evidence-backed recommendations for human review. The primary flow runs from case submission through policy comparison, memory recall, analysis, and a recommendation; recorded decisions and outcomes enrich persistent memory. The README documents additional policy, dashboard, insights, timeline, and demo capabilities. Some route and frontend wiring is inferred from documented responsibilities because those source excerpts were not sampled.

Main entry points: [`frontend/src/services/api.ts`](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/services/api.ts) (REST API client), [`backend/app/main.py`](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/main.py) (FastAPI application), [`backend/app/routes/cases.py`](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/routes/cases.py) (Case endpoints), [`backend/app/services/hindsight_service.py`](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/services/hindsight_service.py) (Persistent memory client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["App shell<br/>[App.tsx]"]
  node_case_form["Case submission"]
  node_recommendation["Recommendation review"]
  node_policy_views["Policy library and detail"]
  node_dashboard_view["Dashboard<br/>[DashboardPage.tsx]"]
  node_learning_views["Memory, insights, demo"]
  node_api_client["REST API client<br/>[api.ts]"]
end

subgraph group_api["API surface"]
  node_server["FastAPI application<br/>[main.py]"]
  node_case_routes["Case endpoints<br/>[cases.py]"]
  node_policy_routes["Policy endpoints<br/>[policies.py]"]
  node_memory_routes["Memory endpoints<br/>[memory.py]"]
  node_insight_routes["Insights and dashboard endpoints<br/>[insights.py]"]
  node_demo_routes["Demo endpoints<br/>[demo.py]"]
end

subgraph group_analysis["Policy analysis"]
  node_analysis_service["Case analysis orchestrator"]
  node_policy_service["SOP comparison<br/>[policy_service.py]"]
  node_policy_store[("SOP definitions<br/>[database.py]")]
  node_groq_service["LLM reasoning client<br/>[groq_service.py]"]
end

subgraph group_learning["Memory and learning"]
  node_insight_service["Drift metrics and insights<br/>[insight_service.py]"]
  node_hindsight_service["Persistent memory client"]
end

node_operator(("Operations user"))
node_hindsight_cloud[("Hindsight Cloud")]
node_groq_api{{"Groq API"}}

node_operator -->|"uses"| node_app
node_app -->|"shows"| node_case_form
node_app -->|"shows"| node_policy_views
node_app -->|"shows"| node_dashboard_view
node_app -->|"shows"| node_learning_views
node_case_form -->|"submits case"| node_api_client
node_api_client -->|"REST requests"| node_server
node_server -->|"dispatches"| node_case_routes
node_server -->|"dispatches"| node_policy_routes
node_server -->|"dispatches"| node_memory_routes
node_server -->|"dispatches"| node_insight_routes
node_server -->|"dispatches"| node_demo_routes
node_case_routes -->|"analyzes case"| node_analysis_service
node_analysis_service -->|"compares steps"| node_policy_service
node_policy_service -->|"reads SOPs"| node_policy_store
node_analysis_service -->|"recalls cases"| node_hindsight_service
node_analysis_service -->|"requests reasoning"| node_groq_service
node_groq_service -->|"completion request"| node_groq_api
node_hindsight_service -->|"recall and retain"| node_hindsight_cloud
node_analysis_service -->|"returns recommendation"| node_case_routes
node_case_routes -->|"returns result"| node_recommendation
node_recommendation -->|"records decision"| node_api_client
node_api_client -->|"decision request"| node_case_routes
node_case_routes -->|"retains outcome"| node_hindsight_service
node_policy_routes -->|"reads policies"| node_policy_store
node_insight_routes -->|"requests metrics"| node_insight_service
node_insight_service -->|"reads policy data"| node_policy_store
node_insight_service -->|"loads experiences"| node_hindsight_service
node_memory_routes -->|"manages memories"| node_hindsight_service
node_demo_routes -->|"runs demo memory"| node_hindsight_service
node_api_client -->|"fetches policies"| node_policy_routes
node_api_client -->|"fetches summaries"| node_insight_routes
node_api_client -->|"fetches timeline"| node_memory_routes

click node_app "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/App.tsx"
click node_case_form "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/pages/AnalyzeCasePage.tsx"
click node_recommendation "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/pages/RecommendationView.tsx"
click node_policy_views "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/pages/PolicyLibraryPage.tsx"
click node_dashboard_view "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/pages/DashboardPage.tsx"
click node_learning_views "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/pages/MemoryTimelinePage.tsx"
click node_api_client "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/services/api.ts"
click node_server "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/main.py"
click node_case_routes "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/routes/cases.py"
click node_policy_routes "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/routes/policies.py"
click node_memory_routes "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/routes/memory.py"
click node_insight_routes "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/routes/insights.py"
click node_demo_routes "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/routes/demo.py"
click node_analysis_service "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/services/analysis_service.py"
click node_policy_service "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/services/policy_service.py"
click node_policy_store "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/models/database.py"
click node_insight_service "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/services/insight_service.py"
click node_hindsight_service "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/services/hindsight_service.py"
click node_groq_service "https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/services/groq_service.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_case_form,node_recommendation,node_policy_views,node_dashboard_view,node_learning_views,node_api_client,node_operator toneBlue
class node_server,node_case_routes,node_policy_routes,node_memory_routes,node_insight_routes,node_demo_routes,node_hindsight_cloud toneAmber
class node_analysis_service,node_policy_service,node_policy_store,node_groq_service,node_groq_api toneMint
class node_insight_service,node_hindsight_service toneRose
```

## Components

### Web application

- [App shell](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Case submission](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/pages/AnalyzeCasePage.tsx): `frontend/src/pages/AnalyzeCasePage.tsx`
- [Recommendation review](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/pages/RecommendationView.tsx): `frontend/src/pages/RecommendationView.tsx`
- [Policy library and detail](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/pages/PolicyLibraryPage.tsx): `frontend/src/pages/PolicyLibraryPage.tsx`
- [Dashboard](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/pages/DashboardPage.tsx): `frontend/src/pages/DashboardPage.tsx`
- [Memory, insights, demo](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/pages/MemoryTimelinePage.tsx): `frontend/src/pages/MemoryTimelinePage.tsx`
- [REST API client](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`

### API surface

- [FastAPI application](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/main.py): `backend/app/main.py`
- [Case endpoints](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/routes/cases.py): `backend/app/routes/cases.py`
- [Policy endpoints](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/routes/policies.py): `backend/app/routes/policies.py`
- [Memory endpoints](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/routes/memory.py): `backend/app/routes/memory.py`
- [Insights and dashboard endpoints](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/routes/insights.py): `backend/app/routes/insights.py`
- [Demo endpoints](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/routes/demo.py): `backend/app/routes/demo.py`

### Policy analysis

- [Case analysis orchestrator](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/services/analysis_service.py): `backend/app/services/analysis_service.py`
- [SOP comparison](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/services/policy_service.py): `backend/app/services/policy_service.py`
- [SOP definitions](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/models/database.py): `backend/app/models/database.py`
- [LLM reasoning client](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/services/groq_service.py): `backend/app/services/groq_service.py`

### Memory and learning

- [Drift metrics and insights](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/services/insight_service.py): `backend/app/services/insight_service.py`
- [Persistent memory client](https://github.com/nohithadachepalli/policy_drift_agent/blob/main/backend/app/services/hindsight_service.py): `backend/app/services/hindsight_service.py`

### Other components

- **Operations user**
- **Hindsight Cloud**
- **Groq API**

## Connections

- Operations user → App shell: uses
- App shell → Case submission: shows
- App shell → Policy library and detail: shows
- App shell → Dashboard: shows
- App shell → Memory, insights, demo: shows
- Case submission → REST API client: submits case
- REST API client → FastAPI application: REST requests
- FastAPI application → Case endpoints: dispatches
- FastAPI application → Policy endpoints: dispatches
- FastAPI application → Memory endpoints: dispatches
- FastAPI application → Insights and dashboard endpoints: dispatches
- FastAPI application → Demo endpoints: dispatches
- Case endpoints → Case analysis orchestrator: analyzes case
- Case analysis orchestrator → SOP comparison: compares steps
- SOP comparison → SOP definitions: reads SOPs
- Case analysis orchestrator → Persistent memory client: recalls cases
- Case analysis orchestrator → LLM reasoning client: requests reasoning
- LLM reasoning client → Groq API: completion request
- Persistent memory client → Hindsight Cloud: recall and retain
- Case analysis orchestrator → Case endpoints: returns recommendation
- Case endpoints → Recommendation review: returns result
- Recommendation review → REST API client: records decision
- REST API client → Case endpoints: decision request
- Case endpoints → Persistent memory client: retains outcome
- Policy endpoints → SOP definitions: reads policies
- Insights and dashboard endpoints → Drift metrics and insights: requests metrics
- Drift metrics and insights → SOP definitions: reads policy data
- Drift metrics and insights → Persistent memory client: loads experiences
- Memory endpoints → Persistent memory client: manages memories
- Demo endpoints → Persistent memory client: runs demo memory
- REST API client → Policy endpoints: fetches policies
- REST API client → Insights and dashboard endpoints: fetches summaries
- REST API client → Memory endpoints: fetches timeline
