Fastify best practices skill
93
97%
Does it follow best practices?
Impact
85%
1.37xAverage score across 4 eval scenarios
Passed
No known issues
An online marketplace is building a new product catalog service. The backend team is working in TypeScript and wants the Fastify API to have strong type guarantees that flow through the entire request/response cycle — from incoming request validation all the way to the serialized response. They've had bugs in production where unvalidated fields leaked into responses and where optional fields caused TypeScript errors that only surfaced at runtime.
The team has three specific pain points they want addressed:
The service manages a product catalog for the marketplace. Products have required and optional fields, and the API must support creating, listing, and retrieving products.
Build a TypeScript Fastify application in src/ with the following:
Routes:
POST /products — create a product, returns 201 with the created productGET /products — list products with optional pagination query params (page, limit), returns 200GET /products/:id — get a product by ID, returns 200 or 404Product shape:
id — string (UUID format)name — string (required, minimum 1 character)description — optional stringprice — number, must be greater than 0category — string (required)inStock — booleanFiles to produce:
src/app.ts — Fastify app buildersrc/routes/products.ts — route definitionssrc/schemas/ — shared schema definitions (if using shared/reusable schemas)package.json — with dependenciesThe app does not need a real database — an in-memory store is sufficient. Focus on the schema definitions, type safety, and response contracts.