November 2026 · 6 min read
One Django backend for four App Store apps
How I run Ryddar, DecorifAI, CartoonifAI and Mood to Drink from a single Django project: one app per product, shared auth, a credits ledger that survives retries, and async AI jobs.
Why one backend
I build and run four iOS apps on my own: Ryddar for motorcycle riders, DecorifAI for AI interior design, CartoonifAI for AI portraits and Mood to Drink for drink ideas. They look nothing alike, but underneath they need the same things: users and sign-in, in-app purchases, push notifications, file storage, an admin, and a deploy pipeline that works when I'm asleep.
Four backends would mean four copies of all of that to patch, monitor and pay for. So all four apps talk to one Django REST Framework project, deployed once. The rule that makes it work is simple: everything shared lives in one place, and everything product-specific lives in that product's own Django app.
One Django app per product
Each product is a normal Django app under products/, with its own models, migrations, admin, serializers, URLs and tests. Its endpoints live under its own prefix, like /api/decorifai/, so the mobile apps never see each other's routes.
backend/
config/ settings, root URLs
products/
ryddar/ rides, spots, alerts, SOS (and the shared accounts app)
decorifai/ room designs, videos, credits
cartoonifai/ styles, portraits, credits
mood2drink/ drink catalogue
scripts/ deploy and backupThe only thing products share is the accounts code (users and social sign-in). They don't touch each other's models, so a change to DecorifAI's credits can't break Ryddar's group rides, and each product has its own test suite in CI.
Shared auth, without forcing sign-up
There is one User model for every app, with JWT authentication (SimpleJWT, rotating refresh tokens and a blacklist) and Sign in with Apple and Google. But nobody wants to create an account before trying an AI photo app. So the AI apps start with an anonymous installation: on first launch the server issues a random token and stores only its hash, and credits belong to that installation. If the user signs in later, the installation is linked to their account and nothing is lost.
Credits as a ledger
The AI apps sell credits. The first version of anything involving money is usually a balance column, and it breaks as soon as the real world shows up: the payment provider retries a webhook, a user double-taps, a network timeout makes the app send the same request again.
So credits are a ledger. Every change (a purchase, a monthly allowance, a generation, a refund, a reward) is a row with a unique reference, such as the store transaction ID. The balance is the sum of the rows. Here is a simplified version of the idea:
class CreditEntry(models.Model):
account = models.ForeignKey(Account, on_delete=models.PROTECT, related_name="entries")
amount = models.IntegerField() # positive adds credits, negative spends or takes back
kind = models.CharField(max_length=30) # "purchase", "generation", "refund", ...
reference = models.CharField(max_length=120, unique=True)
created_at = models.DateTimeField(auto_now_add=True)
def add_entry(account, amount, kind, reference):
# The unique reference makes this safe to call twice for the same event.
return CreditEntry.objects.get_or_create(
reference=reference,
defaults={"account": account, "amount": amount, "kind": kind},
)
@transaction.atomic
def spend(account, cost, reference):
# Lock the account row so two requests can't spend the same credits.
locked = Account.objects.select_for_update().get(pk=account.pk)
balance = locked.entries.aggregate(total=Sum("amount"))["total"] or 0
if balance < cost:
raise InsufficientCredits()
return add_entry(locked, -cost, "generation", reference)Two things make it safe. The unique reference means a retried event finds the existing row instead of adding a second one. And spending runs inside a transaction with select_for_update on the account row, so two requests arriving at the same moment can't both spend the last credit. Refunds from the App Store are just negative entries tied to the original purchase, which also gives me a full history when a user writes to support.
Slow, expensive, sometimes failing AI jobs
A DecorifAI design or a CartoonifAI portrait runs on Replicate and can take from a few seconds to a minute. The API never waits for it. It reserves the credits, starts the prediction with a webhook URL, and returns immediately. Each request carries an idempotency key, so a double-tap returns the same job instead of charging twice. The app then polls the job's status every few seconds.
When Replicate calls the webhook, the backend checks its signature before trusting anything in it. Webhooks can arrive late or not at all, so each poll from the app also asks Replicate directly. If the job failed or was cancelled, the same code path marks it failed and writes a refund entry. Users never pay for a result they didn't get, and because the refund also has a unique reference, it can't happen twice.
Running it alone
The backend runs in Docker on a Hetzner server behind Caddy, which handles HTTPS. Every push runs the test suite in GitHub Actions, and the production deploy only starts after CI passes. A deploy rebuilds the image, then restarts the containers and runs migrations, and a script handles database backups. As the only developer, I rely on that pipeline: a fix ships only after the same tests pass every time.
What I'd do differently
The two AI apps grew one after the other, so some of their code (the Replicate and Cloudinary clients, the credits operations) is similar rather than shared. I'd extract that into one internal package for AI jobs and credits that both products use. I'd also move the accounts app out of the Ryddar package, where it started, into its own top-level app. And one database for everything is simple, but it means a slow migration in one product delays deploys for all four. Today migrations run right after the new containers start; as the apps grow, I'd run them as a separate step before the new code goes live.
Still, for one developer, one well-separated Django project has been the right call: four apps on the App Store, one place to fix bugs, and one deploy pipeline to trust.