Skip to content

Introduction ​

What is Plinth? ​

Plinth is a batteries-included web framework for TypeScript and Node.js. It gives you the pieces a full-stack application needs: a router and HTTP kernel, sessions and CSRF protection, validation, a database layer with an active-record ORM, queues, mail, caching, authentication and authorization, scheduling, real-time broadcasting, and more. Each of these is a separate package published under the @plinthjs scope, and they are designed to fit together without glue code.

You can use Plinth in two ways. The quickest way is to scaffold a complete application with create-plinthjs-app, which wires the packages together for you (see Installation). The other way is to pick the packages you need and install them into an existing project, because every package works on its own.

Here is the smallest useful Plinth program. It builds a router, hands it to the HTTP kernel, and sends a request through the whole pipeline without opening a socket:

ts
import { HttpKernel, Request, Response, Router } from '@plinthjs/http'

const router = new Router()
router.get('/hello/{name}', (request) =>
  Response.json({ greeting: `Hello, ${request.param('name')}!` }),
)

const kernel = new HttpKernel(router)
const response = await kernel.handle(new Request({ method: 'GET', url: '/hello/Ada' }))

response.status // => 200
response.body // => '{"greeting":"Hello, Ada!"}'

To serve the same kernel over HTTP you pass it to serve(kernel, 3000), which is covered in The Request Lifecycle.

Design goals ​

Plinth is built around a few decisions that shape every package.

Zero runtime dependencies ​

No Plinth package depends on a third-party npm module. The only dependencies a package declares are other @plinthjs packages. Where other ecosystems wrap a library, Plinth builds the feature on Node's own modules: the HTTP server is node:http, hashing and encryption use node:crypto, the default database driver uses node:sqlite, files go through node:fs, and the Redis client speaks the wire protocol over node:net.

Features that inherently need a third-party service or driver, such as a MySQL client or an SMTP provider, are exposed as seams you implement or plug in. The generated application, for example, adds mysql2 to its own package.json when you choose MySQL; the framework itself stays dependency-free.

Built on Node built-ins ​

Because the framework sits directly on Node's primitives, you can read how a feature works without wading through layers of wrappers. It also means upgrading Node gives you improvements to the framework for free.

Strict TypeScript ​

The packages are written in TypeScript at its strictest settings and ship their own type declarations. Container tokens, config getters, route handlers, middleware, and query results are all typed, and your editor can follow a value from the place it is bound to the place it is used.

ESM and CJS ​

Every package publishes both an ES module build and a CommonJS build, along with .d.ts files, so it works whether your project uses import or require:

ts
import { Application } from '@plinthjs/core' // ESM
// const { Application } = require('@plinthjs/core') // CommonJS

Every package installs alone ​

Packages declare only the other packages they genuinely need. @plinthjs/cache, @plinthjs/mail, @plinthjs/queue, @plinthjs/validation, and the rest can each be added to a project by themselves:

bash
pnpm add @plinthjs/cache

Packages that need to talk to the HTTP layer (for example @plinthjs/session) depend on @plinthjs/http, and nearly everything leans on the small @plinthjs/support utility package. Shared interfaces live in @plinthjs/contracts, which contains only types, so packages can depend on a shape instead of on each other.

How to read this manual ​

The manual is organised so you can read it from top to bottom, or jump to the topic you need.

  1. Getting started shows how to create an application, how configuration works, what each folder in a generated app is for, and how to deploy it. Start with Installation.
  2. Concepts explains the ideas the rest of the framework rests on: the request lifecycle, the service container, service providers, and facades. Read these before the feature pages; they make everything else easier to follow.
  3. The Basics covers what you use on every project, starting with Routing, then Middleware, Controllers, Requests, Responses, Views, Validation, Sessions, Error handling, and Logging.
  4. Digging Deeper covers the larger feature areas: the console, cache, queues, mail, events, scheduling, and so on.
  5. Security covers authentication, authorization, encryption, hashing, and the token and OAuth packages.
  6. Database and ORM cover the query builder, migrations, and active-record models.
  7. Operations covers the production tooling: the inspector, the monitor, the queue supervisor, and the persistent server.
  8. Testing is in the testing overview.

Code samples are TypeScript. The first example on each page shows the import lines, and later examples leave them out. A trailing comment such as // => 3 shows the value an expression produces. The separate API reference lists every exported class and method; this manual teaches how to use them.

A tour of the packages ​

The packages group naturally by the problem they solve.

Foundation ​

  • @plinthjs/support holds collections, fluent string, array and number helpers, a pipeline, and UUID and ULID generators.
  • @plinthjs/contracts holds interfaces only, with no runtime code. See Helpers and Collections.
  • @plinthjs/core is the kernel: the service container, the config repository, service providers, the Application, and facades. See Concepts.

HTTP ​

  • @plinthjs/http provides the router, Request and Response, middleware, the HTTP kernel, controllers, uploads, and the node:http adapter. See Routing.
  • @plinthjs/session handles sessions, flash data, cookies and CSRF protection.
  • @plinthjs/validation validates input against rules. See Validation.
  • @plinthjs/view is the template compiler behind Views, and @plinthjs/vite with @plinthjs/vite-plugin connect your frontend build; see Vite.
  • @plinthjs/http-client is an HTTP client with retries and a fake for tests. See HTTP Client.
  • @plinthjs/rate-limiter limits attempts. See Rate Limiting.

Data ​

  • @plinthjs/database has connections, the fluent query builder, migrations, seeders, and pagination. See Database.
  • @plinthjs/orm adds active-record models, relationships, casts, factories, and API resources. See ORM.
  • @plinthjs/redis is a Redis client written over node:net. See Redis.
  • @plinthjs/search is a full-text search abstraction. See Search.

Queues, events, and messaging ​

  • @plinthjs/queue runs jobs with retries, chains and batches, and @plinthjs/bus dispatches commands through a middleware pipeline. See Queues.
  • @plinthjs/events is the event dispatcher. See Events.
  • @plinthjs/mail and @plinthjs/notifications send email and multi-channel notifications. See Mail and Notifications.
  • @plinthjs/broadcasting and @plinthjs/websockets provide channels and a WebSocket server. See Broadcasting and WebSockets.

Services ​

  • @plinthjs/cache, @plinthjs/storage (filesystem disks), @plinthjs/logging, @plinthjs/localization, and @plinthjs/scheduling cover the everyday services. See Cache, Filesystem, Logging, Localization, and Scheduling.
  • @plinthjs/feature-flags toggles features per user or scope. See Feature Flags.
  • @plinthjs/process runs operating-system processes, and @plinthjs/concurrency runs work concurrently. See Process and Concurrency.
  • @plinthjs/console is the command framework and prompt toolkit. See Console.

Security ​

  • @plinthjs/auth provides guards, user providers, and authentication middleware. See Authentication.
  • @plinthjs/authorization provides gates and policies. See Authorization.
  • @plinthjs/encryption provides AES-GCM encryption and scrypt hashing. See Encryption and Hashing.
  • @plinthjs/accounts, @plinthjs/api-tokens, @plinthjs/oauth-client, and @plinthjs/oauth-server cover headless account flows, API tokens, and OAuth. See Accounts, API Tokens, OAuth Client, and OAuth Server.

Operations ​

  • @plinthjs/cluster is a persistent application server that boots your app once and reuses it across requests.
  • @plinthjs/queue-supervisor, @plinthjs/monitor, and @plinthjs/inspector supervise queues, record performance, and record what happens inside a request.
  • @plinthjs/repl is an interactive shell with your application loaded. See REPL.

The scaffolder ​

create-plinthjs-app generates an application wired to these packages. It is not a framework package itself, but it is the fastest way to see them working together.

Where to go next ​

Create an application with Installation, then read Configuration and Directory Structure. When you are ready to understand what happens to a request, read The Request Lifecycle.

Released under the MIT License.