skip to content

// open source template

Express boilerplate

A production-grade Express and TypeScript starter that other developers actually fork.

A fully wired Express 5, TypeScript 6 and Prisma 7 backend with layered clean architecture, a single dependency injection container, JWT and CSRF security, structured logging, OpenAPI docs, two test layers with enforced coverage, and security scanning on every change. It ships one AGENTS.md that six AI coding tools read through symlinks, plus slash commands that scaffold a new resource across all eight layers.

sourcechangelog
// pipeline02/22
year
2025
type
open source template
group
platforms and backends
stars
37

//in plain words

Every web app needs a server behind it, and every new one starts with the same week of plumbing: logins, security checks, error handling, logging and automated tests. This is that week, done once and published so a developer can fork it and start on the actual product on day one.

for developers starting a new API who do not want to wire auth, errors and CI again

the problem

//01the problem

Most Express starters stop at hello world. Teams then spend weeks wiring auth, errors, logging and pipelines, and every project does it slightly differently.

how it works

//02how it works

  1. 01

    Layered by responsibility

    Routes, controllers, services and repositories each own one job and talk only to the layer below. A singleton container is the only place in the codebase where a repository, service or controller is constructed, so any layer can be swapped or tested alone.

  2. 02

    Security as defaults

    A 15-minute access token and a 7-day refresh token live in signed HttpOnly cookies and never appear in a response body. A double-submit CSRF token guards every mutating route, with Helmet headers and per-route rate limits on from the first request.

  3. 03

    Errors with a shape

    A typed error hierarchy and Prisma error mapping mean every failure leaves the API in the same predictable response format, with a correlation id in the structured log line that matches it.

  4. 04

    Two test layers with a floor

    Unit tests mock the repositories and finish in milliseconds. Integration tests drive the real app against a RAM-disk Postgres, and every one checks the valid case, bad input, no session, no CSRF token and not found. Coverage thresholds fail the build when they drop.

  5. 05

    Automation around the code

    Pre-commit hooks on staged files, conventional commits, CodeQL, TruffleHog on verified secrets only, dependency review and Dependabot run on every change. Swagger UI is generated at /api-docs.

  6. 06

    Agents that follow the rules

    One AGENTS.md teaches the hard rules, such as no process.env outside config and no raw error responses, and the files for Claude Code, Gemini, Codex, Cursor, Copilot and Windsurf are symlinks to it. Six slash commands scaffold a resource, a middleware, a test or an OpenAPI block the same way every time.

screens

//03screens

  1. The API reference: The Swagger UI served at /api-docs: auth and notes routes grouped, each group's rate limit stated, and the routes that need a token marked.
    01The API referenceThe Swagger UI served at /api-docs: auth and notes routes grouped, each group's rate limit stated, and the routes that need a token marked.
  2. A request sent from the docs: A sign-up sent through Try it out with a CSRF token: the generated curl command, the 201 response and the security headers that came back.
    02A request sent from the docsA sign-up sent through Try it out with a CSRF token: the generated curl command, the 201 response and the security headers that came back.
  3. A session from the terminal: Fetching a CSRF token, signing up, signing in and creating a note with curl, the tokens kept in a cookie jar.
    03A session from the terminalFetching a CSRF token, signing up, signing in and creating a note with curl, the tokens kept in a cookie jar.
  4. Errors in one envelope: Field-level validation errors, a missing token, and the sixth auth request in 15 minutes refused with 429 and RateLimit headers. The stack trace development mode adds is removed with jq.
    04Errors in one envelopeField-level validation errors, a missing token, and the sixth auth request in 15 minutes refused with 429 and RateLimit headers. The stack trace development mode adds is removed with jq.
  5. Structured logs: pnpm dev starting up: the port and URLs, then each request with its correlation ID and the Prisma query behind it.
    05Structured logspnpm dev starting up: the port and URLs, then each request with its correlation ID and the Prisma query behind it.
  6. The unit layer: 37 unit tests in 840 ms with v8 coverage at 97.6% of statements, and the two uncovered lines named.
    06The unit layer37 unit tests in 840 ms with v8 coverage at 97.6% of statements, and the two uncovered lines named.

measured

//04measured

37
github stars
counted on the repository on 3 dec 2026; the live count is in the github block below
9
forks
developers starting new services from it, counted the same day
12
checks on every push
format, lint, three type-checks, knip, audit, build, unit and integration tests, codeql, trufflehog
6
ai coding tools briefed
one agents.md, every tool file a symlink to it

decisions

//05decisions

  1. 01

    chose tokens in signed HttpOnly cookies

    over a bearer token in the response body

    Script on the page cannot read a cookie, which removes the most common way a token leaks. The cost is CSRF, so a double-submit token is wired in from the start instead of being left for later.

  2. 02

    chose a single construction site for every object

    over importing singletons wherever they are needed

    When only the container calls new, the dependency graph is one file long and a test can hand any layer a fake. It takes a getter per object, which the scaffolding command writes for you.

  3. 03

    chose integration tests against a RAM-disk Postgres

    over an in-memory database or mocked Prisma

    Prisma's error codes and the constraints the app relies on only exist in Postgres. A tmpfs container is wiped on every restart and fast enough to run on every push.

  4. 04

    chose one AGENTS.md with symlinks

    over a file per AI tool

    Six copies of the same rules drift. Symlinks mean a rule changed once is changed everywhere, and the repository stays readable to every tool.

try it

//06try it

  1. //clone it and start the database

    git clone https://github.com/KhaledSaeed18/node-express-boilerplate.git && cd node-express-boilerplate && pnpm install && cp .env.example .env && docker compose up -d

    node 22 or later, pnpm, docker

  2. //migrate, then run it

    pnpm prisma:migrate && pnpm prisma:generate && pnpm dev

    api at localhost:3000/api/v1, docs at /api-docs

  3. //run both test layers

    pnpm test:all

highlights

//07highlights

  • 37 stars and 9 forks from developers starting new services
  • Clean architecture with one DI container and interfaces at every boundary
  • Signed HttpOnly cookies for both tokens plus CSRF double-submit
  • Unit and integration suites with coverage thresholds enforced in CI
  • One AGENTS.md read by six AI coding tools, six scaffolding slash commands
  • Revived in April 2026 onto Express 5, Prisma 7 and TypeScript 6

built with

  • Express
  • TypeScript
  • Prisma
  • PostgreSQL
  • Zod
  • Pino
  • OpenAPI
  • Vitest
  • Docker

on githubnode-express-boilerplate

stars
37
forks
9
license
MIT
language
TypeScript
last push
dec 1, 2026

printings

//08printings

  1. First commit

    An Express, Prisma and TypeScript notes API with authentication, express-validator and morgan.

  2. Revival

    Resumed after a year: Zod replaces express-validator, Pino replaces morgan, CSRF, typed config, typed errors, Swagger, Docker, integration tests with thresholds, CI with CodeQL and the first agent instructions. Prisma 6 to 7, Express 4 to 5, TypeScript 5 to 6.

  3. Secrets and dead code

    TruffleHog on every push, knip for unused code and dependencies, and the openapi and security-audit slash commands.

  4. Latest merge

    Maintenance through the dev branch; Dependabot keeps npm and actions current without major bumps.

questions

//09questions

Is this a framework or a starting point?
A template to fork. Two example models, User and Note, show the full path through every layer, and the new-resource slash command scaffolds the next one across routes, controller, service, repository, schema, OpenAPI and tests.
Does it rotate refresh tokens?
No. The refresh endpoint verifies the refresh cookie and issues a new access token. For rotation with reuse detection, passkeys and OpenID Connect, see the Node auth template on this site.
How do I run the tests without a development database?
Unit tests need no database. Integration tests start a RAM-disk Postgres in Docker with one command, migrate it and run against the real app; CI does the same with a Postgres service.
Which AI coding tools understand it?
Claude Code, Gemini CLI, Codex, Cursor, GitHub Copilot and Windsurf, all reading the same AGENTS.md through symlinks, so the rules cannot drift between tools.

related sheets

//10related sheets

//11contact

Say hello.I read everything.

Email is the fastest way to reach me. For anything that needs a conversation, book a call.

to

name
Khaled Saeed
country
Lebanon