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:
2026-05-10 00:16:11 -04:00
parent f0f7a93ed2
commit cc887fb1f6
16 changed files with 34 additions and 29 deletions

View File

@@ -15,13 +15,17 @@ Tree organized by role. Per-framework adapters wrap a single shared kernel; code
```
backends/ server protocol adapters
mizan-django/ Django adapter
mizan-fastapi/ FastAPI adapter (RPC + context + invalidation; AFI-common scope)
mizan-ts/ TypeScript adapter (proves the protocol is language-agnostic)
frontends/ client kernel + per-framework adapters
mizan-base/ framework-agnostic kernel; owns data, status, error; adapters subscribe
mizan-react/ React contexts + hooks over the kernel
mizan-vue/ Vue composables 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
mizan-ssr/ Bun subprocess used by the Django template backend
```
@@ -442,7 +446,7 @@ urlpatterns = [
## 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:**

View File

@@ -30,7 +30,7 @@ The kernel stores only `{params, refetch}`. No `data`, `status`, `error`. Every
## Remaining High
### 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`.
### 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.
### 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.
### 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`.
### H12. Forms triggerValidation captures stale data

View File

@@ -144,8 +144,8 @@ Frontend gets `useChatChannel({ room })`.
## Generate the frontend
The codegen lives in `backends/mizan-django/generate/`. From your frontend
project, point a config at the Django backend and run the CLI:
The codegen is `mizan-generate` (in `protocol/mizan-generate/`). From your
frontend project, point a config at the Django backend and run the CLI:
```js
// frontend/django.config.mjs
@@ -171,7 +171,7 @@ export default {
```
```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

View File

@@ -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"
}
}

View File

@@ -108,9 +108,8 @@ anonymous request. The executor branches on those for `auth=True`,
## Generate the frontend
The codegen lives in `backends/mizan-django/generate/` (the codegen package
is framework-agnostic; the directory name is historical). Point a config at
your FastAPI app and run the CLI:
The codegen is `mizan-generate` (in `protocol/mizan-generate/`). Point a
config at your FastAPI app and run the CLI:
```js
// frontend/fastapi.config.mjs
@@ -133,7 +132,7 @@ export default {
```
```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,

View File

@@ -10,13 +10,17 @@ Tree organized by role.
```
backends/ server protocol adapters
mizan-django/ Django adapter
mizan-fastapi/ FastAPI adapter (AFI-common scope)
mizan-ts/ TypeScript adapter (proves the protocol is language-agnostic)
frontends/ client kernel + per-framework adapters
mizan-base/ framework-agnostic kernel; owns data, status, error; adapters subscribe
mizan-react/ React contexts + hooks over the kernel
mizan-vue/ Vue composables 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
mizan-ssr/ Bun subprocess used by the Django template backend
```

View 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"
}
}