# aiman-hafeez-0/nexa-agent architecture

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

- Interactive diagram: https://gitdiagram.com/aiman-hafeez-0/nexa-agent
- Repository: https://github.com/aiman-hafeez-0/nexa-agent

## Overview

Nexa Agent is a stateful conversational web app. The browser receives the chat UI from Flask, starts a thread, and sends messages to stream or polling endpoints. Those endpoints invoke a compiled LangGraph that classifies intent, then generates a task-oriented or direct response; graph state is keyed by thread and checkpointed to Redis, enabling history retrieval across restarts. The graph obtains models through a provider abstraction, with Groq as the documented backend and Anthropic as an optional code path. The graph and API wiring are supported by sampled source; deployment infrastructure is omitted from this runtime view.

Main entry points: [`app/graph.py`](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/graph.py) (Compiled graph), [`app/llm.py`](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/llm.py) (Model provider), [`main.py`](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/main.py) (Flask app), [`app/routes.py`](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/routes.py) (Stream chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_chat_ui["Chat UI<br/>[index.html]"]
end

subgraph group_api["Flask API"]
  node_flask_app["Flask app<br/>[main.py]"]
  node_chat_start["Start chat<br/>[routes.py]"]
  node_chat_stream["Stream chat<br/>[routes.py]"]
  node_chat_poll["Poll chat<br/>[routes.py]"]
  node_chat_history["Get history<br/>[routes.py]"]
end

subgraph group_conversation["Conversation graph"]
  node_agent_graph["Compiled graph<br/>[graph.py]"]
  node_intent["Classify intent<br/>[graph.py]"]
  node_route_intent["Route intent<br/>[graph.py]"]
  node_task_handler["Handle task<br/>[graph.py]"]
  node_direct_response["Direct response<br/>[graph.py]"]
end

subgraph group_integrations["Model and memory"]
  node_provider["Model provider<br/>[llm.py]"]
  node_groq{{"Groq API"}}
  node_anthropic{{"Anthropic API"}}
  node_checkpoint["Redis checkpointer<br/>[memory.py]"]
  node_redis[("Redis")]
end

node_browser(("Browser"))

node_browser -->|"requests UI"| node_flask_app
node_flask_app -->|"serves page"| node_chat_ui
node_flask_app -->|"registers routes"| node_chat_start
node_browser -->|"starts thread"| node_chat_start
node_chat_start -->|"returns thread ID"| node_browser
node_browser -->|"sends message"| node_chat_stream
node_browser -->|"sends message"| node_chat_poll
node_browser -->|"requests history"| node_chat_history
node_chat_stream -->|"streams graph"| node_agent_graph
node_chat_poll -->|"invokes graph"| node_agent_graph
node_chat_history -->|"reads state"| node_agent_graph
node_agent_graph -->|"starts at"| node_intent
node_intent -->|"classifies with"| node_provider
node_intent -->|"passes intent"| node_route_intent
node_route_intent -->|"routes task"| node_task_handler
node_route_intent -->|"routes otherwise"| node_direct_response
node_task_handler -->|"requests summary"| node_provider
node_direct_response -->|"requests answer"| node_provider
node_provider -->|"calls by default"| node_groq
node_provider -.->|"can call"| node_anthropic
node_agent_graph -->|"loads and saves state"| node_checkpoint
node_checkpoint -->|"persists checkpoints"| node_redis
node_chat_stream -->|"sends SSE tokens"| node_browser
node_chat_poll -->|"returns reply"| node_browser
node_chat_history -->|"returns messages"| node_browser

click node_chat_ui "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/templates/index.html"
click node_flask_app "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/main.py"
click node_chat_start "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/routes.py"
click node_chat_stream "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/routes.py"
click node_chat_poll "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/routes.py"
click node_chat_history "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/routes.py"
click node_agent_graph "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/graph.py"
click node_intent "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/graph.py"
click node_route_intent "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/graph.py"
click node_task_handler "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/graph.py"
click node_direct_response "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/graph.py"
click node_provider "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/llm.py"
click node_checkpoint "https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/memory.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_chat_ui,node_browser toneBlue
class node_flask_app,node_chat_start,node_chat_stream,node_chat_poll,node_chat_history toneAmber
class node_agent_graph,node_intent,node_route_intent,node_task_handler,node_direct_response toneMint
class node_provider,node_groq,node_anthropic,node_checkpoint,node_redis toneRose
```

## Components

### Web interface

- [Chat UI](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/templates/index.html): `templates/index.html`

### Flask API

- [Flask app](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/main.py): `main.py`
- [Start chat](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/routes.py): `app/routes.py`
- [Stream chat](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/routes.py): `app/routes.py`
- [Poll chat](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/routes.py): `app/routes.py`
- [Get history](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/routes.py): `app/routes.py`

### Conversation graph

- [Compiled graph](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/graph.py): `app/graph.py`
- [Classify intent](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/graph.py): `app/graph.py`
- [Route intent](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/graph.py): `app/graph.py`
- [Handle task](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/graph.py): `app/graph.py`
- [Direct response](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/graph.py): `app/graph.py`

### Model and memory

- [Model provider](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/llm.py): `app/llm.py`
- **Groq API**
- **Anthropic API**
- [Redis checkpointer](https://github.com/aiman-hafeez-0/nexa-agent/blob/main/app/memory.py): `app/memory.py`
- **Redis**

### Other components

- **Browser**

## Connections

- Browser → Flask app: requests UI
- Flask app → Chat UI: serves page
- Flask app → Start chat: registers routes
- Browser → Start chat: starts thread
- Start chat → Browser: returns thread ID
- Browser → Stream chat: sends message
- Browser → Poll chat: sends message
- Browser → Get history: requests history
- Stream chat → Compiled graph: streams graph
- Poll chat → Compiled graph: invokes graph
- Get history → Compiled graph: reads state
- Compiled graph → Classify intent: starts at
- Classify intent → Model provider: classifies with
- Classify intent → Route intent: passes intent
- Route intent → Handle task: routes task
- Route intent → Direct response: routes otherwise
- Handle task → Model provider: requests summary
- Direct response → Model provider: requests answer
- Model provider → Groq API: calls by default
- Model provider → Anthropic API: can call
- Compiled graph → Redis checkpointer: loads and saves state
- Redis checkpointer → Redis: persists checkpoints
- Stream chat → Browser: sends SSE tokens
- Poll chat → Browser: returns reply
- Get history → Browser: returns messages
