How ka-206/glyph works
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: main.py FastAPI request boundary · main.jsx Vite bootstrap · App.jsx Upload & chat UI · rag.py Context retrieval
Components 13
Browser client
React/Vite upload and chat application.
- Vite bootstrap · Starts the React client under Node.js 18+.
frontend/src/main.jsx - Upload & chat UI · Collects PDFs and prompts and renders responses.
frontend/src/App.jsx - App styling
frontend/src/App.css - Frontend runtime config
frontend/vite.config.js - Frontend dependencies
frontend/package.json
Local Python service
FastAPI API, volatile session state, and RAG processing.
- FastAPI request boundary · Authoritative local HTTP boundary for uploads and session chat.
backend/main.py - Upload validation · Limits uploads to three PDFs, 10 MB each, and 30 MB total.
backend/main.py - In-memory sessions · Document indexes and chat state disappear on restart.
backend/main.py - RAG pipeline · Keeps document and query processing separate from HTTP concerns.
backend/rag.py - Context retrieval · Selects session-relevant document context for each question.
backend/rag.py - Model input construction · Builds Groq input from the question and retrieved context.
backend/rag.py - Backend dependencies
backend/requirements.txt
External model service
- Groq models · Requires internet access, API key, and configured model.
Connections 15
- 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