# yatinannam/veyl architecture

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

- Interactive diagram: https://gitdiagram.com/yatinannam/veyl
- Repository: https://github.com/yatinannam/veyl

## Overview

Veyl is a permission-aware, multi-tenant document Q&A product. Users sign in, upload classified documents, and ask questions; the backend ingests documents, filters retrieval by tenant and permissions, generates answers only from authorized passages, verifies citations, and audits activity. The graph includes dashboard, identity, document, retrieval, and governance capabilities. Relationships use the supplied source index and excerpts plus explicit README statements; unsampled internals are not assumed beyond those references.

Main entry points: [`backend/app/rag/service.py`](https://github.com/yatinannam/veyl/blob/main/backend/app/rag/service.py) (Answer orchestration), [`backend/app/ingestion/pipeline.py`](https://github.com/yatinannam/veyl/blob/main/backend/app/ingestion/pipeline.py) (Extraction and chunking), [`backend/app/retrieval/search.py`](https://github.com/yatinannam/veyl/blob/main/backend/app/retrieval/search.py) (Permission-filtered search), [`frontend/src/lib/api.ts`](https://github.com/yatinannam/veyl/blob/main/frontend/src/lib/api.ts) (Browser API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["User dashboard"]
  node_dashboard_ui["Web dashboard<br/>[page.tsx]"]
  node_web_api["Browser API client<br/>[api.ts]"]
end

subgraph group_identity["Identity and access"]
  node_auth_routes["Sign-in routes<br/>[router.py]"]
  node_auth_session["Session service<br/>[service.py]"]
  node_auth_context["Session dependencies<br/>[deps.py]"]
  node_policy["Authorization policy<br/>[policy.py]"]
end

subgraph group_documents["Document lifecycle"]
  node_document_routes["Document routes<br/>[router.py]"]
  node_document_service["Document management<br/>[service.py]"]
  node_upload_storage["Original file storage<br/>[storage.py]"]
  node_ingestion_worker["Ingestion worker<br/>[worker.py]"]
  node_ingestion_pipeline["Extraction and chunking<br/>[pipeline.py]"]
  node_extract["Text extraction<br/>[extract.py]"]
  node_chunker["Text chunking<br/>[chunker.py]"]
end

subgraph group_answers["Secure answers"]
  node_query_routes["Question routes<br/>[router.py]"]
  node_rag_service["Answer orchestration<br/>[service.py]"]
  node_search["Permission-filtered search<br/>[search.py]"]
  node_embeddings["Local embeddings<br/>[embeddings.py]"]
  node_prompt["Prompt construction<br/>[prompt.py]"]
  node_llm_client["LLM provider client<br/>[client.py]"]
  node_citations["Citation verification<br/>[citations.py]"]
  node_conversations["Conversation history<br/>[service.py]"]
end

subgraph group_governance["Tenant governance"]
  node_tenant_admin["Tenant management<br/>[router.py]"]
  node_user_admin["User management<br/>[service.py]"]
  node_audit["Append-only audit<br/>[service.py]"]
  node_tenant_scope["Tenant transactions<br/>[tenancy.py]"]
  node_database[("PostgreSQL and pgvector<br/>[schema.py]")]
end

node_people(("Workspace users"))
node_llm_provider["Compatible LLM provider"]

node_people -->|"use"| node_dashboard_ui
node_dashboard_ui -.->|"makes requests"| node_web_api
node_web_api -.->|"calls API"| node_auth_routes
node_web_api -.->|"calls API"| node_document_routes
node_web_api -.->|"calls API"| node_query_routes
node_auth_routes -->|"delegates to"| node_auth_session
node_auth_context -->|"resolves session"| node_auth_session
node_people -.->|"upload documents"| node_document_routes
node_document_routes -->|"delegates to"| node_document_service
node_document_routes -->|"stores uploads"| node_upload_storage
node_document_service -->|"uses storage"| node_upload_storage
node_document_service -->|"checks permissions"| node_policy
node_ingestion_worker -->|"runs ingestion"| node_ingestion_pipeline
node_ingestion_pipeline -->|"extracts text"| node_extract
node_ingestion_pipeline -->|"chunks text"| node_chunker
node_ingestion_pipeline -->|"reads originals"| node_upload_storage
node_ingestion_pipeline -->|"embeds chunks"| node_embeddings
node_people -.->|"ask questions"| node_query_routes
node_query_routes -->|"calls"| node_rag_service
node_rag_service -->|"authorizes query"| node_policy
node_rag_service -->|"retrieves passages"| node_search
node_search -->|"checks access"| node_policy
node_search -->|"embeds query"| node_embeddings
node_rag_service -->|"loads history"| node_conversations
node_conversations -->|"rechecks readability"| node_search
node_rag_service -->|"builds prompt"| node_prompt
node_prompt -->|"formats messages"| node_llm_client
node_rag_service -->|"generates answer"| node_llm_client
node_llm_client -->|"sends completion"| node_llm_provider
node_rag_service -->|"verifies citations"| node_citations
node_tenant_admin -->|"sets tenant scope"| node_tenant_scope
node_user_admin -->|"uses roles"| node_policy
node_rag_service -->|"records questions"| node_audit
node_document_service -->|"records changes"| node_audit
node_auth_session -->|"records sign-ins"| node_audit
node_audit -->|"writes events"| node_database
node_tenant_scope -->|"scopes transactions"| node_database
node_search -->|"queries passages"| node_database
node_rag_service -->|"persists answers"| node_database

click node_dashboard_ui "https://github.com/yatinannam/veyl/blob/main/frontend/src/app/(app)/chat/page.tsx"
click node_web_api "https://github.com/yatinannam/veyl/blob/main/frontend/src/lib/api.ts"
click node_auth_routes "https://github.com/yatinannam/veyl/blob/main/backend/app/auth/router.py"
click node_auth_session "https://github.com/yatinannam/veyl/blob/main/backend/app/auth/service.py"
click node_auth_context "https://github.com/yatinannam/veyl/blob/main/backend/app/auth/deps.py"
click node_policy "https://github.com/yatinannam/veyl/blob/main/backend/app/authz/policy.py"
click node_document_routes "https://github.com/yatinannam/veyl/blob/main/backend/app/documents/router.py"
click node_document_service "https://github.com/yatinannam/veyl/blob/main/backend/app/documents/service.py"
click node_upload_storage "https://github.com/yatinannam/veyl/blob/main/backend/app/documents/storage.py"
click node_ingestion_worker "https://github.com/yatinannam/veyl/blob/main/backend/app/worker.py"
click node_ingestion_pipeline "https://github.com/yatinannam/veyl/blob/main/backend/app/ingestion/pipeline.py"
click node_extract "https://github.com/yatinannam/veyl/blob/main/backend/app/ingestion/extract.py"
click node_chunker "https://github.com/yatinannam/veyl/blob/main/backend/app/ingestion/chunker.py"
click node_query_routes "https://github.com/yatinannam/veyl/blob/main/backend/app/rag/router.py"
click node_rag_service "https://github.com/yatinannam/veyl/blob/main/backend/app/rag/service.py"
click node_search "https://github.com/yatinannam/veyl/blob/main/backend/app/retrieval/search.py"
click node_embeddings "https://github.com/yatinannam/veyl/blob/main/backend/app/retrieval/embeddings.py"
click node_prompt "https://github.com/yatinannam/veyl/blob/main/backend/app/llm/prompt.py"
click node_llm_client "https://github.com/yatinannam/veyl/blob/main/backend/app/llm/client.py"
click node_citations "https://github.com/yatinannam/veyl/blob/main/backend/app/llm/citations.py"
click node_conversations "https://github.com/yatinannam/veyl/blob/main/backend/app/conversations/service.py"
click node_tenant_admin "https://github.com/yatinannam/veyl/blob/main/backend/app/tenants/router.py"
click node_user_admin "https://github.com/yatinannam/veyl/blob/main/backend/app/users/service.py"
click node_audit "https://github.com/yatinannam/veyl/blob/main/backend/app/audit/service.py"
click node_tenant_scope "https://github.com/yatinannam/veyl/blob/main/backend/app/db/tenancy.py"
click node_database "https://github.com/yatinannam/veyl/blob/main/backend/app/db/schema.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_dashboard_ui,node_web_api,node_people toneBlue
class node_auth_routes,node_auth_session,node_auth_context,node_policy toneAmber
class node_document_routes,node_document_service,node_upload_storage,node_ingestion_worker,node_ingestion_pipeline,node_extract,node_chunker toneMint
class node_query_routes,node_rag_service,node_search,node_embeddings,node_prompt,node_llm_client,node_citations,node_conversations toneRose
class node_tenant_admin,node_user_admin,node_audit,node_tenant_scope,node_database,node_llm_provider toneIndigo
```

## Components

### User dashboard

- [Web dashboard](https://github.com/yatinannam/veyl/blob/main/frontend/src/app/(app)/chat/page.tsx): `frontend/src/app/(app)/chat/page.tsx`
- [Browser API client](https://github.com/yatinannam/veyl/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`

### Identity and access

- [Sign-in routes](https://github.com/yatinannam/veyl/blob/main/backend/app/auth/router.py): `backend/app/auth/router.py`
- [Session service](https://github.com/yatinannam/veyl/blob/main/backend/app/auth/service.py): `backend/app/auth/service.py`
- [Session dependencies](https://github.com/yatinannam/veyl/blob/main/backend/app/auth/deps.py): `backend/app/auth/deps.py`
- [Authorization policy](https://github.com/yatinannam/veyl/blob/main/backend/app/authz/policy.py): `backend/app/authz/policy.py`

### Document lifecycle

- [Document routes](https://github.com/yatinannam/veyl/blob/main/backend/app/documents/router.py): `backend/app/documents/router.py`
- [Document management](https://github.com/yatinannam/veyl/blob/main/backend/app/documents/service.py): `backend/app/documents/service.py`
- [Original file storage](https://github.com/yatinannam/veyl/blob/main/backend/app/documents/storage.py): `backend/app/documents/storage.py`
- [Ingestion worker](https://github.com/yatinannam/veyl/blob/main/backend/app/worker.py): `backend/app/worker.py`
- [Extraction and chunking](https://github.com/yatinannam/veyl/blob/main/backend/app/ingestion/pipeline.py): `backend/app/ingestion/pipeline.py`
- [Text extraction](https://github.com/yatinannam/veyl/blob/main/backend/app/ingestion/extract.py): `backend/app/ingestion/extract.py`
- [Text chunking](https://github.com/yatinannam/veyl/blob/main/backend/app/ingestion/chunker.py): `backend/app/ingestion/chunker.py`

### Secure answers

- [Question routes](https://github.com/yatinannam/veyl/blob/main/backend/app/rag/router.py): `backend/app/rag/router.py`
- [Answer orchestration](https://github.com/yatinannam/veyl/blob/main/backend/app/rag/service.py): `backend/app/rag/service.py`
- [Permission-filtered search](https://github.com/yatinannam/veyl/blob/main/backend/app/retrieval/search.py): `backend/app/retrieval/search.py`
- [Local embeddings](https://github.com/yatinannam/veyl/blob/main/backend/app/retrieval/embeddings.py): `backend/app/retrieval/embeddings.py`
- [Prompt construction](https://github.com/yatinannam/veyl/blob/main/backend/app/llm/prompt.py): `backend/app/llm/prompt.py`
- [LLM provider client](https://github.com/yatinannam/veyl/blob/main/backend/app/llm/client.py): `backend/app/llm/client.py`
- [Citation verification](https://github.com/yatinannam/veyl/blob/main/backend/app/llm/citations.py): `backend/app/llm/citations.py`
- [Conversation history](https://github.com/yatinannam/veyl/blob/main/backend/app/conversations/service.py): `backend/app/conversations/service.py`

### Tenant governance

- [Tenant management](https://github.com/yatinannam/veyl/blob/main/backend/app/tenants/router.py): `backend/app/tenants/router.py`
- [User management](https://github.com/yatinannam/veyl/blob/main/backend/app/users/service.py): `backend/app/users/service.py`
- [Append-only audit](https://github.com/yatinannam/veyl/blob/main/backend/app/audit/service.py): `backend/app/audit/service.py`
- [Tenant transactions](https://github.com/yatinannam/veyl/blob/main/backend/app/db/tenancy.py): `backend/app/db/tenancy.py`
- [PostgreSQL and pgvector](https://github.com/yatinannam/veyl/blob/main/backend/app/db/schema.py): `backend/app/db/schema.py`

### Other components

- **Workspace users**
- **Compatible LLM provider**

## Connections

- Workspace users → Web dashboard: use (evidence: `README.md`)
- Web dashboard → Browser API client: makes requests
- Browser API client → Sign-in routes: calls API
- Browser API client → Document routes: calls API
- Browser API client → Question routes: calls API
- Sign-in routes → Session service: delegates to (evidence: `backend/app/auth/router.py`)
- Session dependencies → Session service: resolves session (evidence: `backend/app/auth/deps.py`)
- Workspace users → Document routes: upload documents
- Document routes → Document management: delegates to (evidence: `backend/app/documents/router.py`)
- Document routes → Original file storage: stores uploads (evidence: `backend/app/documents/router.py`)
- Document management → Original file storage: uses storage (evidence: `backend/app/documents/service.py`)
- Document management → Authorization policy: checks permissions (evidence: `backend/app/documents/service.py`)
- Ingestion worker → Extraction and chunking: runs ingestion (evidence: `README.md`)
- Extraction and chunking → Text extraction: extracts text (evidence: `backend/app/ingestion/pipeline.py`)
- Extraction and chunking → Text chunking: chunks text (evidence: `backend/app/ingestion/pipeline.py`)
- Extraction and chunking → Original file storage: reads originals (evidence: `backend/app/ingestion/pipeline.py`)
- Extraction and chunking → Local embeddings: embeds chunks (evidence: `backend/app/ingestion/pipeline.py`)
- Workspace users → Question routes: ask questions
- Question routes → Answer orchestration: calls (evidence: `backend/app/rag/router.py`)
- Answer orchestration → Authorization policy: authorizes query (evidence: `backend/app/rag/service.py`)
- Answer orchestration → Permission-filtered search: retrieves passages (evidence: `backend/app/rag/service.py`)
- Permission-filtered search → Authorization policy: checks access (evidence: `backend/app/retrieval/search.py`)
- Permission-filtered search → Local embeddings: embeds query (evidence: `backend/app/retrieval/search.py`)
- Answer orchestration → Conversation history: loads history (evidence: `backend/app/rag/service.py`)
- Conversation history → Permission-filtered search: rechecks readability (evidence: `backend/app/conversations/service.py`)
- Answer orchestration → Prompt construction: builds prompt (evidence: `backend/app/rag/service.py`)
- Prompt construction → LLM provider client: formats messages (evidence: `backend/app/llm/prompt.py`)
- Answer orchestration → LLM provider client: generates answer (evidence: `backend/app/rag/service.py`)
- LLM provider client → Compatible LLM provider: sends completion (evidence: `backend/app/llm/client.py`)
- Answer orchestration → Citation verification: verifies citations (evidence: `backend/app/rag/service.py`)
- Tenant management → Tenant transactions: sets tenant scope (evidence: `backend/app/tenants/router.py`)
- User management → Authorization policy: uses roles (evidence: `backend/app/users/service.py`)
- Answer orchestration → Append-only audit: records questions (evidence: `backend/app/rag/service.py`)
- Document management → Append-only audit: records changes (evidence: `backend/app/documents/service.py`)
- Session service → Append-only audit: records sign-ins (evidence: `backend/app/auth/service.py`)
- Append-only audit → PostgreSQL and pgvector: writes events (evidence: `backend/app/audit/service.py`)
- Tenant transactions → PostgreSQL and pgvector: scopes transactions (evidence: `backend/app/db/tenancy.py`)
- Permission-filtered search → PostgreSQL and pgvector: queries passages (evidence: `backend/app/retrieval/search.py`)
- Answer orchestration → PostgreSQL and pgvector: persists answers (evidence: `backend/app/rag/service.py`)
