Fastify best practices skill
93
97%
Does it follow best practices?
Impact
85%
1.37xAverage score across 4 eval scenarios
Passed
No known issues
A cloud infrastructure company is expanding their Fastify API service from a single US region to three regions: US-East, EU-West, and APAC. The platform team has been burned multiple times by configuration drift between environments — developers accidentally deployed staging database credentials to production, and an engineer hard-coded if (env === 'production') branches that behaved differently than expected during the EU rollout.
The platform lead wants a strict, validated configuration system for the Fastify backend. It must fail fast at startup if any required settings are missing, and must be easy to use from any plugin without duplicating config loading logic. The company uses .env files locally but injects environment variables directly in CI/CD and Kubernetes.
The API itself is a simple service that exposes a health endpoint and an items endpoint, but the core requirement is the configuration layer. The app must be usable immediately without extra setup beyond environment variables.
Create a working Fastify application with the following structure and files:
src/config.ts — configuration pluginsrc/app.ts — application builder that registers plugins and routessrc/server.ts — entry point that starts the serverpackage.json — with appropriate scripts and dependenciesREADME.md — brief explanation of required environment variables and how to runThe app must expose:
GET /health — returns { status: "ok" }GET /items — returns { items: [] }The configuration must handle at minimum:
PORT — server port, defaults to 3000HOST — bind address, defaults to 0.0.0.0DATABASE_URL — required database connection stringJWT_SECRET — required secret, minimum 32 charactersLOG_LEVEL — optional, defaults to infoThe app should start successfully when the required variables are set, and fail with a clear error at startup if they are missing.