A contract-first approach to building a Node.js backend using Fastify and fastify-openapi-glue, where an OpenAPI spec drives route registration, request validation, and JWT security automatically. Hey API generates typed Fastify route handler interfaces from the spec, eliminating manual type casting. The post walks through scaffolding the project, generating backend types, wiring routes via operationId, implementing a layered architecture (Controller/Service/Repository), and handling security—all derived from the OpenAPI contract rather than hand-written per route.
Table of contents
Other parts:Why Fastify for contract-first backend?Generating backend types from your contractWiring routes with fastify-openapi-glueBuilding the layered architectureSecurity and ValidationSumming up what we’ve builtSort: