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 enableor install withnpm install -g pnpm- npm also works. SwallowKit uses the invoking package manager;
--package-manager npm|pnpmoverrides detection.
- npm also works. SwallowKit uses the invoking package manager;
- 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
npx swallowkit@beta init my-app
cd my-apppnpm dlx swallowkit@beta init my-app
cd my-appFor 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:
| Option | Values | Default |
|---|---|---|
| Frontend | nextjs, react | nextjs (non-interactive default) |
| CI/CD provider | github, azure, skip | (prompted) |
| Backend language | typescript, csharp, python | (prompted) |
| Cosmos DB mode | freetier, serverless | (prompted) |
| Network | outbound, none | (prompted) |
| SWA plan | free, standard | (prompted) |
To skip prompts, pass flags directly:
npx swallowkit@beta init my-app --frontend react --cicd github --backend-language typescript --cosmos-db-mode serverless --vnet none --swa-plan freepnpm dlx swallowkit@beta init my-app --frontend react --cicd github --backend-language typescript --cosmos-db-mode serverless --vnet none --swa-plan free2. Create a model
npx swallowkit create-model todopnpm exec swallowkit create-model todoThis generates shared/models/todo.ts with a template schema. Edit it:
// 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
npx swallowkit scaffold todopnpm exec swallowkit scaffold todoThis generates:
| Layer | Generated files |
|---|---|
| Azure Functions | functions/src/todo.ts (TypeScript backend) |
| BFF routes | app/api/todo/route.ts, app/api/todo/[id]/route.ts |
| UI pages | app/todo/page.tsx, app/todo/[id]/page.tsx, app/todo/new/page.tsx, app/todo/[id]/edit/page.tsx |
| UI components | app/todo/_components/TodoForm.tsx |
| Infrastructure | infra/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
npx swallowkit devpnpm exec swallowkit devThis starts:
- Next.js at http://localhost:3000
- Azure Functions at http://localhost:7071
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 metadataNext steps
- Core concepts — Understand the schema-centric architecture and BFF pattern
- Scaffold guide — Advanced scaffold options, nested schemas, multiple models
- Local development — Dev seeds, mock connectors, backend-specific setup
- Deploy to Azure — Provision resources and set up CI/CD
