Lesson 60 of 60 · Go
Capstone Project – Build a Todo API Service
Duration: 30 minutes
Capstone: Todo API Service
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
Goal
Create a production‑grade Todo service that demonstrates:
- RESTful JSON API (
net/http). - Persistent storage with SQLite.
- JWT‑protected endpoints.
- Dockerized deployment.
- Unit & integration tests.
- CI pipeline using GitHub Actions.
Project Layout (recommended)
/go-todo/
├── cmd/ # `main` packages
│ └── server/main.go
├── internal/
│ ├── model/ # Todo struct, DB helpers
│ ├── api/ # Handlers, middleware
│ └── auth/ # JWT utilities
├── pkg/ # Reusable utilities (e.g., logger)
├── migrations/ # SQL schema files
└── go.mod
Features to implement
- User registration & login – issue JWT.
- CRUD for Todo items – each Todo belongs to a user.
- Pagination (
limit,offset). - Graceful shutdown with context & signal handling.
- Health‑check endpoint (
/healthz). - OpenAPI spec generated via
swaggo. - Dockerfile (multi‑stage) and
docker-compose.ymlfor local dev. - GitHub Actions workflow that:
- Lints (
go vet,staticcheck). - Runs unit tests (
go test ./...). - Builds the Docker image.
- Publishes a release on tag.
- Lints (
Suggested Steps
| Step | Description |
|---|---|
| 1 | Scaffold the module (go mod init github.com/you/todo). |
| 2 | Define the Todo model and SQLite schema (migrations/001_init.sql). |
| 3 | Implement the repository layer (internal/model/repo.go). |
| 4 | Write authentication middleware (JWT). |
| 5 | Build HTTP handlers (internal/api/handlers.go). |
| 6 | Add OpenAPI annotations and generate docs (swag init). |
| 7 | Write unit tests for repo & handlers (*_test.go). |
| 8 | Dockerize and test locally (docker-compose up). |
| 9 | Create a GitHub Actions workflow (.github/workflows/ci.yml). |
| 10 | Deploy to your preferred cloud (Docker, Cloud Run, or K8s). |
Deliverables
- Public GitHub repository.
README.mdwith setup, run, and API usage instructions.- Swagger UI available at
http://localhost:8080/swagger/index.html. - CI badge showing build status.
- Docker image published to GitHub Container Registry.