# mdadnan2/chat-with-pdf architecture

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

- Interactive diagram: https://gitdiagram.com/mdadnan2/chat-with-pdf
- Repository: https://github.com/mdadnan2/chat-with-pdf

## Overview

This is a document-grounded AI workspace: users authenticate, upload documents, then chat with documents or run specialist agents that return answers and sources. The backend exposes separate authentication, upload, document, chat, and agent routes; agent execution can route requests to specialists and uses shared retrieval and model-provider infrastructure. The tree and excerpts establish the backend wiring, but do not show the client’s API call sites or the internals of several services, so those relationships are omitted or marked unverified.

Main entry points: [`server/app/main.py`](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/main.py) (FastAPI application), [`client/services/api.ts`](https://github.com/mdadnan2/chat-with-pdf/blob/main/client/services/api.ts) (API client), [`server/app/agents/orchestrator.py`](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/agents/orchestrator.py) (Agent orchestrator), [`server/app/database/models/user.py`](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/database/models/user.py) (User and document data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web workspace"]
  node_web["Workspace pages<br/>[page.tsx]"]
  node_upload_ui["Document upload UI<br/>[upload-zone.tsx]"]
  node_agent_ui["Agent workspace UI"]
  node_auth_ui["Sign-in and registration<br/>[page.tsx]"]
  node_client_api["API client<br/>[api.ts]"]
end

subgraph group_api["HTTP API"]
  node_app["FastAPI application<br/>[main.py]"]
  node_auth_route["Authentication routes<br/>[auth.py]"]
  node_upload_route["Upload route<br/>[upload.py]"]
  node_document_route["Document routes<br/>[document.py]"]
  node_chat_route["Chat route<br/>[chat.py]"]
  node_agent_route["Agent route<br/>[agent.py]"]
end

subgraph group_identity["Identity and storage"]
  node_auth_service["Authentication service<br/>[auth_service.py]"]
  node_auth_data[("User and document data<br/>[user.py]")]
end

subgraph group_documents["Document intelligence"]
  node_upload_service["Upload processing<br/>[upload_service.py]"]
  node_parser["Document parsing<br/>[parser_service.py]"]
  node_chunking["Chunk creation"]
  node_retrieval["Chunk retrieval"]
  node_embedding["Embedding generation"]
  node_chat_service["Chat service<br/>[chat_service.py]"]
end

subgraph group_agents["Agent execution"]
  node_agent_orchestrator["Agent orchestrator<br/>[orchestrator.py]"]
  node_agent_router["Agent selection<br/>[agent_router.py]"]
  node_specialists["Specialist agents<br/>[base_agent.py]"]
  node_execution["AI execution"]
  node_providers["Model providers"]
end

node_user(("Workspace user"))

node_user -->|"uses"| node_web
node_user -->|"uploads"| node_upload_ui
node_user -->|"signs in"| node_auth_ui
node_web -.->|"requests"| node_client_api
node_upload_ui -.->|"uploads via"| node_client_api
node_agent_ui -.->|"runs via"| node_client_api
node_auth_ui -.->|"authenticates via"| node_client_api
node_client_api -.->|"calls API"| node_app
node_app -->|"registers"| node_upload_route
node_app -->|"registers"| node_chat_route
node_app -->|"registers"| node_agent_route
node_app -->|"registers"| node_auth_route
node_app -->|"registers"| node_document_route
node_auth_route -->|"calls"| node_auth_service
node_auth_service -->|"reads and writes"| node_auth_data
node_upload_route -->|"calls"| node_upload_service
node_document_route -.->|"accesses models"| node_auth_data
node_chat_route -->|"calls"| node_chat_service
node_agent_route -->|"dispatches"| node_agent_orchestrator
node_agent_orchestrator -->|"routes requests"| node_agent_router
node_agent_orchestrator -->|"dispatches"| node_specialists
node_agent_orchestrator -->|"shares execution"| node_execution
node_execution -->|"retrieves context"| node_retrieval
node_retrieval -->|"embeds query"| node_embedding
node_execution -->|"configures providers"| node_providers
node_upload_service -.->|"processes document"| node_parser
node_parser -.->|"produces chunks"| node_chunking
node_chunking -.->|"stores document data"| node_auth_data
node_retrieval -->|"queries chunks"| node_auth_data

click node_web "https://github.com/mdadnan2/chat-with-pdf/blob/main/client/app/chat/page.tsx"
click node_upload_ui "https://github.com/mdadnan2/chat-with-pdf/blob/main/client/components/upload/upload-zone.tsx"
click node_agent_ui "https://github.com/mdadnan2/chat-with-pdf/blob/main/client/components/chat/agent-workspace.tsx"
click node_auth_ui "https://github.com/mdadnan2/chat-with-pdf/blob/main/client/app/login/page.tsx"
click node_client_api "https://github.com/mdadnan2/chat-with-pdf/blob/main/client/services/api.ts"
click node_app "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/main.py"
click node_auth_route "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/routers/auth.py"
click node_upload_route "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/routers/upload.py"
click node_document_route "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/routers/document.py"
click node_chat_route "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/routers/chat.py"
click node_agent_route "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/routers/agent.py"
click node_auth_service "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/auth_service.py"
click node_auth_data "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/database/models/user.py"
click node_upload_service "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/upload_service.py"
click node_parser "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/parser_service.py"
click node_chunking "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/chunking_service.py"
click node_retrieval "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/retrieval_service.py"
click node_embedding "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/embedding_service.py"
click node_chat_service "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/chat_service.py"
click node_agent_orchestrator "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/agents/orchestrator.py"
click node_agent_router "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/agent_router.py"
click node_specialists "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/agents/base_agent.py"
click node_execution "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/ai_execution_service.py"
click node_providers "https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/provider_factory.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_web,node_upload_ui,node_agent_ui,node_auth_ui,node_client_api,node_user toneBlue
class node_app,node_auth_route,node_upload_route,node_document_route,node_chat_route,node_agent_route toneAmber
class node_auth_service,node_auth_data toneMint
class node_upload_service,node_parser,node_chunking,node_retrieval,node_embedding,node_chat_service toneRose
class node_agent_orchestrator,node_agent_router,node_specialists,node_execution,node_providers toneIndigo
```

## Components

### Web workspace

- [Workspace pages](https://github.com/mdadnan2/chat-with-pdf/blob/main/client/app/chat/page.tsx): `client/app/chat/page.tsx`
- [Document upload UI](https://github.com/mdadnan2/chat-with-pdf/blob/main/client/components/upload/upload-zone.tsx): `client/components/upload/upload-zone.tsx`
- [Agent workspace UI](https://github.com/mdadnan2/chat-with-pdf/blob/main/client/components/chat/agent-workspace.tsx): `client/components/chat/agent-workspace.tsx`
- [Sign-in and registration](https://github.com/mdadnan2/chat-with-pdf/blob/main/client/app/login/page.tsx): `client/app/login/page.tsx`
- [API client](https://github.com/mdadnan2/chat-with-pdf/blob/main/client/services/api.ts): `client/services/api.ts`

### HTTP API

- [FastAPI application](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/main.py): `server/app/main.py`
- [Authentication routes](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/routers/auth.py): `server/app/routers/auth.py`
- [Upload route](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/routers/upload.py): `server/app/routers/upload.py`
- [Document routes](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/routers/document.py): `server/app/routers/document.py`
- [Chat route](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/routers/chat.py): `server/app/routers/chat.py`
- [Agent route](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/routers/agent.py): `server/app/routers/agent.py`

### Identity and storage

- [Authentication service](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/auth_service.py): `server/app/services/auth_service.py`
- [User and document data](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/database/models/user.py): `server/app/database/models/user.py`

### Document intelligence

- [Upload processing](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/upload_service.py): `server/app/services/upload_service.py`
- [Document parsing](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/parser_service.py): `server/app/services/parser_service.py`
- [Chunk creation](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/chunking_service.py): `server/app/services/chunking_service.py`
- [Chunk retrieval](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/retrieval_service.py): `server/app/services/retrieval_service.py`
- [Embedding generation](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/embedding_service.py): `server/app/services/embedding_service.py`
- [Chat service](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/chat_service.py): `server/app/services/chat_service.py`

### Agent execution

- [Agent orchestrator](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/agents/orchestrator.py): `server/app/agents/orchestrator.py`
- [Agent selection](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/agent_router.py): `server/app/services/agent_router.py`
- [Specialist agents](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/agents/base_agent.py): `server/app/agents/base_agent.py`
- [AI execution](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/ai_execution_service.py): `server/app/services/ai_execution_service.py`
- [Model providers](https://github.com/mdadnan2/chat-with-pdf/blob/main/server/app/services/provider_factory.py): `server/app/services/provider_factory.py`

### Other components

- **Workspace user**

## Connections

- Workspace user → Workspace pages: uses
- Workspace user → Document upload UI: uploads
- Workspace user → Sign-in and registration: signs in
- Workspace pages → API client: requests
- Document upload UI → API client: uploads via
- Agent workspace UI → API client: runs via
- Sign-in and registration → API client: authenticates via
- API client → FastAPI application: calls API
- FastAPI application → Upload route: registers (evidence: `server/app/main.py`)
- FastAPI application → Chat route: registers (evidence: `server/app/main.py`)
- FastAPI application → Agent route: registers (evidence: `server/app/main.py`)
- FastAPI application → Authentication routes: registers (evidence: `server/app/main.py`)
- FastAPI application → Document routes: registers (evidence: `server/app/main.py`)
- Authentication routes → Authentication service: calls (evidence: `server/app/routers/auth.py`)
- Authentication service → User and document data: reads and writes (evidence: `server/app/services/auth_service.py`)
- Upload route → Upload processing: calls (evidence: `server/app/routers/upload.py`)
- Document routes → User and document data: accesses models
- Chat route → Chat service: calls (evidence: `server/app/routers/chat.py`)
- Agent route → Agent orchestrator: dispatches (evidence: `server/app/routers/agent.py`)
- Agent orchestrator → Agent selection: routes requests (evidence: `server/app/agents/orchestrator.py`)
- Agent orchestrator → Specialist agents: dispatches (evidence: `server/app/agents/orchestrator.py`)
- Agent orchestrator → AI execution: shares execution (evidence: `server/app/agents/orchestrator.py`)
- AI execution → Chunk retrieval: retrieves context (evidence: `server/app/services/ai_execution_service.py`)
- Chunk retrieval → Embedding generation: embeds query (evidence: `server/app/services/retrieval_service.py`)
- AI execution → Model providers: configures providers (evidence: `server/app/services/ai_execution_service.py`)
- Upload processing → Document parsing: processes document
- Document parsing → Chunk creation: produces chunks
- Chunk creation → User and document data: stores document data
- Chunk retrieval → User and document data: queries chunks (evidence: `server/app/services/retrieval_service.py`)
