swallowkit 1.0.0-beta.3 → 1.0.0-beta.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.ja.md +353 -215
- package/README.md +406 -216
- package/dist/__tests__/fixtures.d.ts +22 -0
- package/dist/__tests__/fixtures.d.ts.map +1 -0
- package/dist/__tests__/fixtures.js +146 -0
- package/dist/__tests__/fixtures.js.map +1 -0
- package/dist/cli/commands/add-auth.d.ts +10 -0
- package/dist/cli/commands/add-auth.d.ts.map +1 -0
- package/dist/cli/commands/add-auth.js +444 -0
- package/dist/cli/commands/add-auth.js.map +1 -0
- package/dist/cli/commands/add-connector.d.ts +20 -0
- package/dist/cli/commands/add-connector.d.ts.map +1 -0
- package/dist/cli/commands/add-connector.js +163 -0
- package/dist/cli/commands/add-connector.js.map +1 -0
- package/dist/cli/commands/create-model.d.ts +1 -4
- package/dist/cli/commands/create-model.d.ts.map +1 -1
- package/dist/cli/commands/create-model.js +21 -82
- package/dist/cli/commands/create-model.js.map +1 -1
- package/dist/cli/commands/dev-seeds.d.ts +57 -0
- package/dist/cli/commands/dev-seeds.d.ts.map +1 -0
- package/dist/cli/commands/dev-seeds.js +470 -0
- package/dist/cli/commands/dev-seeds.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +33 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +628 -146
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +3 -1
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +15 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +2696 -1706
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/scaffold.d.ts.map +1 -1
- package/dist/cli/commands/scaffold.js +448 -129
- package/dist/cli/commands/scaffold.js.map +1 -1
- package/dist/cli/index.d.ts +5 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +200 -42
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts +8 -2
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +94 -5
- package/dist/core/config.js.map +1 -1
- package/dist/core/mock/connector-mock-server.d.ts +101 -0
- package/dist/core/mock/connector-mock-server.d.ts.map +1 -0
- package/dist/core/mock/connector-mock-server.js +480 -0
- package/dist/core/mock/connector-mock-server.js.map +1 -0
- package/dist/core/mock/zod-mock-generator.d.ts +14 -0
- package/dist/core/mock/zod-mock-generator.d.ts.map +1 -0
- package/dist/core/mock/zod-mock-generator.js +163 -0
- package/dist/core/mock/zod-mock-generator.js.map +1 -0
- package/dist/core/operations/create-model.d.ts +15 -0
- package/dist/core/operations/create-model.d.ts.map +1 -0
- package/dist/core/operations/create-model.js +171 -0
- package/dist/core/operations/create-model.js.map +1 -0
- package/dist/core/operations/runtime.d.ts +32 -0
- package/dist/core/operations/runtime.d.ts.map +1 -0
- package/dist/core/operations/runtime.js +225 -0
- package/dist/core/operations/runtime.js.map +1 -0
- package/dist/core/operations/scaffold-machine.d.ts +16 -0
- package/dist/core/operations/scaffold-machine.d.ts.map +1 -0
- package/dist/core/operations/scaffold-machine.js +63 -0
- package/dist/core/operations/scaffold-machine.js.map +1 -0
- package/dist/core/project/manifest.d.ts +92 -0
- package/dist/core/project/manifest.d.ts.map +1 -0
- package/dist/core/project/manifest.js +321 -0
- package/dist/core/project/manifest.js.map +1 -0
- package/dist/core/project/validation.d.ts +20 -0
- package/dist/core/project/validation.d.ts.map +1 -0
- package/dist/core/project/validation.js +209 -0
- package/dist/core/project/validation.js.map +1 -0
- package/dist/core/scaffold/auth-generator.d.ts +38 -0
- package/dist/core/scaffold/auth-generator.d.ts.map +1 -0
- package/dist/core/scaffold/auth-generator.js +1244 -0
- package/dist/core/scaffold/auth-generator.js.map +1 -0
- package/dist/core/scaffold/connector-functions-generator.d.ts +41 -0
- package/dist/core/scaffold/connector-functions-generator.d.ts.map +1 -0
- package/dist/core/scaffold/connector-functions-generator.js +1027 -0
- package/dist/core/scaffold/connector-functions-generator.js.map +1 -0
- package/dist/core/scaffold/functions-generator.d.ts +7 -1
- package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
- package/dist/core/scaffold/functions-generator.js +920 -213
- package/dist/core/scaffold/functions-generator.js.map +1 -1
- package/dist/core/scaffold/model-parser.d.ts +20 -1
- package/dist/core/scaffold/model-parser.d.ts.map +1 -1
- package/dist/core/scaffold/model-parser.js +328 -135
- package/dist/core/scaffold/model-parser.js.map +1 -1
- package/dist/core/scaffold/native-schema-generator.d.ts +13 -0
- package/dist/core/scaffold/native-schema-generator.d.ts.map +1 -0
- package/dist/core/scaffold/native-schema-generator.js +677 -0
- package/dist/core/scaffold/native-schema-generator.js.map +1 -0
- package/dist/core/scaffold/nextjs-generator.d.ts +8 -0
- package/dist/core/scaffold/nextjs-generator.d.ts.map +1 -1
- package/dist/core/scaffold/nextjs-generator.js +314 -182
- package/dist/core/scaffold/nextjs-generator.js.map +1 -1
- package/dist/core/scaffold/openapi-generator.d.ts +3 -0
- package/dist/core/scaffold/openapi-generator.d.ts.map +1 -0
- package/dist/core/scaffold/openapi-generator.js +190 -0
- package/dist/core/scaffold/openapi-generator.js.map +1 -0
- package/dist/core/scaffold/ui-generator.d.ts +10 -4
- package/dist/core/scaffold/ui-generator.d.ts.map +1 -1
- package/dist/core/scaffold/ui-generator.js +768 -663
- package/dist/core/scaffold/ui-generator.js.map +1 -1
- package/dist/database/base-model.d.ts +3 -3
- package/dist/database/base-model.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/machine/contracts.d.ts +16 -0
- package/dist/machine/contracts.d.ts.map +1 -0
- package/dist/machine/contracts.js +3 -0
- package/dist/machine/contracts.js.map +1 -0
- package/dist/machine/errors.d.ts +11 -0
- package/dist/machine/errors.d.ts.map +1 -0
- package/dist/machine/errors.js +34 -0
- package/dist/machine/errors.js.map +1 -0
- package/dist/machine/index.d.ts +3 -0
- package/dist/machine/index.d.ts.map +1 -0
- package/dist/machine/index.js +156 -0
- package/dist/machine/index.js.map +1 -0
- package/dist/mcp/index.d.ts +25 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +184 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/types/index.d.ts +65 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/package-manager.d.ts +109 -0
- package/dist/utils/package-manager.d.ts.map +1 -0
- package/dist/utils/package-manager.js +215 -0
- package/dist/utils/package-manager.js.map +1 -0
- package/dist/utils/python-uv.d.ts +21 -0
- package/dist/utils/python-uv.d.ts.map +1 -0
- package/dist/utils/python-uv.js +111 -0
- package/dist/utils/python-uv.js.map +1 -0
- package/package.json +85 -73
- package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +1139 -0
- package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +194 -0
- package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +532 -0
- package/src/__tests__/auth.test.ts +654 -0
- package/src/__tests__/config.test.ts +274 -0
- package/src/__tests__/connector-functions-generator.test.ts +288 -0
- package/src/__tests__/connector-mock-server.test.ts +439 -0
- package/src/__tests__/connector-model-bff.test.ts +162 -0
- package/src/__tests__/dev-seeds.test.ts +173 -0
- package/src/__tests__/dev.test.ts +252 -0
- package/src/__tests__/fixtures.ts +144 -0
- package/src/__tests__/functions-generator.test.ts +237 -0
- package/src/__tests__/init.test.ts +115 -0
- package/src/__tests__/machine.test.ts +251 -0
- package/src/__tests__/mcp.test.ts +117 -0
- package/src/__tests__/model-parser.test.ts +52 -0
- package/src/__tests__/nextjs-generator.test.ts +97 -0
- package/src/__tests__/openapi-generator.test.ts +43 -0
- package/src/__tests__/package-manager.test.ts +189 -0
- package/src/__tests__/python-uv.test.ts +48 -0
- package/src/__tests__/scaffold.test.ts +67 -0
- package/src/__tests__/string-utils.test.ts +75 -0
- package/src/__tests__/ui-generator.test.ts +144 -0
- package/src/__tests__/zod-mock-generator.test.ts +132 -0
- package/src/cli/commands/add-auth.ts +500 -0
- package/src/cli/commands/add-connector.ts +158 -0
- package/src/cli/commands/create-model.ts +62 -0
- package/src/cli/commands/dev-seeds.ts +614 -0
- package/src/cli/commands/dev.ts +1134 -0
- package/src/cli/commands/index.ts +9 -0
- package/src/cli/commands/init.ts +3480 -0
- package/src/cli/commands/provision.ts +193 -0
- package/src/cli/commands/scaffold.ts +1001 -0
- package/src/cli/index.ts +196 -0
- package/src/core/config.ts +312 -0
- package/src/core/mock/connector-mock-server.ts +555 -0
- package/src/core/mock/zod-mock-generator.ts +205 -0
- package/src/core/operations/create-model.ts +174 -0
- package/src/core/operations/runtime.ts +235 -0
- package/src/core/operations/scaffold-machine.ts +91 -0
- package/src/core/project/manifest.ts +402 -0
- package/src/core/project/validation.ts +229 -0
- package/src/core/scaffold/auth-generator.ts +1284 -0
- package/src/core/scaffold/connector-functions-generator.ts +1128 -0
- package/src/core/scaffold/functions-generator.ts +970 -0
- package/src/core/scaffold/model-parser.ts +841 -0
- package/src/core/scaffold/native-schema-generator.ts +798 -0
- package/src/core/scaffold/nextjs-generator.ts +370 -0
- package/src/core/scaffold/openapi-generator.ts +212 -0
- package/src/core/scaffold/ui-generator.ts +1061 -0
- package/src/database/base-model.ts +184 -0
- package/src/database/client.ts +140 -0
- package/src/database/repository.ts +104 -0
- package/src/database/runtime-check.ts +25 -0
- package/src/index.ts +27 -0
- package/src/machine/contracts.ts +17 -0
- package/src/machine/errors.ts +34 -0
- package/src/machine/index.ts +173 -0
- package/src/mcp/index.ts +185 -0
- package/src/types/index.ts +134 -0
- package/src/utils/package-manager.ts +229 -0
- package/src/utils/python-uv.ts +96 -0
package/README.md
CHANGED
|
@@ -1,216 +1,406 @@
|
|
|
1
|
-
# SwallowKit
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/swallowkit)
|
|
4
|
-
[](https://www.npmjs.com/package/swallowkit)
|
|
5
|
-
[](https://www.npmjs.com/package/swallowkit)
|
|
4
|
+
[](https://www.npmjs.com/package/swallowkit)
|
|
5
|
+
[](https://marketplace.visualstudio.com/items?itemName=himanago.swallowkit-vscode)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
8
|
+
English | [日本語](./README.ja.md)
|
|
9
|
+
|
|
10
|
+
**Type-safe schema-driven development toolkit for Next.js applications on Azure**
|
|
11
|
+
|
|
12
|
+
SwallowKit enables developers to build full-stack Next.js applications with external Azure Functions backends while maintaining end-to-end type safety through shared Zod schemas.
|
|
13
|
+
|
|
14
|
+
Deploy your Next.js app to Azure Static Web Apps using standalone mode, and connect to independent Azure Functions for backend operations.
|
|
15
|
+
|
|
16
|
+
Next.js API routes are restricted to use only as BFF (Backend For Frontend), offloading business logic to Azure Functions to provide clear separation between client and server.
|
|
17
|
+
|
|
18
|
+
Featuring Scaffold functionality to automatically generate CRUD operations from Zod schemas, achieving type-safe integration with Cosmos DB and consistent type definitions and validation.
|
|
19
|
+
|
|
20
|
+
> **Note**: This project is in active development. APIs may change in future versions.
|
|
21
|
+
|
|
22
|
+
## ✨ Key Features
|
|
23
|
+
|
|
24
|
+
- **🔄 Zod Schema Sharing** - Keep Zod as the source of truth across frontend, BFF, Azure Functions, and Cosmos DB
|
|
25
|
+
- **⚡ CRUD Code Generation** - Auto-generate Azure Functions + Next.js code with `swallowkit scaffold`
|
|
26
|
+
- **🌐 Multi-language Functions Backends** - Choose TypeScript, C#, or Python for Azure Functions during `init`
|
|
27
|
+
- **🧬 OpenAPI Export + Native Codegen** - For C#/Python backends, `scaffold` exports OpenAPI from Zod and generates backend schema assets with native language tooling
|
|
28
|
+
- **🛡️ Contract Safety** - Keep frontend/BFF contracts aligned with backend implementations through shared Zod or native-generated backend models
|
|
29
|
+
- **🎯 BFF Pattern** - Next.js API Routes as BFF layer with auto-validation and resource inference
|
|
30
|
+
- **☁️ Azure Optimized** - Minimal-cost architecture with Static Web Apps + Functions + Cosmos DB
|
|
31
|
+
- **🚀 Easy Deployment** - Auto-generated Bicep IaC + CI/CD workflows
|
|
32
|
+
- **🤖 AI-Friendly** - Auto-generated instruction files (`AGENTS.md`, `CLAUDE.md`, `.github/copilot-instructions.md`) and layer-specific rules help GitHub Copilot, Claude Code, and OpenAI Codex follow project conventions
|
|
33
|
+
- **🧠 MCP + Machine Interface** - `swallowkit machine ...` exposes deterministic JSON inspection / validation / generation commands, and `swallowkit-mcp` exposes the same capabilities over MCP stdio
|
|
34
|
+
- **🔌 External Data Connectors** - Integrate MySQL, PostgreSQL, REST APIs, and other external data sources alongside Cosmos DB — same Zod-driven scaffold workflow with full type safety
|
|
35
|
+
- **🔐 Authentication & Authorization** - Built-in support for custom JWT auth (with external RDB user stores) and role-based access control per model — with planned Static Web Apps auth integration
|
|
36
|
+
- **🧪 Reusable Dev Seeds** - Turn real Cosmos DB Emulator data into reusable seed files for demos, regression checks, onboarding, and local verification
|
|
37
|
+
- **🧩 [VS Code Extension](https://marketplace.visualstudio.com/items?itemName=himanago.swallowkit-vscode)** - GUI wizard for init/scaffold/dev, right-click model scaffolding, dev server status bar, and TypeScript snippets
|
|
38
|
+
|
|
39
|
+
## 📚 Documentation
|
|
40
|
+
|
|
41
|
+
Visit the **[SwallowKit Documentation](https://himanago.github.io/swallowkit/)** for the full docs (also available in [日本語](https://himanago.github.io/swallowkit/ja/)).
|
|
42
|
+
|
|
43
|
+
- **[CLI Reference](https://himanago.github.io/swallowkit/en/cli-reference)** - All commands in detail
|
|
44
|
+
- **[Scaffold Guide](https://himanago.github.io/swallowkit/en/scaffold-guide)** - CRUD code generation
|
|
45
|
+
- **[Connector Guide](https://himanago.github.io/swallowkit/en/connector-guide)** - External data source integration
|
|
46
|
+
- **[Authentication Guide](https://himanago.github.io/swallowkit/en/auth-guide)** - Authentication and role-based access control
|
|
47
|
+
- **[Zod Schema Sharing Guide](https://himanago.github.io/swallowkit/en/zod-schema-sharing-guide)** - Schema design
|
|
48
|
+
- **[Deployment Guide](https://himanago.github.io/swallowkit/en/deployment-guide)** - Deploy to Azure
|
|
49
|
+
|
|
50
|
+
## 🚀 Quick Start
|
|
51
|
+
|
|
52
|
+
### 1. Create Project
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx swallowkit init my-app
|
|
56
|
+
# or
|
|
57
|
+
pnpm dlx swallowkit init my-app
|
|
58
|
+
cd my-app
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The interactive prompts ask for CI/CD provider, Azure Functions backend language, Cosmos DB mode, and network settings. You can also specify them as flags to skip prompts entirely:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Non-interactive mode (useful for VS Code extensions or automation)
|
|
65
|
+
npx swallowkit init my-app --cicd github --backend-language python --cosmos-db-mode serverless --vnet outbound
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Flag | Values | Description |
|
|
69
|
+
|------|--------|-------------|
|
|
70
|
+
| `--cicd <provider>` | `github`, `azure`, `skip` | CI/CD provider |
|
|
71
|
+
| `--backend-language <language>` | `typescript`, `csharp`, `python` | Azure Functions backend language |
|
|
72
|
+
| `--cosmos-db-mode <mode>` | `freetier`, `serverless` | Cosmos DB pricing mode |
|
|
73
|
+
| `--vnet <option>` | `outbound`, `none` | Network security |
|
|
74
|
+
|
|
75
|
+
Omit any flag to be prompted for that value interactively.
|
|
76
|
+
|
|
77
|
+
### 2. Create Models
|
|
78
|
+
|
|
79
|
+
You can create multiple models at once:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npx swallowkit create-model category todo
|
|
83
|
+
# or
|
|
84
|
+
pnpm dlx swallowkit create-model category todo
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
This generates `shared/models/category.ts` and `shared/models/todo.ts`. Customize them by adding your required fields:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
// shared/models/category.ts
|
|
91
|
+
import { z } from 'zod';
|
|
92
|
+
|
|
93
|
+
export const category = z.object({
|
|
94
|
+
id: z.string(),
|
|
95
|
+
name: z.string().min(1).max(50),
|
|
96
|
+
createdAt: z.string().optional(),
|
|
97
|
+
updatedAt: z.string().optional(),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export type Category = z.infer<typeof category>;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
For parent-child relationships, use **nested schemas** instead of ID references:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// shared/models/todo.ts
|
|
107
|
+
import { z } from 'zod';
|
|
108
|
+
import { category } from './category';
|
|
109
|
+
|
|
110
|
+
export const todo = z.object({
|
|
111
|
+
id: z.string(),
|
|
112
|
+
text: z.string().min(1).max(200),
|
|
113
|
+
completed: z.boolean().default(false),
|
|
114
|
+
category: category.optional(), // Nested object (not categoryId)
|
|
115
|
+
createdAt: z.string().optional(),
|
|
116
|
+
updatedAt: z.string().optional(),
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
export type Todo = z.infer<typeof todo>;
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
> **Tip**: Nesting preserves type safety and stores related data together in the document, which is natural for Cosmos DB's document model.
|
|
123
|
+
|
|
124
|
+
### 3. Generate CRUD Code
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
npx swallowkit scaffold shared/models/todo.ts
|
|
128
|
+
# or
|
|
129
|
+
pnpm dlx swallowkit scaffold shared/models/todo.ts
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
This auto-generates:
|
|
133
|
+
- ✅ Azure Functions (CRUD endpoints + Cosmos DB bindings)
|
|
134
|
+
- ✅ Next.js BFF API Routes (auto-validation + resource inference)
|
|
135
|
+
- ✅ React Components (type-safe forms)
|
|
136
|
+
|
|
137
|
+
If you selected `csharp` or `python` at `init` time, `swallowkit scaffold` also writes an OpenAPI document under `functions/openapi/` and generates native backend schema assets under `functions/generated/`.
|
|
138
|
+
|
|
139
|
+
### 4. Start Development Server
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
npx swallowkit dev
|
|
143
|
+
# or
|
|
144
|
+
pnpm dlx swallowkit dev
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
- Next.js: http://localhost:3000
|
|
148
|
+
- Azure Functions: http://localhost:7071
|
|
149
|
+
|
|
150
|
+
Backend-specific notes:
|
|
151
|
+
|
|
152
|
+
- **Python backends**: `swallowkit dev` uses **uv** for local runtime management. It installs or reuses a project-local `uv` binary under `.uv/bin`, keeps uv-managed Python under `.uv/python`, creates `functions/.venv` for the Functions app, and creates `functions/.codegen-venv` for Python schema generation.
|
|
153
|
+
- **C# backends**: Azure Functions isolated worker can take longer to answer on cold start while the worker build completes. `swallowkit dev` waits for the Functions host to start responding before it prints the backend URL as ready.
|
|
154
|
+
|
|
155
|
+
If you want to replace Cosmos DB Emulator data before startup, you can either generate an environment template or export the data currently stored in the local emulator:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npx swallowkit create-dev-seeds local
|
|
159
|
+
# edit dev-seeds/local/*.json
|
|
160
|
+
npx swallowkit dev --seed-env local
|
|
161
|
+
|
|
162
|
+
# or capture current emulator data as reusable seeds
|
|
163
|
+
npx swallowkit create-dev-seeds local --from-emulator --force
|
|
164
|
+
npx swallowkit dev --seed-env local
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
This workflow is designed for local debugging against the Cosmos DB Emulator:
|
|
168
|
+
|
|
169
|
+
- `create-dev-seeds <environment>` generates one JSON template per schema under `dev-seeds/<environment>/`
|
|
170
|
+
- `create-dev-seeds <environment> --from-emulator` exports the current data from the matching local Cosmos DB Emulator containers into the same file layout
|
|
171
|
+
- each file name maps to a schema/container, for example `shared/models/todo.ts` -> `dev-seeds/local/todo.json` -> `Todos`
|
|
172
|
+
- when you start `dev --seed-env <environment>`, SwallowKit replaces the existing data for each matching container with the JSON documents from that environment
|
|
173
|
+
- containers without a matching JSON file are left untouched
|
|
174
|
+
- if `--seed-env` is omitted, or `dev-seeds/<environment>/` does not exist, current emulator data is preserved
|
|
175
|
+
- exported files strip Cosmos system properties such as `_etag` before saving so they can be replayed safely
|
|
176
|
+
|
|
177
|
+
Why this is useful:
|
|
178
|
+
|
|
179
|
+
- preserve realistic local data that you registered manually while testing the app
|
|
180
|
+
- replay the same state for demos, onboarding sessions, and bug reproduction
|
|
181
|
+
- keep a schema-aligned seed snapshot without hand-copying documents out of the emulator
|
|
182
|
+
- quickly reset your emulator to a known-good state before validating behavior
|
|
183
|
+
|
|
184
|
+
Example file layout:
|
|
185
|
+
|
|
186
|
+
```text
|
|
187
|
+
dev-seeds/
|
|
188
|
+
local/
|
|
189
|
+
todo.json
|
|
190
|
+
category.json
|
|
191
|
+
staging-debug/
|
|
192
|
+
todo.json
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Each `{schema}.json` file can contain either a single JSON object or an array of JSON objects. Every document must include an `id`:
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
[
|
|
199
|
+
{
|
|
200
|
+
"id": "seed-todo-001",
|
|
201
|
+
"name": "Seed todo one",
|
|
202
|
+
"createdAt": "2026-03-21T00:00:00.000Z",
|
|
203
|
+
"updatedAt": "2026-03-21T00:00:00.000Z"
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"id": "seed-todo-002",
|
|
207
|
+
"name": "Seed todo two",
|
|
208
|
+
"createdAt": "2026-03-21T00:00:01.000Z",
|
|
209
|
+
"updatedAt": "2026-03-21T00:00:01.000Z"
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Recommended workflow:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
npx swallowkit create-model todo
|
|
218
|
+
npx swallowkit scaffold shared/models/todo.ts
|
|
219
|
+
npx swallowkit create-dev-seeds local
|
|
220
|
+
# edit dev-seeds/local/todo.json
|
|
221
|
+
npx swallowkit dev --seed-env local
|
|
222
|
+
|
|
223
|
+
# or export your current local Cosmos Emulator data
|
|
224
|
+
npx swallowkit create-dev-seeds local --from-emulator --force
|
|
225
|
+
npx swallowkit dev --seed-env local
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### 5. Use from Frontend
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import { api } from '@/lib/api/backend';
|
|
232
|
+
import type { Todo } from '@/shared/models/todo';
|
|
233
|
+
|
|
234
|
+
// Get all - call BFF endpoint
|
|
235
|
+
const todos = await api.get<Todo[]>('/api/todos');
|
|
236
|
+
|
|
237
|
+
// Create - validated by backend
|
|
238
|
+
const created = await api.post<Todo>('/api/todos', {
|
|
239
|
+
text: 'Buy milk',
|
|
240
|
+
completed: false
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// Update - validated by backend
|
|
244
|
+
const updated = await api.put<Todo>('/api/todos/123', { completed: true });
|
|
245
|
+
|
|
246
|
+
// Delete
|
|
247
|
+
await api.delete('/api/todos/123');
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### 6. Connect External Data Sources (Optional)
|
|
251
|
+
|
|
252
|
+
SwallowKit supports **connectors** for integrating external RDB databases and REST APIs alongside Cosmos DB, using the same Zod-driven workflow:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
# Register a connector
|
|
256
|
+
npx swallowkit add-connector mysql --type rdb --provider mysql --connection-env MYSQL_CONNECTION_STRING
|
|
257
|
+
|
|
258
|
+
# Create a connector-aware model
|
|
259
|
+
npx swallowkit create-model user --connector mysql
|
|
260
|
+
# edit shared/models/user.ts (customize schema + connectorConfig)
|
|
261
|
+
|
|
262
|
+
# Scaffold generates connector-specific Functions code
|
|
263
|
+
npx swallowkit scaffold shared/models/user.ts
|
|
264
|
+
|
|
265
|
+
# Develop locally with mock data (no real MySQL needed)
|
|
266
|
+
npx swallowkit dev --mock-connectors
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
The frontend and BFF layer are completely transparent to data source differences — `callFunction()` works identically for Cosmos DB and connector models. See the **[Connector Guide](https://himanago.github.io/swallowkit/en/connector-guide)** for details.
|
|
270
|
+
|
|
271
|
+
## 🤖 AI / MCP Integration
|
|
272
|
+
|
|
273
|
+
SwallowKit provides a machine-readable CLI surface for coding agents and MCP adapters. Instead of letting AI guess raw filesystem changes, it can go through SwallowKit's official generators, inspectors, and validators.
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
# Inspect framework-owned project metadata
|
|
277
|
+
npx swallowkit machine inspect project
|
|
278
|
+
|
|
279
|
+
# Validate SwallowKit conventions and generated artifacts
|
|
280
|
+
npx swallowkit machine validate project
|
|
281
|
+
|
|
282
|
+
# Generate through the official machine interface
|
|
283
|
+
npx swallowkit machine generate model todo --overwrite never
|
|
284
|
+
npx swallowkit machine generate scaffold todo --api-only
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
`swallowkit machine` is:
|
|
288
|
+
|
|
289
|
+
- non-interactive
|
|
290
|
+
- deterministic
|
|
291
|
+
- JSON-only on stdout
|
|
292
|
+
- structured on success and failure
|
|
293
|
+
|
|
294
|
+
For MCP clients, use the bundled stdio server:
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
npx swallowkit-mcp
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Projects generated by `swallowkit init` include a project-scoped `.mcp.json` bootstrap that launches the locally installed SwallowKit MCP entrypoint. Agent runtimes that support repository MCP discovery can start using the same `swallowkit_*` tools automatically from the project root after project dependencies are installed.
|
|
301
|
+
|
|
302
|
+
When a runtime does not auto-load project MCP config, the generated instruction files still steer the agent toward `swallowkit machine ...`, and you can manually register the same launcher in the client.
|
|
303
|
+
|
|
304
|
+
The MCP server is intentionally a thin adapter with explicit tools only. It delegates real work to the machine CLI.
|
|
305
|
+
|
|
306
|
+
## 🏗️ Architecture
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
310
|
+
│ Frontend (React) │
|
|
311
|
+
│ - Client Components │
|
|
312
|
+
│ - Server Components (SSR) │
|
|
313
|
+
└──────────────────────────┬───────────────────────────────────┘
|
|
314
|
+
│ api.post('/api/todos', data)
|
|
315
|
+
▼
|
|
316
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
317
|
+
│ BFF Layer (Next.js API Routes) │
|
|
318
|
+
│ - Auto Schema Validation (Zod) │
|
|
319
|
+
│ - Error Handling │
|
|
320
|
+
└──────────────────────────┬───────────────────────────────────┘
|
|
321
|
+
│ HTTP Request
|
|
322
|
+
▼
|
|
323
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
324
|
+
│ Azure Functions (Backend) │
|
|
325
|
+
│ - HTTP Triggers (CRUD) │
|
|
326
|
+
│ - Zod Validation (Re-check) │
|
|
327
|
+
│ - Business Logic │
|
|
328
|
+
│ - Data Source Bindings │
|
|
329
|
+
└──────────┬───────────────┼───────────────┬──────────────────┘
|
|
330
|
+
│ │ │
|
|
331
|
+
▼ ▼ ▼
|
|
332
|
+
┌────────────────┐ ┌──────────────┐ ┌──────────────────┐
|
|
333
|
+
│ Azure Cosmos │ │ External │ │ External SaaS │
|
|
334
|
+
│ DB (Default) │ │ RDB (MySQL │ │ APIs (REST) │
|
|
335
|
+
│ │ │ PostgreSQL) │ │ │
|
|
336
|
+
└────────────────┘ └──────────────┘ └──────────────────┘
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
**Key Patterns:**
|
|
340
|
+
- **BFF (Backend For Frontend)**: Next.js API Routes proxy to Azure Functions
|
|
341
|
+
- **Shared Schemas**: Zod schemas stay in `shared/models/` as the source of truth
|
|
342
|
+
- **OpenAPI Export for C#/Python**: Non-TypeScript Functions consume native-generated assets under `functions/generated/`
|
|
343
|
+
- **External Connectors**: MySQL, PostgreSQL, REST APIs — scaffold-generated Functions with the same BFF pattern
|
|
344
|
+
- **Contract Safety**: BFF and backend stay aligned through shared Zod or generated backend models
|
|
345
|
+
- **Managed Identity**: Secure service connections (no connection strings)
|
|
346
|
+
|
|
347
|
+
## 📦 Prerequisites
|
|
348
|
+
|
|
349
|
+
- Node.js 22.x
|
|
350
|
+
- **pnpm** (recommended): `corepack enable` or `npm install -g pnpm`
|
|
351
|
+
- npm also works — SwallowKit auto-detects the package manager (if pnpm is installed, it is always preferred)
|
|
352
|
+
- Azure CLI (`az`) for provisioning and deployment
|
|
353
|
+
- Azure Functions Core Tools 4.x for local Azure Functions development
|
|
354
|
+
- Azure Cosmos DB Emulator (local development)
|
|
355
|
+
- [Official documentation (vNext recommended)](https://learn.microsoft.com/en-us/azure/cosmos-db/emulator-linux)
|
|
356
|
+
- Windows: [Download](https://aka.ms/cosmosdb-emulator)
|
|
357
|
+
- Docker: `docker run -p 8081:8081 mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator`
|
|
358
|
+
|
|
359
|
+
### Backend-specific requirements
|
|
360
|
+
|
|
361
|
+
- TypeScript/Node.js backend: no extra runtime requirement
|
|
362
|
+
- Python backend: uv is used for local environment management
|
|
363
|
+
- C# backend: .NET 10 SDK and Azure Functions Core Tools 4.6.0 or later
|
|
364
|
+
|
|
365
|
+
> Note: C# project generation now targets .NET 10 only. The .NET 8 generation path is no longer kept.
|
|
366
|
+
|
|
367
|
+
## 🚀 Deploy to Azure
|
|
368
|
+
|
|
369
|
+
Deploy your Next.js app to Azure Static Web Apps using standalone mode, and connect to independent Azure Functions for backend operations.
|
|
370
|
+
|
|
371
|
+
**1. Provision resources (Bicep IaC)**
|
|
372
|
+
|
|
373
|
+
```bash
|
|
374
|
+
npx swallowkit provision --resource-group my-app-rg
|
|
375
|
+
# or
|
|
376
|
+
pnpm dlx swallowkit provision --resource-group my-app-rg
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
The command prompts you to choose the primary region and the Static Web App region. After provisioning, the terminal displays the CI/CD values you need for setup. Copy them.
|
|
380
|
+
|
|
381
|
+
**2. Push code**
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
git push origin main
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
**3. Cancel the auto-triggered CI/CD run** — it will fail because secrets are not registered yet.
|
|
388
|
+
|
|
389
|
+
**4. Register the displayed secrets / variables** in GitHub (Settings → Secrets) or Azure DevOps (Pipelines → Library).
|
|
390
|
+
|
|
391
|
+
**5. Manually re-run the CI/CD workflow.**
|
|
392
|
+
|
|
393
|
+
See **[Deployment Guide](https://himanago.github.io/swallowkit/en/deployment-guide)** for details.
|
|
394
|
+
|
|
395
|
+
## License
|
|
396
|
+
|
|
397
|
+
MIT
|
|
398
|
+
|
|
399
|
+
## 🔗 Related Links
|
|
400
|
+
|
|
401
|
+
- [SwallowKit VS Code Extension](https://marketplace.visualstudio.com/items?itemName=himanago.swallowkit-vscode)
|
|
402
|
+
- [Azure Static Web Apps](https://learn.microsoft.com/en-us/azure/static-web-apps/)
|
|
403
|
+
- [Azure Functions](https://learn.microsoft.com/en-us/azure/azure-functions/)
|
|
404
|
+
- [Azure Cosmos DB](https://learn.microsoft.com/en-us/azure/cosmos-db/)
|
|
405
|
+
- [Next.js](https://nextjs.org/)
|
|
406
|
+
- [Zod](https://zod.dev/)
|