Quickback Docs

Quickback Compiler

Transform declarative resource definitions into a production-ready API. The Quickback compiler generates optimized code, validates security, and creates migrations.

The Quickback compiler transforms your declarative resource definitions into a complete, production-ready API. It analyzes your TypeScript definitions at build time, generates optimized code, validates your security configuration, and creates database migrations.

What the Compiler Does

When you run quickback compile, the compiler:

  1. Reads your definitions - Analyzes all defineTable() configurations in your definitions/ folder
  2. Validates security - Checks that firewall, guards, access, and masking are properly configured
  3. Generates API routes - Creates REST endpoints for each resource (GET, POST, PATCH, DELETE, plus batch operations)
  4. Generates actions - Creates custom endpoints from your defineActions() definitions
  5. Creates middleware - Generates authentication, authorization, and data validation logic
  6. Generates TypeScript types - Creates type-safe interfaces for your API
  7. Generates migrations - Automatically runs drizzle-kit generate to create database migration files

Input:

quickback/
├── quickback.config.ts    # Compiler configuration
└── definitions/
    └── features/
        └── rooms/
            ├── rooms.ts        # defineTable(...)
            └── actions.ts      # defineActions(...)

Output:

src/
├── routes/
│   └── rooms.ts            # Generated API handlers
├── middleware/
│   ├── auth.ts             # Authentication logic
│   └── firewall.ts         # Data isolation queries
└── types/
    └── rooms.ts            # TypeScript interfaces

Basic Usage

Compile Your Project

quickback compile

This command:

  • Reads your quickback.config.ts
  • Analyzes all resource definitions
  • Generates the complete API codebase
  • Reports any configuration errors

After Compilation

Once compilation succeeds, you need to:

  1. Apply migrations:

    Run the database migration for your provider. The generated package.json includes the appropriate migration script for your setup.

    Note: The compiler automatically runs drizzle-kit generate during compilation, so you only need to apply the migrations.

  2. Deploy your API:

    npm run deploy      # Cloudflare Workers
    # or
    npm start           # Local development

The Compilation Process

1. Configuration Loading

The compiler reads your quickback.config.ts:

import { defineConfig, defineRuntime, defineDatabase, defineAuth } from "@quickback/compiler";

export default defineConfig({
  name: 'my-app',
  template: 'hono',
  features: ['organizations'],
  providers: {
    runtime: defineRuntime('cloudflare'),
    database: defineDatabase('cloudflare-d1'),
    auth: defineAuth('better-auth'),
  },
});

This determines:

  • Which application template to use (hono or experimental nextjs)
  • Which database adapter to use (D1, SQLite, Turso, etc.)
  • Which authentication system to integrate
  • Which runtime to target (Cloudflare Workers, Bun, Node.js)
  • Which auth plugins to enable (based on features)

2. Resource Discovery

The compiler scans definitions/features/ and identifies:

Resources (with routes):

// definitions/features/rooms/rooms.ts
export default defineTable(rooms, { ... });
// → Generates: GET/POST/PATCH/DELETE /api/v1/rooms
// → Also generates: POST/PATCH/DELETE/PUT /api/v1/rooms/batch (auto-enabled)

Internal tables (no routes):

// definitions/features/rooms/room-bookings.ts
export const roomBookings = sqliteTable(...);
// NO default export → No routes generated

Actions:

// definitions/features/rooms/actions.ts
export default defineActions(rooms, {
  book: { ... },
  cancel: { ... }
});
// → Generates: POST /api/v1/rooms/:id/book, POST /api/v1/rooms/:id/cancel

3. Validation

The compiler validates your configuration at build time, catching errors before deployment. See Definitions for details on what's validated.

4. Code Generation

The compiler generates different files based on your provider:

Cloudflare Workers (Hono)

// Generated: src/routes/rooms.ts
import { Hono } from 'hono';
import { applyFirewall } from '../middleware/firewall';
import { checkAccess } from '../middleware/access';

const app = new Hono();

app.get('/rooms', async (c) => {
  const ctx = c.get('ctx');
  let query = db.select().from(rooms);
  query = applyFirewall(query, ctx, 'rooms');
  await checkAccess(ctx, 'rooms', 'list');
  const results = await query;
  return c.json(results);
});

5. Type Generation

The compiler generates TypeScript types for your API:

// Generated: src/types/rooms.ts
export type Room = typeof rooms.$inferSelect;
export type RoomInsert = typeof rooms.$inferInsert;

Build-Time vs Runtime

Build Time (Compilation)

The compiler validates security configuration, checks for schema/firewall mismatches, generates API route handlers, creates TypeScript types, and prepares migration setup.

Runtime (API Requests)

When your API receives a request: Authentication → Firewall → Access → Guards → Masking → Response. The compiled code handles all of this automatically.

Development Workflow

  1. Define resources in definitions/features/
  2. Compile with quickback compile
  3. Review migrations in drizzle/
  4. Apply migrations for your provider
  5. Test locally with npm run dev
  6. Deploy with npm run deploy

Next Steps

On this page