Move codegen out of mizan-django: protocol/mizan-generate/
The codegen consumes a schema from any backend and emits typed client code for any frontend — it doesn't belong inside a backend adapter. That placement was historical sediment from when there was only a Django backend; it predates the AFI generalization. New top-level slot: `protocol/` for protocol-level tooling. Tree is now: backends/ server protocol adapters frontends/ client kernel + per-framework adapters cores/ shared language-level primitives protocol/ protocol-level tooling workers/ runtime workers / bridges Codegen moves to `protocol/mizan-generate/`. Same file layout under `generator/` (cli.mjs, lib/), preserved via git mv. Package metadata cleaned up: - name: "generate" (placeholder) → "mizan-generate" - description filled in - type: module (cli.mjs is .mjs ESM, was previously declared "commonjs") - bin entry added so `npx mizan-generate --config <config.mjs>` works once the package is published, instead of `node path/to/cli.mjs`. Path-reference fixups: - backends/mizan-django/README.md: `node path/to/...` → `npx mizan-generate` - backends/mizan-fastapi/README.md: same - ISSUES.md: file paths in three issue entries - CLAUDE.md: codegen description + Package Layout section refreshed (added protocol/, mizan-fastapi entry, mizan-python entry) - docs/AFI_ARCHITECTURE.md: Package Layout refreshed identically Verified codegen runs from new location: regenerated the FastAPI example harness's api/ output, identical to pre-move. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,13 +15,17 @@ Tree organized by role. Per-framework adapters wrap a single shared kernel; code
|
|||||||
```
|
```
|
||||||
backends/ server protocol adapters
|
backends/ server protocol adapters
|
||||||
mizan-django/ Django adapter
|
mizan-django/ Django adapter
|
||||||
|
mizan-fastapi/ FastAPI adapter (RPC + context + invalidation; AFI-common scope)
|
||||||
mizan-ts/ TypeScript adapter (proves the protocol is language-agnostic)
|
mizan-ts/ TypeScript adapter (proves the protocol is language-agnostic)
|
||||||
frontends/ client kernel + per-framework adapters
|
frontends/ client kernel + per-framework adapters
|
||||||
mizan-base/ framework-agnostic kernel; owns data, status, error; adapters subscribe
|
mizan-base/ framework-agnostic kernel; owns data, status, error; adapters subscribe
|
||||||
mizan-react/ React contexts + hooks over the kernel
|
mizan-react/ React contexts + hooks over the kernel
|
||||||
mizan-vue/ Vue composables over the kernel
|
mizan-vue/ Vue composables over the kernel
|
||||||
mizan-svelte/ Svelte stores/runes over the kernel
|
mizan-svelte/ Svelte stores/runes over the kernel
|
||||||
cores/ shared language-level primitives (currently empty; mizan-python forthcoming)
|
cores/ shared language-level primitives
|
||||||
|
mizan-python/ @client decorator, registry, MWT, HMAC cache keys; consumed by both Python backends
|
||||||
|
protocol/ protocol-level tooling
|
||||||
|
mizan-generate/ codegen — fetches schema from any backend, emits typed React/Vue/Svelte client
|
||||||
workers/ runtime workers / bridges
|
workers/ runtime workers / bridges
|
||||||
mizan-ssr/ Bun subprocess used by the Django template backend
|
mizan-ssr/ Bun subprocess used by the Django template backend
|
||||||
```
|
```
|
||||||
@@ -442,7 +446,7 @@ urlpatterns = [
|
|||||||
|
|
||||||
## Codegen — Current State
|
## Codegen — Current State
|
||||||
|
|
||||||
The codegen is two-stage and per-framework. Stage 1 (in `mizan-django/generate/`) emits the framework-agnostic protocol layer (`callXxx` for mutations, `fetchXxx` for context bundles, types). Stage 2 emits per-framework hooks/composables/stores that subscribe to the `mizan-base` kernel.
|
The codegen is `protocol/mizan-generate/` — framework-agnostic, two-stage. Stage 1 emits the protocol layer (`callXxx` for mutations, `fetchXxx` for context bundles, types). Stage 2 emits per-framework hooks/composables/stores that subscribe to the `mizan-base` kernel.
|
||||||
|
|
||||||
**What's in place:**
|
**What's in place:**
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ The kernel stores only `{params, refetch}`. No `data`, `status`, `error`. Every
|
|||||||
## Remaining High
|
## Remaining High
|
||||||
|
|
||||||
### H5. Mutation hooks expose no loading/error state
|
### H5. Mutation hooks expose no loading/error state
|
||||||
**File:** `mizan-django/generate/generator/lib/adapters/react.mjs`
|
**File:** `protocol/mizan-generate/generator/lib/adapters/react.mjs`
|
||||||
Returns bare `useCallback`. No `isPending`, `error`, `isSuccess`.
|
Returns bare `useCallback`. No `isPending`, `error`, `isSuccess`.
|
||||||
|
|
||||||
### H7. Redis SCAN blocks request path at scale
|
### H7. Redis SCAN blocks request path at scale
|
||||||
@@ -38,11 +38,11 @@ Returns bare `useCallback`. No `isPending`, `error`, `isSuccess`.
|
|||||||
Synchronous SCAN at 1M keys: multi-second blocking.
|
Synchronous SCAN at 1M keys: multi-second blocking.
|
||||||
|
|
||||||
### H8. Svelte codegen uses Svelte 4 stores
|
### H8. Svelte codegen uses Svelte 4 stores
|
||||||
**File:** `mizan-django/generate/generator/lib/adapters/svelte.mjs`
|
**File:** `protocol/mizan-generate/generator/lib/adapters/svelte.mjs`
|
||||||
Should use Svelte 5 `$state`/`$derived` runes.
|
Should use Svelte 5 `$state`/`$derived` runes.
|
||||||
|
|
||||||
### H9. Svelte destroy() not auto-called
|
### H9. Svelte destroy() not auto-called
|
||||||
**File:** `mizan-django/generate/generator/lib/adapters/svelte.mjs`
|
**File:** `protocol/mizan-generate/generator/lib/adapters/svelte.mjs`
|
||||||
Memory leak if user forgets `onDestroy`.
|
Memory leak if user forgets `onDestroy`.
|
||||||
|
|
||||||
### H12. Forms triggerValidation captures stale data
|
### H12. Forms triggerValidation captures stale data
|
||||||
|
|||||||
@@ -144,8 +144,8 @@ Frontend gets `useChatChannel({ room })`.
|
|||||||
|
|
||||||
## Generate the frontend
|
## Generate the frontend
|
||||||
|
|
||||||
The codegen lives in `backends/mizan-django/generate/`. From your frontend
|
The codegen is `mizan-generate` (in `protocol/mizan-generate/`). From your
|
||||||
project, point a config at the Django backend and run the CLI:
|
frontend project, point a config at the Django backend and run the CLI:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// frontend/django.config.mjs
|
// frontend/django.config.mjs
|
||||||
@@ -171,7 +171,7 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node path/to/mizan-django/generate/generator/cli.mjs --config django.config.mjs
|
npx mizan-generate --config django.config.mjs
|
||||||
```
|
```
|
||||||
|
|
||||||
The codegen drives Django's management command (`export_mizan_schema`) under
|
The codegen drives Django's management command (`export_mizan_schema`) under
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "generate",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"type": "commonjs",
|
|
||||||
"dependencies": {
|
|
||||||
"openapi-typescript": "^7.13.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -108,9 +108,8 @@ anonymous request. The executor branches on those for `auth=True`,
|
|||||||
|
|
||||||
## Generate the frontend
|
## Generate the frontend
|
||||||
|
|
||||||
The codegen lives in `backends/mizan-django/generate/` (the codegen package
|
The codegen is `mizan-generate` (in `protocol/mizan-generate/`). Point a
|
||||||
is framework-agnostic; the directory name is historical). Point a config at
|
config at your FastAPI app and run the CLI:
|
||||||
your FastAPI app and run the CLI:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// frontend/fastapi.config.mjs
|
// frontend/fastapi.config.mjs
|
||||||
@@ -133,7 +132,7 @@ export default {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node path/to/mizan-django/generate/generator/cli.mjs --config fastapi.config.mjs
|
npx mizan-generate --config fastapi.config.mjs
|
||||||
```
|
```
|
||||||
|
|
||||||
The codegen drives `python -m mizan_fastapi.cli <module>` under the hood,
|
The codegen drives `python -m mizan_fastapi.cli <module>` under the hood,
|
||||||
|
|||||||
@@ -10,13 +10,17 @@ Tree organized by role.
|
|||||||
```
|
```
|
||||||
backends/ server protocol adapters
|
backends/ server protocol adapters
|
||||||
mizan-django/ Django adapter
|
mizan-django/ Django adapter
|
||||||
|
mizan-fastapi/ FastAPI adapter (AFI-common scope)
|
||||||
mizan-ts/ TypeScript adapter (proves the protocol is language-agnostic)
|
mizan-ts/ TypeScript adapter (proves the protocol is language-agnostic)
|
||||||
frontends/ client kernel + per-framework adapters
|
frontends/ client kernel + per-framework adapters
|
||||||
mizan-base/ framework-agnostic kernel; owns data, status, error; adapters subscribe
|
mizan-base/ framework-agnostic kernel; owns data, status, error; adapters subscribe
|
||||||
mizan-react/ React contexts + hooks over the kernel
|
mizan-react/ React contexts + hooks over the kernel
|
||||||
mizan-vue/ Vue composables over the kernel
|
mizan-vue/ Vue composables over the kernel
|
||||||
mizan-svelte/ Svelte stores/runes over the kernel
|
mizan-svelte/ Svelte stores/runes over the kernel
|
||||||
cores/ shared language-level primitives (mizan-python forthcoming)
|
cores/ shared language-level primitives
|
||||||
|
mizan-python/ @client decorator, registry, MWT, HMAC cache keys
|
||||||
|
protocol/ protocol-level tooling
|
||||||
|
mizan-generate/ codegen — schema in, typed client out
|
||||||
workers/ runtime workers / bridges
|
workers/ runtime workers / bridges
|
||||||
mizan-ssr/ Bun subprocess used by the Django template backend
|
mizan-ssr/ Bun subprocess used by the Django template backend
|
||||||
```
|
```
|
||||||
|
|||||||
14
protocol/mizan-generate/package.json
Normal file
14
protocol/mizan-generate/package.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "mizan-generate",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Mizan codegen — fetches the schema from any backend adapter and emits typed React/Vue/Svelte client code on top of the runtime kernel.",
|
||||||
|
"type": "module",
|
||||||
|
"bin": {
|
||||||
|
"mizan-generate": "./generator/cli.mjs"
|
||||||
|
},
|
||||||
|
"main": "./generator/cli.mjs",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"openapi-typescript": "^7.13.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user