A production-ready REST API built with Fastify, TypeScript, Prisma, and PostgreSQL. Features API key authentication, health monitoring, and comprehensive test coverage.
- Framework: Fastify
- Language: TypeScript
- Database: PostgreSQL with Prisma ORM
- Testing: Vitest
- Authentication: API Key-based
- Documentation: Swagger/OpenAPI
- Fast and efficient REST API with Fastify
- Type-safe database queries with Prisma
- API key authentication with public route support
- Health check endpoint for monitoring
- Comprehensive test suite with real database testing
- Auto-generated API documentation
- CORS configuration
- Structured logging
- Node.js 18+
- PostgreSQL
- npm or yarn
# Clone the repository
git clone https://github.com/hstm/fastify-sample-api.git
cd fastify-backend
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env with your database credentials
# Generate Prisma client
npx prisma generate
# Run migrations
npx prisma migrate dev# Start development server with hot reload
npm run dev
# Run tests
npm test
# Run tests in CI mode
npm run test:run
# Build for production
npm run build
# Start production server
npm startsrc/
├── routes/ # API route handlers
├── plugins/ # Fastify plugins (auth, prisma, etc.)
├── tests/ # Test files
├── utils/ # Utility functions
├── app.ts # Application setup
└── server.ts # Server entry point
Once the server is running, access the interactive API documentation at:
Swagger UI: http://localhost:3000/docs
The following endpoints are publicly accessible without authentication:
GET / - Welcome message
GET /health - Health check
GET /docs - API documentation