n3rdyme/zod-openapi-starter(opens in a new tab)
Language: TypeScript
- stars
- 10
- watchers
- 1
- forks
- 0
- open issues
- 0
- Last updated
- 02/08/2026
Language: TypeScript
A simple declarative-first Node.js starter project utilizing TypeScript, Fastify, and OpenAPI for scalable and reliable API development.
To set up and run the service:
Install dependencies:
yarn install
Build, lint, and test the package:
yarn all
Run the service:
yarn watch
Run the service with open-telemetry:
yarn trace
The API schema definitions for this project are located in packages/api/src/schema/**. We use @asteasolutions/zod-to-openapi to define and validate APIs. This approach leverages Zod schemas to not only validate but also generate OpenAPI specifications directly from the schema definitions, streamlining the process and ensuring consistency between validation logic and API documentation. A lightweight wrapper has been added to the registry object, registerApi which makes it clean and simple to register an api.
// Register endpoints by calling registerApi registry.registerApi({ tags: ["todos"], name: "createTodo", description: "Create a new to-do item", method: "post", path: "/todos", request: CreateTodoRequestSchema, response: { statusCode: 201, schema: TodoItemSchema, }, roles: ["write"], });
packages/api/src/schema.@asteasolutions/zod-to-openapi to register the endpoint.This repository follows a monorepo setup managed by Yarn Workspaces and Turbo Repo. Below is an overview of the core folders:
api: Defines the OpenAPI schema and handles API-related logic, using Fastify as the HTTP server.client-grpc: A generated gRPC client SDK generated by ts-proto.client-sdk: A generated SDK for clients based on the OpenAPI spec, created with tools like orval.service: Contains business logic and integrates with other packages.The repository provides several root-level scripts to manage and automate common tasks:
all: Runs build, format, lint, and test tasks sequentially.preinstall: Ensures Yarn is used instead of npm to prevent potential dependency issues.build: Builds all packages using Turbo Repo.lint: Runs linting on all packages.format: Formats code using Prettier.test: Runs tests across all packages.watch: Watches for changes in the service package.trace: Starts Jaeger and runs tracing on the service package.jaeger:start and jaeger:stop: Controls the Jaeger Docker instance for distributed tracing.for-each: Executes tasks for each workspace sequentially, useful for complex workflows that require running one task at a time..proto files into gRPC services.This setup offers a highly structured environment for consistent, scalable, and maintainable code. By using Turbo Repo for task orchestration, zod-to-openapi for schema and API definition, and Fastify with fastify-openapi-glue, this project is designed to be efficient and developer-friendly.
Fastify: A fast and low overhead web framework for Node.js.
@grpc/grpc-js: gRPC server runtime.
.proto files directly for use with gRPC.ajv: JSON Schema Validator.
Pino: High-performance logging library for Node.js.
Zod: TypeScript-first schema declaration and validation library.
protoc): For compiling .proto files into gRPC services..proto files. This package allows seamless integration of gRPC types into TypeScript projects.These are used for open-telemetry reporting in development/local environments.