← Lab

Lab project
trut.hu
ActiveDAO · Sustainability2024 — 2026
Sustainability-DAO backend with governance, TTS and AI agents.
FastAPI + SQLAlchemy + Alembic backend with multi-tenant governance and AI-agent flows. 94 personal commits, mypy / ruff / pre-commit hardened, fully containerised with docker-compose.
Architecture
How it's built
An async FastAPI app over SQLAlchemy + Alembic with a Celery fleet of 20 prefork workers and a RedBeat scheduler for the governance heartbeats. Supabase handles JWT auth and tier checks; OpenRouter routes LLM calls; ElevenLabs renders audio summaries; and N8N picks up the rest over a shared volume. Multi-tenant isolation lives at the DB row level so a DAO never sees another DAO's data even through buggy app code.
Data flow
- 01Client request hits FastAPI — Supabase JWT is verified and the caller's subscription tier is read in the same hop.
- 02Allowed requests are persisted to Postgres with the tenant id stamped on every row; rate-limit counters tick in Redis DB 3.
- 03Governance tasks are enqueued to the broker DB; RedBeat fires scheduled DAO digests on its own cadence.
- 04A worker fetches the relevant feeds, calls OpenRouter for summarisation, then ElevenLabs for the audio rendering.
- 05Final audio is written to /n8n/files/{lang}/final_mix.mp3 — N8N picks it up and runs the publish workflow.
- 06Audit trail (who, when, which model) is committed to Postgres; the result is cached in Redis and returned to the user.
Design decisions
- Four Redis DBs separated by purpose — broker, results, RedBeat schedule, rate-limit counters — so noisy neighbours stay in their lane.
- RedBeat over Celery's default PersistentScheduler — survives Beat restarts, picks up new schedule rows live without a redeploy.
- Workers cap at 50 tasks per child to bound memory leaks from long LLM contexts; prefork pool keeps the GIL out of the Pandas math.
- N8N receives finished audio via a shared volume rather than HTTP — file paths are the contract, no marshalling overhead.
- pre-commit hardening: mypy, ruff, black gate every commit so the multi-tenant boundary checks cannot rot.
External integrations
Supabase (JWT + subscription tier)OpenRouter (LLM gateway)ElevenLabs (TTS)N8N (workflow handoff)Postgres 16Redis (4 logical DBs)Flower