# anuj0kumar/personal-ai-rag_fixed architecture

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

- Interactive diagram: https://gitdiagram.com/anuj0kumar/personal-ai-rag_fixed
- Repository: https://github.com/anuj0kumar/personal-ai-rag_fixed

## Overview

This is a local, multi-user PDF knowledge-base application. Users register and authenticate, upload PDFs for text extraction and user-scoped indexing, then ask questions answered from retrieved document context and recent chat history; chat is persisted in SQLite. The FastAPI app also serves a web UI. The README documents an abstract vector-store layer, but the sampled vector service calls ChromaDB directly, so no abstraction-to-service call is asserted. Other links reflect shown code or documented capabilities; unsampled wiring is omitted.

Main entry points: [`app/core/database.py`](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/core/database.py) (SQLAlchemy session), [`app/main.py`](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/main.py) (FastAPI application), [`app/api/endpoints/upload.py`](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/api/endpoints/upload.py) (Upload route), [`app/services/ai_service.py`](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/services/ai_service.py) (RAG chat orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application and UI"]
  node_webui["Web interface<br/>[index.html]"]
  node_fastapi["FastAPI application<br/>[main.py]"]
  node_config["Settings<br/>[config.py]"]
end

subgraph group_identity["Identity and security"]
  node_auth_routes["Auth routes<br/>[auth.py]"]
  node_auth_deps["JWT dependencies<br/>[deps.py]"]
  node_security["Password and tokens<br/>[security.py]"]
  node_users["User model<br/>[user.py]"]
end

subgraph group_ingestion["Document ingestion"]
  node_upload_route["Upload route<br/>[upload.py]"]
  node_pdf["PDF text extraction"]
  node_vector_service["Chunking and retrieval<br/>[vector_service.py]"]
  node_vector_store["Vector-store abstraction<br/>[vector_store.py]"]
  node_document_schema["Document DTOs<br/>[document.py]"]
end

subgraph group_chat["Chat and retrieval"]
  node_chat_route["Chat routes<br/>[chat.py]"]
  node_ai["RAG chat orchestration<br/>[ai_service.py]"]
  node_chat_schema["Chat DTOs<br/>[chat.py]"]
end

subgraph group_storage["Persistence"]
  node_chroma[("ChromaDB index")]
  node_database[("SQLite database")]
  node_db_session["SQLAlchemy session<br/>[database.py]"]
  node_chat_model["Chat history model<br/>[chat_history.py]"]
end

node_user(("User"))
node_ollama["Local Ollama models"]

node_user -->|"uses"| node_webui
node_webui -->|"sends requests"| node_fastapi
node_fastapi -->|"registers routes"| node_auth_routes
node_fastapi -->|"registers routes"| node_chat_route
node_fastapi -->|"registers routes"| node_upload_route
node_fastapi -->|"serves files"| node_webui
node_fastapi -->|"initializes schema"| node_db_session
node_user -->|"registers or logs in"| node_auth_routes
node_auth_routes -->|"queries and writes"| node_db_session
node_auth_routes -->|"queries and creates"| node_users
node_auth_routes -->|"hashes and verifies"| node_security
node_security -->|"reads settings"| node_config
node_auth_deps -->|"reads settings"| node_config
node_auth_deps -->|"fetches user"| node_db_session
node_auth_deps -->|"queries"| node_users
node_upload_route -->|"requires identity"| node_auth_deps
node_upload_route -->|"extracts text"| node_pdf
node_upload_route -->|"indexes text"| node_vector_service
node_upload_route -->|"returns response"| node_document_schema
node_vector_service -->|"reads index path"| node_config
node_vector_service -->|"adds and queries"| node_chroma
node_user -->|"asks questions"| node_chat_route
node_chat_route -->|"requires identity"| node_auth_deps
node_chat_route -->|"requests response"| node_ai
node_chat_route -->|"validates response"| node_chat_schema
node_ai -->|"retrieves context"| node_vector_service
node_ai -->|"loads and saves history"| node_chat_model
node_ai -->|"requests completion"| node_ollama
node_ai -->|"reads model settings"| node_config
node_chat_model -->|"uses ORM base"| node_db_session
node_users -->|"uses ORM base"| node_db_session
node_db_session -->|"reads database URL"| node_config
node_db_session -->|"connects to"| node_database
node_vector_store -.->|"abstracts storage"| node_chroma

click node_webui "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/static/index.html"
click node_fastapi "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/main.py"
click node_config "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/core/config.py"
click node_auth_routes "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/api/endpoints/auth.py"
click node_auth_deps "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/api/deps.py"
click node_security "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/core/security.py"
click node_users "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/models/user.py"
click node_upload_route "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/api/endpoints/upload.py"
click node_pdf "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/services/document_service.py"
click node_vector_service "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/services/vector_service.py"
click node_vector_store "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/services/vector_store.py"
click node_chat_route "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/api/endpoints/chat.py"
click node_ai "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/services/ai_service.py"
click node_chat_schema "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/schemas/chat.py"
click node_document_schema "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/schemas/document.py"
click node_db_session "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/core/database.py"
click node_chat_model "https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/models/chat_history.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_webui,node_fastapi,node_config,node_user toneBlue
class node_auth_routes,node_auth_deps,node_security,node_users toneAmber
class node_upload_route,node_pdf,node_vector_service,node_vector_store,node_document_schema toneMint
class node_chat_route,node_ai,node_chat_schema toneRose
class node_chroma,node_database,node_db_session,node_chat_model,node_ollama toneIndigo
```

## Components

### Application and UI

- [Web interface](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/static/index.html): `static/index.html`
- [FastAPI application](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/main.py): `app/main.py`
- [Settings](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/core/config.py): `app/core/config.py`

### Identity and security

- [Auth routes](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/api/endpoints/auth.py): `app/api/endpoints/auth.py`
- [JWT dependencies](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/api/deps.py): `app/api/deps.py`
- [Password and tokens](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/core/security.py): `app/core/security.py`
- [User model](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/models/user.py): `app/models/user.py`

### Document ingestion

- [Upload route](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/api/endpoints/upload.py): `app/api/endpoints/upload.py`
- [PDF text extraction](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/services/document_service.py): `app/services/document_service.py`
- [Chunking and retrieval](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/services/vector_service.py): `app/services/vector_service.py`
- [Vector-store abstraction](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/services/vector_store.py): `app/services/vector_store.py`
- [Document DTOs](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/schemas/document.py): `app/schemas/document.py`

### Chat and retrieval

- [Chat routes](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/api/endpoints/chat.py): `app/api/endpoints/chat.py`
- [RAG chat orchestration](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/services/ai_service.py): `app/services/ai_service.py`
- [Chat DTOs](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/schemas/chat.py): `app/schemas/chat.py`

### Persistence

- **ChromaDB index**
- **SQLite database**
- [SQLAlchemy session](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/core/database.py): `app/core/database.py`
- [Chat history model](https://github.com/anuj0kumar/personal-ai-rag_fixed/blob/master/app/models/chat_history.py): `app/models/chat_history.py`

### Other components

- **User**
- **Local Ollama models**

## Connections

- User → Web interface: uses (evidence: `README.md`)
- Web interface → FastAPI application: sends requests (evidence: `README.md`)
- FastAPI application → Auth routes: registers routes (evidence: `app/main.py`)
- FastAPI application → Chat routes: registers routes (evidence: `app/main.py`)
- FastAPI application → Upload route: registers routes (evidence: `app/main.py`)
- FastAPI application → Web interface: serves files (evidence: `app/main.py`)
- FastAPI application → SQLAlchemy session: initializes schema (evidence: `app/main.py`)
- User → Auth routes: registers or logs in (evidence: `README.md`)
- Auth routes → SQLAlchemy session: queries and writes (evidence: `app/api/endpoints/auth.py`)
- Auth routes → User model: queries and creates (evidence: `app/api/endpoints/auth.py`)
- Auth routes → Password and tokens: hashes and verifies (evidence: `app/api/endpoints/auth.py`)
- Password and tokens → Settings: reads settings (evidence: `app/core/security.py`)
- JWT dependencies → Settings: reads settings (evidence: `app/api/deps.py`)
- JWT dependencies → SQLAlchemy session: fetches user (evidence: `app/api/deps.py`)
- JWT dependencies → User model: queries (evidence: `app/api/deps.py`)
- Upload route → JWT dependencies: requires identity (evidence: `app/api/endpoints/upload.py`)
- Upload route → PDF text extraction: extracts text (evidence: `app/api/endpoints/upload.py`)
- Upload route → Chunking and retrieval: indexes text (evidence: `app/api/endpoints/upload.py`)
- Upload route → Document DTOs: returns response (evidence: `app/api/endpoints/upload.py`)
- Chunking and retrieval → Settings: reads index path (evidence: `app/services/vector_service.py`)
- Chunking and retrieval → ChromaDB index: adds and queries (evidence: `app/services/vector_service.py`)
- User → Chat routes: asks questions (evidence: `README.md`)
- Chat routes → JWT dependencies: requires identity (evidence: `app/api/endpoints/chat.py`)
- Chat routes → RAG chat orchestration: requests response (evidence: `app/api/endpoints/chat.py`)
- Chat routes → Chat DTOs: validates response (evidence: `app/api/endpoints/chat.py`)
- RAG chat orchestration → Chunking and retrieval: retrieves context (evidence: `app/services/ai_service.py`)
- RAG chat orchestration → Chat history model: loads and saves history (evidence: `app/services/ai_service.py`)
- RAG chat orchestration → Local Ollama models: requests completion (evidence: `README.md`)
- RAG chat orchestration → Settings: reads model settings (evidence: `app/services/ai_service.py`)
- Chat history model → SQLAlchemy session: uses ORM base (evidence: `app/models/chat_history.py`)
- User model → SQLAlchemy session: uses ORM base (evidence: `app/models/user.py`)
- SQLAlchemy session → Settings: reads database URL (evidence: `app/core/database.py`)
- SQLAlchemy session → SQLite database: connects to (evidence: `app/core/database.py`)
- Vector-store abstraction → ChromaDB index: abstracts storage (evidence: `README.md`)
