# soham842op/livedocs architecture

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

- Interactive diagram: https://gitdiagram.com/soham842op/livedocs
- Repository: https://github.com/soham842op/livedocs

## Overview

LiveDocs is a collaborative document editor with JWT-protected Yjs synchronization, durable snapshots, document management, and an AI writing copilot. The main workflow is a user editing in the frontend, syncing document state through the WebSocket service, and invoking backend AI features over REST; the backend also handles auth and document metadata. The graph preserves the documented sharing, upload, RAG, inconsistency, caching, and observability capabilities. Some route and UI wiring is unsampled, so those links are omitted or marked unverified.

Main entry points: [`frontend/src/components/EditorWrapper.tsx`](https://github.com/soham842op/livedocs/blob/master/frontend/src/components/EditorWrapper.tsx) (Editor workflow), [`frontend/src/components/Editor.tsx`](https://github.com/soham842op/livedocs/blob/master/frontend/src/components/Editor.tsx) (Collaborative editor), [`backend/main.py`](https://github.com/soham842op/livedocs/blob/master/backend/main.py) (AI request routes), [`sync-server/index.js`](https://github.com/soham842op/livedocs/blob/master/sync-server/index.js) (WebSocket gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_auth_ui["Auth UI<br/>[page.tsx]"]
  node_auth_context["Auth context<br/>[AuthContext.tsx]"]
  node_document_ui["Document dashboard<br/>[Sidebar.tsx]"]
  node_editor_wrapper["Editor workflow<br/>[EditorWrapper.tsx]"]
  node_editor["Collaborative editor<br/>[Editor.tsx]"]
  node_toolbar["Formatting toolbar<br/>[Toolbar.tsx]"]
  node_suggestions_panel["Suggestions panel"]
  node_inconsistency_panel["Inconsistency panel"]
  node_qa_panel["Q&amp;A panel<br/>[QAPanel.tsx]"]
  node_sections["Section extraction"]
  node_supabase_client["Supabase client<br/>[supabase.ts]"]
end

subgraph group_sync["Realtime sync"]
  node_sync_server["WebSocket gateway<br/>[index.js]"]
  node_persistence["Snapshot persistence<br/>[persistence.js]"]
end

subgraph group_api["Backend API"]
  node_backend_api["Auth and document API<br/>[main.py]"]
  node_ai_routes["AI request routes<br/>[main.py]"]
end

subgraph group_ai["AI services"]
  node_llm["LLM generation<br/>[llm.py]"]
  node_embeddings["Embedding and retrieval<br/>[embeddings.py]"]
  node_observability["LLM cache and events<br/>[observability.py]"]
end

subgraph group_data["Data stores"]
  node_postgres[("Supabase Postgres")]
  node_s3[("S3 snapshots")]
end

node_user(("Document user"))
node_gemini["Gemini API"]

node_user -->|"signs in"| node_auth_ui
node_user -.->|"manages documents"| node_document_ui
node_user -->|"edits document"| node_editor
node_auth_ui -.->|"uses sessions"| node_auth_context
node_editor_wrapper -->|"renders"| node_editor
node_editor -->|"renders"| node_toolbar
node_editor_wrapper -->|"extracts sections"| node_sections
node_editor_wrapper -->|"renders"| node_suggestions_panel
node_editor_wrapper -->|"renders"| node_inconsistency_panel
node_editor_wrapper -->|"renders"| node_qa_panel
node_editor -->|"syncs CRDT"| node_sync_server
node_editor_wrapper -->|"calls REST API"| node_backend_api
node_document_ui -.->|"manages documents"| node_backend_api
node_sync_server -->|"registers persistence"| node_persistence
node_sync_server -->|"checks access"| node_postgres
node_persistence -->|"loads and saves snapshots"| node_s3
node_persistence -->|"reads and updates metadata"| node_postgres
node_backend_api -->|"reads and writes records"| node_postgres
node_ai_routes -->|"calls generation"| node_llm
node_ai_routes -->|"retrieves chunks"| node_embeddings
node_ai_routes -->|"logs and caches"| node_observability
node_llm -->|"requests completions"| node_gemini
node_embeddings -->|"requests embeddings"| node_gemini
node_embeddings -->|"stores and searches vectors"| node_postgres
node_observability -->|"stores events and cache"| node_postgres

click node_auth_ui "https://github.com/soham842op/livedocs/blob/master/frontend/src/app/login/page.tsx"
click node_auth_context "https://github.com/soham842op/livedocs/blob/master/frontend/src/context/AuthContext.tsx"
click node_document_ui "https://github.com/soham842op/livedocs/blob/master/frontend/src/components/Sidebar.tsx"
click node_editor_wrapper "https://github.com/soham842op/livedocs/blob/master/frontend/src/components/EditorWrapper.tsx"
click node_editor "https://github.com/soham842op/livedocs/blob/master/frontend/src/components/Editor.tsx"
click node_toolbar "https://github.com/soham842op/livedocs/blob/master/frontend/src/components/Toolbar.tsx"
click node_suggestions_panel "https://github.com/soham842op/livedocs/blob/master/frontend/src/components/SuggestionsPanel.tsx"
click node_inconsistency_panel "https://github.com/soham842op/livedocs/blob/master/frontend/src/components/InconsistenciesPanel.tsx"
click node_qa_panel "https://github.com/soham842op/livedocs/blob/master/frontend/src/components/QAPanel.tsx"
click node_sections "https://github.com/soham842op/livedocs/blob/master/frontend/src/lib/extract-sections.ts"
click node_supabase_client "https://github.com/soham842op/livedocs/blob/master/frontend/src/lib/supabase.ts"
click node_sync_server "https://github.com/soham842op/livedocs/blob/master/sync-server/index.js"
click node_persistence "https://github.com/soham842op/livedocs/blob/master/sync-server/persistence.js"
click node_backend_api "https://github.com/soham842op/livedocs/blob/master/backend/main.py"
click node_ai_routes "https://github.com/soham842op/livedocs/blob/master/backend/main.py"
click node_llm "https://github.com/soham842op/livedocs/blob/master/backend/llm.py"
click node_embeddings "https://github.com/soham842op/livedocs/blob/master/backend/embeddings.py"
click node_observability "https://github.com/soham842op/livedocs/blob/master/backend/observability.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_auth_ui,node_auth_context,node_document_ui,node_editor_wrapper,node_editor,node_toolbar,node_suggestions_panel,node_inconsistency_panel,node_qa_panel,node_sections,node_supabase_client,node_user toneBlue
class node_sync_server,node_persistence toneAmber
class node_backend_api,node_ai_routes,node_gemini toneMint
class node_llm,node_embeddings,node_observability toneRose
class node_postgres,node_s3 toneIndigo
```

## Components

### Frontend

- [Auth UI](https://github.com/soham842op/livedocs/blob/master/frontend/src/app/login/page.tsx): `frontend/src/app/login/page.tsx`
- [Auth context](https://github.com/soham842op/livedocs/blob/master/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [Document dashboard](https://github.com/soham842op/livedocs/blob/master/frontend/src/components/Sidebar.tsx): `frontend/src/components/Sidebar.tsx`
- [Editor workflow](https://github.com/soham842op/livedocs/blob/master/frontend/src/components/EditorWrapper.tsx): `frontend/src/components/EditorWrapper.tsx`
- [Collaborative editor](https://github.com/soham842op/livedocs/blob/master/frontend/src/components/Editor.tsx): `frontend/src/components/Editor.tsx`
- [Formatting toolbar](https://github.com/soham842op/livedocs/blob/master/frontend/src/components/Toolbar.tsx): `frontend/src/components/Toolbar.tsx`
- [Suggestions panel](https://github.com/soham842op/livedocs/blob/master/frontend/src/components/SuggestionsPanel.tsx): `frontend/src/components/SuggestionsPanel.tsx`
- [Inconsistency panel](https://github.com/soham842op/livedocs/blob/master/frontend/src/components/InconsistenciesPanel.tsx): `frontend/src/components/InconsistenciesPanel.tsx`
- [Q&A panel](https://github.com/soham842op/livedocs/blob/master/frontend/src/components/QAPanel.tsx): `frontend/src/components/QAPanel.tsx`
- [Section extraction](https://github.com/soham842op/livedocs/blob/master/frontend/src/lib/extract-sections.ts): `frontend/src/lib/extract-sections.ts`
- [Supabase client](https://github.com/soham842op/livedocs/blob/master/frontend/src/lib/supabase.ts): `frontend/src/lib/supabase.ts`

### Realtime sync

- [WebSocket gateway](https://github.com/soham842op/livedocs/blob/master/sync-server/index.js): `sync-server/index.js`
- [Snapshot persistence](https://github.com/soham842op/livedocs/blob/master/sync-server/persistence.js): `sync-server/persistence.js`

### Backend API

- [Auth and document API](https://github.com/soham842op/livedocs/blob/master/backend/main.py): `backend/main.py`
- [AI request routes](https://github.com/soham842op/livedocs/blob/master/backend/main.py): `backend/main.py`

### AI services

- [LLM generation](https://github.com/soham842op/livedocs/blob/master/backend/llm.py): `backend/llm.py`
- [Embedding and retrieval](https://github.com/soham842op/livedocs/blob/master/backend/embeddings.py): `backend/embeddings.py`
- [LLM cache and events](https://github.com/soham842op/livedocs/blob/master/backend/observability.py): `backend/observability.py`

### Data stores

- **Supabase Postgres**
- **S3 snapshots**

### Other components

- **Document user**
- **Gemini API**

## Connections

- Document user → Auth UI: signs in (evidence: `README.md`)
- Document user → Document dashboard: manages documents
- Document user → Collaborative editor: edits document (evidence: `README.md`)
- Auth UI → Auth context: uses sessions
- Editor workflow → Collaborative editor: renders (evidence: `frontend/src/components/EditorWrapper.tsx`)
- Collaborative editor → Formatting toolbar: renders (evidence: `frontend/src/components/Editor.tsx`)
- Editor workflow → Section extraction: extracts sections (evidence: `frontend/src/components/EditorWrapper.tsx`)
- Editor workflow → Suggestions panel: renders (evidence: `frontend/src/components/EditorWrapper.tsx`)
- Editor workflow → Inconsistency panel: renders (evidence: `frontend/src/components/EditorWrapper.tsx`)
- Editor workflow → Q&A panel: renders (evidence: `frontend/src/components/EditorWrapper.tsx`)
- Collaborative editor → WebSocket gateway: syncs CRDT (evidence: `frontend/src/components/Editor.tsx`)
- Editor workflow → Auth and document API: calls REST API (evidence: `frontend/src/components/EditorWrapper.tsx`)
- Document dashboard → Auth and document API: manages documents
- WebSocket gateway → Snapshot persistence: registers persistence (evidence: `sync-server/index.js`)
- WebSocket gateway → Supabase Postgres: checks access (evidence: `sync-server/index.js`)
- Snapshot persistence → S3 snapshots: loads and saves snapshots (evidence: `sync-server/persistence.js`)
- Snapshot persistence → Supabase Postgres: reads and updates metadata (evidence: `sync-server/persistence.js`)
- Auth and document API → Supabase Postgres: reads and writes records (evidence: `backend/main.py`)
- AI request routes → LLM generation: calls generation (evidence: `backend/main.py`)
- AI request routes → Embedding and retrieval: retrieves chunks (evidence: `backend/main.py`)
- AI request routes → LLM cache and events: logs and caches (evidence: `backend/main.py`)
- LLM generation → Gemini API: requests completions (evidence: `backend/llm.py`)
- Embedding and retrieval → Gemini API: requests embeddings (evidence: `backend/embeddings.py`)
- Embedding and retrieval → Supabase Postgres: stores and searches vectors (evidence: `backend/embeddings.py`)
- LLM cache and events → Supabase Postgres: stores events and cache (evidence: `backend/observability.py`)
