A modern HTTP API server built with Effect-TS, featuring:
- Bun as the runtime
- Effect HTTP API for type-safe REST endpoints
- Effect Schema for validation
- Drizzle ORM with Effect SQL integration
- SQLite as the database
- Swagger/OpenAPI documentation
src/
├── api/
│ ├── user-api.ts # HTTP API endpoint definitions
│ └── user-handlers.ts # API handlers implementation
├── db/
│ ├── schema.ts # Drizzle schema definitions
│ └── database.ts # Database layer setup
├── repositories/ # Database repositories using Drizzle + Effect SQL
│ └── user-repository.ts
├── schemas/ # Effect Schema definitions for validation
│ └── user.ts
├── migrations/ # Database migrations
│ └── 0001_create_users.ts
└── api-server.ts # HTTP API server entry point
- RESTful API endpoints with full type safety
- Automatic OpenAPI/Swagger documentation at
/docs - Type-safe request/response validation
- Built-in error handling with proper HTTP status codes
- Type-safe database operations with Drizzle ORM
- Effect SQL integration for composable database layers
- Automatic schema inference and type safety
- Built-in migration system
- Type-safe request/response validation using Effect Schema
- Email validation with regex patterns
- Optional fields with proper typing
- Fast startup and execution
- Built-in TypeScript support
- Hot reloading in development
- Bun installed on your system
- Install dependencies:
bun install- Set up the database:
# Push schema changes to database
bun run db:push- Start the HTTP API server:
bun run apiThe server will start on http://localhost:3000 with:
- REST API endpoints available at
/users - Swagger documentation at
http://localhost:3000/docs
bun run api- Start HTTP API server with hot reloadbun run build- Build for productionbun run start- Start production serverbun run db:generate- Generate Drizzle migrationsbun run db:migrate- Run Drizzle migrationsbun run db:push- Push schema changes to databasebun run db:studio- Open Drizzle Studio (database GUI)
The HTTP API provides RESTful endpoints for user management:
Get a list of users with optional pagination.
Query parameters:
limit(optional): Number of users to returnoffset(optional): Number of users to skip
Get a user by ID.
Create a new user.
Request body:
{
"name": "John Doe",
"email": "[email protected]"
}Update an existing user.
Request body:
{
"name": "Jane Doe",
"email": "[email protected]"
}Delete a user by ID.
bun run db:studioThis opens a web-based database GUI for inspecting and editing data.
- Modify
src/db/schema.ts - Generate migration:
bun run db:generate - Apply migration:
bun run db:migrate
Or for development, push directly: bun run db:push
Visit http://localhost:3000/docs when the server is running to access the interactive Swagger documentation.
# Get all users
curl http://localhost:3000/users
# Get user by ID
curl http://localhost:3000/users/1
# Create a new user
curl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "email": "[email protected]"}'
# Update a user
curl -X PATCH http://localhost:3000/users/1 \
-H "Content-Type: application/json" \
-d '{"name": "Jane Doe"}'
# Delete a user
curl -X DELETE http://localhost:3000/users/1- Type-safe HTTP endpoints with automatic validation
- Built-in Swagger/OpenAPI documentation generation
- Composable middleware and error handling
- Request/response schema validation
- Type-safe database operations
- Composable database layers
- Automatic schema inference
- Migration system
- Connection pooling
- Compile-time type safety
- Runtime validation
- Automatic serialization
- Custom validation rules
- Clean separation of concerns
- Testable data access layer
- Dependency injection via Effect services
The template follows functional programming principles with Effect-TS:
- Services: Dependency injection and resource management
- Layers: Composable application architecture
- Effects: Structured concurrency and error handling
- Schemas: Type-safe data validation and transformation
- HTTP API: RESTful endpoints with automatic documentation
-
Add new entities:
- Add to
src/db/schema.ts - Create Effect schemas in
src/schemas/ - Create API endpoints in
src/api/ - Create repository and handlers
- Add to
-
Add middleware: Use HTTP middleware for authentication, logging, etc.
-
Add validation: Extend schemas with custom validation rules
-
Switch databases: Change the database layer in
src/db/database.tsanddrizzle.config.ts
Current schema includes a users table with:
id- Auto-incrementing primary keyname- User's name (required)email- User's email (required, unique)createdAt- Creation timestampupdatedAt- Last update timestamp
MIT