backend

prod-forgeMIT活跃维护

一套用 TypeScript 和 NestJS 写的生产级后端参考实现,把 CI/CD、质量门禁、可观测性、数据库迁移和回滚这些上线必备环节都串起来,适合照着搭自己的服务。

Prod Forge is an open-source reference that shows how to build and operate a production-ready system: AI-assisted development, quality gates, CI/CD, infrastructure, observability, migrations, and rollback.

v1.0.1发布于 2026-11-09 08:23 UTC490star19fork同步于 2026-11-10 11:59 UTC

怎么上手

从 README 代码块原样提取,可能是其中一种安装方式
npm install
npm run db:generate                   # Prisma client (gitignored); lint, tests and start need it
docker compose up -d database cache   # works without .env, using local defaults user/user/app
硬件要求按 README 关键词推断
有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

2 个版本v1.0.1
  1. v1.0.1Release 1.0.1最新正式版2026-11-09 · 2026-11-09 08:23 UTC

    1.0.1 (2026-11-09)

    Bug Fixes

    • accept only short token-like incoming trace ids (6dac133)
    • config: validate database host before building connection URL (c5ece6b)
    • database: check DATABASE_HOST in the seed client and drop untrue host cases (cd0d513)
    • docker: drop npm from the production image, migration task calls the prisma cli (9e3cb4a)
    • e2e: patch of a missing todo answers TODO_NOT_FOUND since owner scoping (b7d8618)
    • keep query strings out of Sentry reports (9216c1c)
    • log the real Sentry status and drop a duplicated CORS comment (2d852b9)
    • make the Claude deny hooks actually deny (c6c8418)
    • make the in-memory throttler fallback follow the Redis script (32ff448)
    • remove the unused REDIS_ENABLED variable (4d95fa9)
    • report an invalid SENTRY_IGNORED_ERRORS with a clear message (6f55ac9)
    • return remaining seconds from the in-memory throttler fallback (cc1b911)
  2. v1.0.02026-11-04 · 2026-11-04 17:26 UTC
    查看更新说明

    First published version of the Prod Forge backend: a NestJS REST API for todos with the production practices the guide describes. Earlier tags (v0.1.0 to v0.2.0, March 2026) were local scaffolding iterations that were never pushed; their content is folded into this release.

    Breaking changes since the 0.2.0 scaffold

    • Access tokens are signed HS256 JWTs verified on every protected route; JWT_SECRET (32+ characters) is required at startup. A login-by-email stub endpoint issues tokens; an identity provider is out of scope.
    • Todos are scoped to their owner for read, update and delete; a foreign id answers 404.
    • Todo pagination uses a real 0-based offset; page size is capped at 100.
    • Title and description have length limits, ids are validated as UUIDs; both are part of the pinned OpenAPI contract.
    • Framework 4xx exceptions keep their status and code; failed health checks return the Terminus 503.
    • /metrics is served at the root only and rejected when the request came through the ALB; /metrics/database returns JSON.
    • Cache keys are versioned, old entries are ignored; entries without an owner count as a miss.
    • SENTRY_DSN is optional, Sentry is enabled only when a DSN is set and SENTRY_ENABLED is true.

    Features

    • Per-user rate limiting behind a trusted proxy; health and metrics endpoints are exempt.
    • Graceful shutdown drains readiness first and waits for in-flight requests before the server closes.
    • Redis cache with scan-based pattern deletion, hit and miss metrics, optional TLS and AUTH token.
    • PostgreSQL through Prisma with pool and statement timeouts and verify-full TLS using the RDS CA bundle.
    • Liveness and readiness endpoints, version endpoint, client-logs endpoint for the web client.
    • The trace id header is exposed to the web client; request logging is GDPR-safe and skips probes.
    • OpenAPI contract exported to docs/openapi.json and checked in CI.

    Observability

    • OpenTelemetry tracing with Tempo, span-aware trace id, W3C traceparent accepted alongside Sentry.
    • Prometheus metrics recorded once per request, Prisma and slow-query metrics, cache metrics.
    • Docker Compose stack with Prometheus, Grafana dashboards, Loki, Promtail and Tempo; alert rules and SLOs that exclude probe and scrape routes.
    • k6 smoke load test.

    Security

    • No secrets in the Docker image, container healthcheck, minimal build context, local compose ports bound to localhost.
    • CI runs npm audit, CodeQL, Trivy and publishes an SBOM with provenance attestations.

    CI/CD

    • CI on pull requests and pushes to main: lint, knip, unit and e2e tests with coverage, OpenAPI check.
    • CD on v* tags: image to ECR, ECS service update, migration task rendered with jq; role, cluster and service names aligned with terraform outputs; Node.js 24.21.0.
    • The commit-msg hook rejects AI attribution trailers.

    Documentation

    • Backend guide from repository strategy to release management, aligned with the code.
    • Agent docs in .claude/docs, cspell dictionary, roadmap, contributing guide, MIT license.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    AI made writing the code easy. Running it in production is still hard.

    This repository is the main guide: a NestJS Todo API taken from the first commit to production, covering quality gates, CI/CD, migrations, observability and rollback. It answers: how do I build and operate a production-ready API?

    Part of Prod Forge — start with the organization overview: https://github.com/prod-forge

    Stack

    LayerTools
    BackendNestJS · Prisma · PostgreSQL · Redis · Docker
    ObservabilityPrometheus · Grafana · Loki · Promtail · Tempo
    QualityESLint · Prettier · Husky · Commitlint · CI/CD

    The full stack table is on the organization page: https://github.com/prod-forge

    Getting started

    Requires Node 24.15 or newer (CI and the image run Node 26), Docker with Compose >= 2.24 (env_file with required: false) and jq.

    npm install
    npm run db:generate                   # Prisma client (gitignored); lint, tests and start need it
    docker compose up -d database cache   # works without .env, using local defaults user/user/app
    printf 'DATABASE_PORT=5332\nJWT_SECRET=%s\n' "$(openssl rand -hex 32)" >> .env   # 5332 is the compose DB host port (.env.common says 5432); JWT_SECRET needs >= 32 chars; append, never overwrite
    npm run db:migration:deploy && npm run db:seed
    npm run start:dev                     # API on http://localhost:3000, Swagger on /docs
    ./scripts/verify-observability.sh     # app in Docker plus Prometheus, Grafana, Loki, Tempo, checked end to end
    

    Grafana runs on http://localhost:3001 (admin / admin). Details: Running the Stack Locally.

    Table of contents

    Conclusion

    Building software is not just about writing code.

    Most engineers learn the craft of coding early in their careers. But the gap between writing working code and running a reliable system in production is wide - and rarely documented in one place.

    This project is an attempt to close that gap.

    Not by providing a magic template you can clone and ship. But by walking through every decision that happens before, during, and after the code is written.

    The stack used here - NestJS, Postgres, Redis, Terraform, AWS - is not the point. These are just tools. The principles behind them apply to almost any production backend, regardless of language or cloud provider.

    What matters is the thinking:

    • Why does repository structure affect team velocity?
    • Why does commit discipline make releases safer?
    • Why does observability matter before something breaks?
    • Why does a rollback plan need to exist before you need it?

    These are not advanced topics. They are basic requirements for any system that real users depend on. The goal of Prod Forge is to make these practices visible, understandable, and reusable.

    What comes next

    Open work is tracked in the roadmap and summarized on the organization page.

    A final thought

    The best time to set up these practices is at the beginning of a project.

    The second best time is now.

    A system without observability is a system you cannot debug under pressure. A team without a defined workflow is a team that slows down as it grows. A deployment without a rollback plan is a deployment that will eventually cause an incident with no recovery path.

    None of these things are difficult to set up. They are just easy to skip. This project exists as a reminder not to skip them.

    Intentionally out of scope

    • Identity provider and password management: the API verifies signed tokens and ships a login stub, see Authentication and Authorization
    • Cursor pagination: list endpoints use offset pagination with count(*), which is enough for the Todo scale, see Performance

    Contributing

    We welcome any kind of contribution, please read the guidelines:

    CONTRIBUTING

    The MIT License

    LICENSE