# For Developers: Stack & Development Cycle

> What a Totalum project is, how it moves from development to production, and how you own it.

A **Totalum project** is a real **Next.js application** with its own databases, written and maintained by Totalum's AI agent as you describe what you want, and yours to download, sync to GitHub and run anywhere.

## The stack

| Layer | What the project uses |
|---|---|
| Framework | **Next.js** (App Router), **React**, **TypeScript** |
| Styling | **Tailwind CSS** with a design-token theme, no UI kit |
| Runtime | **Cloudflare Workers** (one Worker per project and environment) |
| Database | **SQL (SQLite) on Cloudflare D1**, read through **Drizzle ORM**; Turso for databases past 10 GB |
| Sign-in | **better-auth**: e-mail and password, Google, password reset, sessions, rate-limited and captcha-protected. Built-in pages (`/login`, `/register`, `/forgot-password`, `/verify-email`, `/account`) are off until the app needs accounts (`accounts: true` in `src/lib/site.ts`); e-mail confirmation by 8-digit code only when asked (`verifyEmail: true`) |
| Browser icon | Automatic: the logo (`site.logo`), else the app's initials on its brand colour (`/site-icon.svg`) |
| AI | OpenRouter's API through Totalum's AI gateway (`TOTALUM_AI_BASE_URL`, the project key): any OpenRouter model for text, vision, images, video, text-to-speech, transcription, embeddings and rerank, plus decision models (`POST /systemone`: typed answers to yes/no, pick-one and score questions, for classifying, routing and moderating), billed in credits; the app calls it with the Vercel AI SDK or plain `fetch` |
| Built-in features | **[`totalum-sdk`](https://www.totalum.app/docs/sdk)**: e-mail, files, document scan, web scraping, cloud browser, PDF, payments, real-time, scheduled jobs, vector search, logs, analytics |
| Mobile | Capacitor shell that opens the published site, built for Android and iOS by Totalum on paid plans; store uploads use your own Google Play and Apple developer accounts |
| Packages | Any npm package that runs on Workers |

Everything under `src/` runs on Workers, not Node: no filesystem at runtime and no long-lived connections. Recurring work is a scheduled job; real-time is the SDK's real-time channels. The agent knows these rules and writes code that fits them. It logs each key step (`console.log` / `console.error`), checks its work in its own browser, and reads the logs (`npm run logs -- --level error`, or the [Logs API](https://www.totalum.app/docs/api/server)) when something fails.

### OpenAI models on the AI gateway

A text call (chat, responses, messages; also `totalum.ai` chats and browser `extract`) that names an OpenAI model (`openai/…`, except the open-weight `gpt-oss` models):

- **Is screened first.** A safety screen reads the call's text before it goes to OpenAI, which adds about half a second. Content the screen flags is answered by a non-OpenAI model. Text over 200,000 characters is not screened and is always answered by a non-OpenAI model.
- **Falls back in the same call.** When the provider refuses the call, is unavailable or answers empty, another model answers. The response's `model` field shows which model answered; credits are charged for that model only, and failed attempts are never charged.
- **Tries a `models` list one model at a time,** in the order given.
- **Stays on OpenAI only when pinned.** With `provider.only` set to OpenAI, no other model answers: where a fallback would be needed, the call returns an error.

Every AI call: the gateway does not forward the app's `user` value. It sends a non-reversible hash of the account, the project and that user instead, never an e-mail or a raw id.

## Development and production

Each project has **two environments**, like two branches:

| | Development | Production |
|---|---|---|
| Address | The preview (`…-dev-temporal-link-preview-….totalum-project.com`), private, changes monthly | `<projectId>.totalum-project.com` and your custom domain |
| Database | The development database (with demo data) | The live database (real users and data) |
| Changed by | Every prompt, file edit, visual edit, GitHub pull, restore | Only **Publish** |

- **Every change is a version.** A prompt that changes code, a file saved through the API, a visual edit or a restore is saved as a version and deployed to the preview. Any version can be compared and restored.
- **Database changes are migrations.** The agent changes `src/db/schema.ts`, generates a migration in `drizzle/`, and applies it to the development database at once. **Publishing** applies the pending migrations to the live database, then puts the new code live. Migrations only add (new tables, columns, indexes); a migration that would drop or overwrite live data runs only when you confirm it.
- **The agent works on development data.** It writes production rows only when your prompt explicitly asks for it ("in production, mark order 42 as shipped").
- **Publishing is safe.** If the build or a migration fails, the agent tries to fix it; the live site keeps serving the previous version until a publish succeeds.

```text
prompt ─▶ version ─▶ preview + dev database ─▶ … ─▶ Publish ─▶ migrations on live ─▶ new code live
```

## Scaling and performance

Projects are server-rendered at the edge, close to every visitor, and scale from zero to millions of requests without servers to manage. Pages read the database in one round trip; reads go to the copy nearest the visitor. A busy public page can cache its reads for a few seconds. When a database outgrows 10 GB or needs more throughput, it can be [moved to Turso](https://www.totalum.app/docs/api/database-backups#move-to-turso).

## You own everything

- **Code:** [download it](https://www.totalum.app/docs/api/source-files#download-source-code) or [sync it to GitHub](https://www.totalum.app/docs/developers/github) at any time. It runs locally with `npm ci && npm run dev` (see [Run Locally & Self-Host](https://www.totalum.app/docs/developers/self-hosting)) and moves to any other host with its data: [Move to Another Host](https://www.totalum.app/docs/developers/move-to-another-host).
- **Data:** download a [backup](https://www.totalum.app/docs/api/database-backups#download-backup) of either database as standard SQLite SQL, or read rows through the [Database API](https://www.totalum.app/docs/api/database).
- **Files:** every uploaded file is listed and downloadable.

## Lifecycle of an idle project

A project that is not used goes to sleep and wakes on its next prompt in seconds. On the free plan, a project idle for months is archived and, after warnings by e-mail, eventually removed; paid projects are never removed for inactivity.

## Limits

Every plan, project and database limit is on [Limits](https://www.totalum.app/docs/limits); how code fits them is in [Design for the Limits](https://www.totalum.app/docs/developers/limits).
