A backend for a mobile app without writing a backend
Build a complete mobile app backend without managing servers using thelastapi for database, sign-in, file uploads, AI, and in-app purchases.
On this page 9 sections
- What your mobile app gets out of the box
- Provisioning your mobile backend in one command
- Keeping secrets safe: the role of the app key
- User authentication for iOS and Android
- Handling user files and photo uploads
- Mobile subscriptions and in-app purchases
- Analytics and AI features
- No lock-in: taking your mobile data elsewhere
- FAQ
You can build a mobile app backend without writing or managing a server by using thelastapi's unified API for database, authentication, storage, AI, and payments. One command provisions your project with managed Postgres, ready-to-use Google and GitHub sign-in, media storage, and in-app purchase tracking. You interact with every service using standard HTTP calls or minimal edge endpoints, eliminating the work of setting up separate infrastructure.
When you create a mobile application, writing a custom backend often consumes more time than building the client. You usually have to glue together a database instance, write user authentication flows, configure object storage buckets with signed upload links, wire payment webhooks, and stand up gateways for AI models. With thelastapi, you replace that patchwork with one key for your whole app and structured HTTP endpoints.
What your mobile app gets out of the box
A mobile app requires a dependable set of cloud capabilities: user records, persistent structured data, binary assets like profile pictures, billing, and transactional communication. You can provision these services individually or together, choosing only what your mobile client needs:
| Capability | How your mobile app uses it | CLI provisioning |
|---|---|---|
| Database | Postgres accessed via connection string or API routes | --resources database |
| Sign-in | Google and GitHub authentication sessions | --resources auth (brings database) |
| Files | 50 MB asset uploads with permanent or signed links | Included (--resources none) |
| AI Gateway | OpenAI-compatible text, image, audio, and transcription | --resources ai |
| In-App Purchases | iOS App Store and Google Play sync | Included (--resources none) |
| Analytics | Server-side event tracking tied to user IDs | --resources analytics |
If your mobile app only needs one or two pieces—such as media storage or AI models—you can use just one service from an app hosted anywhere without turning on hosting or other resources.
Provisioning your mobile backend in one command
To create your backend environment, install the CLI and initialize a project:
vibiz init "Fitness Tracker" --resources auth,aiThis single command provisions a production Postgres database, sets up authentication endpoints, and configures an AI gateway.
To work locally during mobile development, run:
vibiz devvibiz dev creates a completely isolated development environment. It branches your database schema without copying live customer rows, generates a dedicated development AI key, and writes these settings to .env.development.local. This allows your iOS simulator or Android emulator to run against safe test data.
Keeping secrets safe: the role of the app key
The master key for your project, VIBIZ_APP_KEY (vz_app_…), is a server secret. As detailed in the keys and environments guide, this key grants access to your database environment, billing, and user events. Because mobile binaries (such as .ipa or .apk files) can be decompiled, you must never embed VIBIZ_APP_KEY directly inside your client-side mobile code.
Instead, mobile applications interact with thelastapi in two safe ways:
- Direct client calls for public operations: Public interactions, such as downloading public media files or using public endpoints, do not expose secrets.
- A lightweight intermediary function: For actions requiring
VIBIZ_APP_KEY—such as updating user rows, creating card checkout sessions, or querying sensitive tables—route your mobile requests through a tiny edge function or serverless handler.
That lightweight handler imports @vibiz/app and loads the project environment in two lines:
import { vibiz } from '@vibiz/app';
// Reads process.env.VIBIZ_APP_KEY automatically
await vibiz.loadEnv();Your function does not need database migration scripts, payment SDK integrations, or vendor-specific wrappers. It simply executes the built-in methods provided by @vibiz/app and returns JSON to your mobile screens.
User authentication for iOS and Android
Mobile apps rely heavily on social sign-in. You can enable sign-in providers directly from your terminal:
vibiz auth providers add google
vibiz auth providers add githubIf you prefer to use your own Google OAuth application credentials rather than the default setup, provide your client ID:
vibiz auth providers add google --own --client-id 123456789-clientid.apps.googleusercontent.comSign-in pairs automatically with your project's Postgres instance. When users sign in on your mobile screens, their profile records are populated in your database. Because the database is standard Postgres, you can inspect it, run standard SQL queries, or connect ORMs without vendor-specific dialect constraints.
Handling user files and photo uploads
Most mobile applications require photo uploads for avatars, receipts, or attachments. With thelastapi Files, every project includes a managed file drive that accepts files up to 50 MB.
Your edge endpoint accepts the raw bytes from the mobile device and uploads them directly using the SDK:
import { vibiz } from '@vibiz/app';
export async function handleMobileUpload(fileBuffer: Buffer, fileName: string) {
const file = await vibiz.files.upload(fileBuffer, {
name: fileName,
contentType: 'image/jpeg',
});
// Returns a permanent 32-character random URL
return { url: file.url };
}Every public file receives a permanent URL format (https://thelastapi.dev/f/<key>/<name>), making it immediately viewable in your mobile app's image components without expiring tokens. If an asset is private (such as private documents), upload it with private: true. Private files produce signed links valid for exactly one hour.
Files created by AI models—such as generated images from vibiz/image or audio from vibiz/voice—are automatically saved to this same drive, returning permanent URLs in their API responses.
Mobile subscriptions and in-app purchases
If your mobile app sells digital goods or access tiers, you can manage store subscriptions and web-based card checkouts side by side.
In-App purchases (iOS and Android)
To link your mobile app's native in-app purchases to your backend, configure your application identifiers:
vibiz payments app-store setup --ios com.acme.fitnesstracker --android com.acme.fitnesstrackerOnce configured, the platform records purchases made through the App Store and Google Play. You can check what is active for any user right from your command line:
vibiz payments app-store subscriptions --user u_mobile_123Web checkout links for mobile accounts
If you offer direct subscriptions or account upgrades via card payments, create products and generate checkout links:
vibiz payments products add "Pro Plan" --amount 1200 --interval month --lookup-key pro-monthlyYour edge function can generate a hosted checkout URL that you open in an in-app browser view:
import { vibiz } from '@vibiz/app';
export async function createCheckout(userId: string) {
const { url } = await vibiz.payments.checkout({
lookup_key: 'pro-monthly',
user: userId,
success_url: 'https://fitnesstracker.example.com/billing/success',
cancel_url: 'https://fitnesstracker.example.com/billing/cancel',
});
return { checkoutUrl: url };
}thelastapi acts as the merchant, handling payment processing, billing receipts, and subscription records automatically.
Analytics and AI features
When your mobile app introduces AI features—like voice transcription, coaching chats, or smart summaries—you call the unified AI gateway. The gateway is fully OpenAI-compatible:
import OpenAI from 'openai';
import { vibiz } from '@vibiz/app';
const openai = new OpenAI(vibiz.ai);
const completion = await openai.chat.completions.create({
model: 'vibiz/fast',
messages: [{ role: 'user', content: 'Create a 3-day workout routine.' }],
});To understand user actions inside your app, track custom mobile events server-side without external tracking trackers:
await vibiz.user('u_mobile_123').track('Completed Workout', {
properties: { duration_minutes: 45, type: 'running' },
});All spend, event volume, and model token usage are tracked in your account console and CLI under vibiz usage.
No lock-in: taking your mobile data elsewhere
Using a pre-built backend should never trap your application. Because your database is standard Postgres and your files are standard HTTP assets, you can leave at any time.
Running vibiz export downloads your entire project:
vibiz export --code --dbThis command generates a consistent .sql.gz snapshot of your production Postgres database (including all schemas, tables, rows, triggers, and sequences) and a .zip file containing your source code. You can restore that database into any standard Postgres instance using psql. Read more about complete data portability in no lock-in: how to take your app elsewhere.
To start building your mobile backend without server maintenance, explore what is thelastapi and create your account at thelastapi.dev/start.
Frequently asked questions
Can I put the VIBIZ_APP_KEY directly in my iOS or Android app code?
No. The app key is a server secret with access to your project's data and payments, and compiled mobile binaries can be decompiled. You should keep the key inside a lightweight edge handler or serverless function that your mobile app calls.
How do mobile file uploads work with thelastapi?
Your app streams file bytes up to 50 MB to your backend endpoint, which uploads them using `vibiz.files.upload` or `POST /v1/app/files`. The API returns a permanent 32-character URL that can be stored in your database and rendered directly in mobile image views.
Can my mobile app use standard Postgres queries?
Yes. Your project includes a real Postgres database that you can connect to using standard connection strings, ORMs, or the HTTP API, with full support for migrations and dev branching via `vibiz dev`.
What happens if I want to move my mobile app to another backend later?
You can run `vibiz export --db` at any time to download a complete, consistent SQL dump of your database that restores into any Postgres 15 or newer database using `psql`.