Skip to content

Commit e9410ec

Browse files
fsecada01claude
andcommitted
docs: update documentation for v0.4.0b0 release
- README: version badge, adapter table (Litestar now supported), install instructions, features section (async, SSE, state guard), architecture diagram, project structure, roadmap, requirements, known limitations - CLAUDE.md: version, architecture tree, 0.4.0 features, Litestar deps - docs/index.html: version badge - docs/server_component_spec.md: async_dispatch, SSE streaming section, project structure, future enhancements, summary Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a00089b commit e9410ec

4 files changed

Lines changed: 107 additions & 23 deletions

File tree

CLAUDE.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ This file provides context for AI assistants working on this project.
44

55
## Project Overview
66

7-
**Component Framework** is a Python library for building server-side components with LiveView-style interactivity. It provides a framework-agnostic core with adapters for FastAPI and Django.
7+
**Component Framework** is a Python library for building server-side components with LiveView-style interactivity. It provides a framework-agnostic core with adapters for FastAPI, Django, and Litestar.
88

9-
**Status:** Beta (0.3.0-beta)
9+
**Status:** Beta (0.4.0-beta)
1010
**Language:** Python 3.11+
1111
**License:** MIT
1212

@@ -25,8 +25,9 @@ This file provides context for AI assistants working on this project.
2525
```
2626
component_framework/
2727
├── core/ # Framework-agnostic
28-
│ ├── component.py # Base Component class
28+
│ ├── component.py # Base Component + async_dispatch
2929
│ ├── form.py # Form validation (Pydantic)
30+
│ ├── streaming.py # StreamingComponent + SSE support
3031
│ ├── websocket.py # WebSocket manager
3132
│ ├── registry.py # Component registration
3233
│ ├── renderer.py # Renderer interface
@@ -35,7 +36,10 @@ component_framework/
3536
│ └── composition.py # Slot + composite components (Beta)
3637
3738
├── adapters/ # Framework-specific
38-
│ ├── fastapi.py
39+
│ ├── fastapi.py # FastAPI HTTP + SSE
40+
│ ├── fastapi_websocket.py
41+
│ ├── litestar.py # Litestar HTTP + SSE
42+
│ ├── litestar_websocket.py
3943
│ ├── django_*.py
4044
│ ├── django_permissions.py # FBV decorators (Beta)
4145
│ ├── django_ratelimit.py # RateLimitMixin (Beta)
@@ -166,6 +170,14 @@ All Beta roadmap items are implemented and test-covered:
166170
- Testing utilities (`ComponentTestCase`, `dispatch_event`, `assert_state`)
167171
- Versioned API docs via pdoc + GitHub Pages
168172

173+
## 0.4.0 Features
174+
175+
- Litestar adapter (`[litestar]` extra) — HTTP, WebSocket, SSE
176+
- Async event handlers (`async_dispatch()` / `async_handle_event()`)
177+
- SSE streaming (`StreamingComponent` with async generator handlers)
178+
- State size guard (configurable warning at 64 KB, hard limit at 512 KB)
179+
- JS double-serialisation fix in `component-client.js`
180+
169181
## Future Enhancements (1.0)
170182

171183
- Stable, frozen public API
@@ -185,6 +197,10 @@ All Beta roadmap items are implemented and test-covered:
185197
- uvicorn (server)
186198
- jinjax >= 0.41 (rendering)
187199

200+
### Litestar
201+
- litestar >= 2.0
202+
- jinja2 >= 3.1
203+
188204
### Django
189205
- django >= 4.2
190206
- channels >= 4.0 (WebSocket)

README.md

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Framework-agnostic server components with LiveView-style interactivity inspired
1414

1515
## Development Status
1616

17-
**Current Version:** 0.3.0-beta
17+
**Current Version:** 0.4.0-beta
1818
**API Documentation:** [fsecada01.github.io/component-framework](https://fsecada01.github.io/component-framework/)
1919

2020
The framework has a complete, tested feature set covering the full Beta roadmap. APIs are solidifying — the core lifecycle, permissions, composition, and testing utilities are stable. We welcome feedback before the 1.0 release.
@@ -27,8 +27,8 @@ The framework has a complete, tested feature set covering the full Beta roadmap.
2727
|-----------|--------|---------------|-------|
2828
| **FastAPI** | ✅ Supported | `[fastapi]` | Includes JinjaX renderer and WebSocket adapter |
2929
| **Django** | ✅ Supported | `[django]` | Includes Channels, Cotton, and template renderer |
30+
| **Litestar** | ✅ Supported | `[litestar]` | HTTP + WebSocket adapters (0.4.0+) |
3031
| **Flask** | 🗓 Planned || [Tracking issue #5](https://github.com/fsecada01/component-framework/issues/5) |
31-
| **Litestar** | 🗓 Planned || [Tracking issue #6](https://github.com/fsecada01/component-framework/issues/6) |
3232

3333
---
3434

@@ -43,8 +43,11 @@ pip install "component-framework[django]"
4343
# FastAPI projects
4444
pip install "component-framework[fastapi]"
4545

46-
# Both adapters
47-
pip install "component-framework[fastapi,django]"
46+
# Litestar projects
47+
pip install "component-framework[litestar]"
48+
49+
# Multiple adapters
50+
pip install "component-framework[fastapi,django,litestar]"
4851

4952
# Everything
5053
pip install "component-framework[all]"
@@ -77,11 +80,14 @@ See [CHANGELOG.md](CHANGELOG.md) for the full list of changes.
7780
## Features
7881

7982
### Core
80-
- **Framework-agnostic** — Works with FastAPI, Django, and more
83+
- **Framework-agnostic** — Works with FastAPI, Django, Litestar, and more
8184
- **Server-driven UI** — State lives on the server, not the client
8285
- **Minimal JavaScript** — HTMX handles frontend interactions
8386
- **Reusable components** — Clean OOP boundaries with lifecycle hooks
8487
- **Pluggable renderers** — Jinjax, Django templates, or your own
88+
- **Async event handlers**`async def on_*` handlers properly awaited via `async_dispatch()`
89+
- **SSE streaming**`StreamingComponent` for long-running operations with intermediate renders
90+
- **State size guard** — Configurable warning (64 KB) and hard limit (512 KB) on serialised state
8591

8692
### Forms & Validation
8793
- **Pydantic validation** — Type-safe form handling
@@ -118,9 +124,11 @@ See [CHANGELOG.md](CHANGELOG.md) for the full list of changes.
118124

119125
### Real-Time Updates
120126
- **WebSocket support** — Real-time component updates
127+
- **SSE streaming**`StreamingComponent` with async generator handlers for progressive rendering
121128
- **Broadcasting** — Multi-client synchronisation
122129
- **Django Channels** — Full Channels integration
123130
- **FastAPI WebSocket** — Native FastAPI support
131+
- **Litestar WebSocket** — Native Litestar support
124132

125133
### Caching
126134
- **`CacheMixin`** — Configurable per-component render caching
@@ -290,14 +298,15 @@ class TestCounter(ComponentTestCase):
290298
## Architecture
291299

292300
```
293-
Browser (HTMX/WebSocket)
301+
Browser (HTMX/WebSocket/SSE)
294302
|
295-
Framework Adapter (FastAPI / Django)
303+
Framework Adapter (FastAPI / Django / Litestar)
296304
|
297305
Component Framework Core
298306
- Component lifecycle (mount → hydrate → handle_event → render → dehydrate)
299-
- Event routing (convention-based on_<event> handlers)
300-
- State management (server-owned JSON state)
307+
- Event routing (convention-based on_<event> handlers, sync + async)
308+
- State management (server-owned JSON state with size guards)
309+
- Streaming (StreamingComponent for SSE progressive rendering)
301310
- Permissions (per-component permission_classes)
302311
- Composition (SlotComponent, CompositeComponent)
303312
|
@@ -318,6 +327,7 @@ component-framework/
318327
│ │ ├── registry.py # Component registration
319328
│ │ ├── renderer.py # Renderer interface
320329
│ │ ├── state.py # State storage
330+
│ │ ├── streaming.py # StreamingComponent + SSE support
321331
│ │ ├── permissions.py # Permission classes (Beta)
322332
│ │ └── composition.py # Slot + composite components (Beta)
323333
│ │
@@ -330,24 +340,31 @@ component-framework/
330340
│ │ ├── django_websocket.py # Django Channels
331341
│ │ ├── django_permissions.py # FBV permission decorators (Beta)
332342
│ │ ├── django_ratelimit.py # Rate limiting mixin (Beta)
333-
│ │ └── jinjax_renderer.py # Jinjax rendering
343+
│ │ ├── jinjax_renderer.py # Jinjax rendering
344+
│ │ ├── litestar.py # Litestar HTTP + SSE adapter
345+
│ │ └── litestar_websocket.py # Litestar WebSocket adapter
334346
│ │
335347
│ ├── testing.py # ComponentTestCase + fixtures (Beta)
336348
│ ├── components/ # Example components
337349
│ └── templatetags/components.py # Django template tags
338350
339351
├── examples/
340352
│ ├── fastapi_example.py # FastAPI demo
353+
│ ├── litestar_example.py # Litestar demo
341354
│ └── django_example/ # Complete Django app
342355
343-
├── tests/ # 20 test modules
344-
│ ├── test_component.py # Core component tests
356+
├── tests/ # 23 test modules, 404 tests
357+
│ ├── test_component.py # Core component + async dispatch tests
345358
│ ├── test_form.py # Form validation tests
346359
│ ├── test_registry.py # Registry tests
347360
│ ├── test_state.py # State storage tests
361+
│ ├── test_streaming.py # StreamingComponent + SSE tests
348362
│ ├── test_websocket.py # WebSocket manager tests
349363
│ ├── test_fastapi_adapter.py # FastAPI adapter tests
364+
│ ├── test_fastapi_sse.py # FastAPI SSE endpoint tests
350365
│ ├── test_fastapi_websocket.py # FastAPI WebSocket tests
366+
│ ├── test_litestar_adapter.py # Litestar adapter tests
367+
│ ├── test_litestar_sse.py # Litestar SSE endpoint tests
351368
│ ├── test_django_views.py # Django views tests
352369
│ ├── test_django_model.py # Django model binding tests
353370
│ ├── test_django_renderer.py # Django renderer tests
@@ -490,6 +507,13 @@ just claude-prompt PROMPT_FILE=prompts/WORKFLOW.md
490507
- [x] Versioned API documentation (GitHub Pages + pdoc)
491508
- [x] Optional extras — FastAPI/Uvicorn/JinjaX no longer mandatory (`[fastapi]`, `[django]`, `[all]`)
492509

510+
### 0.4.0 (Complete)
511+
- [x] Litestar adapter — HTTP, WebSocket, SSE (`[litestar]` extra)
512+
- [x] Async event handlers — `async_dispatch()` / `async_handle_event()`
513+
- [x] SSE streaming — `StreamingComponent` with async generator handlers
514+
- [x] State size guard — configurable warning (64 KB) and hard limit (512 KB)
515+
- [x] JS double-serialisation fix in `component-client.js`
516+
493517
### 1.0 (Planned)
494518
- [ ] Stable, frozen public API
495519
- [ ] Performance benchmarks and optimisation
@@ -517,6 +541,7 @@ Current benchmarks (local development):
517541
Optional extras:
518542
- `[fastapi]` — FastAPI 0.109+, Uvicorn, JinjaX 0.41+
519543
- `[django]` — Django 4.2+, Django Channels 4.0+, channels-redis 4.1+, django-cotton 0.9+
544+
- `[litestar]` — Litestar 2.0+, Jinja2 3.1+
520545
- `[websockets]` — websockets 12.0+
521546
- `[all]` — all of the above
522547

@@ -527,7 +552,7 @@ Optional extras:
527552
- State must be JSON-serialisable
528553
- WebSocket scaling requires a Redis channel layer
529554
- CSRF handling for WebSockets is manual
530-
- State size limits not enforced (keep state minimal)
555+
- SSE streaming requires ASGI deployment (Django) or any async framework (FastAPI/Litestar)
531556

532557
---
533558

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@
491491
<!-- topbar -->
492492
<header class="topbar">
493493
<a href="index.html" class="topbar__logo">component-framework</a>
494-
<span class="topbar__badge">BETA 0.3.0</span>
494+
<span class="topbar__badge">BETA 0.4.0</span>
495495
<nav aria-label="Top navigation">
496496
<ul class="topbar__links">
497497
<li><a href="index.html">Docs</a></li>

docs/server_component_spec.md

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class Component:
165165
# ---------- Dispatch ----------
166166

167167
def dispatch(self, event=None, payload=None, state=None):
168-
168+
"""Synchronous dispatch — use for sync handlers only."""
169169
if state:
170170
self.hydrate(state)
171171
else:
@@ -176,6 +176,23 @@ class Component:
176176

177177
html = self.render()
178178

179+
return {
180+
"html": html,
181+
"state": self.dehydrate(),
182+
}
183+
184+
async def async_dispatch(self, event=None, payload=None, state=None):
185+
"""Async dispatch — supports both sync and async on_* handlers."""
186+
if state:
187+
self.hydrate(state)
188+
else:
189+
self.mount()
190+
191+
if event:
192+
await self.async_handle_event(event, payload or {})
193+
194+
html = self.render()
195+
179196
return {
180197
"html": html,
181198
"state": self.dehydrate(),
@@ -490,6 +507,30 @@ Model updated →
490507
HTMX swap
491508
```
492509

510+
## SSE Streaming (0.4.0+)
511+
512+
`StreamingComponent` enables long-running operations that emit intermediate renders:
513+
514+
```python
515+
from component_framework.core.streaming import StreamingComponent
516+
517+
@registry.register("rag_query")
518+
class RagQueryComponent(StreamingComponent):
519+
template_name = "rag_query.html"
520+
521+
async def on_analyze(self, query: str):
522+
async for step in rag_service.stream(query):
523+
self.state["step"] = step
524+
yield # emit SSE frame with current render
525+
self.state["done"] = True
526+
```
527+
528+
Each `yield` triggers `render()` and emits a `data:` SSE frame. The final frame
529+
includes `"stream_done": true`. Non-generator handlers produce a single frame,
530+
making the streaming endpoint backward-compatible.
531+
532+
Adapter endpoints: `POST /components/{name}/stream` (FastAPI, Litestar).
533+
493534
---
494535

495536
# Suggested Project Structure
@@ -500,11 +541,13 @@ core/
500541
renderer.py
501542
registry.py
502543
state.py
544+
streaming.py
503545
model.py
504546
505547
adapters/
506548
fastapi.py
507549
litestar.py
550+
litestar_websocket.py
508551
django.py
509552
jinjax.py
510553
@@ -539,12 +582,9 @@ No HTTP required.
539582

540583
- Automatic form generation from model metadata
541584
- DOM morphing integration
542-
- WebSocket adapter layer
543585
- Component diffing
544586
- Devtools inspector
545-
- Permission system
546587
- Dependency injection
547-
- Optimistic UI engine
548588

549589
---
550590

@@ -555,7 +595,10 @@ This architecture provides:
555595
- LiveView-like server interactivity
556596
- Minimal JavaScript
557597
- Framework independence
558-
- Django and FastAPI compatibility
598+
- Django, FastAPI, and Litestar compatibility
599+
- Async event handler support
600+
- SSE streaming for long-running operations
601+
- State size guards
559602
- Clean OOP boundaries
560603
- Extensible rendering system
561604

0 commit comments

Comments
 (0)