https://github.com/aejkatappaja/workout_tracker
Production-ready workout tracker API in Go with clean architecture, authentication, and PostgreSQL. Built for scalability and maintainability.
https://github.com/aejkatappaja/workout_tracker
api clean-architecture docker go jwt middleware postgresql rest testing
Last synced: about 2 months ago
JSON representation
Production-ready workout tracker API in Go with clean architecture, authentication, and PostgreSQL. Built for scalability and maintainability.
- Host: GitHub
- URL: https://github.com/aejkatappaja/workout_tracker
- Owner: Aejkatappaja
- Created: 2025-09-03T21:38:18.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-09-03T21:49:41.000Z (10 months ago)
- Last Synced: 2025-09-03T23:28:57.993Z (10 months ago)
- Topics: api, clean-architecture, docker, go, jwt, middleware, postgresql, rest, testing
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Workout Tracker API
REST API in Go for tracking workouts and exercises. Bearer token auth, CRUD on workouts with exercise entries, PostgreSQL storage.
## Stack
- **Go 1.24** with [Chi](https://github.com/go-chi/chi) router
- **PostgreSQL** with [pgx](https://github.com/jackc/pgx) driver
- **[Goose](https://github.com/pressly/goose)** for migrations
- **Docker Compose** for local dev (app DB + test DB)
## API
| Method | Route | Auth | Description |
|--------|-------|------|-------------|
| `POST` | `/users` | — | Register |
| `POST` | `/tokens/authentication` | — | Login (get bearer token) |
| `GET` | `/workouts/{id}` | Bearer | Get workout with entries |
| `POST` | `/workouts` | Bearer | Create workout |
| `PUT` | `/workouts/{id}` | Bearer | Update workout |
| `DELETE` | `/workouts/{id}` | Bearer | Delete workout |
| `GET` | `/health` | — | Health check |
## Data model
Workouts contain exercise entries. Each entry tracks either **reps** or **duration** (mutually exclusive, enforced by a `CHECK` constraint).
- `users` → `tokens` (bearer, SHA-256 hashed, scoped, expirable)
- `users` → `workouts` → `workout_entries` (sets, reps/duration, weight, order)
## Run
```bash
docker compose up -d
go run migrations/fs.go # apply migrations
go run main.go # starts on :8080
Test
docker compose up -d # test_db runs on :5433
go test ./...
Project structure
internal/
├── api/ # HTTP handlers
├── app/ # App config, DI wiring
├── middleware/ # Auth middleware (bearer token)
├── routes/ # Route definitions
├── store/ # PostgreSQL repositories (interface-based)
├── tokens/ # Token generation + hashing
└── utils/ # Request/response helpers
migrations/ # Goose SQL migrations