# rma-mun/langchain-rag-fastapi-service architecture

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

- Interactive diagram: https://gitdiagram.com/rma-mun/langchain-rag-fastapi-service
- Repository: https://github.com/rma-mun/langchain-rag-fastapi-service

## Overview

1. **System shape**
   - The repository is a three-part application: a **Vue 3 frontend**, a **FastAPI backend**, and a separate **Django user service**.
   - The FastAPI app is the main business API; the Django service is dedicated to user registration/login/profile/avatar handling.

2. **Frontend boundary**
   - `front/` is a client-only SPA built with Vue 3, Vite, Pinia, Vue Router, and Vant.
   - It hosts the main product screens: note editor/list, daily review, AI chat, knowledge base, session management, login/register, and profile/settings.
   - It talks to the backend over HTTP and relies on JWT-based auth state in the browser.

3. **FastAPI backend as the core orchestration layer**
   - `backend/main.py` starts the API server and wires the routers under `backend/app/router/`.
   - The backend is organized as a classic API/service split:
     - **routers** expose endpoints,
     - **services** implement note/review business logic,
     - **rag/** contains retrieval and document-processing pipelines,
     - **agent/** contains LLM tool orchestration,
     - **models/** and **schemas/** define persistence and API payloads.

4. **Authentication and user isolation**
   - Authentication is handled by the Django service, not by the FastAPI app.
   - The FastAPI backend includes auth utilities and uses the configured `DJANGO_API_URL` to integrate with that service.
   - The architecture is designed for **per-user isolation**: user identity is used to scope notes, knowledge documents, chat history, and retrieval results.

5. **Django user service**
   - `DjangoUserService/` is a standalone Django app with user, file, and utility modules.
   - It owns user lifecycle operations and avatar/file upload.
   - It uses **MySQL** for user data, **Redis** for cache/session-related use, and **Celery** for background tasks.

6. **Note management subsystem**
   - Notes are handled in `backend/app/router/note_router.py` and `backend/app/services/note_service.py`.
   - The note flow is: create/edit note → persist to MySQL → generate tags/classification with LLM assistance → index content for semantic search and related-note recommendations.
   - The frontend note editor integrates inline AI completion and related-note panels to support writing while editing.

7. **Knowledge base and RAG pipeline**
   - Uploaded knowledge files are processed by the RAG stack in `backend/app/rag/`.
   - Pipeline stages are:
     - file ingestion and format-specific parsing (`document_handler/`),
     - text chunking (`text_spliter.py`),
     - deduplication via MD5 tracking (`md5_manager/`),
     - vector storage in **ChromaDB** (`vector_store.py`),
     - retrieval through hybrid retrievers and reranking,
     - answer generation with LLM prompts and context assembly.
   - Supported formats include TXT, PDF, MD, PPTX, and DOCX.

8. **Chat and agent subsystem**
   - `backend/app/router/chat.py` and `backend/app/agent/` implement the AI chat experience.
   - The chat flow is not just “prompt and response”; it uses an **agent + tools** pattern, which can call RAG retrieval and related helpers before producing the final answer.
   - Chat sessions and history are persisted in MySQL, enabling multi-turn continuity and session replay.

9. **Daily review / spaced repetition**
   - Review logic is isolated in `review_service.py` and `review_router.py`.
   - It uses an **Ebbinghaus-style spaced repetition schedule** to surface notes for review on timed intervals.
   - Review records are stored in MySQL, and the frontend shows them as a dedicated daily review workflow.

10. **Data stores and infrastructure**
   - **MySQL** stores durable relational data: users, notes, review records, and chat history.
   - **Redis** is used for caching and background coordination.
   - **ChromaDB** stores vector embeddings for both knowledge documents and note-related semantic search.
   - Local or remote LLMs are supported through configuration: **DashScope/Aliyun** or **Ollama**, with a separate reranker model path configured locally.

11. **Model and prompt layer**
   - Prompts are externalized in `backend/app/prompt/`, which makes the AI behaviors configurable without changing business routes.
   - The backend also supports embedding and reranking model configuration, so retrieval quality is a first-class architectural concern rather than an implementation detail.

12. **Main end-to-end flows**
   - **Login/register**: frontend → Django user service → JWT returned → frontend uses token for backend calls.
   - **Note writing**: frontend editor → FastAPI note API → MySQL + semantic indexing → AI completion / related-note retrieval.
   - **Document Q&A**: frontend knowledge upload → FastAPI RAG ingestion → ChromaDB indexing → chat/query endpoint → LLM response with citations.
   - **Daily review**: scheduled/query-based retrieval of due notes → spaced-repetition logic → review UI.

Main entry points: [`front/src/router/index.js`](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/router/index.js) (Client Router), [`backend/app/router`](https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/backend/app/router) (API Routers), [`backend/app/services/note_service.py`](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/services/note_service.py) (Note Service), [`backend/app/rag/rag_service.py`](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/rag/rag_service.py) (RAG Pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Vue SPA"]
  node_front_app["Frontend App<br/>Vue3 SPA<br/>[App.vue]"]
  node_front_router["Client Router<br/>Vue Router<br/>[index.js]"]
  node_front_store["Auth Store<br/>Pinia state<br/>[index.js]"]
  node_front_api["API Client<br/>HTTP client<br/>[api.js]"]
  node_front_note["Note Editor<br/>screen<br/>[NoteEditor.vue]"]
  node_front_review["Daily Review<br/>screen<br/>[DailyReview.vue]"]
  node_front_chat["AI Chat<br/>screen<br/>[AIChat.vue]"]
  node_front_knowledge["Knowledge Base<br/>screen<br/>[KnowledgeBase.vue]"]
  node_front_account["Login Profile<br/>screen set<br/>[Login.vue]"]
end

subgraph group_backend["FastAPI Core"]
  node_backend_main["API Server<br/>FastAPI app<br/>[main.py]"]
  node_backend_router["API Routers<br/>HTTP endpoints"]
  node_backend_note["Note Service<br/>business service<br/>[note_service.py]"]
  node_backend_review["Review Service<br/>spaced repetition<br/>[review_service.py]"]
  node_backend_chat["Chat Agent<br/>LLM orchestration<br/>[agent.py]"]
  node_backend_rag["RAG Pipeline<br/>retrieval pipeline<br/>[rag_service.py]"]
  node_backend_models[("Domain Models<br/>persistence models")]
  node_backend_prompts["Prompt Pack<br/>prompt assets"]
  node_backend_utils["Auth Config<br/>integration utils"]
  node_backend_db[("Data Stores<br/>infrastructure")]
  node_backend_vector[("Vector Store<br/>ChromaDB<br/>[vector_store.py]")]
end

subgraph group_usersvc["Django User Service"]
  node_django_app["Django Service<br/>Django app"]
  node_django_user["User Module<br/>accounts API"]
  node_django_file["File Module<br/>upload API"]
  node_django_utils["User Utils<br/>support code"]
end

node_front_app -->|"routes"| node_front_router
node_front_app -->|"state"| node_front_store
node_front_app -->|"requests"| node_front_api
node_front_router -->|"navigates"| node_front_note
node_front_router -->|"navigates"| node_front_review
node_front_router -->|"navigates"| node_front_chat
node_front_router -->|"navigates"| node_front_knowledge
node_front_router -->|"navigates"| node_front_account
node_front_api -->|"http"| node_backend_main
node_front_account -->|"auth"| node_django_user
node_front_account -->|"upload"| node_django_file
node_backend_main -->|"mounts"| node_backend_router
node_backend_router -->|"note api"| node_backend_note
node_backend_router -->|"review api"| node_backend_review
node_backend_router -->|"chat api"| node_backend_chat
node_backend_router -->|"knowledge api"| node_backend_rag
node_backend_note -->|"persist"| node_backend_models
node_backend_note -->|"index"| node_backend_vector
node_backend_note -->|"llm prompts"| node_backend_prompts
node_backend_review -->|"persist"| node_backend_models
node_backend_chat -->|"tools"| node_backend_rag
node_backend_chat -->|"persist"| node_backend_models
node_backend_rag -->|"retrieve"| node_backend_vector
node_backend_rag -->|"compose"| node_backend_prompts
node_backend_utils -.->|"integrates"| node_django_user
node_backend_utils -->|"connects"| node_backend_db
node_django_app -->|"hosts"| node_django_user
node_django_app -->|"hosts"| node_django_file
node_django_app -->|"supports"| node_django_utils

click node_front_app "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/App.vue"
click node_front_router "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/router/index.js"
click node_front_store "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/store/index.js"
click node_front_api "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/config/api.js"
click node_front_note "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/views/NoteEditor.vue"
click node_front_review "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/views/DailyReview.vue"
click node_front_chat "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/views/AIChat.vue"
click node_front_knowledge "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/views/KnowledgeBase.vue"
click node_front_account "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/views/Login.vue"
click node_backend_main "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/main.py"
click node_backend_router "https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/backend/app/router"
click node_backend_note "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/services/note_service.py"
click node_backend_review "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/services/review_service.py"
click node_backend_chat "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/agent/agent.py"
click node_backend_rag "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/rag/rag_service.py"
click node_backend_models "https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/backend/app/models"
click node_backend_prompts "https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/backend/app/prompt"
click node_backend_utils "https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/backend/app/utils"
click node_backend_db "https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/backend/app/db"
click node_backend_vector "https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/rag/vector_store.py"
click node_django_app "https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/DjangoUserService/DjangoUserService"
click node_django_user "https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/DjangoUserService/apps/user"
click node_django_file "https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/DjangoUserService/apps/file"
click node_django_utils "https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/DjangoUserService/apps/utils"

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_front_app,node_front_router,node_front_store,node_front_api,node_front_note,node_front_review,node_front_chat,node_front_knowledge,node_front_account toneBlue
class node_backend_main,node_backend_router,node_backend_note,node_backend_review,node_backend_chat,node_backend_rag,node_backend_models,node_backend_prompts,node_backend_utils,node_backend_db,node_backend_vector toneAmber
class node_django_app,node_django_user,node_django_file,node_django_utils toneMint
```

## Components

### Vue SPA

Client-side product UI and browser state.

- [Frontend App](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/App.vue): Vue3 SPA · Single-page application shell for the product UI. · `front/src/App.vue`
- [Client Router](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/router/index.js): Vue Router · Route-level navigation for product screens. · `front/src/router/index.js`
- [Auth Store](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/store/index.js): Pinia state · Browser state for user, session, theme, and language. · `front/src/store/index.js`
- [API Client](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/config/api.js): HTTP client · Frontend API configuration and backend request entrypoint. · `front/src/config/api.js`
- [Note Editor](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/views/NoteEditor.vue): screen · Writing, inline completion, and related-note UI. · `front/src/views/NoteEditor.vue`
- [Daily Review](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/views/DailyReview.vue): screen · Spaced-repetition review workflow and review cards. · `front/src/views/DailyReview.vue`
- [AI Chat](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/views/AIChat.vue): screen · Multi-turn assistant chat and knowledge Q&A entrypoint. · `front/src/views/AIChat.vue`
- [Knowledge Base](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/views/KnowledgeBase.vue): screen · Document upload and knowledge management UI. · `front/src/views/KnowledgeBase.vue`
- [Login Profile](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/front/src/views/Login.vue): screen set · Login, register, profile, sessions, and settings screens. · `front/src/views/Login.vue`

### FastAPI Core

Main business API, orchestration, RAG, and note/review services.

- [API Server](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/main.py): FastAPI app · Application bootstrap and router wiring. · `backend/main.py`
- [API Routers](https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/backend/app/router): HTTP endpoints · Main endpoint layer for chat, notes, review, knowledge, and health. · `backend/app/router`
- [Note Service](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/services/note_service.py): business service · Create/edit notes, tagging, indexing, and related-note logic. · `backend/app/services/note_service.py`
- [Review Service](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/services/review_service.py): spaced repetition · Due-note selection and Ebbinghaus-style review scheduling. · `backend/app/services/review_service.py`
- [Chat Agent](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/agent/agent.py): LLM orchestration · Agent and tool-based chat execution with RAG helpers. · `backend/app/agent/agent.py`
- [RAG Pipeline](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/rag/rag_service.py): retrieval pipeline · Document ingestion, chunking, retrieval, reranking, and answer assembly. · `backend/app/rag/rag_service.py`
- [Domain Models](https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/backend/app/models): persistence models · MySQL-backed note, review, and chat history entities. · `backend/app/models`
- [Prompt Pack](https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/backend/app/prompt): prompt assets · Externalized prompts for writing, review, chat, and RAG behavior. · `backend/app/prompt`
- [Auth Config](https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/backend/app/utils): integration utils · Auth helpers, config loading, file/image/pdf utilities, and backend integration glue. · `backend/app/utils`
- [Data Stores](https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/backend/app/db): infrastructure · MySQL and Redis connections used by the FastAPI backend. · `backend/app/db`
- [Vector Store](https://github.com/rma-mun/langchain-rag-fastapi-service/blob/master/backend/app/rag/vector_store.py): ChromaDB · Embedding index for note search and document retrieval. · `backend/app/rag/vector_store.py`

### Django User Service

Standalone user, file, and auth service.

- [Django Service](https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/DjangoUserService/DjangoUserService): Django app · Standalone user lifecycle and file service. · `DjangoUserService/DjangoUserService`
- [User Module](https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/DjangoUserService/apps/user): accounts API · Registration, login, profile, avatar, and auth endpoints. · `DjangoUserService/apps/user`
- [File Module](https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/DjangoUserService/apps/file): upload API · Avatar and file upload handling. · `DjangoUserService/apps/file`
- [User Utils](https://github.com/rma-mun/langchain-rag-fastapi-service/tree/master/DjangoUserService/apps/utils): support code · Cache and rate-limit helpers for the user service. · `DjangoUserService/apps/utils`

## Connections

- Frontend App → Client Router: routes · The app shell is driven by client routing.
- Frontend App → Auth Store: state · The app reads auth and session state from Pinia.
- Frontend App → API Client: requests · Screens call the backend through the shared API client.
- Client Router → Note Editor: navigates · Routes expose the note editor.
- Client Router → Daily Review: navigates · Routes expose the review workflow.
- Client Router → AI Chat: navigates · Routes expose AI chat.
- Client Router → Knowledge Base: navigates · Routes expose knowledge management.
- Client Router → Login Profile: navigates · Routes expose auth and profile screens.
- API Client → API Server: http · Frontend talks to the FastAPI service over HTTP.
- Login Profile → User Module: auth · Login and registration go through the Django user service.
- Login Profile → File Module: upload · Profile and avatar files use the file service.
- API Server → API Routers: mounts · The server wires the application routers.
- API Routers → Note Service: note api · Note endpoints delegate to the note service.
- API Routers → Review Service: review api · Review endpoints delegate to the review service.
- API Routers → Chat Agent: chat api · Chat endpoints delegate to the agent layer.
- API Routers → RAG Pipeline: knowledge api · Knowledge endpoints feed the RAG pipeline.
- Note Service → Domain Models: persist · Notes and related metadata are stored relationally.
- Note Service → Vector Store: index · Notes are indexed for semantic search and recommendations.
- Note Service → Prompt Pack: llm prompts · Tagging and autocomplete use prompt assets.
- Review Service → Domain Models: persist · Review records and due-state data live in MySQL.
- Chat Agent → RAG Pipeline: tools · The agent can call retrieval and helper tools.
- Chat Agent → Domain Models: persist · Chat sessions and history are stored relationally.
- RAG Pipeline → Vector Store: retrieve · RAG reads and writes embeddings in ChromaDB.
- RAG Pipeline → Prompt Pack: compose · Answer generation is driven by prompt templates.
- Auth Config → User Module: integrates · Backend auth utilities integrate with the Django user service.
- Auth Config → Data Stores: connects · Shared backend utilities configure database and cache access.
- Django Service → User Module: hosts · The Django project hosts the user module.
- Django Service → File Module: hosts · The Django project hosts the file module.
- Django Service → User Utils: supports · The Django project includes cache and rate-limit helpers.
