This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
RectangularFile is a Flask-based document management system for handwritten notes from e-ink tablets. It uses any OpenAI-compatible vision API (vLLM, Ollama, OpenAI, Claude, etc.) for handwriting recognition and document processing.
python main.py- Run the application in development modepython app.py- Alternative entry point for compatibilitypython create_edits.py- Utility for database editspython db_migration_tool.py- Database migration utility
pip install -r requirements.txt- Install all dependencies
- Uses systemd service file:
rectangular-file.service - Production path:
/mnt/onyxfor PDF storage - Database path:
/mnt/rectangularfile/pdf_index.db
-
Flask Application (
app/)- Factory pattern with
create_app()function - Single-user authentication via Flask-Login
- Template-based UI with search, document viewer, and folder browser
- Factory pattern with
-
Database Layer (
db/)- SQLite database with schema versioning
DatabaseManagerhandles connections and operationsSchemaManagermanages database migrations- Stores document metadata, OCR results, and annotations
-
Document Processing (
processing/)FileWatchermonitors filesystem changesPDFProcessorhandles PDF text extractionVisionAPIClientperforms AI-powered handwriting recognition via OpenAI-compatible APIOCRQueueManagermanages async OCR processingDocumentArchivermoves processed files to archive directoryHTMLProcessorprocesses HTML files- Modular document sources:
BooxPDFSource,SaberNoteSource
-
Utilities (
utils/)helpers.py- Common utility functionswordcloud.py- Word cloud generation
- Files are detected by
FileWatcherin monitored directories PDFProcessorextracts basic text and metadataVisionAPIClientperforms handwriting OCR via external inference API- Results stored in database for search and browsing
DocumentArchivermoves processed files to archive (enabling re-upload detection)- Web interface provides search, viewing, and editing capabilities
All configuration is centralized in config.py with environment variable support:
Required Environment Variables:
SECRET_KEY- Flask secret key (generate withpython -c 'import secrets; print(secrets.token_hex(32))')APP_PASSWORD_HASH- SHA256 hash of admin password
Inference API Configuration:
INFERENCE_API_BASE- OpenAI-compatible API endpoint (default:http://localhost:8000/v1)INFERENCE_API_KEY- API key for cloud providers (optional for local servers)INFERENCE_MODEL- Model identifier (default:Qwen/Qwen2.5-VL-7B-Instruct)INFERENCE_MAX_TOKENS- Max response tokens (default:2048)INFERENCE_TIMEOUT- Request timeout in seconds (default:120)
File Storage:
UPLOAD_FOLDER- File monitoring directory (default:/mnt/onyx)DATABASE_PATH- SQLite database location (default:/mnt/rectangularfile/pdf_index.db)DEBUG_IMAGES_DIR- Debug output directory (default:/mnt/rectangularfile/debug_images)
Archive Configuration:
ARCHIVE_ENABLED- Enable document archiving (default:true)ARCHIVE_FOLDER- Archive directory (default:/mnt/rectangularfile/archive)ARCHIVE_PRESERVE_STRUCTURE- Maintain folder structure in archive (default:true)
Document Sources:
BOOX_ENABLED- Enable Boox PDF source (default:true)BOOX_FOLDER- Boox watch directory (defaults toUPLOAD_FOLDER)SABER_ENABLED- Enable Saber notes source (default:false)SABER_FOLDER- Saber sync folder (default:/mnt/webdav/saber)SABER_PASSWORD- Saber encryption password
Server Configuration:
POLLING_INTERVAL- File watcher interval in seconds (default:30.0)FLASK_HOST- Server bind address (default:0.0.0.0)FLASK_PORT- Server port (default:5000)FLASK_DEBUG- Debug mode (default:false)
RectangularFile works with any OpenAI-compatible vision API:
Local Servers:
- vLLM:
INFERENCE_API_BASE=http://localhost:8000/v1 - Ollama:
INFERENCE_API_BASE=http://localhost:11434/v1 - llama.cpp:
INFERENCE_API_BASE=http://localhost:8080/v1
Cloud APIs:
- OpenAI:
INFERENCE_API_BASE=https://api.openai.com/v1withINFERENCE_API_KEY=sk-... - Anthropic (via proxy): Use an OpenAI-compatible proxy
The system detects colored annotations in handwritten notes:
- RED ink → TODOs/action items (synced to CalDAV if configured)
- GREEN ink → Tags/categories
pdf_documents- Document metadata, processing status, archive pathspdf_text_content- Extracted and OCR text by pagedocument_annotations- Detected annotations (red TODOs, green tags)edit_history- Track user edits to transcriptionssettings- Application settings (CalDAV, inference API, etc.)
- PDF files (primary focus)
- Saber encrypted notes (.sbe files)
- HTML files (basic support)
- This is a single-user application with simple authentication
- No local GPU required — inference is handled by external API
- File watching uses polling by default (configurable interval)
- Processed documents are moved to archive to enable re-upload detection
- Database uses SQLite with WAL mode for concurrent access