Architecture
NotebookTG is a layered system with Telegram bot + FastAPI backend sharing services.
Runtime Layers
Telegram
→Bot
Services
→DB + Vector
→LLM
Interface
User-facing entry points
notebooktg/app/botTelegram Botaiogram handlers, commands, callbacksnotebooktg/app/apiFastAPIHTTP routes for notebooks, uploads, Q&AApplication
Business logic and workflows
notebooktg/app/servicesServicesNotebook, upload, note, sharing, answer, generationRetrieval & Ingestion
Data processing pipeline
notebooktg/app/ingestionIngestionPDF, TXT, DOCX, MD, CSV, EPUB extractionnotebooktg/app/retrievalRetrievalChunking, vector search, citation mappingInfrastructure
Core utilities and storage
notebooktg/app/dbDatabaseAsync SQLAlchemy, Alembic migrationsnotebooktg/app/llmLLMProvider abstraction for chat and embeddingsnotebooktg/app/coreCoreSettings, prompts, logging, validationTech Stack
Backend
Python, FastAPI, aiogram
Database
PostgreSQL + Alembic
Vector Store
Qdrant (or memory)
LLM
OpenAI-compatible
Design Decisions
- • Source grounding is notebook-scoped by default — retrieval searches within the selected notebook
- • Citations map to persisted chunks and are never fabricated
- • Notebooks carry persona, style, and answer-length preferences
- • Prompts layer protection against prompt injection — uploaded text treated as untrusted
- • Fallback behavior is explicit when evidence is missing
