Architecture
Containers, layers of the app, directories and the path of a request.
Containers
flowchart TB
B["Browser / PWA"] -- HTTPS --> C["caddy<br/>TLS, HSTS, compression"]
C --> A["app :8000<br/>Starlette + Uvicorn"]
C -. overlay .-> W["wiki :8000"]
A --> S["Sandbox process<br/>per import"]
A --- D[("/data<br/>SQLCipher + AES-GCM")]
A -. IMAP/SMTP .-> M["Mail server"]
A -. overlay .-> R["imap-relay<br/>Proton Bridge"]
| Container | Image | Purpose |
|---|---|---|
caddy |
official Caddy image | TLS (Let's Encrypt or internal CA), routing, headers. Admin API switched off. |
app |
Dockerfile in the repository |
Clipr: API, frontend files, background tasks |
wiki |
wiki/Dockerfile |
Optional, see Running the wiki |
imap-relay |
imap-relay/ |
Optional, TCP forwarding to the Proton Mail Bridge on the host |
All containers run read-only (read_only), without extra privileges (cap_drop: ALL, no-new-privileges) and with memory and process limits. Only caddy has open ports.
The app
A single ASGI application (Starlette, Uvicorn with one worker) serves the API and the frontend.
app/clipr/
├── main.py app, routes, start and stop of background tasks
├── middleware.py security headers, session, CSRF, two-factor requirement, error handling
├── config.py settings from the environment (CLIPR_*), validated at start
├── db.py databases (SQLCipher), migrations, request context
├── crypto.py key derivation, AES-GCM, key wrapping
├── security.py passwords (scrypt), sessions, throttling, security log
├── stores.py users.py ticket store per account, accounts
├── sso.py single sign-on for companion services
├── i18n.py translation of server messages
├── api/ HTTP endpoints per area (auth, tickets, codes, mail, groups, vault, mfa, admin, settings, sso)
└── services/ domain logic
├── pipeline.py import: analysis and storing
├── sandbox.py analysis of foreign files in an isolated subprocess
├── extract.py layout.py classify.py codes.py barcode.py
├── parsers/ rail_db, event, event_layout, transit_pass, bahncard
├── tickets.py rules.py tickets, stacks, states, deadlines
├── mail.py inbox.py IMAP fetching, sealed inbox for vaults
├── shares.py exchange.py groups.py sharing and groups
├── mailer.py mfa.py ics.py storage.py maintenance.py
web/ frontend (ES modules, no build), service worker, translation catalogue
Path of a request
- Caddy accepts the connection, terminates TLS and forwards to
app:8000. Caddy ignores incomingX-Forwarded-*from clients; Uvicorn only honours them from its own network (FORWARDED_ALLOW_IPS). - SecurityHeaders sets CSP, HSTS,
X-Frame-Options,Permissions-Policy, COOP/CORP and caching rules. - Auth resolves the session from the cookie
__Host-clipr_session, checks the CSRF header and the origin on writing requests, enforces the two-factor requirement and creates the request context with the account's ticket store. - The endpoint in
api/validates input and callsservices/. - Errors are answered uniformly as JSON (see HTTP API).
Background tasks
The app runs these alongside:
- Mail scheduler with a worker pool – see Mail retrieval
- Maintenance (
services/maintenance.py, hourly): delete expired sessions and email tokens, remove self-registered accounts unconfirmed after 48 h, expire group invitations and ticket offers, clean up orphaned packets and SSO grants, trim the security log after 180 days, update storage use per account and apply automatic archiving (only for accounts without a vault; vaults on unlock)
Technologies
| Area | Used |
|---|---|
| Server | Python 3.13, Starlette, Uvicorn |
| Databases | SQLite with SQLCipher (encrypted) |
| Cryptography | cryptography (AES-256-GCM, HKDF, X25519, Ed25519), scrypt |
| PDF and images | pdfplumber, pypdf, Poppler (rendering), Tesseract via pytesseract (OCR), Pillow, zxing-cpp (codes and UIC barcodes, optional) |
| Two-factor | pyotp (TOTP), webauthn (passkeys), segno (QR codes) |
| Frontend | native ES modules, pdf.js, no framework, no build step |
| Proxy | Caddy 2 |