This document provides an overview of the audiobook automation system architecture, designed for developers who want to understand how the system works internally.
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Web Browser βββββΊβ FastAPI Web βββββΊβ SQLite DB β
β (Frontend) β β Application β β (Storage) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β Notification β
β Services β
β (Discord, etc.) β
βββββββββββββββββββ
audiobook_dev/
βββ docs/ # Documentation (this folder)
β βββ user-guide/ # User documentation
β βββ development/ # Developer documentation
β βββ api/ # API documentation
βββ src/ # Source code
β βββ main.py # Application entry point
β βββ webui.py # FastAPI web interface
β βββ db.py # Database operations
β βββ config.py # Configuration management
β βββ utils.py # Utility functions
β βββ metadata.py # Audiobook metadata handling
β βββ qbittorrent.py # qBittorrent integration
β βββ token_gen.py # Token generation/validation
β βββ html.py # HTML template utilities
β βββ notify/ # Notification modules
β βββ discord.py # Discord notifications
β βββ gotify.py # Gotify notifications
β βββ ntfy.py # Ntfy notifications
β βββ pushover.py # Pushover notifications
βββ templates/ # Jinja2 HTML templates
β βββ base.html # Base template
β βββ index.html # Home page
β βββ approval.html # Approval page
β βββ rejection.html # Rejection page
β βββ success.html # Success page
β βββ failure.html # Failure page
β βββ token_expired.html # Token expired page
β βββ 401_page.html # Unauthorized page
βββ static/ # Static web assets
β βββ css/
β β βββ style.css # Main stylesheet
β βββ js/
β βββ app.js # Main JavaScript
βββ tests/ # Test suite
βββ config/ # Configuration files
β βββ config.yaml # Main configuration
βββ logs/ # Application logs
βββ db.sqlite # SQLite database
FastAPI-based web server that handles:
- HTTP Routes - All web endpoints and API routes
- Template Rendering - Jinja2 template processing
- Request Handling - Form processing and validation
- Authentication - Token-based security
- Static File Serving - CSS, JS, and asset delivery
Key endpoints:
GET /- Home pagePOST /audiobook-requests- Submit new requestsGET /approve/{token}- Approval endpointGET /reject/{token}- Rejection endpointGET /requests- Browse requests
SQLite-based data persistence with:
- Request Storage - Audiobook request data
- Token Management - Approval/rejection tokens
- Audit Logging - Request history and changes
- Schema Management - Database initialization and migrations
Database schema:
CREATE TABLE requests (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
author TEXT,
status TEXT DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE tokens (
id INTEGER PRIMARY KEY,
token TEXT UNIQUE NOT NULL,
request_id INTEGER,
action TEXT NOT NULL,
expires_at TIMESTAMP NOT NULL,
used_at TIMESTAMP,
FOREIGN KEY (request_id) REFERENCES requests (id)
);YAML-based configuration handling:
- Environment-aware - Development vs production settings
- Validation - Configuration validation and defaults
- Hot-reloading - Dynamic configuration updates
- Security - Sensitive data handling
Multi-platform notification delivery supporting:
- Discord - Webhook-based Discord notifications
- Gotify - Self-hosted push notifications
- Ntfy - Simple push notification service
- Pushover - Mobile push notifications
Each notification module implements a common interface:
class NotificationService:
def send_approval_request(self, request_data: dict) -> bool
def send_approval_notification(self, request_data: dict) -> bool
def send_rejection_notification(self, request_data: dict) -> boolCryptographically secure token management with:
- URL-safe tokens - Base64-encoded random tokens
- Expiration handling - Time-based token validity
- Single-use enforcement - Prevents token reuse
- Secure validation - Constant-time comparison
Modern, CSP-compliant frontend featuring:
- External CSS/JS - No inline styles or scripts
- Responsive Design - Mobile-first approach
- Progressive Enhancement - Works without JavaScript
- Accessibility - WCAG 2.1 AA compliance
- Modern CSS - CSS Grid, Flexbox, custom properties
Content-Security-Policy:
default-src 'self';
style-src 'self' fonts.googleapis.com;
font-src 'self' fonts.gstatic.com;
img-src 'self' example.com;
script-src 'self'- Cryptographically random tokens (32 bytes)
- Time-limited validity (configurable expiration)
- Single-use enforcement
- Secure transmission (HTTPS recommended)
- Server-side validation for all user inputs
- SQL injection prevention via parameterized queries
- XSS protection via template escaping
- CSRF protection via token validation
User submits form β FastAPI validates β Database stores β Notification sent
User clicks approval link β Token validated β Database updated β Success page shown
Event triggered β Notification service called β Message formatted β External service delivery
graph TD
A[User Request] --> B[FastAPI Validation]
B --> C[Database Storage]
C --> D[Token Generation]
D --> E[Notification Dispatch]
E --> F[External Services]
G[Approval Click] --> H[Token Validation]
H --> I[Database Update]
I --> J[Success Response]
K[Admin Interface] --> L[Request Management]
L --> M[Bulk Operations]
- Graceful degradation - System continues operating with reduced functionality
- User-friendly messages - Clear error communication
- Detailed logging - Comprehensive error tracking
- Recovery mechanisms - Automatic retry and fallback options
- Connection pooling - Manages database connections efficiently
- Transaction rollback - Maintains data consistency
- Backup strategies - Regular database backups
- Migration support - Schema version management
- Unit Tests - Individual component testing
- Integration Tests - Cross-component functionality
- End-to-End Tests - Full workflow validation
- Performance Tests - Load and stress testing
tests/
βββ conftest.py # Test configuration
βββ test_config.py # Configuration tests
βββ test_database_integration.py # Database tests
βββ test_end_to_end.py # E2E tests
βββ test_main_integration.py # Application tests
βββ test_webui.py # Web interface tests
βββ test_*.py # Feature-specific tests
- Database indexing - Optimized query performance
- Static file caching - Browser cache optimization
- Template caching - Jinja2 template compilation caching
- Connection pooling - Efficient resource utilization
- Request logging - Detailed request/response logging
- Performance metrics - Response time tracking
- Error monitoring - Exception tracking and alerting
- Resource usage - CPU, memory, and disk monitoring
- Setup - Virtual environment and dependencies
- Configuration - Development-specific settings
- Database - Local SQLite database
- Testing - Automated test execution
- Debugging - Enhanced logging and debugging tools
- Environment setup - Production server configuration
- Database migration - Schema updates and data migration
- Static asset optimization - Minification and compression
- Process management - Service management and monitoring
- Backup strategies - Data protection and recovery
This architecture supports the system's core principles:
- Simplicity - Easy to understand and maintain
- Security - Built with security best practices
- Scalability - Designed to handle growth
- Maintainability - Clean, documented codebase
- User Experience - Intuitive and responsive interface