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.
Files changed (201) hide show
  1. package/LICENSE +21 -21
  2. package/README.ja.md +353 -215
  3. package/README.md +406 -216
  4. package/dist/__tests__/fixtures.d.ts +22 -0
  5. package/dist/__tests__/fixtures.d.ts.map +1 -0
  6. package/dist/__tests__/fixtures.js +146 -0
  7. package/dist/__tests__/fixtures.js.map +1 -0
  8. package/dist/cli/commands/add-auth.d.ts +10 -0
  9. package/dist/cli/commands/add-auth.d.ts.map +1 -0
  10. package/dist/cli/commands/add-auth.js +444 -0
  11. package/dist/cli/commands/add-auth.js.map +1 -0
  12. package/dist/cli/commands/add-connector.d.ts +20 -0
  13. package/dist/cli/commands/add-connector.d.ts.map +1 -0
  14. package/dist/cli/commands/add-connector.js +163 -0
  15. package/dist/cli/commands/add-connector.js.map +1 -0
  16. package/dist/cli/commands/create-model.d.ts +1 -4
  17. package/dist/cli/commands/create-model.d.ts.map +1 -1
  18. package/dist/cli/commands/create-model.js +21 -82
  19. package/dist/cli/commands/create-model.js.map +1 -1
  20. package/dist/cli/commands/dev-seeds.d.ts +57 -0
  21. package/dist/cli/commands/dev-seeds.d.ts.map +1 -0
  22. package/dist/cli/commands/dev-seeds.js +470 -0
  23. package/dist/cli/commands/dev-seeds.js.map +1 -0
  24. package/dist/cli/commands/dev.d.ts +33 -0
  25. package/dist/cli/commands/dev.d.ts.map +1 -1
  26. package/dist/cli/commands/dev.js +628 -146
  27. package/dist/cli/commands/dev.js.map +1 -1
  28. package/dist/cli/commands/index.d.ts +1 -0
  29. package/dist/cli/commands/index.d.ts.map +1 -1
  30. package/dist/cli/commands/index.js +3 -1
  31. package/dist/cli/commands/index.js.map +1 -1
  32. package/dist/cli/commands/init.d.ts +15 -0
  33. package/dist/cli/commands/init.d.ts.map +1 -1
  34. package/dist/cli/commands/init.js +2696 -1706
  35. package/dist/cli/commands/init.js.map +1 -1
  36. package/dist/cli/commands/scaffold.d.ts.map +1 -1
  37. package/dist/cli/commands/scaffold.js +448 -129
  38. package/dist/cli/commands/scaffold.js.map +1 -1
  39. package/dist/cli/index.d.ts +5 -1
  40. package/dist/cli/index.d.ts.map +1 -1
  41. package/dist/cli/index.js +200 -42
  42. package/dist/cli/index.js.map +1 -1
  43. package/dist/core/config.d.ts +8 -2
  44. package/dist/core/config.d.ts.map +1 -1
  45. package/dist/core/config.js +94 -5
  46. package/dist/core/config.js.map +1 -1
  47. package/dist/core/mock/connector-mock-server.d.ts +101 -0
  48. package/dist/core/mock/connector-mock-server.d.ts.map +1 -0
  49. package/dist/core/mock/connector-mock-server.js +480 -0
  50. package/dist/core/mock/connector-mock-server.js.map +1 -0
  51. package/dist/core/mock/zod-mock-generator.d.ts +14 -0
  52. package/dist/core/mock/zod-mock-generator.d.ts.map +1 -0
  53. package/dist/core/mock/zod-mock-generator.js +163 -0
  54. package/dist/core/mock/zod-mock-generator.js.map +1 -0
  55. package/dist/core/operations/create-model.d.ts +15 -0
  56. package/dist/core/operations/create-model.d.ts.map +1 -0
  57. package/dist/core/operations/create-model.js +171 -0
  58. package/dist/core/operations/create-model.js.map +1 -0
  59. package/dist/core/operations/runtime.d.ts +32 -0
  60. package/dist/core/operations/runtime.d.ts.map +1 -0
  61. package/dist/core/operations/runtime.js +225 -0
  62. package/dist/core/operations/runtime.js.map +1 -0
  63. package/dist/core/operations/scaffold-machine.d.ts +16 -0
  64. package/dist/core/operations/scaffold-machine.d.ts.map +1 -0
  65. package/dist/core/operations/scaffold-machine.js +63 -0
  66. package/dist/core/operations/scaffold-machine.js.map +1 -0
  67. package/dist/core/project/manifest.d.ts +92 -0
  68. package/dist/core/project/manifest.d.ts.map +1 -0
  69. package/dist/core/project/manifest.js +321 -0
  70. package/dist/core/project/manifest.js.map +1 -0
  71. package/dist/core/project/validation.d.ts +20 -0
  72. package/dist/core/project/validation.d.ts.map +1 -0
  73. package/dist/core/project/validation.js +209 -0
  74. package/dist/core/project/validation.js.map +1 -0
  75. package/dist/core/scaffold/auth-generator.d.ts +38 -0
  76. package/dist/core/scaffold/auth-generator.d.ts.map +1 -0
  77. package/dist/core/scaffold/auth-generator.js +1244 -0
  78. package/dist/core/scaffold/auth-generator.js.map +1 -0
  79. package/dist/core/scaffold/connector-functions-generator.d.ts +41 -0
  80. package/dist/core/scaffold/connector-functions-generator.d.ts.map +1 -0
  81. package/dist/core/scaffold/connector-functions-generator.js +1027 -0
  82. package/dist/core/scaffold/connector-functions-generator.js.map +1 -0
  83. package/dist/core/scaffold/functions-generator.d.ts +7 -1
  84. package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
  85. package/dist/core/scaffold/functions-generator.js +920 -213
  86. package/dist/core/scaffold/functions-generator.js.map +1 -1
  87. package/dist/core/scaffold/model-parser.d.ts +20 -1
  88. package/dist/core/scaffold/model-parser.d.ts.map +1 -1
  89. package/dist/core/scaffold/model-parser.js +328 -135
  90. package/dist/core/scaffold/model-parser.js.map +1 -1
  91. package/dist/core/scaffold/native-schema-generator.d.ts +13 -0
  92. package/dist/core/scaffold/native-schema-generator.d.ts.map +1 -0
  93. package/dist/core/scaffold/native-schema-generator.js +677 -0
  94. package/dist/core/scaffold/native-schema-generator.js.map +1 -0
  95. package/dist/core/scaffold/nextjs-generator.d.ts +8 -0
  96. package/dist/core/scaffold/nextjs-generator.d.ts.map +1 -1
  97. package/dist/core/scaffold/nextjs-generator.js +314 -182
  98. package/dist/core/scaffold/nextjs-generator.js.map +1 -1
  99. package/dist/core/scaffold/openapi-generator.d.ts +3 -0
  100. package/dist/core/scaffold/openapi-generator.d.ts.map +1 -0
  101. package/dist/core/scaffold/openapi-generator.js +190 -0
  102. package/dist/core/scaffold/openapi-generator.js.map +1 -0
  103. package/dist/core/scaffold/ui-generator.d.ts +10 -4
  104. package/dist/core/scaffold/ui-generator.d.ts.map +1 -1
  105. package/dist/core/scaffold/ui-generator.js +768 -663
  106. package/dist/core/scaffold/ui-generator.js.map +1 -1
  107. package/dist/database/base-model.d.ts +3 -3
  108. package/dist/database/base-model.js +3 -3
  109. package/dist/index.d.ts +2 -2
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +2 -1
  112. package/dist/index.js.map +1 -1
  113. package/dist/machine/contracts.d.ts +16 -0
  114. package/dist/machine/contracts.d.ts.map +1 -0
  115. package/dist/machine/contracts.js +3 -0
  116. package/dist/machine/contracts.js.map +1 -0
  117. package/dist/machine/errors.d.ts +11 -0
  118. package/dist/machine/errors.d.ts.map +1 -0
  119. package/dist/machine/errors.js +34 -0
  120. package/dist/machine/errors.js.map +1 -0
  121. package/dist/machine/index.d.ts +3 -0
  122. package/dist/machine/index.d.ts.map +1 -0
  123. package/dist/machine/index.js +156 -0
  124. package/dist/machine/index.js.map +1 -0
  125. package/dist/mcp/index.d.ts +25 -0
  126. package/dist/mcp/index.d.ts.map +1 -0
  127. package/dist/mcp/index.js +184 -0
  128. package/dist/mcp/index.js.map +1 -0
  129. package/dist/types/index.d.ts +65 -0
  130. package/dist/types/index.d.ts.map +1 -1
  131. package/dist/utils/package-manager.d.ts +109 -0
  132. package/dist/utils/package-manager.d.ts.map +1 -0
  133. package/dist/utils/package-manager.js +215 -0
  134. package/dist/utils/package-manager.js.map +1 -0
  135. package/dist/utils/python-uv.d.ts +21 -0
  136. package/dist/utils/python-uv.d.ts.map +1 -0
  137. package/dist/utils/python-uv.js +111 -0
  138. package/dist/utils/python-uv.js.map +1 -0
  139. package/package.json +85 -73
  140. package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +1139 -0
  141. package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +194 -0
  142. package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +532 -0
  143. package/src/__tests__/auth.test.ts +654 -0
  144. package/src/__tests__/config.test.ts +274 -0
  145. package/src/__tests__/connector-functions-generator.test.ts +288 -0
  146. package/src/__tests__/connector-mock-server.test.ts +439 -0
  147. package/src/__tests__/connector-model-bff.test.ts +162 -0
  148. package/src/__tests__/dev-seeds.test.ts +173 -0
  149. package/src/__tests__/dev.test.ts +252 -0
  150. package/src/__tests__/fixtures.ts +144 -0
  151. package/src/__tests__/functions-generator.test.ts +237 -0
  152. package/src/__tests__/init.test.ts +115 -0
  153. package/src/__tests__/machine.test.ts +251 -0
  154. package/src/__tests__/mcp.test.ts +117 -0
  155. package/src/__tests__/model-parser.test.ts +52 -0
  156. package/src/__tests__/nextjs-generator.test.ts +97 -0
  157. package/src/__tests__/openapi-generator.test.ts +43 -0
  158. package/src/__tests__/package-manager.test.ts +189 -0
  159. package/src/__tests__/python-uv.test.ts +48 -0
  160. package/src/__tests__/scaffold.test.ts +67 -0
  161. package/src/__tests__/string-utils.test.ts +75 -0
  162. package/src/__tests__/ui-generator.test.ts +144 -0
  163. package/src/__tests__/zod-mock-generator.test.ts +132 -0
  164. package/src/cli/commands/add-auth.ts +500 -0
  165. package/src/cli/commands/add-connector.ts +158 -0
  166. package/src/cli/commands/create-model.ts +62 -0
  167. package/src/cli/commands/dev-seeds.ts +614 -0
  168. package/src/cli/commands/dev.ts +1134 -0
  169. package/src/cli/commands/index.ts +9 -0
  170. package/src/cli/commands/init.ts +3480 -0
  171. package/src/cli/commands/provision.ts +193 -0
  172. package/src/cli/commands/scaffold.ts +1001 -0
  173. package/src/cli/index.ts +196 -0
  174. package/src/core/config.ts +312 -0
  175. package/src/core/mock/connector-mock-server.ts +555 -0
  176. package/src/core/mock/zod-mock-generator.ts +205 -0
  177. package/src/core/operations/create-model.ts +174 -0
  178. package/src/core/operations/runtime.ts +235 -0
  179. package/src/core/operations/scaffold-machine.ts +91 -0
  180. package/src/core/project/manifest.ts +402 -0
  181. package/src/core/project/validation.ts +229 -0
  182. package/src/core/scaffold/auth-generator.ts +1284 -0
  183. package/src/core/scaffold/connector-functions-generator.ts +1128 -0
  184. package/src/core/scaffold/functions-generator.ts +970 -0
  185. package/src/core/scaffold/model-parser.ts +841 -0
  186. package/src/core/scaffold/native-schema-generator.ts +798 -0
  187. package/src/core/scaffold/nextjs-generator.ts +370 -0
  188. package/src/core/scaffold/openapi-generator.ts +212 -0
  189. package/src/core/scaffold/ui-generator.ts +1061 -0
  190. package/src/database/base-model.ts +184 -0
  191. package/src/database/client.ts +140 -0
  192. package/src/database/repository.ts +104 -0
  193. package/src/database/runtime-check.ts +25 -0
  194. package/src/index.ts +27 -0
  195. package/src/machine/contracts.ts +17 -0
  196. package/src/machine/errors.ts +34 -0
  197. package/src/machine/index.ts +173 -0
  198. package/src/mcp/index.ts +185 -0
  199. package/src/types/index.ts +134 -0
  200. package/src/utils/package-manager.ts +229 -0
  201. package/src/utils/python-uv.ts +96 -0
package/README.md CHANGED
@@ -1,216 +1,406 @@
1
- # SwallowKit
2
-
3
- [![npm version](https://img.shields.io/npm/v/swallowkit.svg)](https://www.npmjs.com/package/swallowkit)
4
- [![npm downloads](https://img.shields.io/npm/dm/swallowkit.svg)](https://www.npmjs.com/package/swallowkit)
5
- [![license](https://img.shields.io/npm/l/swallowkit.svg)](./LICENSE)
6
-
7
- English | [日本語](./README.ja.md)
8
-
9
- **Type-safe schema-driven development toolkit for Next.js applications on Azure**
10
-
11
- 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.
12
-
13
- Deploy your Next.js app to Azure Static Web Apps using standalone mode, and connect to independent Azure Functions for backend operations.
14
-
15
- 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.
16
-
17
- Featuring Scaffold functionality to automatically generate CRUD operations from Zod schemas, achieving type-safe integration with Cosmos DB and consistent type definitions and validation.
18
-
19
- > **Note**: This project is in active development. APIs may change in future versions.
20
-
21
- ## ✨ Key Features
22
-
23
- - **🔄 Zod Schema Sharing** - Same schema across frontend, BFF, Azure Functions, and Cosmos DB
24
- - **⚡ CRUD Code Generation** - Auto-generate Azure Functions + Next.js code with `swallowkit scaffold`
25
- - **🛡️ Full Type Safety** - End-to-end TypeScript from client to database
26
- - **🎯 BFF Pattern** - Next.js API Routes as BFF layer with auto-validation and resource inference
27
- - **☁️ Azure Optimized** - Minimal-cost architecture with Static Web Apps + Functions + Cosmos DB
28
- - **🚀 Easy Deployment** - Auto-generated Bicep IaC + CI/CD workflows
29
-
30
- ## 📚 Documentation
31
-
32
- - **[CLI Reference](./docs/cli-reference.md)** - All commands in detail
33
- - **[Scaffold Guide](./docs/scaffold-guide.md)** - CRUD code generation
34
- - **[Zod Schema Sharing Guide](./docs/zod-schema-sharing-guide.md)** - Schema design
35
- - **[Deployment Guide](./docs/deployment-guide.md)** - Deploy to Azure
36
-
37
- ## 🚀 Quick Start
38
-
39
- ### 1. Create Project
40
-
41
- ```bash
42
- npx swallowkit init my-app
43
- cd my-app
44
- ```
45
-
46
- ### 2. Create Models
47
-
48
- You can create multiple models at once:
49
-
50
- ```bash
51
- npx swallowkit create-model category todo
52
- ```
53
-
54
- This generates `shared/models/category.ts` and `shared/models/todo.ts`. Customize them by adding your required fields:
55
-
56
- ```typescript
57
- // shared/models/category.ts
58
- import { z } from 'zod';
59
-
60
- export const category = z.object({
61
- id: z.string(),
62
- name: z.string().min(1).max(50),
63
- createdAt: z.string().optional(),
64
- updatedAt: z.string().optional(),
65
- });
66
-
67
- export type Category = z.infer<typeof category>;
68
- ```
69
-
70
- For parent-child relationships, use **nested schemas** instead of ID references:
71
-
72
- ```typescript
73
- // shared/models/todo.ts
74
- import { z } from 'zod';
75
- import { category } from './category';
76
-
77
- export const todo = z.object({
78
- id: z.string(),
79
- text: z.string().min(1).max(200),
80
- completed: z.boolean().default(false),
81
- category: category.optional(), // Nested object (not categoryId)
82
- createdAt: z.string().optional(),
83
- updatedAt: z.string().optional(),
84
- });
85
-
86
- export type Todo = z.infer<typeof todo>;
87
- ```
88
-
89
- > **Tip**: Nesting preserves type safety and stores related data together in the document, which is natural for Cosmos DB's document model.
90
-
91
- ### 3. Generate CRUD Code
92
-
93
- ```bash
94
- npx swallowkit scaffold shared/models/todo.ts
95
- ```
96
-
97
- This auto-generates:
98
- - ✅ Azure Functions (CRUD endpoints + Cosmos DB bindings)
99
- - ✅ Next.js BFF API Routes (auto-validation + resource inference)
100
- - React Components (type-safe forms)
101
-
102
- ### 4. Start Development Server
103
-
104
- ```bash
105
- npx swallowkit dev
106
- ```
107
-
108
- - Next.js: http://localhost:3000
109
- - Azure Functions: http://localhost:7071
110
-
111
- ### 5. Use from Frontend
112
-
113
- ```typescript
114
- import { api } from '@/lib/api/backend';
115
- import type { Todo } from '@/shared/models/todo';
116
-
117
- // Get all - call BFF endpoint
118
- const todos = await api.get<Todo[]>('/api/todos');
119
-
120
- // Create - validated by backend
121
- const created = await api.post<Todo>('/api/todos', {
122
- text: 'Buy milk',
123
- completed: false
124
- });
125
-
126
- // Update - validated by backend
127
- const updated = await api.put<Todo>('/api/todos/123', { completed: true });
128
-
129
- // Delete
130
- await api.delete('/api/todos/123');
131
- ```
132
-
133
- ## 🏗️ Architecture
134
-
135
- ```
136
- ┌─────────────────────────────────────────────────────────────┐
137
- │ Frontend (React) │
138
- │ - Client Components │
139
- │ - Server Components (SSR) │
140
- └──────────────────────────┬───────────────────────────────────┘
141
- │ api.post('/api/todos', data)
142
-
143
- ┌─────────────────────────────────────────────────────────────┐
144
- │ BFF Layer (Next.js API Routes) │
145
- │ - Auto Schema Validation (Zod) │
146
- │ - Error Handling │
147
- └──────────────────────────┬───────────────────────────────────┘
148
- HTTP Request
149
-
150
- ┌─────────────────────────────────────────────────────────────┐
151
- │ Azure Functions (Backend) │
152
- - HTTP Triggers (CRUD) │
153
- - Zod Validation (Re-check) │
154
- │ - Business Logic │
155
- │ - Cosmos DB Bindings │
156
- └──────────────────────────┬───────────────────────────────────┘
157
-
158
-
159
- ┌─────────────────────────────────────────────────────────────┐
160
- │ Azure Cosmos DB │
161
- │ - NoSQL Database │
162
- │ - Zod Schema Validation │
163
- └─────────────────────────────────────────────────────────────┘
164
- ```
165
-
166
- **Key Patterns:**
167
- - **BFF (Backend For Frontend)**: Next.js API Routes proxy to Azure Functions
168
- - **Shared Schemas**: Zod schemas used across frontend, BFF, Functions, and DB
169
- - **Type Safety**: TypeScript types auto-inferred from Zod
170
- - **Managed Identity**: Secure service connections (no connection strings)
171
-
172
- ## 📦 Prerequisites
173
-
174
- - Node.js 22.x
175
- - Azure Cosmos DB Emulator (local development)
176
- - [Official documentation (vNext recommended)](https://learn.microsoft.com/en-us/azure/cosmos-db/emulator-linux)
177
- - Windows: [Download](https://aka.ms/cosmosdb-emulator)
178
- - Docker: `docker run -p 8081:8081 mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator`
179
-
180
- ## 🚀 Deploy to Azure
181
-
182
- Deploy your Next.js app to Azure Static Web Apps using standalone mode, and connect to independent Azure Functions for backend operations.
183
-
184
- **1. Provision resources (Bicep IaC)**
185
-
186
- ```bash
187
- npx swallowkit provision --resource-group my-app-rg --location japaneast
188
- ```
189
-
190
- After provisioning, the required CI/CD secret values are displayed in the terminal. Copy them.
191
-
192
- **2. Push code**
193
-
194
- ```bash
195
- git push origin main
196
- ```
197
-
198
- **3. Cancel the auto-triggered CI/CD run** — it will fail because secrets are not registered yet.
199
-
200
- **4. Register the displayed secret values** in GitHub (Settings → Secrets) or Azure DevOps (Pipelines → Library).
201
-
202
- **5. Manually re-run the CI/CD workflow.**
203
-
204
- See **[Deployment Guide](./docs/deployment-guide.md)** for details.
205
-
206
- ## License
207
-
208
- MIT
209
-
210
- ## 🔗 Related Links
211
-
212
- - [Azure Static Web Apps](https://learn.microsoft.com/en-us/azure/static-web-apps/)
213
- - [Azure Functions](https://learn.microsoft.com/en-us/azure/azure-functions/)
214
- - [Azure Cosmos DB](https://learn.microsoft.com/en-us/azure/cosmos-db/)
215
- - [Next.js](https://nextjs.org/)
216
- - [Zod](https://zod.dev/)
1
+ # SwallowKit
2
+
3
+ [![npm version](https://img.shields.io/npm/v/swallowkit.svg)](https://www.npmjs.com/package/swallowkit)
4
+ [![npm downloads](https://img.shields.io/npm/dm/swallowkit.svg)](https://www.npmjs.com/package/swallowkit)
5
+ [![VS Code Marketplace](https://img.shields.io/visual-studio-marketplace/v/himanago.swallowkit-vscode?label=VS%20Code%20Extension)](https://marketplace.visualstudio.com/items?itemName=himanago.swallowkit-vscode)
6
+ [![license](https://img.shields.io/npm/l/swallowkit.svg)](./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/)