Fullstack Meta-Framework (ob:router)¶
Starting in Orbita v0.2.0, ob:router brings a complete, zero-boilerplate fullstack web architecture combining the best ideas from Django (modular apps), Angular/Vue (clean .tyl + .html + .css separation with @if/@for), Laravel (fluent ctx & validation), and Rails (CLI generators & conventions).
Quickstart¶
Scaffold a ready-to-run fullstack web app in one command:
This creates the canonical Orbita web layout:
my-web-app/
├── ob.toml # Build manifest, scripts, dependencies, [embed]
├── config.toml # Runtime config ([server], [database]) — deploy-friendly!
├── .gitignore
├── public/ # Static files served at /public/*
│ └── styles.css
├── storage/ # Local SQLite database (app.db)
└── src/
├── main.tyl # App entrypoint
└── apps/
└── home/
└── routes/
├── _layout.tyl / _layout.html
├── _404.html
└── index.tyl / index.html
Fluent Router API¶
-- src/main.tyl
local http = require("ob:http")
local router = require("ob:router")
local app = router.new()
:static("/public", "public")
:use(router.security_headers())
:use(router.rate_limit({ max = 20, window_secs = 60, path_prefix = "/auth" }))
:use(router.csrf())
:mount("/auth", "src/apps/auth/routes")
:mount("/", "src/apps/tasks/routes")
:get("/health", function(ctx)
return ctx:json({ status = "ok", version = ob.version })
end)
http.serve(app:handler()) -- reads [server] from config.toml + $HOST/$PORT
Paired .tyl + .html + .css Templates¶
ob:router automatically pairs files sharing the same base name (index.tyl + index.html + index.css):
-- src/apps/tasks/routes/index.tyl
local Tasks = require("apps/tasks/model")
local TaskCard = require("apps/tasks/components/task_card/task_card")
return {
components = { TaskCard = TaskCard },
load = function(ctx)
return {
heading = "Inbox",
tasks = Tasks:select():order_by("id", "desc"):all(),
}
end,
action = function(ctx)
local data, errs = ctx:validate({
title = "required|min:3|max:120",
priority = "in:low,medium,high",
})
if errs then
return { errors = errs }
end
Tasks:create({ title = data.title, priority = data.priority or "medium" })
ctx:flash("success", "Task created!")
return ctx:redirect("/", 303)
end,
}
<!-- src/apps/tasks/routes/index.html -->
<h1>{{ heading }}</h1>
@if (errors and errors.title) {
<div class="error">{{ errors.title }}</div>
}
@for (task in tasks) {
<TaskCard :task="task" />
} @empty {
<p>No tasks yet.</p>
}
Template Syntax Reference¶
| Syntax | Purpose |
|---|---|
{{ expr }} |
HTML-escaped interpolation (XSS-safe) |
{{{ expr }}} |
Raw unescaped HTML interpolation |
@if (cond) { ... } @else if (...) { ... } @else { ... } |
Conditional blocks |
@for (item in list) { ... } @empty { ... } |
Loops with built-in empty fallback |
:attr="expr" / href="{{ url }}" |
Dynamic attributes (omits false/nil, supports booleans & objects) |
@click="action" / @submit.prevent="save" |
Declarative event bindings (data-ob-on-*) |
<slot /> |
Injects child page content inside _layout.html |
<MyComp :prop="val" /> |
Renders reusable components |
Request Context (ctx) & Built-In Security¶
Every middleware, loader, action, and route handler shares the same ctx table:
- Input:
ctx.params,ctx.query(URL-decoded),ctx.headers,ctx.cookies,ctx.remote_addr,ctx:form(),ctx:json_body(),ctx:files()(multipart/form-data). - Validation:
local data, errs = ctx:validate({ email = "required|email", password = "required|min:6" }). - Responses:
ctx:html(...),ctx:json(data, status?),ctx:redirect(url, status?),ctx:text(...),ctx:not_found(),ctx:status(code). - Cookies & Flash:
ctx:set_cookie(name, val, opts?),ctx:clear_cookie(name),ctx:flash("success", "Saved!")(auto-exposed asflashin.htmltemplates). - Security Middlewares:
router.security_headers({ csp?, hsts?, frame_options? })router.csrf()(double-submit cookie +csrf_tokenin templates)router.rate_limit({ max, window_secs, path_prefix? })router.cors({ origin, methods?, headers?, credentials? })- Production Errors: Set
APP_ENV=productionto log real errors on the server while hiding stack traces from clients.
CLI Generators & Browser Live Reload¶
ob g app billing # Creates src/apps/billing/
ob g route billing/invoices/[id] # Creates .tyl + .html paired route
ob g component billing/badge # Creates .tyl + .html + .css component
ob g migration create_invoices # Creates migrations/001_create_invoices.sql
When running with --watch, Orbita restarts the HTTP server on save and automatically reloads open browser tabs via /__orbita/client.js.