# tt959/ecommerce-agent architecture

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

- Interactive diagram: https://gitdiagram.com/tt959/ecommerce-agent
- Repository: https://github.com/tt959/ecommerce-agent

## Overview

This is an e-commerce after-sales support agent. A client submits a chat message to the FastAPI service; the agent recalls user memory, classifies one or more intents, runs applicable order/knowledge/transfer actions, and generates a response. Session history is persisted, and long-term memory is extracted after the response. Separate branches cover document ingestion and offline evaluation. Relationships for unsampled implementation details are included only where the README or source index supports them.

Main entry points: [`src/main.py`](https://github.com/tt959/ecommerce-agent/blob/main/src/main.py) (FastAPI API), [`src/graph.py`](https://github.com/tt959/ecommerce-agent/blob/main/src/graph.py) (Intent Classification), [`src/long_term_memory.py`](https://github.com/tt959/ecommerce-agent/blob/main/src/long_term_memory.py) (Long-Term Memory), [`src/rag_tool.py`](https://github.com/tt959/ecommerce-agent/blob/main/src/rag_tool.py) (FAQ and Product RAG)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Sessions"]
  node_api["FastAPI API<br/>[main.py]"]
  node_sessions["Session History<br/>[memory.py]"]
end

subgraph group_agent["Agent Workflow"]
  node_recall["Memory Recall<br/>[graph.py]"]
  node_classify["Intent Classification<br/>[graph.py]"]
  node_signals["Intent Signals<br/>[memory_signals.py]"]
  node_dispatch["Parallel Tool Dispatch<br/>[graph.py]"]
  node_reply["Response Generation<br/>[graph.py]"]
  node_evaluation["Offline Evaluation<br/>[evaluation.py]"]
end

subgraph group_knowledge["Knowledge and Memory"]
  node_rag["FAQ and Product RAG<br/>[rag_tool.py]"]
  node_longmemory["Long-Term Memory"]
  node_embed["Text Embeddings<br/>[embeddings.py]"]
  node_redisclient["Redis Client<br/>[redis_client.py]"]
  node_ingest["Document Ingestion<br/>[document_loader.py]"]
  node_seed["Knowledge Initialization<br/>[insert_data.py]"]
end

subgraph group_business["Business Data"]
  node_orders["Order Query<br/>[tools.py]"]
  node_dbaccess["Async Database Access<br/>[database.py]"]
end

node_client(("Client"))
node_redis[("Redis")]
node_mysql[("MySQL Orders")]
node_llm["Chat Model"]
node_milvus[("Milvus Collections")]

node_client -->|"sends request"| node_api
node_api -->|"loads history"| node_sessions
node_sessions -->|"persists history"| node_redis
node_api -->|"invokes agent"| node_recall
node_recall -->|"then classifies"| node_classify
node_classify -->|"checks signals"| node_signals
node_classify -->|"completes intents"| node_llm
node_classify -->|"routes intents"| node_dispatch
node_dispatch -->|"queries orders"| node_orders
node_orders -->|"uses sessions"| node_dbaccess
node_dbaccess -->|"queries orders"| node_mysql
node_dispatch -->|"searches knowledge"| node_rag
node_dispatch -->|"passes tool results"| node_reply
node_recall -->|"searches memories"| node_longmemory
node_reply -->|"uses recalled context"| node_longmemory
node_reply -->|"generates reply"| node_llm
node_rag -->|"embeds query"| node_embed
node_rag -->|"searches collections"| node_milvus
node_rag -->|"uses cache"| node_redisclient
node_longmemory -->|"embeds memories"| node_embed
node_longmemory -->|"stores and searches"| node_milvus
node_redisclient -->|"connects to"| node_redis
node_api -->|"writes after reply"| node_longmemory
node_api -->|"processes uploads"| node_ingest
node_ingest -->|"embeds chunks"| node_embed
node_ingest -->|"inserts chunks"| node_milvus
node_seed -->|"vectorizes seed data"| node_embed
node_seed -->|"initializes knowledge"| node_milvus
node_evaluation -->|"evaluates intents"| node_classify
node_evaluation -->|"judges answers"| node_reply

click node_api "https://github.com/tt959/ecommerce-agent/blob/main/src/main.py"
click node_sessions "https://github.com/tt959/ecommerce-agent/blob/main/src/memory.py"
click node_recall "https://github.com/tt959/ecommerce-agent/blob/main/src/graph.py"
click node_classify "https://github.com/tt959/ecommerce-agent/blob/main/src/graph.py"
click node_signals "https://github.com/tt959/ecommerce-agent/blob/main/src/memory_signals.py"
click node_dispatch "https://github.com/tt959/ecommerce-agent/blob/main/src/graph.py"
click node_orders "https://github.com/tt959/ecommerce-agent/blob/main/src/tools.py"
click node_dbaccess "https://github.com/tt959/ecommerce-agent/blob/main/src/database.py"
click node_rag "https://github.com/tt959/ecommerce-agent/blob/main/src/rag_tool.py"
click node_reply "https://github.com/tt959/ecommerce-agent/blob/main/src/graph.py"
click node_longmemory "https://github.com/tt959/ecommerce-agent/blob/main/src/long_term_memory.py"
click node_embed "https://github.com/tt959/ecommerce-agent/blob/main/src/embeddings.py"
click node_redisclient "https://github.com/tt959/ecommerce-agent/blob/main/src/redis_client.py"
click node_ingest "https://github.com/tt959/ecommerce-agent/blob/main/src/document_loader.py"
click node_seed "https://github.com/tt959/ecommerce-agent/blob/main/src/insert_data.py"
click node_evaluation "https://github.com/tt959/ecommerce-agent/blob/main/src/evaluation.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_api,node_sessions,node_client toneBlue
class node_recall,node_classify,node_signals,node_dispatch,node_reply,node_evaluation,node_redis,node_mysql,node_milvus toneAmber
class node_rag,node_longmemory,node_embed,node_redisclient,node_ingest,node_seed toneMint
class node_orders,node_dbaccess toneRose
class node_llm toneIndigo
```

## Components

### API and Sessions

- [FastAPI API](https://github.com/tt959/ecommerce-agent/blob/main/src/main.py): `src/main.py`
- [Session History](https://github.com/tt959/ecommerce-agent/blob/main/src/memory.py): `src/memory.py`

### Agent Workflow

- [Memory Recall](https://github.com/tt959/ecommerce-agent/blob/main/src/graph.py): `src/graph.py`
- [Intent Classification](https://github.com/tt959/ecommerce-agent/blob/main/src/graph.py): `src/graph.py`
- [Intent Signals](https://github.com/tt959/ecommerce-agent/blob/main/src/memory_signals.py): `src/memory_signals.py`
- [Parallel Tool Dispatch](https://github.com/tt959/ecommerce-agent/blob/main/src/graph.py): `src/graph.py`
- [Response Generation](https://github.com/tt959/ecommerce-agent/blob/main/src/graph.py): `src/graph.py`
- [Offline Evaluation](https://github.com/tt959/ecommerce-agent/blob/main/src/evaluation.py): `src/evaluation.py`

### Knowledge and Memory

- [FAQ and Product RAG](https://github.com/tt959/ecommerce-agent/blob/main/src/rag_tool.py): `src/rag_tool.py`
- [Long-Term Memory](https://github.com/tt959/ecommerce-agent/blob/main/src/long_term_memory.py): `src/long_term_memory.py`
- [Text Embeddings](https://github.com/tt959/ecommerce-agent/blob/main/src/embeddings.py): `src/embeddings.py`
- [Redis Client](https://github.com/tt959/ecommerce-agent/blob/main/src/redis_client.py): `src/redis_client.py`
- [Document Ingestion](https://github.com/tt959/ecommerce-agent/blob/main/src/document_loader.py): `src/document_loader.py`
- [Knowledge Initialization](https://github.com/tt959/ecommerce-agent/blob/main/src/insert_data.py): `src/insert_data.py`

### Business Data

- [Order Query](https://github.com/tt959/ecommerce-agent/blob/main/src/tools.py): `src/tools.py`
- [Async Database Access](https://github.com/tt959/ecommerce-agent/blob/main/src/database.py): `src/database.py`

### Other components

- **Client**
- **Redis**
- **MySQL Orders**
- **Chat Model**
- **Milvus Collections**

## Connections

- Client → FastAPI API: sends request (evidence: `README.md`)
- FastAPI API → Session History: loads history (evidence: `src/main.py`)
- Session History → Redis: persists history (evidence: `README.md`)
- FastAPI API → Memory Recall: invokes agent (evidence: `src/main.py`)
- Memory Recall → Intent Classification: then classifies (evidence: `README.md`)
- Intent Classification → Intent Signals: checks signals (evidence: `src/graph.py`)
- Intent Classification → Chat Model: completes intents (evidence: `README.md`)
- Intent Classification → Parallel Tool Dispatch: routes intents (evidence: `README.md`)
- Parallel Tool Dispatch → Order Query: queries orders (evidence: `src/graph.py`)
- Order Query → Async Database Access: uses sessions (evidence: `src/tools.py`)
- Async Database Access → MySQL Orders: queries orders (evidence: `README.md`)
- Parallel Tool Dispatch → FAQ and Product RAG: searches knowledge (evidence: `src/graph.py`)
- Parallel Tool Dispatch → Response Generation: passes tool results (evidence: `README.md`)
- Memory Recall → Long-Term Memory: searches memories (evidence: `src/graph.py`)
- Response Generation → Long-Term Memory: uses recalled context (evidence: `src/graph.py`)
- Response Generation → Chat Model: generates reply (evidence: `README.md`)
- FAQ and Product RAG → Text Embeddings: embeds query (evidence: `src/rag_tool.py`)
- FAQ and Product RAG → Milvus Collections: searches collections (evidence: `src/rag_tool.py`)
- FAQ and Product RAG → Redis Client: uses cache (evidence: `src/rag_tool.py`)
- Long-Term Memory → Text Embeddings: embeds memories (evidence: `src/long_term_memory.py`)
- Long-Term Memory → Milvus Collections: stores and searches (evidence: `src/long_term_memory.py`)
- Redis Client → Redis: connects to (evidence: `src/redis_client.py`)
- FastAPI API → Long-Term Memory: writes after reply (evidence: `src/main.py`)
- FastAPI API → Document Ingestion: processes uploads (evidence: `src/main.py`)
- Document Ingestion → Text Embeddings: embeds chunks (evidence: `src/document_loader.py`)
- Document Ingestion → Milvus Collections: inserts chunks (evidence: `src/document_loader.py`)
- Knowledge Initialization → Text Embeddings: vectorizes seed data (evidence: `src/insert_data.py`)
- Knowledge Initialization → Milvus Collections: initializes knowledge (evidence: `README.md`)
- Offline Evaluation → Intent Classification: evaluates intents (evidence: `src/evaluation.py`)
- Offline Evaluation → Response Generation: judges answers (evidence: `README.md`)
