A clean, scalable API built with Hono, Drizzle ORM, PostgreSQL, and Domain-Driven Design principles.
This project follows a layered domain-driven architecture with clear separation of concerns:
src/
├── domain/ # Domain layer (business logic)
│ ├── entities/ # Domain entities with business rules
│ ├── repositories/ # Repository interfaces
│ └── services/ # Domain services
├── infrastructure/ # Infrastructure layer (external concerns)
│ ├── repositories/ # Repository implementations
│ └── container/ # Dependency injection container
├── presentation/ # Presentation layer (HTTP)
│ ├── controllers/ # HTTP controllers
│ ├── routes/ # Route definitions
│ ├── middleware/ # HTTP middleware
│ └── validations/ # Request/response validation schemas
├── database/ # Database layer
│ ├── schema.ts # Drizzle schema definitions
│ └── connection.ts # Database connection management
├── app.ts # Application setup and middleware
└── server.ts # Server entry point
- Domain-Driven Design: Clear separation between domain logic and infrastructure
- Type Safety: Full TypeScript support with Zod validation
- Database: PostgreSQL with Drizzle ORM for type-safe database operations
- HTTP Framework: Hono for fast, lightweight HTTP handling
- Dependency Injection: Clean dependency management with tsyringe
- Validation: Request/response validation with Zod schemas
- Error Handling: Centralized error handling middleware
- Database Migrations: Automated schema migrations with Drizzle Kit
- Node.js 18+
- PostgreSQL database
- Yarn or npm
Copy the example environment file and configure it:
cp env.example .env
The .env
file should contain:
DATABASE_URL=postgres://postgres:postgres@localhost:5432/honor
PORT=3000
NODE_ENV=development
# Start PostgreSQL database
docker-compose up -d postgres
# Wait for database to be ready, then install dependencies
yarn install
# Generate database schema
yarn db:generate
# Run migrations
yarn db:migrate
# Start development server
yarn dev
# Install dependencies
yarn install
# Generate database schema
yarn db:generate
# Run migrations
yarn db:migrate
# Start development server
yarn dev
The API will be available at http://localhost:3000
# Development
yarn dev # Start development server with hot reload
yarn build # Build for production
yarn start # Start production server
# Database
yarn db:generate # Generate migrations from schema changes
yarn db:migrate # Apply migrations to database
yarn db:studio # Open Drizzle Studio (database GUI)
# Docker
docker-compose up -d postgres # Start PostgreSQL database
docker-compose up -d drizzle-studio # Start Drizzle Studio (with studio profile)
docker-compose down # Stop all services
docker-compose down -v # Stop and remove volumes
# Generate migrations from schema changes
yarn db:generate
# Apply migrations to database
yarn db:migrate
# Open Drizzle Studio (database GUI)
yarn db:studio
# Start PostgreSQL database
docker-compose up -d postgres
# Start Drizzle Studio (requires postgres to be running)
docker-compose --profile studio up -d drizzle-studio
# View logs
docker-compose logs postgres
# Stop all services
docker-compose down
# Stop and remove volumes (will delete all data)
docker-compose down -v
Access Points:
- PostgreSQL:
localhost:5432
- Drizzle Studio:
http://localhost:4983
The API uses centralized error handling with consistent error responses:
{
"success": false,
"error": "Error message",
"statusCode": 400
}
# Run tests (when implemented)
yarn test
# Run tests in watch mode
yarn test:watch
# Run tests with coverage
yarn test:coverage
# Build the application
yarn build
# Start production server
yarn start
Variable | Description | Default |
---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgres://postgres:postgres@localhost:5432/honor |
PORT |
Server port | 3000 |
NODE_ENV |
Environment mode | development |
- Hono: Fast, lightweight web framework
- Drizzle ORM: Type-safe database ORM
- PostgreSQL: Robust relational database
- TypeScript: Type-safe JavaScript
- Zod: Schema validation
- tsyringe: Dependency injection container
- tsx: TypeScript execution environment
MIT
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
For support and questions, please open an issue in the GitHub repository.