# ermihageez/rag architecture

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

- Interactive diagram: https://gitdiagram.com/ermihageez/rag
- Repository: https://github.com/ermihageez/rag

## Overview

eTech RAG is a local-first B2B sales and marketing application. A user query enters through the API or copilot, is routed through a LangGraph agent workflow for lead discovery, tender scoring and knowledge retrieval, then produces sales intelligence and a draft for approval and optional n8n delivery. The repository also documents document RAG, conversational sales, marketing, MCP tools and an ML training pipeline. Arrows cite the README or indexed source references; unsampled subsystem internals and some runtime wiring are represented only where documented.

Main entry points: [`src/agents/graph.py`](https://github.com/ermihageez/rag/blob/main/src/agents/graph.py) (LangGraph workflow), [`src/api.py`](https://github.com/ermihageez/rag/blob/main/src/api.py) (FastAPI service), [`src/rag/retriever.py`](https://github.com/ermihageez/rag/blob/main/src/rag/retriever.py) (RAG retrieval), [`src/agents/llm.py`](https://github.com/ermihageez/rag/blob/main/src/agents/llm.py) (LLM integration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User interfaces"]
  node_ui["React dashboard<br/>[App.tsx]"]
  node_api["FastAPI service<br/>[api.py]"]
  node_copilot["Copilot routes<br/>[routes.py]"]
end

subgraph group_agents["Sales agent workflow"]
  node_graph["LangGraph workflow<br/>[graph.py]"]
  node_supervisor["Supervisor<br/>[supervisor.py]"]
  node_lead["Lead discovery<br/>[lead_agent.py]"]
  node_tender["Tender scoring<br/>[tender_agent.py]"]
  node_knowledge_agent["Knowledge agent<br/>[knowledge_agent.py]"]
  node_sales_intel["Sales intelligence<br/>[sales_agent.py]"]
  node_content["Content drafting<br/>[content_agent.py]"]
  node_approval["Approval gate<br/>[approval_agent.py]"]
end

subgraph group_knowledge["Knowledge retrieval"]
  node_rag_load["Document loading<br/>[data_loader.py]"]
  node_ocr["OCR fallback<br/>[ocr_loader.py]"]
  node_embedding["Chunk and embed<br/>[embedding.py]"]
  node_faiss[("FAISS index<br/>[vectorstore.py]")]
  node_retriever["RAG retrieval<br/>[retriever.py]"]
end

subgraph group_business["Sales and marketing"]
  node_sales["Sales assistant<br/>[engine.py]"]
  node_marketing["Marketing pipeline"]
end

subgraph group_platform["Data and integrations"]
  node_mcp["MCP tools"]
  node_memory[("Conversation memory<br/>[postgres_memory.py]")]
  node_evaluation["Evaluation framework"]
  node_training["ML training pipeline<br/>[pipeline.py]"]
  node_training_sink[("Training event sink<br/>[training_sink.py]")]
  node_metrics["Pipeline metrics<br/>[metrics.py]"]
  node_llm["LLM integration<br/>[llm.py]"]
end

node_user(("Sales user"))
node_ollama(("Ollama"))
node_n8n(("n8n delivery"))

node_user -.->|"uses"| node_ui
node_ui -.->|"requests"| node_api
node_user -->|"submits query"| node_api
node_api -->|"runs agents"| node_graph
node_copilot -->|"builds and runs"| node_graph
node_graph -->|"routes"| node_supervisor
node_graph -->|"dispatches"| node_lead
node_graph -->|"dispatches"| node_tender
node_graph -->|"dispatches"| node_knowledge_agent
node_graph -->|"dispatches"| node_sales_intel
node_graph -->|"dispatches"| node_content
node_graph -->|"dispatches"| node_approval
node_lead -->|"searches leads"| node_mcp
node_tender -->|"fetches tenders"| node_mcp
node_knowledge_agent -.->|"retrieves context"| node_retriever
node_retriever -->|"queries"| node_faiss
node_retriever -.->|"via index query"| node_embedding
node_rag_load -->|"uses fallback"| node_ocr
node_faiss -->|"embeds documents"| node_embedding
node_api -->|"serves sales flow"| node_sales
node_api -->|"serves marketing"| node_marketing
node_api -->|"serves RAG"| node_retriever
node_graph -->|"uses memory"| node_memory
node_content -.->|"generates drafts"| node_llm
node_llm -->|"infers locally"| node_ollama
node_api -->|"delivers payload"| node_n8n
node_training -->|"evaluates models"| node_evaluation
node_training -.->|"builds from events"| node_training_sink
node_training -.->|"reports metrics"| node_metrics
node_api -->|"records events"| node_training_sink
node_llm -->|"increments counters"| node_metrics
node_embedding -->|"loads embedding model"| node_llm

click node_ui "https://github.com/ermihageez/rag/blob/main/ui/src/App.tsx"
click node_api "https://github.com/ermihageez/rag/blob/main/src/api.py"
click node_copilot "https://github.com/ermihageez/rag/blob/main/src/copilot/routes.py"
click node_graph "https://github.com/ermihageez/rag/blob/main/src/agents/graph.py"
click node_supervisor "https://github.com/ermihageez/rag/blob/main/src/agents/supervisor/supervisor.py"
click node_lead "https://github.com/ermihageez/rag/blob/main/src/agents/lead/lead_agent.py"
click node_tender "https://github.com/ermihageez/rag/blob/main/src/agents/tender/tender_agent.py"
click node_knowledge_agent "https://github.com/ermihageez/rag/blob/main/src/agents/knowledge/knowledge_agent.py"
click node_sales_intel "https://github.com/ermihageez/rag/blob/main/src/agents/sales_intelligence/sales_agent.py"
click node_content "https://github.com/ermihageez/rag/blob/main/src/agents/content/content_agent.py"
click node_approval "https://github.com/ermihageez/rag/blob/main/src/agents/approval/approval_agent.py"
click node_mcp "https://github.com/ermihageez/rag/tree/main/mcp_server/tools"
click node_rag_load "https://github.com/ermihageez/rag/blob/main/src/rag/data_loader.py"
click node_ocr "https://github.com/ermihageez/rag/blob/main/src/ocr_loader.py"
click node_embedding "https://github.com/ermihageez/rag/blob/main/src/rag/embedding.py"
click node_faiss "https://github.com/ermihageez/rag/blob/main/src/rag/vectorstore.py"
click node_retriever "https://github.com/ermihageez/rag/blob/main/src/rag/retriever.py"
click node_memory "https://github.com/ermihageez/rag/blob/main/src/memory/postgres_memory.py"
click node_sales "https://github.com/ermihageez/rag/blob/main/src/sales_assistant/engine.py"
click node_marketing "https://github.com/ermihageez/rag/tree/main/src/marketing"
click node_evaluation "https://github.com/ermihageez/rag/tree/main/src/evaluation"
click node_training "https://github.com/ermihageez/rag/blob/main/app/ml/pipeline.py"
click node_training_sink "https://github.com/ermihageez/rag/blob/main/app/ml/training_sink.py"
click node_metrics "https://github.com/ermihageez/rag/blob/main/app/ml/metrics.py"
click node_llm "https://github.com/ermihageez/rag/blob/main/src/agents/llm.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_copilot,node_user toneBlue
class node_graph,node_supervisor,node_lead,node_tender,node_knowledge_agent,node_sales_intel,node_content,node_approval toneAmber
class node_rag_load,node_ocr,node_embedding,node_faiss,node_retriever toneMint
class node_sales,node_marketing toneRose
class node_mcp,node_memory,node_evaluation,node_training,node_training_sink,node_metrics,node_llm,node_ollama,node_n8n toneIndigo
```

## Components

### User interfaces

- [React dashboard](https://github.com/ermihageez/rag/blob/main/ui/src/App.tsx): `ui/src/App.tsx`
- [FastAPI service](https://github.com/ermihageez/rag/blob/main/src/api.py): `src/api.py`
- [Copilot routes](https://github.com/ermihageez/rag/blob/main/src/copilot/routes.py): `src/copilot/routes.py`

### Sales agent workflow

- [LangGraph workflow](https://github.com/ermihageez/rag/blob/main/src/agents/graph.py): `src/agents/graph.py`
- [Supervisor](https://github.com/ermihageez/rag/blob/main/src/agents/supervisor/supervisor.py): `src/agents/supervisor/supervisor.py`
- [Lead discovery](https://github.com/ermihageez/rag/blob/main/src/agents/lead/lead_agent.py): `src/agents/lead/lead_agent.py`
- [Tender scoring](https://github.com/ermihageez/rag/blob/main/src/agents/tender/tender_agent.py): `src/agents/tender/tender_agent.py`
- [Knowledge agent](https://github.com/ermihageez/rag/blob/main/src/agents/knowledge/knowledge_agent.py): `src/agents/knowledge/knowledge_agent.py`
- [Sales intelligence](https://github.com/ermihageez/rag/blob/main/src/agents/sales_intelligence/sales_agent.py): `src/agents/sales_intelligence/sales_agent.py`
- [Content drafting](https://github.com/ermihageez/rag/blob/main/src/agents/content/content_agent.py): `src/agents/content/content_agent.py`
- [Approval gate](https://github.com/ermihageez/rag/blob/main/src/agents/approval/approval_agent.py): `src/agents/approval/approval_agent.py`

### Knowledge retrieval

- [Document loading](https://github.com/ermihageez/rag/blob/main/src/rag/data_loader.py): `src/rag/data_loader.py`
- [OCR fallback](https://github.com/ermihageez/rag/blob/main/src/ocr_loader.py): `src/ocr_loader.py`
- [Chunk and embed](https://github.com/ermihageez/rag/blob/main/src/rag/embedding.py): `src/rag/embedding.py`
- [FAISS index](https://github.com/ermihageez/rag/blob/main/src/rag/vectorstore.py): `src/rag/vectorstore.py`
- [RAG retrieval](https://github.com/ermihageez/rag/blob/main/src/rag/retriever.py): `src/rag/retriever.py`

### Sales and marketing

- [Sales assistant](https://github.com/ermihageez/rag/blob/main/src/sales_assistant/engine.py): `src/sales_assistant/engine.py`
- [Marketing pipeline](https://github.com/ermihageez/rag/tree/main/src/marketing): `src/marketing`

### Data and integrations

- [MCP tools](https://github.com/ermihageez/rag/tree/main/mcp_server/tools): `mcp_server/tools`
- [Conversation memory](https://github.com/ermihageez/rag/blob/main/src/memory/postgres_memory.py): `src/memory/postgres_memory.py`
- [Evaluation framework](https://github.com/ermihageez/rag/tree/main/src/evaluation): `src/evaluation`
- [ML training pipeline](https://github.com/ermihageez/rag/blob/main/app/ml/pipeline.py): `app/ml/pipeline.py`
- [Training event sink](https://github.com/ermihageez/rag/blob/main/app/ml/training_sink.py): `app/ml/training_sink.py`
- [Pipeline metrics](https://github.com/ermihageez/rag/blob/main/app/ml/metrics.py): `app/ml/metrics.py`
- [LLM integration](https://github.com/ermihageez/rag/blob/main/src/agents/llm.py): `src/agents/llm.py`

### Other components

- **Sales user**
- **Ollama**
- **n8n delivery**

## Connections

- Sales user → React dashboard: uses
- React dashboard → FastAPI service: requests
- Sales user → FastAPI service: submits query (evidence: `README.md`)
- FastAPI service → LangGraph workflow: runs agents (evidence: `src/api.py`)
- Copilot routes → LangGraph workflow: builds and runs (evidence: `src/copilot/routes.py`)
- LangGraph workflow → Supervisor: routes (evidence: `src/agents/graph.py`)
- LangGraph workflow → Lead discovery: dispatches (evidence: `src/agents/graph.py`)
- LangGraph workflow → Tender scoring: dispatches (evidence: `src/agents/graph.py`)
- LangGraph workflow → Knowledge agent: dispatches (evidence: `src/agents/graph.py`)
- LangGraph workflow → Sales intelligence: dispatches (evidence: `src/agents/graph.py`)
- LangGraph workflow → Content drafting: dispatches (evidence: `src/agents/graph.py`)
- LangGraph workflow → Approval gate: dispatches (evidence: `src/agents/graph.py`)
- Lead discovery → MCP tools: searches leads (evidence: `README.md`)
- Tender scoring → MCP tools: fetches tenders (evidence: `README.md`)
- Knowledge agent → RAG retrieval: retrieves context
- RAG retrieval → FAISS index: queries (evidence: `src/rag/retriever.py`)
- RAG retrieval → Chunk and embed: via index query
- Document loading → OCR fallback: uses fallback (evidence: `src/rag/data_loader.py`)
- FAISS index → Chunk and embed: embeds documents (evidence: `src/rag/vectorstore.py`)
- FastAPI service → Sales assistant: serves sales flow (evidence: `src/api.py`)
- FastAPI service → Marketing pipeline: serves marketing (evidence: `src/api.py`)
- FastAPI service → RAG retrieval: serves RAG (evidence: `src/api.py`)
- LangGraph workflow → Conversation memory: uses memory (evidence: `src/agents/graph.py`)
- Content drafting → LLM integration: generates drafts
- LLM integration → Ollama: infers locally (evidence: `README.md`)
- FastAPI service → n8n delivery: delivers payload (evidence: `README.md`)
- ML training pipeline → Evaluation framework: evaluates models (evidence: `app/ml/pipeline.py`)
- ML training pipeline → Training event sink: builds from events
- ML training pipeline → Pipeline metrics: reports metrics
- FastAPI service → Training event sink: records events (evidence: `src/api.py`)
- LLM integration → Pipeline metrics: increments counters (evidence: `src/agents/llm.py`)
- Chunk and embed → LLM integration: loads embedding model (evidence: `src/rag/embedding.py`)
