NotebookTG
NotebookTG

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, callbacks
notebooktg/app/apiFastAPIHTTP routes for notebooks, uploads, Q&A

Application

Business logic and workflows

notebooktg/app/servicesServicesNotebook, upload, note, sharing, answer, generation

Retrieval & Ingestion

Data processing pipeline

notebooktg/app/ingestionIngestionPDF, TXT, DOCX, MD, CSV, EPUB extraction
notebooktg/app/retrievalRetrievalChunking, vector search, citation mapping

Infrastructure

Core utilities and storage

notebooktg/app/dbDatabaseAsync SQLAlchemy, Alembic migrations
notebooktg/app/llmLLMProvider abstraction for chat and embeddings
notebooktg/app/coreCoreSettings, prompts, logging, validation

Tech 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