Docke
Documents for multiple companies, with an audit trail.


On this page: 01Why it exists
Why it exists
The group was going to migrate all its documentation to the cloud. I developed Docke for that migration, around the teams’ routine: documents kept separate by company, search in scanned text, filing deadlines, legal retention, and an audit trail.
Problem, system, and proof
Problem
Documents from multiple companies to organize in the cloud, with deadlines and legal retention.
System
Electronic document management for multiple companies: search in scanned text (OCR), compliance deadlines, legal retention, and a hash-chained audit trail.
Proof
89 tests
83 backend and 6 end-to-end, on GitHub Actions. Checked on 9 Nov 2026.
A closer look
-
Company dashboard
Documents, folders, anchored items, and recent uploads for the selected company, with documents by folder.
-
Folders with OCR
Each folder lists its documents with type, size, and the OCR mark, which lets you search inside the scanned text.
-
Audit trail
Every upload, view, and download is logged in a hash-chained trail.
-
Navigation bar
Home, documents, search, and anchored items sit at the bottom of the screen, as in a phone app, with the upload button at the top.
How it was built
Architecture
The React frontend talks to a FastAPI API, which stores data in Supabase's PostgreSQL and files in Cloudflare R2. The browser sends the file straight to R2; the API only confirms the upload and creates an OCR job. A background worker reads the file, extracts the text with Tesseract, and writes it to the document, where Postgres full-text search finds it.
View in code: README.md L37–51 documents.py L213–275 documents_service.py L166 ocr_worker.py L1–16 search_service.py L57–95
- Direct upload to R2
- SHA-256 confirmation
- OCR queue
- Text search
- Hash-chained trail
Technical decisions
Company isolation in the database itself
Each user request opens a transaction, passes the JWT claims to Postgres with
set_config('request.jwt.claims'), and switches role withSET LOCAL role authenticated. So the Row Level Security policies apply to every query on that connection, and access by company or folder is blocked by the database, not just by the API.SET LOCALonly lasts inside an explicit transaction, so the whole request runs inside one. Admin operations and the worker use a separate connection that bypasses RLS and checks permissions in code.View in code: dependencies.py L251–288 README.md L20 README.md L50 20260627000003_rls_policies.sql dependencies.py L291–295
Files go straight to storage
The browser uploads the file to R2 through a presigned URL, in 10 MB parts from 20 MB up. Then the API checks the real size with a HEAD request, because the URL doesn't enforce a limit, and computes the SHA-256. If the company already has an identical file, the API returns 409 and deletes the object and the pending record, so no garbage is left in the bucket.
View in code: README.md L51 Documents.tsx L400–401 Documents.tsx L462–463 documents.py L224–266 storage_service.py L117–137 documents.py L321
OCR in a queue inside Postgres
Confirming the upload writes a job to the
ocr_jobstable, and a worker takes the oldest one withFOR UPDATE SKIP LOCKED, so multiple workers don't compete for the same job. A job stuck in processing for more than 10 minutes goes back to the queue, up to 3 attempts; after that it staysfailed. Tesseract reads Portuguese and English; for images, after preprocessing with OpenCV.View in code: ocr_worker.py L1–35 ocr_worker.py L73–99 ocr_service.py L5 ocr_service.py L76
Challenge
The trail is verified by its links
Each event stores an HMAC-SHA256 computed over its content and the hash of the company's previous event. The first verification sorted events by timestamp and reported a broken chain with no tampering, because events in the same transaction share a timestamp. I rewrote the verification to follow the links from the first event. The end was still uncovered: deleting the most recent event went unnoticed; now the last stored hash must exist, or the trail shows as truncated.
View in code: 20260723000015_event_store_activity_log.sql L40–80 20261017000001_activity_log_verify_chain_by_links.sql L1–67 20261026000002_seguranca_rls_trilha_links.sql L47–51 20261026000002_seguranca_rls_trilha_links.sql L122–135 test_audit_chain.py L57–163
Testing
The backend has 83 tests collected by pytest, from 30 functions (three are parametrized: one runs 50 times and two run 3 times each); the integration tests run against a local Supabase and cover company isolation through RLS, permissions, OCR, share links, and the trail flagging an event that was altered, deleted, or cut off at the end. The 6 Playwright tests sign in to the demo, switch identities, open a PDF, and search. GitHub Actions runs both on every push to main.
View in code: tests e2e ci.yml e2e.yml test_demo_seed_templates.py L11
Stack and links
Stack
React 19, TypeScript, Vite, Tailwind CSS, FastAPI, PostgreSQL (RLS), Supabase, Tesseract, pytest, Playwright


