How wondertech-byte/go-task-task-manager works
Purpose and Runtime
GoTask is a single-process REST API for task management. It runs on Go, serves HTTP through Gin, persists data with GORM, and uses PostgreSQL. The executable entry point is main.go.
Application Bootstrap
main.go initializes configuration, establishes the database connection/migration path, creates the Gin router, registers routes, and starts the server on port 8080. Startup composition crosses these boundaries:
• main.go
• config/config.go
• db/db.go
Configuration Boundary
Environment-backed database settings are centralized in config/config.go, with .env.example defining the expected local environment contract. Configuration should remain separate from request handling and persistence logic.
Persistence and Schema
db/db.go owns PostgreSQL/GORM connection setup and database migration. The task schema is represented by models/task.go; GORM maps this model to the database and handlers use it for CRUD operations.
• db/db.go
• models/task.go
HTTP Routing Layer
routes/routes.go defines the versioned /api/v1/tasks resource surface and maps collection/item methods to task handlers. The API supports list/create, single-task retrieval, full and partial updates, and deletion.
• routes/routes.go
• handlers/task_handler.go
Task Request Processing
handlers/task_handler.go is the primary application layer: it receives Gin requests, parses path/query/body input, validates task fields, executes GORM operations, and returns HTTP responses. List requests support status filtering and pagination; mutation requests distinguish PUT replacement from PATCH partial updates.
• handlers/task_handler.go
• models/task.go
• db/db.go
Primary Flow and External Dependency
Request flow is: client → Gin router → task handler → GORM → PostgreSQL → JSON HTTP response. The key external service is PostgreSQL, provisioned independently and accessed with credentials supplied through environment configuration. There is no separate service, queue, frontend, or domain-service layer evident in the repository.
Main entry points: task_handler.go Task handler · main.go Application entry point · db.go Database setup · config.go Environment config
Components 14
Bootstrap
- Application entry point · Composes startup and starts HTTP on port 8080.
main.go - Environment config · Centralizes database settings.
config/config.go - Local env contract
.env.example
HTTP API
- Gin router
main.go - Task routes · Defines the versioned /api/v1/tasks resource.
routes/routes.go - Task handler · Validates input, performs CRUD, and returns JSON responses.
handlers/task_handler.go - List filtering · Supports status filtering and pagination.
handlers/task_handler.go - Task mutations · Distinguishes PUT replacement from PATCH partial updates.
handlers/task_handler.go - JSON response
handlers/task_handler.go
Persistence
- Database setup · Connects to PostgreSQL and runs migrations.
db/db.go - Task schema
models/task.go - GORM · Maps task CRUD operations to PostgreSQL.
Other components
- API client
- PostgreSQL · Independently provisioned task datastore.
Connections 18
- Local env contract → Environment config: documents
- Application entry point → Environment config: loads
- Application entry point → Database setup: initializes
- Application entry point → Gin router: creates
- Application entry point → Task routes: registers
- Environment config → Database setup: database credentials
- Database setup → GORM: configures
- Database setup → Task schema: migrates
- GORM → PostgreSQL: connects
- API client → Gin router: HTTP request
- Gin router → Task routes: dispatches
- Task routes → Task handler: maps task methods
- Task handler → List filtering: processes list requests
- Task handler → Task mutations: processes writes
- Task handler → Task schema: uses
- Task handler → GORM: executes CRUD
- Task handler → JSON response: returns
- JSON response → API client: HTTP response