Skip to content

Getting started ​

See package manager commands and troubleshooting for pnpm 11/12 and npm usage.

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

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

Choose React for a Vite SPA with a SWA managed Functions BFF. The React guide covers its generated paths, authentication, local development and deployment. The path examples below use Next.js unless stated otherwise.

Prerequisites ​

  • Node.js 22.14 or later
  • pnpm (recommended) — run corepack enable or install with npm install -g pnpm
    • npm also works. SwallowKit uses the invoking package manager; --package-manager npm|pnpm overrides detection.
  • 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@beta init my-app
cd my-app
bash
pnpm dlx swallowkit@beta init my-app
cd my-app

For Next.js, the command runs create-next-app. For React, it generates a Vite + React Router SPA and a separate managed Functions BFF.

Interactive prompts ask for:

OptionValuesDefault
Frontendnextjs, reactnextjs (non-interactive default)
CI/CD providergithub, azure, skip(prompted)
Backend languagetypescript, csharp, python(prompted)
Cosmos DB modefreetier, serverless(prompted)
Networkoutbound, none(prompted)
SWA planfree, standard(prompted)

To skip prompts, pass flags directly:

bash
npx swallowkit@beta init my-app --frontend react --cicd github --backend-language typescript --cosmos-db-mode serverless --vnet none --swa-plan free
bash
pnpm dlx swallowkit@beta init my-app --frontend react --cicd github --backend-language typescript --cosmos-db-mode serverless --vnet none --swa-plan free

2. Create a model ​

bash
npx swallowkit create-model todo
bash
pnpm exec 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/v4';

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>;

id must be a required z.string() on persistent models. Declare createdAt and updatedAt as optional when needed. Standard forms do not ask for these values; the BFF removes them from input and the backend sets them during create/update.

3. Generate CRUD code ​

bash
npx swallowkit scaffold todo
bash
pnpm exec 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/migrations/0001-create-todo-container/main.bicep

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

React instead generates bff/src/todo/index.ts, bff/todo/function.json, and pages/forms/route registrations under src/pages/todo/.

4. Start the development server ​

bash
npx swallowkit dev
bash
pnpm exec swallowkit dev

This starts:

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

For React, dev also starts the managed BFF (7073) and SWA CLI (4280). Open http://localhost:4280/todo so /api requests pass through the managed BFF. Standalone Functions stay on 7071 and are never linked to SWA.

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
│   └── migrations/        # Versioned Cosmos DB container definitions
├── lib/
│   └── api/               # BFF helper (callFunction)
└── .swallowkit/           # Project metadata

Next steps ​

Released under the MIT License.