Example App
apps/example-api is the reference application in this repository.
It demonstrates how Semitra’s subsystems fit together in one Worker app.
Top-level structure
Section titled “Top-level structure”apps/example-api/ app/ channels/ controllers/ jobs/ mailboxes/ mailers/ models/ policies/ resources/ config/ application.ts routes.ts db/ migrate/ schema.ts src/ index.tsWhat to read first
Section titled “What to read first”If you are reading the example app for orientation, start in this order:
config/routes.tsapp/controllers/application_controller.tsapp/controllers/api/v1/posts_controller.tsapp/models/application_record.tsapp/models/post.tsapp/resources/post_resource.tsapp/policies/post_policy.ts
That path mirrors Semitra’s request flow.
Important patterns shown by the example
Section titled “Important patterns shown by the example”- current-user hydration through a shared application controller
- tenant resolution through headers and subdomains
- record schemas defined with
s.object(...) - policy guards enforced at the controller level
- resource-based serialization
- job execution that delegates to a mailer
- channel broadcasting with validated messages
Representative snippets from the repo:
resolver: composeTenantResolvers( headerTenantResolver(), subdomainTenantResolver())
// app/controllers/api/v1/posts_controller.tsawait this.authorize(post, "show");return this.renderResource(post);
// app/resources/post_resource.tsthis.attribute("excerpt", (post) => typeof post.content === "string" ? post.content.slice(0, 32) : null);A concrete request walkthrough
Section titled “A concrete request walkthrough”For POST /api/v1/posts:
- the route resolves to
api/v1/posts#create - the controller validates the
postpayload - the controller authorizes against
PostPolicy this.model(Post)binds the record class to the request runtime- the record validates and persists through D1
- the controller renders
PostResource - the client receives serialized JSON
The same pattern shows up in the non-HTTP subsystems too:
WelcomeEmailJobvalidates its payload and delegates delivery to a mailerNotificationsChannelvalidates incoming messages and broadcasts to a room
Why this app matters
Section titled “Why this app matters”Semitra is still best understood by reading live framework code and a live app together. This example is the reference implementation for the current repo, so it is the right place to verify how the docs map to reality.