A Go-based facility reservation system built with a contract-first approach using modern tooling for type-safe development.
This project uses a contract-first architecture with two key boundaries that drive code generation:
- Data Contract: Database schema (
_db/schema.sql
) defines the data model - API Contract: TypeSpec specification (
spec/main.tsp
) defines the interface
The architecture uses the following key technologies:
- Atlas: Database schema-as-code for migrations and schema management
- sqlc: Type-safe Go code generation from SQL queries
- ogen: HTTP server generation from TypeSpec API specifications
- PostgreSQL: Primary database with pgx driver for connection pooling
- Docker and Docker Compose
- Go 1.21+
- Ports 5432 and 5433 available on localhost
-
Install development dependencies:
make dev-deps
-
Start the database:
make db-up
-
Setup database schema:
make db-setup
-
Build and test:
make build_dev
-
Run the server:
go run cmd/api-server/main.go
The API provides three main endpoint groups:
/api/v1/admin/users/
- User management (admin only)/api/v1/facilities/
- Facility CRUD operations/api/v1/me/
- Current user profile
- Schema Changes: Modify
_db/schema.sql
- Apply Schema:
make atlas-apply
- Update Queries: Edit
_db/query_*.sql
- Generate Code:
make sqlc-generate
- API Changes: Modify
spec/main.tsp
- Update Server:
make ogen
- Implement Logic: Update
internal/api_service.go
- Test:
make build_dev
make db-up # Start PostgreSQL
make db-down # Stop database
make db-setup # Setup schema
make atlas-apply # Apply schema changes
make sqlc-generate # Generate Go code from SQL
make build_dev # Full development build pipeline
make test-short # Unit tests only
make test-integration # Integration tests with database
make fmt # Format code
make lint # Run linter
make ogen # Generate Go server from TypeSpec
make tsp # Generate TypeSpec schema only
- Development:
postgres://postgres:postgres@localhost:5432/facility_reservation_db?sslmode=disable
- Test:
postgres://postgres:postgres@localhost:5433/facility_reservation_db?sslmode=disable
- Custom: Set
DATABASE_URL
environment variable or use-database-url
flag
_db/ # Database schema and queries
├── schema.sql # Database schema (source of truth)
└── query_*.sql # SQL queries for CRUD operations
api/ # Auto-generated HTTP server code
internal/
├── db/ # Auto-generated database code
├── api_service.go # Business logic implementation
└── db_service.go # Database service
spec/
└── main.tsp # TypeSpec API specification
cmd/api-server/ # Server entry point
- Never edit files in
api/
orinternal/db/
directories (auto-generated) - Database schema in
_db/schema.sql
is the single source of truth - All code changes must pass
make build_dev
before being considered complete - No database functions - all business logic stays in the application layer