# Backend foundations (PRO)

import { Callout } from "fumadocs-ui/components/callout";
import { Accordion, Accordions } from "fumadocs-ui/components/accordion";
import { Step, Steps } from "fumadocs-ui/components/steps";
import { Badge } from "@pycolors/ui";
import {
  CreditCard,
  Database,
  Download,
  GitBranch,
  Layers3,
  LockKeyhole,
  Server,
  ShieldCheck,
} from "lucide-react";

import { PreferAvoid } from "@/components/docs/prefer-avoid";
import { DocsDecisionGrid } from "@/components/docs/docs-decision-grid";
import { DocsFeatureGrid } from "@/components/docs/docs-feature-grid";
import { DocsLinks } from "@/components/docs/docs-links";
import { DocsUpgradeCTA } from "@/components/docs/docs-upgrade-cta";

<div className="flex flex-wrap items-center gap-2">
  <Badge variant="outline">
    Starter Pro
  </Badge>

  <Badge>
    Backend
  </Badge>
</div>

## Backend foundations that make the product real

Starter Free gives you a **frontend SaaS surface**.

Starter Pro gives you the **backend structure, data model, and server-side foundations** required to run a real product.

This is where your app stops behaving like a demo and starts behaving like a system:

* real persistence
* real users
* real ownership
* real billing state
* real server-side rules
* real product behavior

<DocsUpgradeCTA title="The backend is where your product becomes real." description="Starter Pro gives you the structure to connect users, billing, data, and access without rebuilding the foundation from scratch." productSlug="starter-pro" buyLabel="Get Starter Pro" secondaryHref="/docs/starter-pro/getting-started" secondaryLabel="Setup guide" />

<Callout title="Core idea">
  A SaaS is not only screens. It is data, rules, ownership, access, billing state, and server-side boundaries.
</Callout>

### What this solves

A lot of SaaS products do not fail because the UI is weak.

They fail because the backend becomes unclear:

* data ownership is duplicated
* auth and billing are not connected cleanly
* access rules leak into components
* product logic is scattered across pages
* schema decisions become expensive to change
* mocked data turns into fragile production logic

Starter Pro gives you a structured foundation so backend work can scale with the product instead of slowing it down.

### What is included

<DocsFeatureGrid
  columns={2}
  tone="platform"
  items={[
  {
    title: 'Database-ready structure',
    description:
      'Prisma-oriented schema foundations, migration-ready data modeling, and a clean path from mock data to persistence.',
    icon: Database,
  },
  {
    title: 'Server-side patterns',
    description:
      'Server-side boundaries for product logic, integration logic, access checks, and future API growth.',
    icon: Server,
  },
  {
    title: 'Auth-aware logic',
    description:
      'User ownership, protected data access, session-aware behavior, and backend rules tied to real identity.',
    icon: LockKeyhole,
  },
  {
    title: 'Billing-aware boundaries',
    description:
      'Product access foundations that can connect billing state, subscription status, and plan-aware behavior.',
    icon: CreditCard,
  },
]}
/>

### Architecture layers

Starter Pro backend foundations are organized around clear responsibilities.

<DocsDecisionGrid
  columns={2}
  items={[
  {
    eyebrow: 'Data',
    title: 'Data layer',
    icon: Database,
    description:
      'The data layer defines persistence, schema ownership, and typed access to application state.',
    items: [
      'Prisma schema foundations',
      'migration-ready structure',
      'typed database access',
      'auth and billing models',
      'future domain models',
    ],
  },
  {
    eyebrow: 'Application',
    title: 'Application layer',
    icon: Layers3,
    description:
      'The application layer owns product behavior, domain operations, validation, and reusable backend logic.',
    items: [
      'server-side product logic',
      'domain-oriented boundaries',
      'feature-level operations',
      'validation points',
      'reusable backend helpers',
    ],
  },
  {
    eyebrow: 'Integration',
    title: 'Integration layer',
    icon: GitBranch,
    description:
      'The integration layer keeps external systems and cross-cutting services away from product UI.',
    items: [
      'auth context',
      'Stripe billing context',
      'webhook processing',
      'email provider boundaries',
      'secure delivery integration',
    ],
  },
  {
    eyebrow: 'Access',
    title: 'Access layer',
    icon: ShieldCheck,
    description:
      'The access layer keeps product data, billing state, and user permissions server-verifiable.',
    items: [
      'protected routes',
      'ownership checks',
      'plan-aware access',
      'admin and user boundaries',
      'server-verifiable permissions',
    ],
  },
]}
/>

<Callout title="System rule">
  Keep product rules close to the backend.
  UI can reflect access, but sensitive logic should be server-verifiable.
</Callout>

## Starter Free vs Starter Pro

| Capability           | Starter Free   | Starter Pro                      |
| -------------------- | -------------- | -------------------------------- |
| Data source          | Mocked         | Database-ready                   |
| Persistence          | Not included   | Included foundation              |
| Prisma schema        | Not included   | Included foundation              |
| User ownership       | Conceptual     | Auth-aware                       |
| Billing access       | Conceptual     | Billing-aware                    |
| Protected data       | Mocked         | Server-oriented                  |
| Server-side patterns | Minimal        | Production-oriented              |
| Domain boundaries    | Frontend-first | Backend-ready                    |
| Best use case        | Validate UX    | Build launchable product systems |

<Callout title="Simple distinction">
  Starter Free gives you the surface.
  Starter Pro gives you the system underneath.
</Callout>

## Architecture

### Data model responsibilities

A real SaaS backend needs models that represent the business layer, not only UI data.

Starter Pro is designed around responsibilities such as:

| Area          | Purpose                                 |
| ------------- | --------------------------------------- |
| User          | Identity, profile, ownership, sessions  |
| Account       | OAuth provider connections              |
| Session       | Active authenticated sessions           |
| Customer      | Billing relationship to Stripe          |
| Product       | Sellable product or plan family         |
| Price         | Stripe price and commercial plan        |
| Subscription  | Access, status, lifecycle, and renewals |
| Invoice       | Payment history and billing state       |
| WebhookEvent  | Reliable event processing               |
| Domain models | Your actual product entities            |

<Callout type="info" title="Why this matters">
  A SaaS backend is not only CRUD.
  It is the place where identity, revenue, ownership, and product behavior meet.
</Callout>

### Feature example

A feature such as `Projects` behaves very differently depending on the backend layer underneath it.

<DocsDecisionGrid
  columns={2}
  items={[
  {
    eyebrow: 'Without backend',
    title: 'Demo-style feature',
    description:
      'A demo feature is useful for validating UX, but it does not yet enforce ownership, persistence, or access.',
    items: [
      'mock state',
      'fake persistence',
      'no ownership rules',
      'no protected access',
      'no billing-aware behavior',
    ],
  },
  {
    eyebrow: 'With backend',
    title: 'Product-ready feature',
    icon: Database,
    tone: 'pro',
    description:
      'A product-ready feature connects UI, persistence, identity, access, and future billing behavior.',
    items: [
      'database model',
      'real create/update/delete flows',
      'user ownership',
      'protected access',
      'auth and billing integration points',
    ],
  },
]}
/>

This is the difference between a demo feature and a real feature.

## Implementation path

<Steps>
  <Step>
    ### Validate the existing foundation

    Before adding your domain logic, confirm that auth, billing, database setup, and local seed flows work.
  </Step>

  <Step>
    ### Define your first domain model

    Add the product entity that matters most to your SaaS.

    ```prisma title="schema.prisma"
    model Project {
      id        String   @id @default(cuid())
      name      String
      ownerId   String
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
    }
    ```
  </Step>

  <Step>
    ### Add ownership rules

    Connect product data to the authenticated user, customer, or organization model.

    ```ts title="server/projects/access.ts"
    export function canAccessProject(projectOwnerId: string, userId: string) {
      return projectOwnerId === userId;
    }
    ```
  </Step>

  <Step>
    ### Keep product logic server-side

    The UI should call the product flow.

    It should not own sensitive rules.
  </Step>

  <Step>
    ### Connect billing when needed

    If the feature is paid or plan-dependent, add plan-aware checks near the server boundary.
  </Step>
</Steps>

## What you avoid building yourself

Without Starter Pro, you usually need to design and wire:

* database schema foundations
* auth-to-user relationships
* billing-to-customer relationships
* subscription access rules
* protected route behavior
* webhook state persistence
* product ownership checks
* delivery access rules
* domain separation patterns

This is often time-consuming, easy to duplicate, and expensive to refactor later.

### Backend rules

Use these rules when extending the backend.

<PreferAvoid
  prefer={[
  'clear domain boundaries',
  'server-verifiable ownership checks',
  'centralized plan access logic',
  'database models that reflect product behavior',
  'backend helpers for repeated rules',
]}
  avoid={[
  'putting access rules only in the UI',
  'duplicating ownership checks across components',
  'mixing billing logic into unrelated features',
  'treating mock data like production data',
  'adding domain models without access rules',
]}
/>

## Decision guide

<DocsDecisionGrid
  columns={2}
  items={[
  {
    eyebrow: 'Starter Pro',
    title: 'Use Starter Pro when persistence becomes real',
    href: '/docs/starter-pro/getting-started',
    icon: Database,
    tone: 'pro',
    description:
      'Use Starter Pro when mocked product state is no longer enough and the backend is becoming part of the launch path.',
    items: [
      'you need real data',
      'mock states are no longer enough',
      'users need ownership rules',
      'billing status affects product access',
      'backend structure is becoming a blocker',
      'you want less architectural uncertainty before launch',
    ],
    cta: 'Start setup →',
  },
  {
    eyebrow: 'Starter Free',
    title: 'Stay on Free while validating UX',
    icon: Layers3,
    description:
      'Stay on Starter Free when product flows are still changing and persistence would slow learning.',
    items: [
      'you are still validating UX',
      'product flows are not stable yet',
      'persistence is not required',
      'backend work would slow learning',
    ],
  },
]}
/>

<Callout title="Upgrade when persistence becomes real">
  Starter Free helps you validate the product surface.
  Starter Pro gives you the backend foundation that makes the product launchable.
</Callout>

### Production checklist

Before treating the backend as launch-ready, validate:

* database migrations
* seed data
* user model
* session model
* billing customer mapping
* subscription state
* webhook event handling
* ownership checks
* protected data access
* plan-aware access logic
* server-side validation
* error handling
* deployment environment variables

<Callout type="info" title="Validation principle">
  Do not build new product complexity on top of an unvalidated backend.
  Confirm the foundation first.
</Callout>

## Common questions

<Accordions type="single">
  <Accordion title="Is Starter Pro a full backend product?">
    No. It gives you the backend foundations needed to launch faster. You still build your domain models, workflows, and product-specific rules.
  </Accordion>

  <Accordion title="Can I change the schema?">
    Yes. The schema is meant to be extended. Keep auth, billing, and ownership boundaries clear when adding product-specific models.
  </Accordion>

  <Accordion title="Should access control live in the frontend?">
    No. The frontend can reflect access state, but sensitive checks should live on the server or in backend-aware logic.
  </Accordion>

  <Accordion title="How does billing connect to backend logic?">
    Billing state should be synchronized from Stripe and stored in your app so server-side logic can decide access reliably.
  </Accordion>
</Accordions>

<DocsUpgradeCTA title="Connect users, billing, data, and access." description="Starter Pro gives you a stronger backend baseline so your first serious work can be product logic, not infrastructure repair." productSlug="starter-pro" buyLabel="Get Starter Pro" secondaryHref="/pricing" secondaryLabel="View pricing" />

## Next steps

<DocsLinks
  variant="grid"
  items={[
  {
    title: 'Secure delivery',
    href: '/docs/starter-pro/delivery',
    description:
      'Learn how backend ownership and billing state can unlock secure product delivery.',
    icon: Download,
  },
  {
    title: 'Billing system',
    href: '/docs/starter-pro/billing',
    description:
      'Review how subscription state and customer ownership connect to backend rules.',
    icon: CreditCard,
  },
  {
    title: 'Authentication system',
    href: '/docs/starter-pro/auth',
    description:
      'Understand how users, sessions, and identity connect to product data.',
    icon: LockKeyhole,
  },
  {
    title: 'Production checklist',
    href: '/docs/starter-pro/production-checklist',
    description:
      'Validate authentication, billing, backend, and delivery before launch.',
    icon: ShieldCheck,
  },
]}
/>