Case study

Magick Box

AI creative platform for image, video, music and podcast generation

Backend developer · 2024 – present · live

~250
REST endpoints
21
Feature packages
~58
MongoDB collections
181
pytest tests

How it fits together

REQUESTBACKGROUNDclientiOS / webFastAPI21 packagesCeleryacks lateproviderVeo · SunoPOST /chat202 pendingenqueueMongoDB~58 collectionsRediscache · limitsFFmpegnormaliseS3stored assetSocket.IORedis pub/substreamed back to the client
A generation request. The reply is immediate; the render finishes later and is pushed back.

The shape of it

One FastAPI service, sliced by feature rather than by layer. Each of the twenty-one packages carries its own routes, services, repositories, schemas and dependency-injection providers, so a feature can be read, tested and changed without touching the rest. Repositories sit behind interfaces and are resolved through an async container, which is what makes the service layer testable without a database.

Generation is slow, so nothing waits on it

A request to make a film or a track returns immediately with a pending message. The real work runs on Celery with late acknowledgements, so a worker dying mid-render puts the job back rather than dropping it, and retries back off exponentially up to ten minutes. Progress streams to the client over Socket.IO while FFmpeg normalises audio and converts video at the end.

Mini Cinema

A multi-shot film pipeline where the model plans the shots, the user approves the plan, and only then does the render start. The tricky part was the message contract. Reasoning, status, approval gates and finished media all arrive as typed content blocks in one stream, so the client renders each as its own bubble without guessing at the payload.

Paying for it

Credits are deducted atomically, and every grant path is idempotent, because Stripe and RevenueCat both retry webhooks and rewarded-ad callbacks can arrive twice. Signatures are verified on every hook. A reconciler walks subscriptions to catch anything the webhooks missed.

Running it

One Docker image, built with uv in a multi-stage build, serves both the web process and the Celery worker depending on how it is started. Helm charts deploy it to Kubernetes on AWS with horizontal autoscaling, and Istio handles mutual TLS and retries between services.

Stack

Python 3.12FastAPIPydanticMongoDBRedisCelerySocket.IODockerKubernetesHelmIstioAWS