Backend Development
Setup
Requires current Go version.
cd backend
cp .env.example .env # then edit with your values
go mod tidy
Running Locally
source .env
go run main.go
The server starts on HOST_PORT (default 8080). Migrations run automatically.
Adding a New Endpoint
- Define an input DTO in
models/with validation tags. - Add a controller function in
controllers/. - Register the route in
routes/routes.go. - Add the validation schema to the middleware registration if needed.
Database Migrations
Creating a Migration
make migrate-create NAME=add_foo_column
This creates two files in database/migrations/: NNNNNN_add_foo_column.up.sql and .down.sql.
Running Migrations
Migrations run automatically on startup. To apply or roll back manually:
make migrate-up
make migrate-down
make migrate-status
Models and DTOs
GORM models (Contact, Activity, etc.) live alongside input DTOs (ContactInput, etc.) in models/. DTOs are what controllers receive after validation while models are what GORM persists.
All models include UserID uint for tenant isolation.
Services
Complex business logic lives in services/. Controllers call services; services own multi-step operations (e.g. sending emails). Services receive a *gorm.DB and any needed config, they do not access *gin.Context.
Testing
go test ./...
Tests use an in-memory SQLite database (auto-migrated). See Testing.