# vpr184222/careflow-agent architecture

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

- Interactive diagram: https://gitdiagram.com/vpr184222/careflow-agent
- Repository: https://github.com/vpr184222/careflow-agent

## Overview

CareFlow Agent is a synthetic healthcare-operations workspace for policy questions and reviewer-gated case updates. An operator selects a case and submits a query; the API invokes a LangGraph agent that reads the case and retrieves policy evidence, then returns an extractive answer and, when requested, a pending proposal. A reviewer decision is persisted with the case change and audit event in one transaction. The graph follows the sampled API, agent, store and UI code; the README documents the Ollama option and broader workflow capabilities.

Main entry points: [`backend/app/agent.py`](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/agent.py) (Execute tools), [`backend/app/store.py`](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/store.py) (Persistence and decisions), [`backend/app/main.py`](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/main.py) (HTTP API), [`frontend/src/App.tsx`](https://github.com/vpr184222/careflow-agent/blob/main/frontend/src/App.tsx) (Case workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Operator workspace"]
  node_ui["Case workspace<br/>[App.tsx]"]
  node_api["HTTP API<br/>[main.py]"]
end

subgraph group_agent["Agent workflow"]
  node_agent_run["Agent run<br/>[agent.py]"]
  node_planner["Plan tools<br/>[agent.py]"]
  node_tool_exec["Execute tools<br/>[agent.py]"]
  node_answer["Render answer<br/>[agent.py]"]
end

subgraph group_evidence["Policy evidence"]
  node_policy_files["Policy documents"]
  node_retriever["TF-IDF retrieval<br/>[retrieval.py]"]
end

subgraph group_review["Review and persistence"]
  node_proposal["Pending proposal<br/>[agent.py]"]
  node_store["Persistence and decisions<br/>[store.py]"]
  node_sqlite[("SQLite<br/>[store.py]")]
end

node_operator(("Operator"))
node_reviewer(("Reviewer"))
node_ollama["Local Ollama"]

node_operator -->|"uses"| node_ui
node_reviewer -->|"decides"| node_ui
node_ui -->|"requests"| node_api
node_api -->|"runs agent"| node_agent_run
node_api -->|"reads and decides"| node_store
node_agent_run -->|"starts graph"| node_planner
node_planner -->|"dispatches tools"| node_tool_exec
node_planner -->|"routes without tools"| node_answer
node_tool_exec -->|"replans"| node_planner
node_tool_exec -->|"routes results"| node_answer
node_planner -->|"requests tool calls"| node_ollama
node_tool_exec -->|"reads case"| node_store
node_tool_exec -->|"searches policies"| node_retriever
node_policy_files -->|"loads documents"| node_retriever
node_tool_exec -->|"creates proposal"| node_proposal
node_answer -->|"reports pending"| node_proposal
node_agent_run -->|"saves run"| node_store
node_store -->|"persists state"| node_sqlite
node_ollama -->|"returns reply"| node_planner
node_store -->|"commits decision and audit"| node_sqlite

click node_ui "https://github.com/vpr184222/careflow-agent/blob/main/frontend/src/App.tsx"
click node_api "https://github.com/vpr184222/careflow-agent/blob/main/backend/app/main.py"
click node_agent_run "https://github.com/vpr184222/careflow-agent/blob/main/backend/app/agent.py"
click node_planner "https://github.com/vpr184222/careflow-agent/blob/main/backend/app/agent.py"
click node_tool_exec "https://github.com/vpr184222/careflow-agent/blob/main/backend/app/agent.py"
click node_answer "https://github.com/vpr184222/careflow-agent/blob/main/backend/app/agent.py"
click node_policy_files "https://github.com/vpr184222/careflow-agent/tree/main/backend/data/policies"
click node_retriever "https://github.com/vpr184222/careflow-agent/blob/main/backend/app/retrieval.py"
click node_proposal "https://github.com/vpr184222/careflow-agent/blob/main/backend/app/agent.py"
click node_store "https://github.com/vpr184222/careflow-agent/blob/main/backend/app/store.py"
click node_sqlite "https://github.com/vpr184222/careflow-agent/blob/main/backend/app/store.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_ui,node_api,node_reviewer toneBlue
class node_agent_run,node_planner,node_tool_exec,node_answer toneAmber
class node_policy_files,node_retriever toneMint
class node_proposal,node_store,node_sqlite toneRose
class node_operator,node_ollama toneIndigo
```

## Components

### Operator workspace

- [Case workspace](https://github.com/vpr184222/careflow-agent/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [HTTP API](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/main.py): `backend/app/main.py`

### Agent workflow

- [Agent run](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/agent.py): `backend/app/agent.py`
- [Plan tools](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/agent.py): `backend/app/agent.py`
- [Execute tools](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/agent.py): `backend/app/agent.py`
- [Render answer](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/agent.py): `backend/app/agent.py`

### Policy evidence

- [Policy documents](https://github.com/vpr184222/careflow-agent/tree/main/backend/data/policies): `backend/data/policies`
- [TF-IDF retrieval](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/retrieval.py): `backend/app/retrieval.py`

### Review and persistence

- [Pending proposal](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/agent.py): `backend/app/agent.py`
- [Persistence and decisions](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/store.py): `backend/app/store.py`
- [SQLite](https://github.com/vpr184222/careflow-agent/blob/main/backend/app/store.py): `backend/app/store.py`

### Other components

- **Operator**
- **Reviewer**
- **Local Ollama**

## Connections

- Operator → Case workspace: uses (evidence: `README.md`)
- Reviewer → Case workspace: decides (evidence: `README.md`)
- Case workspace → HTTP API: requests (evidence: `frontend/src/App.tsx`)
- HTTP API → Agent run: runs agent (evidence: `backend/app/main.py`)
- HTTP API → Persistence and decisions: reads and decides (evidence: `backend/app/main.py`)
- Agent run → Plan tools: starts graph (evidence: `backend/app/agent.py`)
- Plan tools → Execute tools: dispatches tools (evidence: `backend/app/agent.py`)
- Plan tools → Render answer: routes without tools (evidence: `backend/app/agent.py`)
- Execute tools → Plan tools: replans (evidence: `backend/app/agent.py`)
- Execute tools → Render answer: routes results (evidence: `backend/app/agent.py`)
- Plan tools → Local Ollama: requests tool calls (evidence: `backend/app/agent.py`)
- Execute tools → Persistence and decisions: reads case (evidence: `backend/app/agent.py`)
- Execute tools → TF-IDF retrieval: searches policies (evidence: `backend/app/agent.py`)
- Policy documents → TF-IDF retrieval: loads documents (evidence: `backend/app/retrieval.py`)
- Execute tools → Pending proposal: creates proposal (evidence: `backend/app/agent.py`)
- Render answer → Pending proposal: reports pending (evidence: `backend/app/agent.py`)
- Agent run → Persistence and decisions: saves run (evidence: `backend/app/agent.py`)
- Persistence and decisions → SQLite: persists state (evidence: `backend/app/store.py`)
- Local Ollama → Plan tools: returns reply (evidence: `backend/app/agent.py`)
- Persistence and decisions → SQLite: commits decision and audit (evidence: `backend/app/store.py`)
