Skip to content

Getting started

This page walks you through creating a SwallowKit project and generating your first CRUD flow.

By the end, you will have a running Next.js application with typed BFF routes, Azure Functions backend handlers, and React UI components — all generated from a single Zod schema.

Prerequisites

  • Node.js 20 or later
  • pnpm (recommended) — run corepack enable or install with npm install -g pnpm
    • npm also works. SwallowKit auto-detects the package manager (pnpm is preferred when available).
  • Azure Functions Core Tools 4.x — required for local Functions development
  • Azure Cosmos DB Emulator — required for local data storage
    • Windows: Download
    • Docker: docker run -p 8081:8081 mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator

1. Create a project

bash
npx swallowkit init my-app
cd my-app
bash
pnpm dlx swallowkit init my-app
cd my-app

The command runs create-next-app internally and then adds SwallowKit's project structure on top.

Interactive prompts ask for:

OptionValuesDefault
CI/CD providergithub, azure, skip(prompted)
Backend languagetypescript, csharp, python(prompted)
Cosmos DB modefreetier, serverless(prompted)
Networkoutbound, none(prompted)

To skip prompts, pass flags directly:

bash
npx swallowkit init my-app --cicd github --backend-language typescript --cosmos-db-mode serverless --vnet none
bash
pnpm dlx swallowkit init my-app --cicd github --backend-language typescript --cosmos-db-mode serverless --vnet none

2. Create a model

bash
npx swallowkit create-model todo
bash
pnpm swallowkit create-model todo

This generates shared/models/todo.ts with a template schema. Edit it:

typescript
// shared/models/todo.ts
import { z } from 'zod';

export const todo = z.object({
  id: z.string(),
  text: z.string().min(1).max(200),
  completed: z.boolean().default(false),
  createdAt: z.string().optional(),
  updatedAt: z.string().optional(),
});

export type Todo = z.infer<typeof todo>;

The id, createdAt, and updatedAt fields are managed by the backend. Define them as optional() in the schema.

3. Generate CRUD code

bash
npx swallowkit scaffold todo
bash
pnpm swallowkit scaffold todo

This generates:

LayerGenerated files
Azure Functionsfunctions/src/todo.ts (TypeScript backend)
BFF routesapp/api/todo/route.ts, app/api/todo/[id]/route.ts
UI pagesapp/todo/page.tsx, app/todo/[id]/page.tsx, app/todo/new/page.tsx, app/todo/[id]/edit/page.tsx
UI componentsapp/todo/_components/TodoForm.tsx
Infrastructureinfra/containers/todo-container.bicep

For C# backends, the Functions file is functions/Crud/TodoCrudFunctions.cs. For Python, it is functions/blueprints/todo.py.

4. Start the development server

bash
npx swallowkit dev
bash
pnpm swallowkit dev

This starts:

Open http://localhost:3000/todo to see the generated UI.

5. Verify the result

  • Navigate to http://localhost:3000/todo/new and create a todo item
  • The form submits to the BFF route, which forwards to Azure Functions
  • The item is stored in the local Cosmos DB Emulator
  • The list page shows the created item

What was generated

After init and scaffold, the project structure looks like:

my-app/
├── app/
│   ├── api/todo/          # BFF routes (auto-validation, proxy to Functions)
│   └── todo/              # React pages and components
├── shared/models/
│   └── todo.ts            # Zod schema (source of truth)
├── functions/src/
│   └── todo.ts            # Azure Functions CRUD handlers
├── infra/
│   ├── main.bicep         # Azure resource definitions
│   └── containers/        # Cosmos DB container definitions
├── lib/
│   └── api/               # BFF helper (callFunction)
└── .swallowkit/           # Project metadata

Next steps

Released under the MIT License.