The backend/server for the Scribe application built with Hono and OpenAPI. This is a fully documented, type-safe JSON API with automatic OpenAPI documentation generation.
- Hono - Fast, lightweight web framework
- @hono/zod-openapi - OpenAPI 3.0 integration with Zod validation
- TypeScript - Type-safe development
- Drizzle ORM - Type-safe ORM with PostgreSQL support
- drizzle-zod - Zod schema generation from database tables
- PostgreSQL - Primary database
- Zod - Runtime type validation and schema definition
- drizzle-zod - Database schema to Zod schema conversion
- Scalar - Interactive API documentation
- OpenAPI 3.0 - Automatic API specification generation
- Vitest - Fast unit testing framework
- ESLint with @antfu/eslint-config - Code linting
- Prettier - Code formatting
- pino - Structured logging
- Developer Documentation - Complete guides for API development
- Auth0 Integration Guide - How to create protected routes
- Quick Reference - Common patterns and examples
-
Clone and install dependencies:
git clone <repository-url> cd scribe-server npm install
-
Set up environment variables:
cp .env.example .env # Edit .env with your database credentialsRequired environment variables:
NODE_ENV=development PORT=9999 LOG_LEVEL=info DATABASE_URL=postgresql://user:password@localhost:5432/dbname AUTH0_DOMAIN=your-tenant.auth0.com AUTH0_AUDIENCE=http://localhost:9999
-
Set up a local database:
Install Postgres locally, create a database, and update your
.env:DATABASE_URL=postgresql://user:password@localhost:5432/scribe_dev
-
Run database migrations:
npm run db:migrate
-
Start development server:
npm run dev
-
View API documentation:
- Open http://localhost:9999/reference for interactive API docs
- Open http://localhost:9999/doc for OpenAPI specification
# Development server with hot reload
npm run dev
# Type checking
npm run typecheck
# Linting
npm run lint
npm run lint:fix
# Code formatting
npm run format
npm run format:check
# Testing
npm run test
npm run test --watch
# Build for production
npm run build
# Production server
npm run start
# Database
npm run db:migrate # Apply pending migrations
npm run db:generate <name> # Generate a new named migration
npm run db:studio # Open Drizzle Studiosrc/
βββ routes/ # OpenAPI route definitions
βββ handlers/ # Business logic handlers
βββ db/ # Database schema and configuration
βββ lib/ # Utility functions and configuration
βββ middlewares/ # Custom middleware
βββ server/ # Server configuration
βββ test/ # Test utilities
βββ app.ts # Main application setup
βββ index.ts # Application entry point
βββ env.ts # Environment configuration
- index.ts - Application entry point using
@hono/node-server - app.ts - Main Hono application setup and OpenAPI configuration
- env.ts - Environment variable validation with Zod
- src/server/server.ts - Base server configuration with middleware
- src/db/schema.ts - Database schema definitions with Drizzle
- src/lib/configure-open-api.ts - OpenAPI documentation setup
The project follows a route-handler architecture:
- Routes (
src/routes/) - Define OpenAPI routes with validation schemas - Handlers (
src/handlers/) - Contain business logic and database operations - Database (
src/db/) - Schema definitions and database connection - Utilities (
src/lib/) - Shared utilities and configuration
The project includes a complete Tasks feature implementation demonstrating the architecture. See the following files for reference:
- Database Schema:
src/db/schema.ts- Table definitions and Zod validation schemas - Handler Functions:
src/handlers/task.handler.ts- Business logic and database operations - Route Definitions:
src/routes/task.route.ts- OpenAPI route specifications - Tests:
src/handlers/task.handler.test.ts- Handler testing patterns
| Method | Path | Description |
|---|---|---|
| GET | / |
API Index |
| GET | /health |
Health Check |
| GET | /doc |
OpenAPI Specification |
| GET | /reference |
Scalar API Documentation |
| GET | /api/public |
Public data (no auth) |
| Method | Path | Description |
|---|---|---|
| GET | /api/protected |
Protected user data |
| Method | Path | Description |
|---|---|---|
| GET | /tasks |
List all tasks |
| POST | /tasks |
Create a task |
| GET | /tasks/{id} |
Get one task by id |
| PATCH | /tasks/{id} |
Update one task by id |
| DELETE | /tasks/{id} |
Delete one task by id |
Please read CONTRIBUTING.md for detailed information about:
- Project architecture and patterns
- Adding new features
- Testing guidelines
- Code style and conventions
- Pull request process