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:
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:
import { Application } from '@plinthjs/core' // ESM
// const { Application } = require('@plinthjs/core') // CommonJSEvery 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:
pnpm add @plinthjs/cachePackages 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.
- 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.
- 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.
- The Basics covers what you use on every project, starting with Routing, then Middleware, Controllers, Requests, Responses, Views, Validation, Sessions, Error handling, and Logging.
- Digging Deeper covers the larger feature areas: the console, cache, queues, mail, events, scheduling, and so on.
- Security covers authentication, authorization, encryption, hashing, and the token and OAuth packages.
- Database and ORM cover the query builder, migrations, and active-record models.
- Operations covers the production tooling: the inspector, the monitor, the queue supervisor, and the persistent server.
- 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/supportholds collections, fluent string, array and number helpers, a pipeline, and UUID and ULID generators.@plinthjs/contractsholds interfaces only, with no runtime code. See Helpers and Collections.@plinthjs/coreis the kernel: the service container, the config repository, service providers, theApplication, and facades. See Concepts.
HTTP
@plinthjs/httpprovides the router,RequestandResponse, middleware, the HTTP kernel, controllers, uploads, and thenode:httpadapter. See Routing.@plinthjs/sessionhandles sessions, flash data, cookies and CSRF protection.@plinthjs/validationvalidates input against rules. See Validation.@plinthjs/viewis the template compiler behind Views, and@plinthjs/vitewith@plinthjs/vite-pluginconnect your frontend build; see Vite.@plinthjs/http-clientis an HTTP client with retries and a fake for tests. See HTTP Client.@plinthjs/rate-limiterlimits attempts. See Rate Limiting.
Data
@plinthjs/databasehas connections, the fluent query builder, migrations, seeders, and pagination. See Database.@plinthjs/ormadds active-record models, relationships, casts, factories, and API resources. See ORM.@plinthjs/redisis a Redis client written overnode:net. See Redis.@plinthjs/searchis a full-text search abstraction. See Search.
Queues, events, and messaging
@plinthjs/queueruns jobs with retries, chains and batches, and@plinthjs/busdispatches commands through a middleware pipeline. See Queues.@plinthjs/eventsis the event dispatcher. See Events.@plinthjs/mailand@plinthjs/notificationssend email and multi-channel notifications. See Mail and Notifications.@plinthjs/broadcastingand@plinthjs/websocketsprovide channels and a WebSocket server. See Broadcasting and WebSockets.
Services
@plinthjs/cache,@plinthjs/storage(filesystem disks),@plinthjs/logging,@plinthjs/localization, and@plinthjs/schedulingcover the everyday services. See Cache, Filesystem, Logging, Localization, and Scheduling.@plinthjs/feature-flagstoggles features per user or scope. See Feature Flags.@plinthjs/processruns operating-system processes, and@plinthjs/concurrencyruns work concurrently. See Process and Concurrency.@plinthjs/consoleis the command framework and prompt toolkit. See Console.
Security
@plinthjs/authprovides guards, user providers, and authentication middleware. See Authentication.@plinthjs/authorizationprovides gates and policies. See Authorization.@plinthjs/encryptionprovides AES-GCM encryption and scrypt hashing. See Encryption and Hashing.@plinthjs/accounts,@plinthjs/api-tokens,@plinthjs/oauth-client, and@plinthjs/oauth-servercover headless account flows, API tokens, and OAuth. See Accounts, API Tokens, OAuth Client, and OAuth Server.
Operations
@plinthjs/clusteris a persistent application server that boots your app once and reuses it across requests.@plinthjs/queue-supervisor,@plinthjs/monitor, and@plinthjs/inspectorsupervise queues, record performance, and record what happens inside a request.@plinthjs/replis 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.