> ## Documentation Index
> Fetch the complete documentation index at: https://docs.launchtoday.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Backend Overview

> Server-side API and deployment options

The Launch backend is a lightweight Node server designed for mobile-first
products: authentication, payments, uploads, and a type-safe API surface for
the app.

## Prerequisites

* PostgreSQL database available
* `.env` values configured for the features you will use

## Steps

1. Configure env vars: [Environment Variables](/backend/environment-variables)
2. Choose ORM: [Database ORM](/backend/database-orm)
3. Provision a DB (optional): [Neon Database](/backend/neon)
4. Run migrations in `apps/api`
5. Start the server with `pnpm dev`

## Tech Stack

<CardGroup cols={2}>
  <Card title="Koa" icon="server">
    Minimal Node.js server framework. Easy to understand and customize.
  </Card>

  <Card title="Prisma + Drizzle" icon="database">
    Switchable ORM adapters for PostgreSQL (Prisma default, Drizzle optional).
  </Card>

  <Card title="PostgreSQL" icon="elephant">
    Reliable, production-ready relational database.
  </Card>

  <Card title="tRPC" icon="arrows-left-right">
    End-to-end typesafe APIs without code generation.
  </Card>
</CardGroup>

## What's Included

* **Authentication API** - Session management with Better Auth
* **User Management** - Profile storage and updates
* **Payment Webhooks** - Stripe webhook handlers
* **Database Migrations** - Prisma schema + migrations (or Drizzle tooling)
* **Type Safety** - Shared `AppRouter` types for mobile + web

## File Structure

```
apps/api/
├── src/
│   ├── routers/           # tRPC routers (chat, stripe, upload, user)
│   ├── routes/            # REST endpoints (auth, webhooks, ai streaming)
│   ├── services/          # Business logic (auth, AI, payments)
│   ├── lib/               # ORM adapters, S3, Stripe clients
│   ├── config/            # Env/config
│   ├── app.ts             # Koa app wiring
│   └── index.ts           # Server entry point
├── prisma/                # schema.prisma + migrations
└── package.json
```

## Deployment Options

The backend can be deployed to various platforms:

| Platform | Type       | Best For                         |
| -------- | ---------- | -------------------------------- |
| Railway  | Container  | Simple deploys, auto-scaling     |
| Vercel   | Serverless | Edge functions, fast cold starts |
| Fly.io   | Container  | Global distribution              |
| AWS      | Various    | Enterprise, custom infra         |

## Troubleshooting

* **Database connection errors**: confirm `DATABASE_URL`
* **Auth provider errors**: verify provider env vars

## Next Steps

<CardGroup cols={2}>
  <Card title="Railway Deployment" icon="train" href="/backend/railway-deployment">
    Deploy to Railway in minutes
  </Card>

  <Card title="Environment Variables" icon="key" href="/backend/environment-variables">
    Configure your backend
  </Card>
</CardGroup>
