Lunaar Mobile Backend
Go

Lunaar Mobile Backend

Multi-Tenant Go Backend for the Lunaar Mobile Apps

Overview

The Lunaar Mobile Backend is a Go service that powers all of the Lunaar mobile apps from a single multi-tenant codebase. It re-implements the .NET AI services in Go - with unit tests that guard prompt parity against the originals - and adds per-app isolation, a credit economy and store billing. Every app is a tenant, identified by its app-id and restricted to the AI services it actually ships.

What It Does

It exposes REST APIs for studio photography, product shots, jewelry and glasses try-on, food visuals, sketch-to-render and image upscaling, running each generation as an async job. A request deducts credits, uploads inputs and enqueues work in one transaction; a worker consumes the job, calls the AI model, stores the result and marks it complete. It also manages per-user credit wallets and reconciles RevenueCat subscriptions from the App Store and Play.

Tech Stack

GochiPostgreSQLRabbitMQMinIO/S3JWTAIRevenueCat

Key Features

Multi-tenant by design: each app validated via an X-App-Id header against an apps table, with row-level isolation and a per-app allowed-service list enforced by middleware

Seven registered AI services (studio, product shot, jewelry and glasses try-on, food visual, sketch-to-render and upscale) behind a shared generic pipeline

Credit economy with row-locked atomic deduction (HTTP 402 on insufficient balance) and idempotent refunds that cannot double-credit

Plan catalog in code (free, weekly, yearly) with a one-time signup grant and non-accumulative monthly resets

RevenueCat webhook billing handling purchases, renewals, plan changes, cancellations, expirations and billing issues, with event dedup and safe retries

Separate API and worker binaries, with the API auto-running embedded database migrations on boot

Scheduled maintenance jobs: monthly credit reset, refund recovery, stale-operation sweep and outbox cleanup

JWT auth (register/login/refresh/delete) with email verification and per-IP rate limits on sensitive routes

Technical Highlights

Go 1.25 with the chi router and httprate rate limiting, JWT auth and a standard response envelope
PostgreSQL via pgx/pgxpool with embedded golang-migrate migrations, RabbitMQ (topic exchange mirroring the .NET topology) and MinIO/S3 storage
Transactional outbox with a relay that drains unpublished events to RabbitMQ once per second, so a committed operation is never orphaned
Generic Service[T] core pipeline with per-service concurrency limits to respect AI model quotas
AI image-edit integration supporting both cloud-hosted and direct auth styles, plus a streaming (SSE) upscaler client with 2x-16x support
Layered architecture (cmd binaries, platform, domain packages, service registry) so adding a new AI service never touches the entrypoints

Key Achievements

01

Consolidated the backend for the entire Lunaar mobile suite into one multi-tenant Go service with strict per-app service gating

02

Achieved verified prompt parity with the original .NET services through dedicated unit tests

03

Guaranteed credit integrity under concurrency via row-locked deductions and idempotent, recoverable refunds

04

Built a resilient async pipeline with outbox delivery plus stale-operation and refund-recovery sweeps that self-heal stuck jobs

Impact & Results

Built at Group Taiga as the shared engine behind the Lunaar suite of mobile apps, it lets many branded apps run on one codebase while staying isolated and independently monetized. The multi-tenant model, credit economy and outbox-backed pipeline make it a production billing and generation backend, not just an API wrapper.