Restructure tree by role; rename mizan-runtime → mizan-base
packages/ flattens into: backends/ server protocol adapters (mizan-django, mizan-ts) frontends/ client kernel + framework adapters (mizan-base, mizan-react, mizan-vue, mizan-svelte) workers/ runtime workers (mizan-ssr) cores/ shared language-level primitives (empty for now; mizan-python forthcoming) The frontend kernel (was packages/mizan-runtime, now frontends/mizan-base) is renamed to reflect its role — it's the shared base that frontend adapters depend on directly. Reflects the substrate position that per-framework adapters wrap a single shared kernel; codegen targets the adapter, not the raw kernel. Path updates landed in: Makefile, two Gitea workflows, Dockerfile.test, four example/harness config files, .claude/settings.local.json, four docs (CLAUDE/ISSUES/ROADMAP/AFI_ARCHITECTURE), four codegen templates (stage1 + react/vue/svelte adapters), and three package.jsons (the mizan-base rename plus mizan-vue/svelte peerDeps). Generated files under examples/django-react-site/harness/src/api/ still reference @mizan/runtime — left as-is; they're regenerated artifacts and the harness is non-functional pending the React wrapper-layer codegen. Also folded in a pre-existing fix: the Gitea workflows had working-directory: react / django pointing at a layout that predates packages/, never updated. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
105
backends/mizan-django/README.md
Normal file
105
backends/mizan-django/README.md
Normal file
@@ -0,0 +1,105 @@
|
||||
# mizan (Python)
|
||||
|
||||
Django server functions framework. See the [monorepo root](../README.md) for full documentation.
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
uv add "mizan[channels,allauth] @ git+https://git.impactsoundworks.com/isw/mizan.git#subdirectory=django"
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
```python
|
||||
# settings.py
|
||||
INSTALLED_APPS = ["mizan", ...]
|
||||
|
||||
# urls.py
|
||||
path("api/mizan/", include("mizan.urls"))
|
||||
|
||||
# asgi.py (optional, for WebSocket)
|
||||
from mizan import wrap_asgi
|
||||
application = wrap_asgi(get_asgi_application())
|
||||
```
|
||||
|
||||
## Define Functions
|
||||
|
||||
```python
|
||||
from mizan.client import client
|
||||
from mizan.setup.registry import register
|
||||
from pydantic import BaseModel
|
||||
|
||||
class Output(BaseModel):
|
||||
message: str
|
||||
|
||||
@client
|
||||
def echo(request, text: str) -> Output:
|
||||
return Output(message=text)
|
||||
|
||||
register(echo, "echo")
|
||||
```
|
||||
|
||||
Register in `apps.py`:
|
||||
|
||||
```python
|
||||
def ready(self):
|
||||
import myapp.mizan_clients
|
||||
```
|
||||
|
||||
## Auth
|
||||
|
||||
```python
|
||||
@client(auth=True) # requires authentication
|
||||
@client(auth='staff') # requires is_staff
|
||||
@client(auth='superuser') # requires is_superuser
|
||||
@client(auth=my_callable) # custom check
|
||||
```
|
||||
|
||||
## Contexts
|
||||
|
||||
```python
|
||||
@client(context='global') # fetched once, SSR-hydrated, becomes useCurrentUser()
|
||||
@client(context='local') # fetched with params, becomes <GreetProvider>
|
||||
```
|
||||
|
||||
## Forms
|
||||
|
||||
```python
|
||||
from mizan.forms import mizanFormMixin, mizanFormMeta
|
||||
|
||||
class ContactForm(mizanFormMixin, forms.Form):
|
||||
mizan = mizanFormMeta(name="contact", title="Contact Us")
|
||||
name = forms.CharField()
|
||||
email = forms.EmailField()
|
||||
|
||||
def on_submit_success(self, request):
|
||||
return {"sent": True}
|
||||
```
|
||||
|
||||
Auto-registers `contact.schema`, `contact.validate`, `contact.submit`. Generates `useContactForm()` with Zod validation.
|
||||
|
||||
## Channels
|
||||
|
||||
```python
|
||||
from mizan.channels import ReactChannel
|
||||
|
||||
class ChatChannel(ReactChannel):
|
||||
class Params(BaseModel):
|
||||
room: str
|
||||
class DjangoMessage(BaseModel):
|
||||
text: str
|
||||
|
||||
def authorize(self, params):
|
||||
return self.user.is_authenticated
|
||||
def group(self, params):
|
||||
return f"chat_{params.room}"
|
||||
```
|
||||
|
||||
Generates `useChatChannel({ room })`.
|
||||
|
||||
## Running Tests
|
||||
|
||||
```bash
|
||||
uv sync --extra dev --extra channels
|
||||
uv run pytest
|
||||
```
|
||||
Reference in New Issue
Block a user