Skip to main content

Backend

The TinkerPilot backend is a Python application built with FastAPI. It serves as the core engine for the entire application, handling API requests, AI inference, database operations, and serving the frontend in a production environment.

API Server

The main entry point for the backend is backend/app/main.py. This file initializes the FastAPI application, sets up middleware, and includes all the API routers.

Lifespan Management

The @asynccontextmanager lifespan function in main.py handles startup and shutdown logic. On startup, it:

  • Ensures all necessary directories exist.
  • Initializes the SQLite database.
  • Handles background tasks like indexing an Obsidian vault (if configured) and pre-warming the daily digest.

CORS Middleware

The backend is configured with CORS (Cross-Origin Resource Sharing) to allow the frontend development server (running on localhost:3000) to communicate with the API server (running on localhost:8000).

Serving the Frontend

In a production build (created via the global installer), the FastAPI server is also responsible for serving the static Next.js frontend. The serve_frontend function in main.py handles this, allowing TinkerPilot to run as a single, self-contained application.

API Endpoints

The API is organized into several routers, each corresponding to a specific feature. The main routers are:

RouterPrefixDescription
chat_router/apiHandles chat messages and WebSocket connections
documents_router/apiManages document ingestion and retrieval
meetings_router/apiHandles meeting transcription and summaries
tasks_router/apiProvides CRUD operations for tasks
digest_router/apiGenerates the daily digest
search_router/apiPowers the unified search
utils_router/apiProvides various developer utilities

Here is a list of the most important endpoints:

MethodEndpointDescription
GET/api/healthHealth check
POST/api/chatSend a chat message (with/without RAG)
WS/api/ws/chatWebSocket streaming chat
GET/api/chat/historyGet chat history
POST/api/documents/uploadUpload and ingest a file
POST/api/documents/ingestIngest a local path
GET/api/documentsList indexed documents
POST/api/meetings/transcribeUpload audio and transcribe
GET/api/meetingsList meetings
POST/GET/PUT/DELETE/api/tasksTask CRUD
GET/api/digestGenerate daily digest
GET/POST/api/searchUnified search
POST/api/utils/explainExplain code
POST/api/utils/cmdNatural language to shell command
POST/api/utils/git-digestSummarize git activity
POST/api/utils/speakText-to-speech (returns WAV)
GET/api/utils/voicesList available TTS voices

Database

TinkerPilot uses SQLite for storing structured data. The database models are defined in backend/app/db/models.py using SQLModel.

Database Schema

There are four main tables in the database:

  • Document: Tracks ingested documents for RAG. It stores metadata like the filename, path, file type, and the number of chunks.
  • Meeting: Stores meeting transcriptions and summaries, along with metadata like the date, duration, and the path to the audio file.
  • Task: Represents a single task or to-do item. Tasks can be linked to a source, such as a meeting or a document.
  • ChatMessage: Stores the chat history for all conversations. Each message has a role (user or assistant) and content.

This simple but effective schema allows TinkerPilot to store and manage all the user's data locally.

Python Dependencies (installed automatically)

PackagePurpose
fastapi, uvicornBackend API server
moonshine-voiceSpeech-to-text (pulls PyTorch)
kokoroText-to-speech (pulls PyTorch)
chromadbVector database for RAG
sqlmodel, aiosqliteSQLite ORM + async driver
PyMuPDF, python-docxPDF and DOCX parsing
sounddevice, soundfileAudio I/O
typer, richCLI framework
httpxHTTP client (Ollama communication)
pyyamlConfig file parsing
img2pdfImage-to-PDF conversion

Note: The installer pre-installs only the minimal ML runtime needed for your platform — just torch (for TTS) and onnxruntime (for STT). Unnecessary transitive dependencies like torchaudio, torchvision, and onnxruntime-gpu are avoided. On Linux without an NVIDIA GPU, CPU-only PyTorch (~1 GB) is used instead of the default CUDA build (~2.5 GB).