Skip to content

Project · Go Programming (backend and cloud)

Project: a maintenance-dues API for a housing society

Projectexpert· about 10 hours· 8 steps

The brief

Green Valley Co-operative Housing Society collects monthly maintenance by UPI and tracks it in a spreadsheet that never adds up. You build its REST API in Go: flats, payments with their UPI reference, and a monthly dues report, stored in SQLite, with validation, proper status codes, request logs with IDs, graceful shutdown and handler tests.

Why it matters

Society, school-fee and rent apps across India (and most internal tools at any company) are exactly this: a small JSON API over a SQL database. Choosing the right status codes, never trusting input, using placeholders in SQL, and shutting down without dropping requests are what separate a backend developer from someone who followed a tutorial.

Skills you practise

  • net/http ServeMux with methods and {wildcards}
  • encoding/json with validation
  • database/sql with SQLite and placeholders
  • LEFT JOIN and GROUP BY reports
  • middleware with slog and request IDs
  • graceful shutdown
  • httptest

You need

  • Go 1.22 or newer installed from go.dev/dl
  • curl: on Windows use Git Bash or WSL for these commands (in PowerShell, curl is a different command, and JSON quoting is hard)
  • Internet access once, for go get modernc.org/sqlite

What you will have at the end

A Go REST API (example.com/society) with flats, UPI payments and a monthly dues report in SQLite, JSON errors with the right status codes, request logs with IDs, graceful shutdown, and passing httptest tests.

How it is marked (rubric, 100 points)
Correct API behaviourEvery endpoint returns the right status (200, 201, 400, 404, 405, 409) and JSON body; the dues report is right for every flat.35
Safe data handlingBodies are size-limited and validated, unknown fields refused, SQL uses placeholders only, rows are closed and rows.Err() checked.25
Production habitsStructured request logs with request IDs, internal errors logged but not leaked, graceful shutdown on SIGTERM and Ctrl+C.25
Testshttptest tests with a fresh database per test, covering success and error cases, all passing.15

0/8 steps done

Step 1 of 8

Add the SQLite driver and open the database

go.mod requires modernc.org/sqlite, and the server logs database ready and listening.

Run go mod init example.com/society, create the files from the tabs, and add the driver with go get modernc.org/sqlite. database/sql is the standard interface; a driver registers itself by a blank import, _ "modernc.org/sqlite", under the name "sqlite". In store.Open: sql.Open (which does not connect yet), SetMaxOpenConns(1) because SQLite allows one writer, PingContext to really connect, then ExecContext for each schema statement. Close the pool if any of them fails. Run the server, wait for the listening line, then press Ctrl+C.

$ mkdir society && cd society
$ go mod init example.com/society
$ go get modernc.org/sqlite
go: added modernc.org/sqlite v1.34.4
...
Run this on your machine, then paste the output below
$ go list -m modernc.org/sqlite; go run .
Your notes: main.go, internal/store/store.go, internal/httpapi/api.go, internal/httpapi/middleware.go, internal/httpapi/api_test.go

Write down each command you ran. It goes into your project summary.