# abujubair7/edith architecture

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

- Interactive diagram: https://gitdiagram.com/abujubair7/edith
- Repository: https://github.com/abujubair7/edith

## Overview

1. **What this repo is**
   - This is a two-tier TypeScript application: a **React/Vite frontend** and a **Node backend**.
   - The naming suggests a **chat + document-assistant** product rather than a general web app: there are PDF processing utilities, retrieval logic, and multiple LLM backends.

2. **Frontend boundary**
   - The frontend lives in `frontend/` and is a **client-only UI** built with **React + TypeScript + Vite**.
   - Its job is presentation and user interaction: `ChatPage`, `LoginPage`, message rendering, markdown rendering, chat history, and a typewriter effect.
   - `src/api.ts` is the main boundary to the backend; the browser does not appear to talk directly to AI providers.

3. **Frontend UI structure**
   - `pages/ChatPage.tsx` is the main interaction surface for conversations.
   - `components/MessageBubble.tsx` and `MarkdownRenderer.tsx` show that assistant responses are rendered as rich text, not plain strings.
   - `hooks/useChatHistory.ts` and `hooks/useTypewriter.ts` indicate local UI state management for conversation persistence and streaming-like message display.

4. **Backend entry point and API layer**
   - The backend lives in `backend/` and starts from `src/app.ts`.
   - This file is the likely HTTP server and request routing boundary for the frontend.
   - The backend appears to expose a single application API that orchestrates AI calls, document extraction, and retrieval rather than exposing those concerns directly to the browser.

5. **LLM integration is split by provider**
   - `src/assistant/gemini.ts` and `src/interfaces/gemini.interface.ts` indicate one integration path for **Gemini**.
   - `src/localAI/ollama.ts` and `src/interfaces/ollama.interface.ts` indicate a second path for **local models via Ollama**.
   - This is an important architectural boundary: the repo supports both **cloud AI** and **local AI** with provider-specific contracts.

6. **Assistant orchestration layer**
   - `src/assistant/extractor.ts` looks like the high-level orchestration for turning content into structured outputs.
   - The naming suggests it coordinates prompts, tool logic, or extraction workflows rather than being a provider wrapper itself.
   - This is likely where incoming user requests are translated into the right model call and post-processed into UI-ready responses.

7. **Document ingestion and retrieval path**
   - `src/utils/processPdf.ts` is the clearest sign of a **PDF ingestion pipeline**.
   - `src/localAI/localExtract.ts`, `src/localAI/rag.ts`, and `src/utils/cosineSimilarity.ts` suggest a local **RAG-style retrieval flow**: extract text, compare chunks or candidates, and select the most relevant context.
   - The architecture likely supports asking questions over uploaded PDFs or extracted document content.

8. **Data flow through the backend**
   - A typical flow is: **frontend sends user input and/or document context → backend parses/processes it → PDF text is extracted if needed → relevant chunks are ranked using similarity logic → chosen context is passed to Gemini or Ollama → response is returned to the frontend**.
   - This keeps document processing and AI orchestration on the server side, away from the browser.

9. **Core abstraction boundaries**
   - The `interfaces/` folder shows the project uses explicit provider contracts, which helps isolate the app from vendor-specific request/response shapes.
   - The `utils/` folder contains shared low-level helpers, while `assistant/` and `localAI/` contain higher-level workflow logic.
   - That separation makes it easier to swap model providers or change the retrieval strategy without rewriting the UI.

10. **Tech stack and runtime boundaries**
   - Frontend runtime: **browser**, built with **React/TypeScript/Vite**.
   - Backend runtime: **Node.js/TypeScript**.
   - External dependencies that materially affect architecture are **Gemini API** and **Ollama**; both are first-class integration points.

11. **What is not central here**
   - The README included in the repo is an **MCP notes document**, but the file tree does not show an actual MCP server implementation.
   - So MCP should be treated as background documentation/context, not a runtime subsystem in this repository.

12. **How to draw the architecture**
   - Draw three main blocks: **UI client**, **backend orchestrator**, and **model/document services**.
   - Inside the backend, split into **API entrypoint**, **assistant orchestration**, **document processing/RAG**, and **provider adapters**.
   - Show the backend as the only component that touches **Gemini/Ollama** and the only component that performs **PDF parsing and similarity-based retrieval**.

Main entry points: [`frontend/src/pages/ChatPage.tsx`](https://github.com/abujubair7/edith/blob/main/frontend/src/pages/ChatPage.tsx) (Chat page), [`backend/src/assistant/extractor.ts`](https://github.com/abujubair7/edith/blob/main/backend/src/assistant/extractor.ts) (Assistant core), [`backend/src/localAI/rag.ts`](https://github.com/abujubair7/edith/blob/main/backend/src/localAI/rag.ts) (RAG flow), [`frontend/src/App.tsx`](https://github.com/abujubair7/edith/blob/main/frontend/src/App.tsx) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["App shell<br/>React app<br/>[App.tsx]"]
  node_frontend_chat["Chat page<br/>UI page<br/>[ChatPage.tsx]"]
  node_frontend_login["Login page<br/>UI page<br/>[LoginPage.tsx]"]
  node_frontend_api["API client<br/>HTTP client<br/>[api.ts]"]
  node_frontend_bubbles["Message UI<br/>rendering<br/>[MessageBubble.tsx]"]
  node_frontend_markdown["Markdown<br/>renderer"]
  node_frontend_history(("Chat history<br/>hook<br/>[useChatHistory.ts]"))
  node_frontend_typewriter(("Typewriter<br/>hook<br/>[useTypewriter.ts]"))
end

subgraph group_backend["Backend"]
  node_backend_app["Server app<br/>HTTP server<br/>[app.ts]"]
  node_backend_extractor["Assistant core<br/>orchestration<br/>[extractor.ts]"]
  node_backend_gemini["Gemini adapter<br/>provider adapter<br/>[gemini.ts]"]
  node_backend_ollama["Ollama adapter<br/>provider adapter<br/>[ollama.ts]"]
  node_backend_rag["RAG flow<br/>retrieval pipeline<br/>[rag.ts]"]
  node_backend_extract["Text extract<br/>document extraction<br/>[localExtract.ts]"]
  node_backend_pdf["PDF process<br/>document pipeline<br/>[processPdf.ts]"]
  node_backend_similarity{{"Similarity<br/>scoring utility"}}
  node_backend_tools["Shared tools<br/>helpers<br/>[tools.ts]"]
  node_iface_gemini["Gemini iface<br/>contract"]
  node_iface_ollama["Ollama iface<br/>contract"]
end

subgraph group_providers["Model providers"]
end

node_frontend_app -->|"renders"| node_frontend_chat
node_frontend_app -->|"routes to"| node_frontend_login
node_frontend_chat -->|"calls"| node_frontend_api
node_frontend_chat -->|"uses"| node_frontend_bubbles
node_frontend_bubbles -->|"formats"| node_frontend_markdown
node_frontend_chat -->|"stores"| node_frontend_history
node_frontend_chat -->|"animates"| node_frontend_typewriter
node_frontend_api -->|"requests"| node_backend_app
node_backend_app -->|"orchestrates"| node_backend_extractor
node_backend_extractor -->|"cloud path"| node_backend_gemini
node_backend_extractor -->|"local path"| node_backend_ollama
node_backend_extractor -->|"retrieves context"| node_backend_rag
node_backend_rag -->|"reads text"| node_backend_extract
node_backend_extract -->|"parses"| node_backend_pdf
node_backend_rag -->|"ranks"| node_backend_similarity
node_backend_extractor -->|"uses"| node_backend_tools
node_backend_gemini -->|"implements"| node_iface_gemini
node_backend_ollama -->|"implements"| node_iface_ollama

click node_frontend_app "https://github.com/abujubair7/edith/blob/main/frontend/src/App.tsx"
click node_frontend_chat "https://github.com/abujubair7/edith/blob/main/frontend/src/pages/ChatPage.tsx"
click node_frontend_login "https://github.com/abujubair7/edith/blob/main/frontend/src/pages/LoginPage.tsx"
click node_frontend_api "https://github.com/abujubair7/edith/blob/main/frontend/src/api.ts"
click node_frontend_bubbles "https://github.com/abujubair7/edith/blob/main/frontend/src/components/MessageBubble.tsx"
click node_frontend_markdown "https://github.com/abujubair7/edith/blob/main/frontend/src/components/MarkdownRenderer.tsx"
click node_frontend_history "https://github.com/abujubair7/edith/blob/main/frontend/src/hooks/useChatHistory.ts"
click node_frontend_typewriter "https://github.com/abujubair7/edith/blob/main/frontend/src/hooks/useTypewriter.ts"
click node_backend_app "https://github.com/abujubair7/edith/blob/main/backend/src/app.ts"
click node_backend_extractor "https://github.com/abujubair7/edith/blob/main/backend/src/assistant/extractor.ts"
click node_backend_gemini "https://github.com/abujubair7/edith/blob/main/backend/src/assistant/gemini.ts"
click node_backend_ollama "https://github.com/abujubair7/edith/blob/main/backend/src/localAI/ollama.ts"
click node_backend_rag "https://github.com/abujubair7/edith/blob/main/backend/src/localAI/rag.ts"
click node_backend_extract "https://github.com/abujubair7/edith/blob/main/backend/src/localAI/localExtract.ts"
click node_backend_pdf "https://github.com/abujubair7/edith/blob/main/backend/src/utils/processPdf.ts"
click node_backend_similarity "https://github.com/abujubair7/edith/blob/main/backend/src/utils/cosineSimilarity.ts"
click node_backend_tools "https://github.com/abujubair7/edith/blob/main/backend/src/utils/tools.ts"
click node_iface_gemini "https://github.com/abujubair7/edith/blob/main/backend/src/interfaces/gemini.interface.ts"
click node_iface_ollama "https://github.com/abujubair7/edith/blob/main/backend/src/interfaces/ollama.interface.ts"

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_frontend_app,node_frontend_chat,node_frontend_login,node_frontend_api,node_frontend_bubbles,node_frontend_markdown,node_frontend_history,node_frontend_typewriter toneBlue
class node_backend_app,node_backend_extractor,node_backend_gemini,node_backend_ollama,node_backend_rag,node_backend_extract,node_backend_pdf,node_backend_similarity,node_backend_tools,node_iface_gemini,node_iface_ollama toneAmber
```

## Components

### Frontend

React/Vite client UI

- [App shell](https://github.com/abujubair7/edith/blob/main/frontend/src/App.tsx): React app · Top-level client application and routing container. · `frontend/src/App.tsx`
- [Chat page](https://github.com/abujubair7/edith/blob/main/frontend/src/pages/ChatPage.tsx): UI page · Primary conversation and document-assistant interface. · `frontend/src/pages/ChatPage.tsx`
- [Login page](https://github.com/abujubair7/edith/blob/main/frontend/src/pages/LoginPage.tsx): UI page · Authentication or entry screen for the client. · `frontend/src/pages/LoginPage.tsx`
- [API client](https://github.com/abujubair7/edith/blob/main/frontend/src/api.ts): HTTP client · Browser-side boundary for calling backend endpoints. · `frontend/src/api.ts`
- [Message UI](https://github.com/abujubair7/edith/blob/main/frontend/src/components/MessageBubble.tsx): rendering · Chat message presentation and rich-text rendering. · `frontend/src/components/MessageBubble.tsx`
- [Markdown](https://github.com/abujubair7/edith/blob/main/frontend/src/components/MarkdownRenderer.tsx): renderer · Formats assistant responses as markdown content. · `frontend/src/components/MarkdownRenderer.tsx`
- [Chat history](https://github.com/abujubair7/edith/blob/main/frontend/src/hooks/useChatHistory.ts): hook · Client-side conversation persistence and state sync. · `frontend/src/hooks/useChatHistory.ts`
- [Typewriter](https://github.com/abujubair7/edith/blob/main/frontend/src/hooks/useTypewriter.ts): hook · Streaming-style text reveal for assistant output. · `frontend/src/hooks/useTypewriter.ts`

### Backend

Node orchestration and retrieval

- [Server app](https://github.com/abujubair7/edith/blob/main/backend/src/app.ts): HTTP server · Backend entrypoint and request routing boundary. · `backend/src/app.ts`
- [Assistant core](https://github.com/abujubair7/edith/blob/main/backend/src/assistant/extractor.ts): orchestration · Coordinates prompts, extraction, and response shaping. · `backend/src/assistant/extractor.ts`
- [Gemini adapter](https://github.com/abujubair7/edith/blob/main/backend/src/assistant/gemini.ts): provider adapter · Cloud-model integration for Gemini. · `backend/src/assistant/gemini.ts`
- [Ollama adapter](https://github.com/abujubair7/edith/blob/main/backend/src/localAI/ollama.ts): provider adapter · Local-model integration for Ollama. · `backend/src/localAI/ollama.ts`
- [RAG flow](https://github.com/abujubair7/edith/blob/main/backend/src/localAI/rag.ts): retrieval pipeline · Ranks document chunks and prepares relevant context. · `backend/src/localAI/rag.ts`
- [Text extract](https://github.com/abujubair7/edith/blob/main/backend/src/localAI/localExtract.ts): document extraction · Extracts structured text from local content sources. · `backend/src/localAI/localExtract.ts`
- [PDF process](https://github.com/abujubair7/edith/blob/main/backend/src/utils/processPdf.ts): document pipeline · Handles PDF parsing and preprocessing. · `backend/src/utils/processPdf.ts`
- [Similarity](https://github.com/abujubair7/edith/blob/main/backend/src/utils/cosineSimilarity.ts): scoring utility · Computes cosine similarity for retrieval ranking. · `backend/src/utils/cosineSimilarity.ts`
- [Shared tools](https://github.com/abujubair7/edith/blob/main/backend/src/utils/tools.ts): helpers · Common backend utilities used across orchestration paths. · `backend/src/utils/tools.ts`
- [Gemini iface](https://github.com/abujubair7/edith/blob/main/backend/src/interfaces/gemini.interface.ts): contract · Type contract for Gemini requests and responses. · `backend/src/interfaces/gemini.interface.ts`
- [Ollama iface](https://github.com/abujubair7/edith/blob/main/backend/src/interfaces/ollama.interface.ts): contract · Type contract for Ollama requests and responses. · `backend/src/interfaces/ollama.interface.ts`

## Connections

- App shell → Chat page: renders · The app shell hosts the chat experience.
- App shell → Login page: routes to · The app shell also exposes the login entry screen.
- Chat page → API client: calls · Chat interactions are sent through the API client.
- Chat page → Message UI: uses · Conversation UI is composed from message bubbles.
- Message UI → Markdown: formats · Assistant text is rendered as markdown.
- Chat page → Chat history: stores · Chat page relies on history state management.
- Chat page → Typewriter: animates · Assistant replies can be revealed progressively.
- API client → Server app: requests · Browser requests terminate at the backend server.
- Server app → Assistant core: orchestrates · The server delegates response generation to assistant logic.
- Assistant core → Gemini adapter: cloud path · One execution path targets Gemini.
- Assistant core → Ollama adapter: local path · Another execution path targets Ollama.
- Assistant core → RAG flow: retrieves context · Assistant orchestration can pull relevant document context.
- RAG flow → Text extract: reads text · RAG starts from extracted local content.
- Text extract → PDF process: parses · PDF processing feeds document extraction.
- RAG flow → Similarity: ranks · Similarity scoring selects the most relevant chunks.
- Assistant core → Shared tools: uses · Orchestration shares common backend helpers.
- Gemini adapter → Gemini iface: implements · Gemini adapter follows the Gemini contract.
- Ollama adapter → Ollama iface: implements · Ollama adapter follows the Ollama contract.
