You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A production-inspired REST API built with Go, designed around a complete order management workflow with authentication, session management, inventory control, and scalable layered architecture.
Features
JWT authentication with refresh token rotation
Multi-device session management and revocation
Order lifecycle management with enforced status transitions
Automatic inventory control (stock reservation and restoration)
Soft delete for users, products, and orders
Pagination and filtering on list endpoints
Per-IP rate limiting
Structured JSON logging with request tracing
Swagger documentation
PostgreSQL with connection pooling and transactional guarantees
# 1. Clone and install dependencies
git clone <repo-url>cd golang-task-manager-api
go mod download
# 2. Configure environment
cp .env.example .env
# Edit .env with your database credentials and secrets# 3. Run database migrations
make migrate-up
# 4. Start the server
make run
The server starts at http://localhost:<API_PORT>.
Makefile Commands
Command
Description
make run
Start the API server
make migrate-up
Apply all pending migrations
make migrate-down
Rollback the last migration
Running with Docker
Prerequisites: Docker, Docker Compose
# 1. Configure environment
cp .env.example .env
# Edit .env — set DB_HOST=db to match the compose service name# 2. Start the database and API
docker compose up --build
# 3. Run migrations (first time only)
docker compose --profile tools run --rm migrate
Note: The API container mounts .env as a read-only volume (/app/.env) so the application can load it via godotenv. When DB_HOST is set to db, it resolves to the PostgreSQL container defined in docker-compose.yml.
Docker Compose Services
Service
Description
db
PostgreSQL 17 with health check and named volume
api
Multi-stage Go build (builder: golang:1.24-alpine, runtime: alpine:3.21)
migrate
One-off migration runner (migrate/migrate), enabled via --profile tools
Any other transition is rejected with a 400 error.
Order creation:
At least one item with quantity > 0 is required.
total_amount is calculated server-side from current product prices (not trusted from client).
Each OrderItem stores the unit price and subtotal at the time of purchase (price snapshot).
Stock management:
When an order transitions to paid: stock is decremented atomically inside a database transaction. If any product has insufficient stock, the entire operation is rolled back.
When a paid order is cancelled: stock is automatically restored for all items.
Isolation:
Users can only view and manage their own orders — cross-user access returns 404.