Skip to main content

The architecture of Strutvane

How one TypeScript framework turns a migration into a secured API and an admin UI, and the few strict rules that keep its packages from turning into spaghetti.

Updated 19 min readMarkdown
The architecture of Strutvane

Most business apps are the same app wearing different clothes.

There's a list of customers, a list of invoices, a list of orders. Each list needs a table in the database, an API, validation, permissions, a "this customer must never see that customer's rows" rule, and a set of admin screens. Then you add the next table and do it all again.

Strutvane is my answer to that repetition. It's an open-source (MIT) TypeScript framework for business (B2B) apps, built around one promise: describe your data once, and get migrations, a secured API, auth and a full admin UI as code you own.

This post is the map. It explains how the pieces fit together, which rules they follow, and why those rules exist. You don't need to have read the other posts in the series; if you've built a web app before, you'll be fine.


The big picture

The whole developer flow fits in a few commands:

npm create strutvane@latest my-app        ← asks questions, then installs, migrates, seeds, commits
cd my-app
npm run dev                               ← API + UI on http://localhost:3000, one port, hot reload

node strut make:migration create_posts_table --seeder
                                          ← writes the migration, the model, a factory and a seeder

The installer, create-strutvane, is live on npm (0.2.0-next.6). node strut is the project's command-line tool. It's a small strut.js file in the app root, so it works the same way in PowerShell, cmd, bash and zsh. (npx strutvane <command> does exactly the same thing.)

You then describe the table in the migration file. A migration is a small, versioned script that changes the database schema:

// database/migrations/2026_11_16_093000_create_posts_table.ts (node strut make:migration create_posts_table --seeder)
import { migration } from '@strutvane/framework/schema'

export default migration({
  up(schema) {
    schema.create('posts', (t) => {
      t.id()
      t.string('title', 200)
      t.slug('slug').from('title')
      t.foreignId('author_id').constrained('users').cascadeOnDelete()
      t.timestamps()
      t.softDeletes()
    })
  },
  down(schema) {
    schema.dropIfExists('posts')
  },
})

Then you run node strut migrate. It applies the migration to the database, and it also replays every migration in memory, in a sandboxed child process with no secrets and no network access. From that replay it writes generated files into .strutvane/: TypeScript types for each table, and a resources.json file that describes every resource (labels, which fields can be searched, sorted and filtered, relations and so on). The secured CRUD API (create, read, update, delete) and the admin screens are driven by that metadata.

Because the types, the SQL and the metadata all come from the same recorded operations, they can't drift apart. Columns live in exactly one place: the migration.

Diagram: a migration file goes through node strut migrate and becomes database tables, typed models, resource metadata, a secured CRUD API, admin screens and seed data One migration file is the source of truth; one command produces everything else.

Models hold behaviour only. Their columns come from the generated types, so a model can be tiny:

// app/models/post.ts: columns come from the generated .strutvane/types/models.d.ts
import { Model } from '@strutvane/framework/database'

export class Post extends Model('posts', { fillable: ['title'] }) {
  author() {
    return this.belongsTo(User, 'author_id')
  }
}

const page = await Post.query().with('author').orderBy('created_at', 'desc').paginate(25)

The repository and package map

Strutvane lives in the GitHub organisation vishwajit-vm, with one repository per role. At the centre is a single package.

@strutvane/framework is the backend and database core. It is one npm package, with one version, and it exposes its internal layers as subpaths (separate entry points of the same package):

  • @strutvane/framework/contracts: shared types and wire protocols. It imports nothing of ours.
  • @strutvane/framework/core: the kernel. That's the container, providers, config, hooks and events.
  • @strutvane/framework/devkit: the toolkit that installers and generators use.
  • @strutvane/framework/console: the CLI behind node strut.

Around those layers sit the framework's own modules: routing, the ORM (the layer that maps tables to TypeScript objects), migrations, the CRUD API, authorization policies, tenancy and logging.

Everything else is an add-on in its own repository. These are live on npm today:

Package What it does Live version
@strutvane/framework backend, database, CLI 0.2.0-next.5
@strutvane/auth sign-in, 2FA, passkeys, tokens, teams, policies 0.2.0-next.5
@strutvane/ui the admin's behaviour 0.2.0-next.3
@strutvane/design-crisp the default look 0.2.0-next.1
@strutvane/design-vivid a colourful look 0.2.0-next.1
@strutvane/redis cache, locks, sessions, rate limits on Redis or Valkey 0.2.0-next.1
@strutvane/health health checks, history and alerts 0.2.0-next.1
@strutvane/social-login "Sign in with Google / Microsoft / GitHub / Apple" 0.2.0-next.0
strutvane the npx strutvane guard 0.2.0-next.0
create-strutvane the installer (npm create strutvane) 0.2.0-next.6

Around the code there are a few more repositories:

  • the hub, which holds the blueprint, the decision records (ADRs) and the RFCs;
  • tooling, which syncs one set of configs and CI workflows into every repo;
  • the docs site;

An app-template repo (the skeleton) and a log viewer are on the roadmap.

Diagram: the framework package with its console, modules, core, devkit and contracts layers, and add-on packages pointing up at it One framework package with internal layers, and add-ons that each live in their own repository.


The dependency rules, and why they exist

A package ecosystem stays healthy only if dependencies flow in one direction. Strutvane writes that direction down and checks it in CI.

Inside the framework:

  • contracts imports nothing of ours;
  • core and devkit import only contracts;
  • console may use contracts, core and devkit;
  • the framework's own modules use contracts and core.

The parts import each other by relative path, never through the package name.

For add-ons:

  • Every add-on depends only on the published @strutvane/framework, as a peer dependency. A peer dependency means "I need this, but the app installs it, not me".
  • Add-ons import the framework only through its subpaths.
  • Add-ons never import each other.

The peer rule is about having exactly one copy of the framework in an app. The kernel's container hands out services by token, and some checks compare classes with instanceof. Both quietly break if two copies of the kernel are loaded side by side. With a peer dependency, the app owns the one copy and every add-on shares it.

Two more rules keep things honest:

  • Committed code depends only on published versions. Local link:, file: and workspace: specs are refused by CI, so a repo never secretly relies on a sibling checkout.
  • Design packages are the one layered case. @strutvane/design-crisp and @strutvane/design-vivid list @strutvane/ui as their peer, because they implement the UI's design contract.

The six allowed connections

If add-ons can't import each other, how do they cooperate? Through exactly six mechanisms, listed in the hub's integration map. The rule is blunt: if a connection isn't on the map, it isn't allowed, and a new connection is added to the map in the same pull request.

  1. Contracts (types). These are shared shapes such as Actor, Problem and QueryFilter, so both sides compile against one definition.
  2. Container tokens. A token is a named slot for a live service behind an interface. For example, auth provides PermissionProvider and the framework calls it on every request. Each token has a documented fallback. With no permission provider, the app refuses to boot outside local development unless you explicitly declare a public API.
  3. Hooks. A hook is a named interception point in another package's pipeline. Auth uses http.onRequest to work out who the user is and which team (tenant) they're in. A resource.beforeQuery hook can only narrow results, never widen them.
  4. Domain events. These are facts that others react to, like post.created. Model events fire only after the transaction commits, so a rolled-back write never triggers anything.
  5. Installer enhances. This is code and config added when two packages meet. Install auth and ui, in either order, and you get the sign-in screens.
  6. HTTP + manifest. This is runtime data between server and browser. The UI reads /.well-known/strutvane.json and calls the CRUD API.

Diagram: six cards for contracts, container tokens, hooks, domain events, installer enhances and HTTP plus manifest Packages meet only in these six ways; anything else is not allowed.


The life of one request

Here is what happens when the browser asks for a list of posts. The app's entry point is a small, readable bootstrap/app.ts:

// bootstrap/app.ts
import { dirname } from 'node:path'
import { Application } from '@strutvane/framework'
import web from '../routes/web.ts'

export default Application.configure({ basePath: dirname(import.meta.dirname) })
  .withRouting({ web, health: '/up' })
  .withMiddleware((m) => m.validateCsrfTokens({ except: ['webhooks/*'] }))
  .withCommands([sendReportsCommand])
  .create()

A request then passes through a fixed sequence. Middleware is code that runs before (and around) your route handler, and every step here can say no:

  1. Front door. The Host header must be on the allowlist, and body size, JSON depth and field count are capped.
  2. Session and CSRF. CSRF (cross-site request forgery) is when another site tricks your browser into sending a request. Every unsafe request that rides on a session cookie must prove it came from your own pages: a same-origin signal, an exact Origin, or a session-bound token. Bearer-token API calls skip the check, because browsers never attach those by themselves.
  3. Rate limits. The throttle middleware applies named limiters per IP and per user, with Retry-After headers.
  4. Who is asking? Auth's http.onRequest hook resolves the user (the actor) and their team.
  5. Routing picks the route and the resource controller.
  6. Validation uses a schema generated from the migration. Unknown fields are rejected, and writes accept only columns the model marks as fillable.
  7. The policy check is deny-by-default; more on this below.
  8. The database query goes through the ORM, which adds the tenant scope and uses bound parameters only.
  9. The response has fields the user may not read stripped out by the resource.serialize hook, and it gets security headers such as a CSP with per-request nonces, nosniff and frame-ancestors 'none'.

When any step refuses, the answer has one shape: an RFC 9457 "problem". That's a standard JSON error format with a stable, lowercase code and structured issues that point at the exact field. Messages come from catalogues, never hard-coded strings, and stack traces never appear in production.

Diagram: ten numbered steps from request arrival through front door, session and CSRF, rate limits, identity, routing, validation, policy check, database and response, with a problem+json lane underneath Every request to the generated API takes the same path, and every step can refuse.


Migrations first, and four levels of control

Generated code has a reputation problem: it's great on day one and painful on day ninety, when you've edited it and the generator wants to overwrite your changes.

Strutvane handles this in two ways.

First, migrations are the only source of truth. Columns are never typed on the command line or redeclared in models. Generated, machine-owned files live in .strutvane/ and are committed, so a fresh clone type-checks. CI fails when they're stale.

Second, there's a ladder of control, so you only take ownership of as much as you need:

  • L0 · Declare. Write the migration and run migrate. You get the API, types and screens with no other files.
  • L1 · Configure. Adjust labels, icons, sidebar groups, which columns show, and which fields can be searched or filtered.
  • L2 · Override. Replace one piece and keep the rest. That might be a resource hook, a single form widget, a single table cell or one message. The UI resolves overrides from most to least specific (Resource.field, then the field's widget, then the field type, then the default), so you never fork the renderer.
  • L3 · Eject. Take full ownership of the source. The blueprint plans commands for this, such as node strut design:eject, which copies a design's source into your app.

The ownership rule behind all of it, as the blueprint sets it out: files you own are never overwritten.

  • An auto() column list keeps picking up new columns.
  • An explicit list is reported on, not rewritten.
  • A dropped column that your code still uses becomes a TypeScript error, not a runtime surprise.

Authorization and multi-tenancy: two locks on every row

This is the part of a B2B app where mistakes hurt most, so Strutvane treats it as architecture, not a feature.

Authorization is deny-by-default. A policy is a set of rules per model. No rule means no access. A deny always beats an allow. Here's a real policy from the auth package:

export const invoicePolicy = definePolicy('invoice', { schema: invoice }, ({ allow, deny, field }) => {
  allow(['viewAny', 'view'], { role: ['accountant', 'manager'] })
  allow(['view', 'update'], { when: ({ actor, row }) => row.ownerId.eq(actor.id) }) // compiles to SQL
  allow('approve', { role: 'manager', when: ({ row }) => row.amount.lte(10_000) })
  deny('delete', { when: ({ row }) => row.status.eq('paid'), name: 'paid-is-final' }) // deny wins
  field('internalNotes').readable({ role: 'manager' })
})

The clever bit is that one rule is used in two places:

  • for a single record ("may Ana update this invoice?"), it runs in memory;
  • for a list ("show me the invoices Ana may see"), it compiles to a parameterised SQL WHERE clause.

Both paths share one rule tree and the same strict, NULL-safe semantics (ADR-0008), so the list a user sees and the records they can open always agree. Property-based tests compare the two paths against real Postgres. Lists are filtered in the database, which keeps pagination counts correct, and a typo such as row.amout doesn't even compile.

Multi-tenancy means many customer companies (tenants, or teams) share the same tables, each row tagged with its tenant. Strutvane enforces the boundary twice:

  • Lock 1, in the app. The ORM adds a tenant scope to every query. The tenant id on a new row comes from the request context, never from the request body.
  • Lock 2, in the database. On PostgreSQL, row-level security (RLS) makes the database itself filter rows by tenant, under the rules of ADR-0007:
    • the tenant policy is RESTRICTIVE and forced;
    • the tenant is set inside each transaction only, so a pooled connection never carries it into someone else's request;
    • the rules require the app to connect with its own database role that doesn't own the tables and can't bypass RLS (a separate role runs the migrations);
    • an unset tenant matches zero rows, so it fails closed.

Rows outside your team or your rules answer 404, exactly like rows that don't exist. On MySQL and SQLite, where RLS isn't available, the tenant scope is backed by generated cross-tenant tests, and the docs say so plainly.

Diagram: a request from Ana of team Acme flows through the policy, then a SQL filter plus tenant scope, then Postgres row-level security Lock 1 is the policy plus the ORM's tenant scope; lock 2 is the database's own row-level security.


The admin UI: reads, never guesses

The admin UI is split into what it does and what it looks like.

  • @strutvane/ui is the behaviour: lists, forms, detail pages, the sidebar, a command palette, keyboard shortcuts, the unsaved-changes guard and accessibility. It has no colours or layout chrome of its own.
  • A design package is the look: tokens for light and dark, fonts, the shell (sidebar, top bar, sign-in layout), component skins, a chart palette and illustrations. Crisp is the quiet default; Vivid is the colourful one.

The UI never imports the server. It speaks HTTP only. At startup it reads the resource manifest, a JSON document at /.well-known/strutvane.json that lists every resource, its fields, labels and relations, and what this user may do. Auth's manifest.build hook adapts the manifest per user: fields they can't read are left out, and fields they can't write are marked read-only. The UI then draws a list, detail, create and edit page for every resource, with zero per-resource code.

Hiding a button is a convenience, not a security rule. The API checks every call again.

Plugging in a design looks like this:

import '@strutvane/design-crisp/fonts.css' // Inter Variable + Geist Mono (optional; falls back to system fonts)
import { DesignProvider } from '@strutvane/ui/design'
import { StrutvaneApp } from '@strutvane/ui/react'
import { crisp } from '@strutvane/design-crisp'

export function Admin({ nonce }: { nonce: string }) {
  return (
    <DesignProvider design={crisp} nonce={nonce}>
      <StrutvaneApp apiUrl="/api" appName="Northwind Ops" />
    </DesignProvider>
  )
}

Every design, first-party or community, is built with defineDesign() and must pass the designConformance() test kit. It checks that:

  • every slot is filled;
  • every token pair meets WCAG AA contrast in both themes;
  • there are no hard-coded colours;
  • axe finds zero violations on the reference screens;
  • nothing scrolls sideways at 375 px.

That's why switching designs changes every screen without touching one.

Diagram: the browser side with @strutvane/ui and pluggable designs Crisp, Vivid and your own, exchanging the manifest and data with the server side's manifest, manifest.build hook and CRUD API The UI asks for the manifest, then the data; designs plug into the UI through one contract.


How add-ons install themselves

Strutvane is designed for an ecosystem that grows past 100 packages, so nothing that touches "the list of packages" is hard-coded.

Every package declares a strutvane block in its own package.json. It covers what the package is, which framework range it supports, and what it installs. No code runs to read it. Today you add a package like this:

node strut install:redis      # today: node strut add redis

The installer:

  • writes typed config;
  • adds documented keys to .env and .env.example, with secrets left empty and never written to .env.example;
  • registers the package's service provider;
  • adds migrations and screens where needed.

Three rules apply to every installer:

  • Idempotent. Running it twice changes nothing.
  • Order-independent. Install order never changes the result; whichever package arrives second adds the connecting pieces (the enhances mechanism).
  • Reversible and respectful. node strut remove <name> reverses the package's own pieces. A file whose shape the installer doesn't recognise is left alone, and the lines to add are printed for you instead.

Package migrations go through an extra gate, because they run as the database owner. A package's migration folder is used only when the package is a direct dependency with a contributor name, the app has actually enabled it, and every file resolves inside the package's own folder.

The roadmap adds a published catalogue index built from these manifests, so the installer, node strut add and the docs all read one list, and a new package appears everywhere without code changes.


Logging and errors

Logging lives in the framework (ADR-0022), configured from .env:

LOG_CHANNEL=stack        # single | daily | stack | stderr | stdout | slack | null | any channel you define
LOG_STACK=daily          # channels the stack writes to, comma-separated (e.g. daily,slack)
LOG_LEVEL=debug          # emergency alert critical error warning notice info debug
LOG_DAILY_DAYS=14        # how many days of daily files to keep

Here's how it behaves:

  • Files go to storage/logs/.
  • In code you write Log.info(), Log.channel('payments').warning() or Log.withContext({ orderId }).
  • The request id, user and tenant are attached automatically.
  • Redaction is always on. Tokens, passwords, keys and cookies are scrubbed before anything is written, and that can't be turned off per channel.
  • Extra processes, such as a queue worker, write their own file next to the main one, so files never interleave.

Package code logs only through the framework's logger; CI fails on a stray console. in source. A separate log viewer package for browsing logs is on the roadmap.

Errors have one model end to end. Every failure is an RFC 9457 problem with a stable lowercase code and structured issues. Messages come from per-locale catalogues that the UI shares, so a server-side validation error lands on the right form field with the right wording.


The release pipeline and quality gates

A framework is only as trustworthy as the way it ships. Every package repo runs the same CI workflows, synced from the tooling repo, and nine production-readiness gates (R1–R9) define what "ready" means. Each repo records the evidence for every gate.

The gate before any merge: lint → typecheck → tests with coverage → build. On top of that:

  • Platforms. It runs on Linux, Windows and macOS, on Node 24 and 26.
  • Coverage. The thresholds are 90/90/85/90 (statements, branches, functions, lines).
  • Strictness. Tests run with --unhandled-rejections=strict, so a forgotten promise fails the build.
  • 3× green. The suite must pass three runs in a row before work is merged, so flaky tests can't hide.
  • Supply chain. There's a dependency audit, a secrets scan, and checks on the published tarball and its type exports. Installs only run dependency install scripts from an explicit allowlist.

Publishing is staged (ADR-0016 and ADR-0018):

  1. Versions are bumped on main with Changesets, which also writes the changelog.
  2. CI stages the new version through npm trusted publishing. That uses OIDC, a short-lived identity handed to the CI job, so no npm token is stored anywhere. Every version carries provenance, a signed link back to the exact commit and build.
  3. A maintainer approves the staged version on npmjs.com with 2FA. That click is the release.

A CI run alone can never make a version live. Before 1.0, releases go to npm's latest tag, so npm create strutvane@latest just works.

Diagram: eight steps from a change through the CI matrix, the gate, three green runs, versioning on main, CI staging, human approval with 2FA, to live on npm Three operating systems, three green runs, and a human with 2FA between CI and your app.


What's next

The core is live on npm today: framework and auth at 0.2.0-next.5; ui at 0.2.0-next.3; both designs, redis and health at 0.2.0-next.1; social-login and the npx guard at 0.2.0-next.0; and the installer, create-strutvane, at 0.2.0-next.6.

The current targets:

  • 0.2.0 and a demo app working end to end: early December 2026.
  • 0.3, background work: queues, mail, notifications, the scheduler and cache drivers, targeted for mid-December 2026.
  • 1.0: January 2027.

Targets can move. Quality gates don't.

If you take one idea from this post, let it be this: the architecture is mostly rules, not code. One source of truth for data. One copy of the framework. Six ways for packages to talk. Two locks on every row. A human between CI and npm. The code follows from those rules, and the rules are written down in the hub, where anyone can read and challenge them.

— Vishwajit VM


Part of the Strutvane series. Strutvane™ is open source under the MIT licence.

About the author

  • Hi, I'm Vishwajit VM, a backend & AI engineer from New Delhi. For 5+ years I've built the parts of apps you don't see: APIs, databases, queues and AI agents, for teams in hiring, real estate, finance, retail and civic tech. My rule is simple: a system should keep working when something goes wrong. Right now I'm a backend developer at SPNX, building an EU VAT-registration platform that runs in production. After hours I'm building Strutvane, an open-source TypeScript framework for business apps (I'm writing about it as a series on my blog, vishwajitvm.hashnode.dev), plus my own products such as DevFlow-AI (self-hosted AI code review) and Hopline (encrypted peer-to-peer file transfer). Day to day I work with Python, FastAPI, Node.js, TypeScript, NestJS, PostgreSQL, Redis, Docker, LangGraph and RAG, and I've shipped plenty of Laravel/PHP and React along the way. Outside work, I'm a part-time photographer. See my work at https://vishwajit-labs-web.vercel.app/

No comments yet. Be the first to comment.