AI-assisted development
Stario works well with agents when the repo has one obvious shape: a small bootstrap, explicit routes, feature folders, pure views, and one local instruction file. This how-to is the shortest path from an empty folder to a Stario app an agent can extend without guessing.
1. Create the project
uv init --app my-appcd my-appuv add "stario>=4,<5"uv add --dev ruff pyright pytest pytest-asynciocurl -o AGENTS.md https://stario.dev/AGENTS.mdThat AGENTS.md file is the important part. It contains the commands, project layout, Stario invariants, Datastar guidance, and common mistakes. In many editors, that one file is enough agent context.
If your tool wants web context too, point it at llms.txt for a short doc index or llms-full.txt for compact framework notes.
2. Start with the product shape
Use the layout in AGENTS.md from the first commit. Do not start with a flat root-level main.py, routes.py, and handlers.py and plan to split later.
The fastest path is to copy examples/chat-room, rename the features, and delete what you do not need. It shows the structure Stario apps should grow into:
app/main.pyis the composition root.app/common/holds shared shell, markup, identity, and helpers.app/features/<name>/urls.pyownsUrlPathconstants.app/features/<name>/handlers.pyowns handler factories andregister_<feature>(app, ...).app/features/<name>/views.pyturns data into HTML.Optional
data.py,models.py,signals.py, andsubjects.pyappear only when the feature needs them.tests/test_<feature>.pyusesTestClientagainst the productionbootstrap.
The single-file examples, Hello world and Realtime tiles, are for learning mechanics. They are not the preferred shape for a new product.
3. Run the app
uv run stario watch app.main:bootstrapOpen http://127.0.0.1:8000. For a one-shot server without reload, run uv run stario serve app.main:bootstrap. If the port is busy, set STARIO_PORT.
4. Use the examples as references
When you ask an agent to build a feature, give it AGENTS.md plus the closest example project:
examples/chat-roomfor the recommended product layout:app/main.py,app/common/,app/features/, SQLite, Relay, Datastar, and tests.examples/tilesfor a single-file walkthrough of Relay, SSE, broad Datastar morphs, and command/query routes.examples/hello-worldfor the smallest handler, markup, and signal shape.
Use chat-room as the reference for project structure. Use tiles and hello-world to understand mechanics before you split them into the product layout.
5. Add realtime only when it helps
Most Stario routes can stay plain HTTP: render a page, receive a form or action, redirect or return a response. Add Datastar when the user experience needs push updates: presence, collaborative state, background progress, live search results, or another server-originated change.
The shape stays simple:
GET /pagerenders the first document.The page opens
GET /subscribewith Datastar.Action routes mutate server state and publish a Relay notification.
The subscribe handler re-reads authoritative state and sends HTML patches with
SSE(w).
Start by morphing the whole page or a large stable fragment on each update. That keeps the code easy to review: server state in, HTML out. Datastar morphs the live DOM, and compression makes repeated markup reasonable for many apps.
Only switch to dedicated target patches after the broad morph is correct and has proved too expensive or too disruptive. A common second step is a stable shell that owns data.signals(...) and data.init(...), plus an inner #feature-live fragment patched with selector=... and mode="outer".
Related
AGENTS.md - copy into every Stario app repo
Structuring larger applications - feature folders,
urls.py, andregister_*The go-to architecture - Datastar, SSE, Relay, and broad morphs
Testing with TestClient - integration tests against
bootstrapexamples/chat-room- runnable reference layout