Skip to content

Tutorial — Part 1: Project & Routing

In this 5-part tutorial, we will build a complete Mini Blog with Orbita. In Part 1, you will scaffold the project, configure runtime settings, and learn how ob:router maps files and modular apps to URLs.


1. Scaffold the Project & Apps

ob init mini-blog --web
cd mini-blog

ob g app posts
ob g app auth

This creates two self-contained Django-style apps under src/apps/posts/ and src/apps/auth/.

2. Configure config.toml

Runtime settings live in config.toml (separate from ob.toml), and can always be overridden in production with HOST, PORT, and ORBITA_DB:

[server]
host = "127.0.0.1"
port = 3000

[database]
path = "storage/blog.db"

3. Understand File-Based Routing (ob:router)

When you mount a directory with :mount(prefix, dir), Orbita maps files inside routes/ directly to URL patterns — both from disk (ob run) and inside compiled binaries (ob build --compile):

File inside routes/ URL Pattern Purpose
index.tyl + index.html / Home page
about.tyl + about.html /about Static page
posts/[id].tyl + [id].html /posts/:id Dynamic parameter (ctx.params.id)
docs/[...slug].tyl /docs/*slug Catch-all parameter (ctx.params.slug)
_layout.tyl + _layout.html (wrapper) Shared layout for this directory and subdirectories
_404.html / _error.html (error) Custom 404 and 500 pages

4. Wire src/main.tyl

Open src/main.tyl and mount static assets, security middlewares, and both apps:

local http = require("ob:http")
local router = require("ob:router")

local app = router.new()
    :static("/public", "public")
    :use(router.security_headers())
    :use(router.csrf())
    :mount("/auth", "src/apps/auth/routes")
    :mount("/", "src/apps/posts/routes")

-- Reads [server] from config.toml or HOST/PORT env vars automatically
http.serve(app:handler())

You can also mix explicit fluent routes (like health checks or JSON APIs) on the same router:

app:get("/api/health", function(ctx)
    return ctx:json({ ok = true, app = "mini-blog" })
end)

5. Run with Live Reload

ob run --watch --allow-net --allow-read=. --allow-write=storage src/main.tyl

Visit http://127.0.0.1:3000 and http://127.0.0.1:3000/api/health. Whenever you edit a .tyl, .html, or .css file, Orbita restarts the server cleanly and reloads the browser automatically.


Next: Part 2: Database, Migrations & Models →