# favas-fv8/hr_policy_assistant architecture

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

- Interactive diagram: https://gitdiagram.com/favas-fv8/hr_policy_assistant
- Repository: https://github.com/favas-fv8/hr_policy_assistant

## Overview

HR Policy Assistant supports HR-admin account and policy-document management, plus employee authentication, document browsing, and grounded policy Q&A. The central workflow is PDF upload, extraction and chunking, embedding and storage, then question embedding, similarity retrieval, and an answer with source references. The graph includes the frontend, API/domain areas, and the RAG internals. Some backend views and frontend pages were not excerpted; their capabilities and links are included only where the README or source index supports them.

Main entry points: [`backend/rag/pipeline.py`](https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/rag/pipeline.py) (RAG pipeline), [`frontend/hr-frontend/src/App.tsx`](https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/App.tsx) (Application routes), [`frontend/hr-frontend/src/services/chatService.ts`](https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/services/chatService.ts) (Chat service), [`frontend/hr-frontend/src/services/documentService.ts`](https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/services/documentService.ts) (Document service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["Application routes<br/>[App.tsx]"]
  node_chat_ui["Chat interface<br/>[chat.tsx]"]
  node_documents_ui["Document library<br/>[documents.tsx]"]
  node_employees_ui["Employee management<br/>[employees.tsx]"]
  node_http["HTTP client<br/>[http.ts]"]
  node_chat_service["Chat service<br/>[chatService.ts]"]
  node_document_service["Document service<br/>[documentService.ts]"]
end

subgraph group_identity["Identity and access"]
  node_auth_state["Auth state<br/>[authContext.tsx]"]
  node_auth_api["Accounts API"]
end

subgraph group_content["Policy documents"]
  node_documents_api["Documents API"]
  node_processing_task["Processing task<br/>[tasks.py]"]
end

subgraph group_rag["Retrieval and answers"]
  node_chat_api["Chat API<br/>[views.py]"]
  node_rag_pipeline["RAG pipeline<br/>[pipeline.py]"]
  node_chunking["Text chunking<br/>[chunking.py]"]
  node_embedding["Embedding generator<br/>[generator.py]"]
  node_similarity["Similarity search<br/>[similarity.py]"]
end

subgraph group_data["Persistent data"]
  node_doc_store[("Document and chunk models<br/>[models.py]")]
  node_chat_store[("Conversations and messages<br/>[models.py]")]
  node_database[("PostgreSQL")]
end

node_employee(("Employee"))
node_hr_admin(("HR admin"))
node_gemini["Google Gemini"]

node_employee -->|"uses"| node_app
node_hr_admin -->|"uses"| node_app
node_app -->|"routes to"| node_chat_ui
node_app -->|"routes to"| node_documents_ui
node_app -->|"routes to"| node_employees_ui
node_app -->|"uses"| node_auth_state
node_chat_ui -->|"calls"| node_chat_service
node_documents_ui -->|"calls"| node_document_service
node_employees_ui -->|"manages users"| node_auth_api
node_auth_state -->|"calls"| node_http
node_chat_service -->|"calls"| node_http
node_document_service -->|"calls"| node_http
node_auth_state -->|"requests auth"| node_auth_api
node_chat_service -->|"requests chat"| node_chat_api
node_document_service -->|"requests documents"| node_documents_api
node_documents_api -.->|"starts processing"| node_processing_task
node_processing_task -->|"calls"| node_rag_pipeline
node_chat_api -->|"calls"| node_rag_pipeline
node_rag_pipeline -->|"chunks text"| node_chunking
node_rag_pipeline -->|"generates vectors"| node_embedding
node_rag_pipeline -->|"searches vectors"| node_similarity
node_rag_pipeline -->|"reads and writes"| node_doc_store
node_embedding -->|"requests embeddings"| node_gemini
node_rag_pipeline -->|"requests answers"| node_gemini
node_similarity -.->|"retrieves chunks"| node_doc_store
node_doc_store -->|"persists"| node_database
node_chat_store -->|"persists"| node_database
node_chat_api -.->|"manages history"| node_chat_store

click node_app "https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/App.tsx"
click node_chat_ui "https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/pages/chat.tsx"
click node_documents_ui "https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/pages/documents.tsx"
click node_employees_ui "https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/pages/employees.tsx"
click node_http "https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/services/http.ts"
click node_chat_service "https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/services/chatService.ts"
click node_document_service "https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/services/documentService.ts"
click node_auth_state "https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/state/authContext.tsx"
click node_auth_api "https://github.com/favas-fv8/hr_policy_assistant/tree/main/backend/accounts"
click node_chat_api "https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/chat/api/views.py"
click node_documents_api "https://github.com/favas-fv8/hr_policy_assistant/tree/main/backend/documents"
click node_processing_task "https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/documents/tasks.py"
click node_rag_pipeline "https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/rag/pipeline.py"
click node_chunking "https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/rag/chunking.py"
click node_embedding "https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/embeddings/generator.py"
click node_similarity "https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/vector/similarity.py"
click node_doc_store "https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/documents/models.py"
click node_chat_store "https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/chat/models.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_app,node_chat_ui,node_documents_ui,node_employees_ui,node_http,node_chat_service,node_document_service toneBlue
class node_auth_state,node_auth_api toneAmber
class node_documents_api,node_processing_task toneMint
class node_chat_api,node_rag_pipeline,node_chunking,node_embedding,node_similarity toneRose
class node_doc_store,node_chat_store,node_database,node_employee,node_hr_admin,node_gemini toneIndigo
```

## Components

### Web application

- [Application routes](https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/App.tsx): `frontend/hr-frontend/src/App.tsx`
- [Chat interface](https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/pages/chat.tsx): `frontend/hr-frontend/src/pages/chat.tsx`
- [Document library](https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/pages/documents.tsx): `frontend/hr-frontend/src/pages/documents.tsx`
- [Employee management](https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/pages/employees.tsx): `frontend/hr-frontend/src/pages/employees.tsx`
- [HTTP client](https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/services/http.ts): `frontend/hr-frontend/src/services/http.ts`
- [Chat service](https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/services/chatService.ts): `frontend/hr-frontend/src/services/chatService.ts`
- [Document service](https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/services/documentService.ts): `frontend/hr-frontend/src/services/documentService.ts`

### Identity and access

- [Auth state](https://github.com/favas-fv8/hr_policy_assistant/blob/main/frontend/hr-frontend/src/state/authContext.tsx): `frontend/hr-frontend/src/state/authContext.tsx`
- [Accounts API](https://github.com/favas-fv8/hr_policy_assistant/tree/main/backend/accounts): `backend/accounts`

### Policy documents

- [Documents API](https://github.com/favas-fv8/hr_policy_assistant/tree/main/backend/documents): `backend/documents`
- [Processing task](https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/documents/tasks.py): `backend/documents/tasks.py`

### Retrieval and answers

- [Chat API](https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/chat/api/views.py): `backend/chat/api/views.py`
- [RAG pipeline](https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/rag/pipeline.py): `backend/rag/pipeline.py`
- [Text chunking](https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/rag/chunking.py): `backend/rag/chunking.py`
- [Embedding generator](https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/embeddings/generator.py): `backend/embeddings/generator.py`
- [Similarity search](https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/vector/similarity.py): `backend/vector/similarity.py`

### Persistent data

- [Document and chunk models](https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/documents/models.py): `backend/documents/models.py`
- [Conversations and messages](https://github.com/favas-fv8/hr_policy_assistant/blob/main/backend/chat/models.py): `backend/chat/models.py`
- **PostgreSQL**

### Other components

- **Employee**
- **HR admin**
- **Google Gemini**

## Connections

- Employee → Application routes: uses
- HR admin → Application routes: uses
- Application routes → Chat interface: routes to (evidence: `frontend/hr-frontend/src/App.tsx`)
- Application routes → Document library: routes to (evidence: `frontend/hr-frontend/src/App.tsx`)
- Application routes → Employee management: routes to (evidence: `frontend/hr-frontend/src/App.tsx`)
- Application routes → Auth state: uses (evidence: `frontend/hr-frontend/src/App.tsx`)
- Chat interface → Chat service: calls (evidence: `frontend/hr-frontend/src/pages/chat.tsx`)
- Document library → Document service: calls (evidence: `frontend/hr-frontend/src/pages/documents.tsx`)
- Employee management → Accounts API: manages users
- Auth state → HTTP client: calls (evidence: `frontend/hr-frontend/src/state/authContext.tsx`)
- Chat service → HTTP client: calls (evidence: `frontend/hr-frontend/src/services/chatService.ts`)
- Document service → HTTP client: calls (evidence: `frontend/hr-frontend/src/services/documentService.ts`)
- Auth state → Accounts API: requests auth (evidence: `frontend/hr-frontend/src/state/authContext.tsx`)
- Chat service → Chat API: requests chat
- Document service → Documents API: requests documents (evidence: `frontend/hr-frontend/src/services/documentService.ts`)
- Documents API → Processing task: starts processing (evidence: `backend/documents/tasks.py`)
- Processing task → RAG pipeline: calls (evidence: `backend/documents/tasks.py`)
- Chat API → RAG pipeline: calls (evidence: `backend/chat/api/views.py`)
- RAG pipeline → Text chunking: chunks text (evidence: `backend/rag/pipeline.py`)
- RAG pipeline → Embedding generator: generates vectors (evidence: `backend/rag/pipeline.py`)
- RAG pipeline → Similarity search: searches vectors (evidence: `backend/rag/pipeline.py`)
- RAG pipeline → Document and chunk models: reads and writes (evidence: `backend/rag/pipeline.py`)
- Embedding generator → Google Gemini: requests embeddings
- RAG pipeline → Google Gemini: requests answers
- Similarity search → Document and chunk models: retrieves chunks
- Document and chunk models → PostgreSQL: persists
- Conversations and messages → PostgreSQL: persists
- Chat API → Conversations and messages: manages history
