# mahmoudosama20/support-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/mahmoudosama20/support-assistant
- Repository: https://github.com/mahmoudosama20/support-assistant

## Overview

This is a Nile Wallet support assistant combining an intent-classifier experiment with an async request service. Its principal workflow accepts a chat query, preprocesses and routes it, then returns a grounded RAG answer, read-only SQL result, clarification, or refusal; responses are validated and traced. The graph preserves the separate routing and intent models and the RAG and SQL stages. Relationships use README documentation and the shown service, agent, builder, and retrieval code; unsampled internals are represented only where documented.

Main entry points: [`src/agent/core.py`](https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/core.py) (Support Agent), [`src/rag/retriever.py`](https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/retriever.py) (Hybrid Retriever), [`src/agent/build.py`](https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/build.py) (RAG Tool Adapter), [`src/service/app.py`](https://github.com/mahmoudosama20/support-assistant/blob/main/src/service/app.py) (FastAPI Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Service API"]
  node_service["FastAPI Service<br/>[app.py]"]
  node_tracing["Request Tracing<br/>[trace_log.py]"]
end

subgraph group_orchestration["Agent Routing"]
  node_agent["Support Agent<br/>[core.py]"]
  node_preprocess["Query Preprocessing<br/>[preprocess.py]"]
  node_policy["Deterministic Policy<br/>[policy.py]"]
  node_rag_tool["RAG Tool Adapter<br/>[build.py]"]
end

subgraph group_rag["Knowledge Retrieval"]
  node_chunking["KB Chunking<br/>[chunking.py]"]
  node_hybrid["Hybrid Retriever<br/>[retriever.py]"]
  node_bm25["BM25 Search<br/>[bm25.py]"]
  node_dense["Dense Search<br/>[dense.py]"]
  node_reranker["Cross-Encoder Reranker<br/>[rerank.py]"]
  node_evidence["Evidence Gate<br/>[context.py]"]
  node_rag_answer["Grounded Answer<br/>[answer.py]"]
end

subgraph group_sql["SQL Tool"]
  node_sql_generation["SQL Generation<br/>[generate.py]"]
  node_sql_validation["SQL Validation<br/>[validate.py]"]
  node_sql_execution["Read-Only Execution<br/>[execute.py]"]
  node_support_db[("Support Database<br/>[seed.py]")]
end

subgraph group_models["Models and LLM"]
  node_route_model["Route Classifier<br/>[models.py]"]
  node_intent_model["Intent Classifier<br/>[models.py]"]
  node_llm["LLM Client<br/>[client.py]"]
end

node_client(("Chat Client"))
node_llm_provider(("LLM Provider"))

node_client -->|"sends chat"| node_service
node_service -->|"handles query"| node_agent
node_service -->|"writes trace"| node_tracing
node_agent -->|"preprocesses"| node_preprocess
node_agent -->|"infers route"| node_route_model
node_agent -->|"infers intent"| node_intent_model
node_agent -->|"selects action"| node_policy
node_agent -->|"dispatches RAG"| node_rag_tool
node_agent -->|"dispatches SQL"| node_sql_generation
node_rag_tool -->|"retrieves passages"| node_hybrid
node_rag_tool -->|"gates evidence"| node_evidence
node_rag_tool -->|"requests answer"| node_rag_answer
node_chunking -->|"provides chunks"| node_bm25
node_hybrid -->|"searches lexically"| node_bm25
node_hybrid -->|"searches semantically"| node_dense
node_hybrid -->|"reranks fusion"| node_reranker
node_hybrid -->|"returns ranked hits"| node_evidence
node_evidence -->|"supplies context"| node_rag_answer
node_rag_answer -->|"generates claims"| node_llm
node_sql_generation -->|"validates query"| node_sql_validation
node_sql_generation -->|"requests SQL"| node_llm
node_sql_validation -->|"authorizes query"| node_sql_execution
node_sql_execution -->|"reads rows"| node_support_db
node_llm -->|"calls completion API"| node_llm_provider

click node_service "https://github.com/mahmoudosama20/support-assistant/blob/main/src/service/app.py"
click node_tracing "https://github.com/mahmoudosama20/support-assistant/blob/main/src/service/trace_log.py"
click node_agent "https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/core.py"
click node_preprocess "https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/preprocess.py"
click node_policy "https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/policy.py"
click node_route_model "https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/models.py"
click node_intent_model "https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/models.py"
click node_rag_tool "https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/build.py"
click node_chunking "https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/chunking.py"
click node_hybrid "https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/retriever.py"
click node_bm25 "https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/bm25.py"
click node_dense "https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/dense.py"
click node_reranker "https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/rerank.py"
click node_evidence "https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/context.py"
click node_rag_answer "https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/answer.py"
click node_sql_generation "https://github.com/mahmoudosama20/support-assistant/blob/main/src/sqltool/generate.py"
click node_sql_validation "https://github.com/mahmoudosama20/support-assistant/blob/main/src/sqltool/validate.py"
click node_sql_execution "https://github.com/mahmoudosama20/support-assistant/blob/main/src/sqltool/execute.py"
click node_support_db "https://github.com/mahmoudosama20/support-assistant/blob/main/src/supportdb/seed.py"
click node_llm "https://github.com/mahmoudosama20/support-assistant/blob/main/src/llm/client.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_service,node_tracing,node_client toneBlue
class node_agent,node_preprocess,node_policy,node_rag_tool toneAmber
class node_chunking,node_hybrid,node_bm25,node_dense,node_reranker,node_evidence,node_rag_answer toneMint
class node_sql_generation,node_sql_validation,node_sql_execution,node_support_db toneRose
class node_route_model,node_intent_model,node_llm,node_llm_provider toneIndigo
```

## Components

### Service API

- [FastAPI Service](https://github.com/mahmoudosama20/support-assistant/blob/main/src/service/app.py): `src/service/app.py`
- [Request Tracing](https://github.com/mahmoudosama20/support-assistant/blob/main/src/service/trace_log.py): `src/service/trace_log.py`

### Agent Routing

- [Support Agent](https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/core.py): `src/agent/core.py`
- [Query Preprocessing](https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/preprocess.py): `src/agent/preprocess.py`
- [Deterministic Policy](https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/policy.py): `src/agent/policy.py`
- [RAG Tool Adapter](https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/build.py): `src/agent/build.py`

### Knowledge Retrieval

- [KB Chunking](https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/chunking.py): `src/rag/chunking.py`
- [Hybrid Retriever](https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/retriever.py): `src/rag/retriever.py`
- [BM25 Search](https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/bm25.py): `src/rag/bm25.py`
- [Dense Search](https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/dense.py): `src/rag/dense.py`
- [Cross-Encoder Reranker](https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/rerank.py): `src/rag/rerank.py`
- [Evidence Gate](https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/context.py): `src/rag/context.py`
- [Grounded Answer](https://github.com/mahmoudosama20/support-assistant/blob/main/src/rag/answer.py): `src/rag/answer.py`

### SQL Tool

- [SQL Generation](https://github.com/mahmoudosama20/support-assistant/blob/main/src/sqltool/generate.py): `src/sqltool/generate.py`
- [SQL Validation](https://github.com/mahmoudosama20/support-assistant/blob/main/src/sqltool/validate.py): `src/sqltool/validate.py`
- [Read-Only Execution](https://github.com/mahmoudosama20/support-assistant/blob/main/src/sqltool/execute.py): `src/sqltool/execute.py`
- [Support Database](https://github.com/mahmoudosama20/support-assistant/blob/main/src/supportdb/seed.py): `src/supportdb/seed.py`

### Models and LLM

- [Route Classifier](https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/models.py): `src/agent/models.py`
- [Intent Classifier](https://github.com/mahmoudosama20/support-assistant/blob/main/src/agent/models.py): `src/agent/models.py`
- [LLM Client](https://github.com/mahmoudosama20/support-assistant/blob/main/src/llm/client.py): `src/llm/client.py`

### Other components

- **Chat Client**
- **LLM Provider**

## Connections

- Chat Client → FastAPI Service: sends chat (evidence: `README.md`)
- FastAPI Service → Support Agent: handles query (evidence: `src/service/app.py`)
- FastAPI Service → Request Tracing: writes trace (evidence: `src/service/app.py`)
- Support Agent → Query Preprocessing: preprocesses (evidence: `README.md`)
- Support Agent → Route Classifier: infers route (evidence: `src/agent/core.py`)
- Support Agent → Intent Classifier: infers intent (evidence: `src/agent/core.py`)
- Support Agent → Deterministic Policy: selects action (evidence: `README.md`)
- Support Agent → RAG Tool Adapter: dispatches RAG (evidence: `src/agent/core.py`)
- Support Agent → SQL Generation: dispatches SQL (evidence: `README.md`)
- RAG Tool Adapter → Hybrid Retriever: retrieves passages (evidence: `src/agent/build.py`)
- RAG Tool Adapter → Evidence Gate: gates evidence (evidence: `src/agent/build.py`)
- RAG Tool Adapter → Grounded Answer: requests answer (evidence: `src/agent/build.py`)
- KB Chunking → BM25 Search: provides chunks (evidence: `src/rag/bm25.py`)
- Hybrid Retriever → BM25 Search: searches lexically (evidence: `src/rag/retriever.py`)
- Hybrid Retriever → Dense Search: searches semantically (evidence: `src/rag/retriever.py`)
- Hybrid Retriever → Cross-Encoder Reranker: reranks fusion (evidence: `src/rag/retriever.py`)
- Hybrid Retriever → Evidence Gate: returns ranked hits (evidence: `src/agent/build.py`)
- Evidence Gate → Grounded Answer: supplies context (evidence: `src/rag/answer.py`)
- Grounded Answer → LLM Client: generates claims (evidence: `src/rag/answer.py`)
- SQL Generation → SQL Validation: validates query (evidence: `src/sqltool/generate.py`)
- SQL Generation → LLM Client: requests SQL (evidence: `README.md`)
- SQL Validation → Read-Only Execution: authorizes query (evidence: `README.md`)
- Read-Only Execution → Support Database: reads rows (evidence: `README.md`)
- LLM Client → LLM Provider: calls completion API (evidence: `src/llm/client.py`)
