Bakcend server for the Garmin Smart Knee Sleeve capstone project. This service powers the mobile application by exposing a REST API to manage the users workout sessions and metrics.
The other key repositories can be found here:
At a high level, the backend is responsible for:
- authenticating requests and associating them with application users
- storing calibration data used by the knee-tracking workflow
- creating and managing workout sessions, sets, and reps
- persisting workout history for providing data analytics in the app
- The Mobile Application sends HTTPS requests to the backend.
- Requests enter the HTTP handler layer
- Middle handlers authentication and logging
- The service layer applies our desired business logic and dictates application behaviour
- The repository layer persists and retrieves data from PostgreSQL.
The production environment is deployed on AWS and currently uses:
- Amazon EC2: Application server
- Amazon RDS for PostgreSQL: Persistent relational storage
- Amazon ECR: Container image storage
- Github Actions + OIDC for CI/CD deployment
- Cloudwatch Logs for backend request and application log collection
The application server runs and a public subnet and communicates with the PostgreSQL database, The database is deployed in private subnets, and both resources exist inside a Virtual Private Cloud (VPC).
cmd/ # Application entrypoint
internal/ # Core go application code
core/service/ # Business logic
data/ # Connection to repository layer
db/ # sqlc-generated database code
http/
handlers/ # HTTP handlers
middleware/ # Auth, logging, and HTTP middleware
responses/ # Shared response helpers
infra/ # AWS Infrastrucuture Configuration (OpenTofu)
db/
migration/ # Goose migrations
queries/ # Source SQL for sqlc
seeds/ # Development/Production seed data
scripts/ # CI/CD and production management scripts
-
Go Go 1.25 or higher: https://go.dev/dl/
-
Make (Optional) If on windows, a version of make must be installed, Chocolatey package manager is recommended: https://chocolatey.org/install
- Once Chocolatey is installed run the following command in an elevated powershell:
choco install make
- Once Chocolatey is installed run the following command in an elevated powershell:
-
Docker Desktop
Download: docker.com/products/docker-desktop
→ Make sure Docker is running in the background
-
Create environment file Mac/Unix:
cp .env.example .envWindows:copy .env.example .env -
Ensure Dependencies are up to date
go mod download
-
Ensure docker is running and launch container
docker compose up --build
-
Confirm server status
- Navigate to http://localhost:8080/health
- Status should be "OK"
This project uses Go Modules for dependency management. Here's how to work with packages:
To add a new dependency to the project:
go get github.com/example/packageThis will automatically update your go.mod and go.sum files.
After cloning the repository, install all dependencies:
go mod downloadTo update dependencies and clean up unused ones:
go mod tidyThis command ensures your go.mod file correctly reflects all dependencies used in the codebase.
This project includes a Makefile with common commands listed below.
Alternatively, run make to list all available commands
# Go Application
make build # Build the application
make run # Run the application
make dev # Run the application with live reload (docker-compose)
make test # Run tests
make clean # Clean build artifacts
# Database & migrations
make migrations-status # Show goose migration status
make migrations-up # Apply all up migrations
make migrations-down # Roll back one migration
make migrations-reset # Roll back ALL migrations to base (dangerous in prod!)
make migrations-create # Create a new migration (pass name=foo)
make migrations-redo # Re-run the latest migration (down then up)
make migrations-up-to # Migrate up to a specific version (pass version=<num>)
make migrations-down-to # Migrate down to a specific version (pass version=<num>)
# DB helpers
make db-seed # Seed the database with test
# sqlc (DB codegen)
make sqlc-gen # Run sqlc generate inside the dev container
make sqlc-vet # Run sqlc vet (validate) inside the dev containerThis project supports live reload using Air via Docker. This allows you to automatically rebuild and restart the server when code changes are detected.
To use live reload, simply run:
# Using the make command (recommended)
make devThe configuration for Air is in the .air.toml file in the project root. No need to install Air locally as it runs in a Docker container.
To run migrations:
make migrations-up
This project uses sqlc to generate type-safe Go database code from SQL queries. sqlc is run inside the dev container so it uses the same database client and environment as the app.
Common commands
# Validate SQL and schema without generating code
make sqlc-vet
# Generate Go code from queries
make sqlc-genFor a simple web-based UI to inspect the database, this project includes pgweb.
Once the containers are running (make dev), pgweb will be available at:
From here you can:
- Browse tables and data
- Run ad-hoc SQL queries
- Inspect schema and relationships
This is useful for debugging or quick database exploration without using psql.
For local development and testing of protected endpoints:
In your .env file:
APP_ENV=development
DEV_BYPASS_SECRET=your-local-secretWhen calling protected endpoints, the following headers are required:
X-Dev-SecretX-Dev-User-Id

