# bymarcelolewin/care-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/bymarcelolewin/care-assistant
- Repository: https://github.com/bymarcelolewin/care-assistant

## Overview

#### Purpose and Runtime Entry Points
CARE Assistant is a learning-focused insurance coverage chatbot. A FastAPI server starts at `app/main.py`, initializes mock data, mounts REST APIs, and serves the statically exported Next.js frontend. The operational entry point is `uvicorn app.main:app`; the browser client begins at `frontend/app/page.tsx`.

#### HTTP and Session Boundary
The backend API separates chat execution, graph inspection, and session lifecycle:
- `app/api/chat.py` accepts chat turns, retrieves/updates conversation context, invokes the agent, and returns response plus execution details.
- `app/api/sessions.py` owns server-side session/conversation management.
- `app/api/graph.py` exposes agent graph structure for UI visualization.
This is a single-server POC rather than a separately deployed frontend/backend system.

#### Agent State and LangGraph Orchestration
The core control flow is a LangGraph 1.0 agent:
- `app/graph/state.py` defines the shared typed state: messages, user context, tool results, and execution/trace information.
- `app/graph/graph.py` composes the executable workflow.
- `app/graph/nodes.py` runs the Ollama-backed LangChain model and tool-oriented stages; `app/graph/edges.py` conditionally routes between LLM/tool/final-response paths.
A chat request enters with session state, loops through LLM-directed tool calls when needed, then persists and returns the updated state.

#### LLM and External Observability
The agent uses a local Ollama model (default `llama3.2`), configured in `app/graph/nodes.py`; Ollama must run independently on the host. LangChain provides LLM/tool integration and LangGraph provides stateful execution. Optional LangSmith tracing is enabled through environment settings (`.env.example`) and is nonessential to local operation.

#### Domain Data and Tool Layer
Tools isolate insurance-domain lookups from orchestration:
- `app/tools/coverage.py` resolves plan coverage.
- `app/tools/benefits.py` verifies benefits.
- `app/tools/claims.py` retrieves claim status/history.
- `app/data/loader.py` loads root-level JSON fixtures from `data/user_profiles.json`, `data/insurance_plans.json`, and `data/claims_data.json`.
There is no database or live insurer integration; data access is local mock-data lookup.

#### Frontend Chat and Observability UI
The Next.js 15 static client calls FastAPI through `frontend/lib/api.ts` and renders the chat workflow from `frontend/components/chat/ChatWindow.tsx`. It presents messages and loading/thinking state, then conditionally surfaces execution internals through draggable windows:
- `frontend/components/observability/DraggableMemoryWindow.tsx`
- `frontend/components/observability/DraggableGraphWindow.tsx`
- `frontend/components/observability/DraggableStepsWindow.tsx`
These consume API response/state and graph endpoints, keeping agent observability distinct from the conversational UI.

#### Deployment Shape
Python 3.12–3.13 dependencies are managed by uv (`pyproject.toml`, `uv.lock`); frontend dependencies and static export are managed by npm under `frontend/package.json`. Building Next.js produces `frontend/out/`, which `app/main.py` serves. Required infrastructure is only the FastAPI process plus local Ollama; LangSmith is an optional cloud service.

Main entry points: [`app/main.py`](https://github.com/bymarcelolewin/care-assistant/blob/main/app/main.py) (Application entry), [`app/data/loader.py`](https://github.com/bymarcelolewin/care-assistant/blob/main/app/data/loader.py) (Fixture loader), [`frontend/app/page.tsx`](https://github.com/bymarcelolewin/care-assistant/blob/main/frontend/app/page.tsx) (Browser client), [`frontend/lib/api.ts`](https://github.com/bymarcelolewin/care-assistant/blob/main/frontend/lib/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["FastAPI server"]
  node_main["Application entry<br/>FastAPI bootstrap<br/>[main.py]"]
  node_chat_api["Chat API<br/>REST route<br/>[chat.py]"]
  node_sessions_api["Sessions API<br/>REST route<br/>[sessions.py]"]
  node_graph_api["Graph API<br/>REST route<br/>[graph.py]"]
  node_session_context[("Conversation state<br/>server session")]
end

subgraph group_agent["Agent workflow"]
  node_agent_graph{{"LangGraph workflow<br/>agent orchestrator<br/>[graph.py]"}}
  node_agent_state["Shared agent state<br/>typed state<br/>[state.py]"]
  node_agent_nodes["LLM and tool stages<br/>LangGraph nodes<br/>[nodes.py]"]
  node_agent_edges["Conditional routing<br/>LangGraph edges<br/>[edges.py]"]
  node_ollama(("Local Ollama<br/>local model runtime"))
end

subgraph group_domain["Mock domain data"]
  node_tools["Insurance tools<br/>domain tool layer"]
  node_coverage_tool["Coverage lookup<br/>tool<br/>[coverage.py]"]
  node_benefits_tool["Benefits lookup<br/>tool<br/>[benefits.py]"]
  node_claims_tool["Claims lookup<br/>tool<br/>[claims.py]"]
  node_data_loader["Fixture loader<br/>mock data access<br/>[loader.py]"]
  node_fixtures[("JSON fixtures<br/>local mock data<br/>[user_profiles.json]")]
end

subgraph group_frontend["Static frontend"]
  node_browser["Browser client<br/>Next.js page<br/>[page.tsx]"]
  node_frontend_api["API client<br/>[api.ts]"]
  node_chat_window["Chat window<br/>conversation UI<br/>[ChatWindow.tsx]"]
  node_observability["Observability windows<br/>draggable UI"]
end

node_main -->|"mounts"| node_chat_api
node_main -->|"mounts"| node_sessions_api
node_main -->|"mounts"| node_graph_api
node_main -->|"initializes"| node_data_loader
node_main -->|"serves static export"| node_browser
node_browser -->|"renders"| node_chat_window
node_browser -->|"uses"| node_frontend_api
node_browser -->|"shows"| node_observability
node_frontend_api -->|"chat turns"| node_chat_api
node_frontend_api -->|"session lifecycle"| node_sessions_api
node_frontend_api -->|"graph inspection"| node_graph_api
node_chat_api -->|"loads and persists"| node_session_context
node_chat_api -->|"invokes"| node_agent_graph
node_agent_graph -->|"updates"| node_agent_state
node_agent_graph -->|"executes"| node_agent_nodes
node_agent_edges -->|"routes loop"| node_agent_nodes
node_agent_nodes -->|"LLM inference"| node_ollama
node_agent_nodes -->|"tool calls"| node_tools
node_tools -->|"coverage"| node_coverage_tool
node_tools -->|"benefits"| node_benefits_tool
node_tools -->|"claims"| node_claims_tool
node_coverage_tool -->|"lookup"| node_data_loader
node_benefits_tool -->|"lookup"| node_data_loader
node_claims_tool -->|"lookup"| node_data_loader
node_data_loader -->|"loads"| node_fixtures
node_graph_api -.->|"inspects"| node_agent_graph
node_observability -->|"visualizes"| node_graph_api

click node_main "https://github.com/bymarcelolewin/care-assistant/blob/main/app/main.py"
click node_chat_api "https://github.com/bymarcelolewin/care-assistant/blob/main/app/api/chat.py"
click node_sessions_api "https://github.com/bymarcelolewin/care-assistant/blob/main/app/api/sessions.py"
click node_graph_api "https://github.com/bymarcelolewin/care-assistant/blob/main/app/api/graph.py"
click node_agent_graph "https://github.com/bymarcelolewin/care-assistant/blob/main/app/graph/graph.py"
click node_agent_state "https://github.com/bymarcelolewin/care-assistant/blob/main/app/graph/state.py"
click node_agent_nodes "https://github.com/bymarcelolewin/care-assistant/blob/main/app/graph/nodes.py"
click node_agent_edges "https://github.com/bymarcelolewin/care-assistant/blob/main/app/graph/edges.py"
click node_coverage_tool "https://github.com/bymarcelolewin/care-assistant/blob/main/app/tools/coverage.py"
click node_benefits_tool "https://github.com/bymarcelolewin/care-assistant/blob/main/app/tools/benefits.py"
click node_claims_tool "https://github.com/bymarcelolewin/care-assistant/blob/main/app/tools/claims.py"
click node_data_loader "https://github.com/bymarcelolewin/care-assistant/blob/main/app/data/loader.py"
click node_fixtures "https://github.com/bymarcelolewin/care-assistant/blob/main/data/user_profiles.json"
click node_browser "https://github.com/bymarcelolewin/care-assistant/blob/main/frontend/app/page.tsx"
click node_frontend_api "https://github.com/bymarcelolewin/care-assistant/blob/main/frontend/lib/api.ts"
click node_chat_window "https://github.com/bymarcelolewin/care-assistant/blob/main/frontend/components/chat/ChatWindow.tsx"
click node_observability "https://github.com/bymarcelolewin/care-assistant/blob/main/frontend/components/observability/DraggableGraphWindow.tsx"

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_main,node_chat_api,node_sessions_api,node_graph_api,node_session_context toneBlue
class node_agent_graph,node_agent_state,node_agent_nodes,node_agent_edges,node_ollama toneAmber
class node_tools,node_coverage_tool,node_benefits_tool,node_claims_tool,node_data_loader,node_fixtures toneMint
class node_browser,node_frontend_api,node_chat_window,node_observability toneRose
```

## Components

### FastAPI server

- [Application entry](https://github.com/bymarcelolewin/care-assistant/blob/main/app/main.py): FastAPI bootstrap · Initializes mock data, mounts APIs, and serves the static client. · `app/main.py`
- [Chat API](https://github.com/bymarcelolewin/care-assistant/blob/main/app/api/chat.py): REST route · Runs chat turns and returns responses with execution details. · `app/api/chat.py`
- [Sessions API](https://github.com/bymarcelolewin/care-assistant/blob/main/app/api/sessions.py): REST route · Manages server-side sessions and conversations. · `app/api/sessions.py`
- [Graph API](https://github.com/bymarcelolewin/care-assistant/blob/main/app/api/graph.py): REST route · Exposes agent graph structure for visualization. · `app/api/graph.py`
- **Conversation state**: server session

### Agent workflow

- [LangGraph workflow](https://github.com/bymarcelolewin/care-assistant/blob/main/app/graph/graph.py): agent orchestrator · Executes the stateful LLM and tool loop. · `app/graph/graph.py`
- [Shared agent state](https://github.com/bymarcelolewin/care-assistant/blob/main/app/graph/state.py): typed state · Carries messages, user context, tool results, and trace data. · `app/graph/state.py`
- [LLM and tool stages](https://github.com/bymarcelolewin/care-assistant/blob/main/app/graph/nodes.py): LangGraph nodes · Runs the Ollama-backed model and tool-oriented stages. · `app/graph/nodes.py`
- [Conditional routing](https://github.com/bymarcelolewin/care-assistant/blob/main/app/graph/edges.py): LangGraph edges · Routes among LLM, tool, and final-response paths. · `app/graph/edges.py`
- **Local Ollama**: local model runtime · Independently runs the default llama3.2 model.

### Mock domain data

- **Insurance tools**: domain tool layer · Coverage, benefits, and claims lookups.
- [Coverage lookup](https://github.com/bymarcelolewin/care-assistant/blob/main/app/tools/coverage.py): tool · `app/tools/coverage.py`
- [Benefits lookup](https://github.com/bymarcelolewin/care-assistant/blob/main/app/tools/benefits.py): tool · `app/tools/benefits.py`
- [Claims lookup](https://github.com/bymarcelolewin/care-assistant/blob/main/app/tools/claims.py): tool · `app/tools/claims.py`
- [Fixture loader](https://github.com/bymarcelolewin/care-assistant/blob/main/app/data/loader.py): mock data access · Loads local user, plan, and claims JSON fixtures. · `app/data/loader.py`
- [JSON fixtures](https://github.com/bymarcelolewin/care-assistant/blob/main/data/user_profiles.json): local mock data · User profiles, insurance plans, and claims data. · `data/user_profiles.json`

### Static frontend

- [Browser client](https://github.com/bymarcelolewin/care-assistant/blob/main/frontend/app/page.tsx): Next.js page · Starts the chat experience and observability UI. · `frontend/app/page.tsx`
- [API client](https://github.com/bymarcelolewin/care-assistant/blob/main/frontend/lib/api.ts): FastAPI client · `frontend/lib/api.ts`
- [Chat window](https://github.com/bymarcelolewin/care-assistant/blob/main/frontend/components/chat/ChatWindow.tsx): conversation UI · Renders messages and thinking state. · `frontend/components/chat/ChatWindow.tsx`
- [Observability windows](https://github.com/bymarcelolewin/care-assistant/blob/main/frontend/components/observability/DraggableGraphWindow.tsx): draggable UI · Memory, graph, and execution-step views. · `frontend/components/observability/DraggableGraphWindow.tsx`

## Connections

- Application entry → Chat API: mounts
- Application entry → Sessions API: mounts
- Application entry → Graph API: mounts
- Application entry → Fixture loader: initializes
- Application entry → Browser client: serves static export
- Browser client → Chat window: renders
- Browser client → API client: uses
- Browser client → Observability windows: shows
- API client → Chat API: chat turns
- API client → Sessions API: session lifecycle
- API client → Graph API: graph inspection
- Chat API → Conversation state: loads and persists
- Chat API → LangGraph workflow: invokes
- LangGraph workflow → Shared agent state: updates
- LangGraph workflow → LLM and tool stages: executes
- Conditional routing → LLM and tool stages: routes loop
- LLM and tool stages → Local Ollama: LLM inference
- LLM and tool stages → Insurance tools: tool calls
- Insurance tools → Coverage lookup: coverage
- Insurance tools → Benefits lookup: benefits
- Insurance tools → Claims lookup: claims
- Coverage lookup → Fixture loader: lookup
- Benefits lookup → Fixture loader: lookup
- Claims lookup → Fixture loader: lookup
- Fixture loader → JSON fixtures: loads
- Graph API → LangGraph workflow: inspects
- Observability windows → Graph API: visualizes
