# ka-206/glyph architecture

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

- Interactive diagram: https://gitdiagram.com/ka-206/glyph
- Repository: https://github.com/ka-206/glyph

## Overview

#### Purpose and topology
Glyph is a local PDF question-answering application: a React/Vite browser client uploads PDFs and submits chat questions to a FastAPI service. The backend maintains session state in memory, performs retrieval-augmented generation (RAG), and calls Groq-hosted models. Core boundaries are the browser, local HTTP API, in-memory backend state, PDF/RAG processing, and the external Groq API.

Paths: `frontend/src/App.jsx`, `backend/main.py`, `backend/rag.py`

#### Frontend entry and interaction layer
The Vite application boots from `frontend/src/main.jsx` and renders the primary chat/upload experience from `frontend/src/App.jsx`. It is responsible for collecting PDF files and user prompts, calling the backend at the configured local address, and rendering upload/chat responses. Styling is colocated with the application rather than separated into a component library.

Paths: `frontend/src/main.jsx`, `frontend/src/App.jsx`, `frontend/src/App.css`

#### API service and request boundary
`backend/main.py` is the FastAPI/uvicorn entry point (`uvicorn main:app --reload`). It is the authoritative boundary for frontend requests, including file-upload validation and session-oriented chat operations. The backend enforces at most three PDFs, 10 MB per file, and 30 MB total per upload; clients should not be trusted to enforce these limits.

Paths: `backend/main.py`, `backend/.env.example`

#### Document ingestion and RAG stage
`backend/rag.py` encapsulates the document intelligence layer: PDF-derived content is prepared for retrieval, relevant context is selected for a question, and that context is used to form model input. This module separates document/query processing from HTTP concerns in `main.py`, making it the principal place to evolve chunking, retrieval, prompt construction, or answer-source behavior.

Paths: `backend/rag.py`, `backend/main.py`

#### Session and control flow
The expected flow is: user selects PDFs → frontend uploads to FastAPI → backend validates and indexes/prepares documents for an in-memory session → user sends a question → backend retrieves session-relevant document context → backend invokes Groq → answer returns to the frontend chat UI. Sessions disappear on backend restart, so neither document state nor chat state is durable.

Paths: `frontend/src/App.jsx`, `backend/main.py`, `backend/rag.py`

#### Runtime, dependencies, and external service
The frontend runs under Node.js 18+ using Vite; the backend requires Python 3.10+ and FastAPI dependencies declared in `backend/requirements.txt`. Groq is the material external dependency and requires internet access plus `GROQ_API_KEY` and `GROQ_MODEL_NAME`; the README’s default model is `llama-3.3-70b-versatile`. Local development assumes the backend at `http://127.0.0.1:8000`.

Paths: `frontend/package.json`, `frontend/vite.config.js`, `backend/requirements.txt`

Main entry points: [`backend/main.py`](https://github.com/ka-206/glyph/blob/master/backend/main.py) (FastAPI request boundary), [`frontend/src/main.jsx`](https://github.com/ka-206/glyph/blob/master/frontend/src/main.jsx) (Vite bootstrap), [`frontend/src/App.jsx`](https://github.com/ka-206/glyph/blob/master/frontend/src/App.jsx) (Upload & chat UI), [`backend/rag.py`](https://github.com/ka-206/glyph/blob/master/backend/rag.py) (Context retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser client"]
  node_vite{{"Vite bootstrap<br/>frontend runtime<br/>[main.jsx]"}}
  node_app["Upload &amp; chat UI<br/>React app<br/>[App.jsx]"]
  node_styles["App styling<br/>CSS<br/>[App.css]"]
  node_frontend_config["Frontend runtime config<br/>Vite config<br/>[vite.config.js]"]
  node_frontend_deps["Frontend dependencies<br/>package manifest<br/>[package.json]"]
end

subgraph group_backend["Local Python service"]
  node_api["FastAPI request boundary<br/>FastAPI service<br/>[main.py]"]
  node_upload_validation["Upload validation<br/>API policy<br/>[main.py]"]
  node_session_state[("In-memory sessions<br/>volatile state<br/>[main.py]")]
  node_rag["RAG pipeline<br/>document intelligence<br/>[rag.py]"]
  node_retrieval["Context retrieval<br/>RAG stage<br/>[rag.py]"]
  node_model_input["Model input construction<br/>RAG stage<br/>[rag.py]"]
  node_backend_deps["Backend dependencies<br/>Python requirements<br/>[requirements.txt]"]
end

subgraph group_external["External model service"]
  node_groq{{"Groq models<br/>external LLM API"}}
end

node_vite -->|"renders"| node_app
node_styles -->|"styles"| node_app
node_frontend_config -->|"configures"| node_vite
node_frontend_deps -->|"provides runtime"| node_vite
node_app -->|"local HTTP upload/chat"| node_api
node_api -->|"validates uploads"| node_upload_validation
node_upload_validation -->|"accepted PDFs"| node_rag
node_api -->|"maintains session"| node_session_state
node_rag -->|"prepares document index"| node_session_state
node_api -->|"question + session"| node_retrieval
node_session_state -->|"indexed documents"| node_retrieval
node_retrieval -->|"relevant context"| node_model_input
node_model_input -->|"model request"| node_groq
node_groq -->|"answer"| node_api
node_backend_deps -->|"provides runtime"| node_api

click node_vite "https://github.com/ka-206/glyph/blob/master/frontend/src/main.jsx"
click node_app "https://github.com/ka-206/glyph/blob/master/frontend/src/App.jsx"
click node_styles "https://github.com/ka-206/glyph/blob/master/frontend/src/App.css"
click node_frontend_config "https://github.com/ka-206/glyph/blob/master/frontend/vite.config.js"
click node_frontend_deps "https://github.com/ka-206/glyph/blob/master/frontend/package.json"
click node_api "https://github.com/ka-206/glyph/blob/master/backend/main.py"
click node_upload_validation "https://github.com/ka-206/glyph/blob/master/backend/main.py"
click node_session_state "https://github.com/ka-206/glyph/blob/master/backend/main.py"
click node_rag "https://github.com/ka-206/glyph/blob/master/backend/rag.py"
click node_retrieval "https://github.com/ka-206/glyph/blob/master/backend/rag.py"
click node_model_input "https://github.com/ka-206/glyph/blob/master/backend/rag.py"
click node_backend_deps "https://github.com/ka-206/glyph/blob/master/backend/requirements.txt"

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_vite,node_app,node_styles,node_frontend_config,node_frontend_deps toneBlue
class node_api,node_upload_validation,node_session_state,node_rag,node_retrieval,node_model_input,node_backend_deps toneAmber
class node_groq toneMint
```

## Components

### Browser client

React/Vite upload and chat application.

- [Vite bootstrap](https://github.com/ka-206/glyph/blob/master/frontend/src/main.jsx): frontend runtime · Starts the React client under Node.js 18+. · `frontend/src/main.jsx`
- [Upload & chat UI](https://github.com/ka-206/glyph/blob/master/frontend/src/App.jsx): React app · Collects PDFs and prompts and renders responses. · `frontend/src/App.jsx`
- [App styling](https://github.com/ka-206/glyph/blob/master/frontend/src/App.css): CSS · `frontend/src/App.css`
- [Frontend runtime config](https://github.com/ka-206/glyph/blob/master/frontend/vite.config.js): Vite config · `frontend/vite.config.js`
- [Frontend dependencies](https://github.com/ka-206/glyph/blob/master/frontend/package.json): package manifest · `frontend/package.json`

### Local Python service

FastAPI API, volatile session state, and RAG processing.

- [FastAPI request boundary](https://github.com/ka-206/glyph/blob/master/backend/main.py): FastAPI service · Authoritative local HTTP boundary for uploads and session chat. · `backend/main.py`
- [Upload validation](https://github.com/ka-206/glyph/blob/master/backend/main.py): API policy · Limits uploads to three PDFs, 10 MB each, and 30 MB total. · `backend/main.py`
- [In-memory sessions](https://github.com/ka-206/glyph/blob/master/backend/main.py): volatile state · Document indexes and chat state disappear on restart. · `backend/main.py`
- [RAG pipeline](https://github.com/ka-206/glyph/blob/master/backend/rag.py): document intelligence · Keeps document and query processing separate from HTTP concerns. · `backend/rag.py`
- [Context retrieval](https://github.com/ka-206/glyph/blob/master/backend/rag.py): RAG stage · Selects session-relevant document context for each question. · `backend/rag.py`
- [Model input construction](https://github.com/ka-206/glyph/blob/master/backend/rag.py): RAG stage · Builds Groq input from the question and retrieved context. · `backend/rag.py`
- [Backend dependencies](https://github.com/ka-206/glyph/blob/master/backend/requirements.txt): Python requirements · `backend/requirements.txt`

### External model service

- **Groq models**: external LLM API · Requires internet access, API key, and configured model.

## Connections

- Vite bootstrap → Upload & chat UI: renders
- App styling → Upload & chat UI: styles
- Frontend runtime config → Vite bootstrap: configures
- Frontend dependencies → Vite bootstrap: provides runtime
- Upload & chat UI → FastAPI request boundary: local HTTP upload/chat
- FastAPI request boundary → Upload validation: validates uploads
- Upload validation → RAG pipeline: accepted PDFs
- FastAPI request boundary → In-memory sessions: maintains session
- RAG pipeline → In-memory sessions: prepares document index
- FastAPI request boundary → Context retrieval: question + session
- In-memory sessions → Context retrieval: indexed documents
- Context retrieval → Model input construction: relevant context
- Model input construction → Groq models: model request
- Groq models → FastAPI request boundary: answer
- Backend dependencies → FastAPI request boundary: provides runtime
