Lecture Session · Module 7

Data Modeling, ORM & Backend Architecture

Eleven technical workouts that take one sentence of requirements and end with a running endpoint you would not be embarrassed to review. One clinic schema throughout — designed, mapped to Go, then organised into layers that survive a second developer.

✓
Modelentities, keys, relationships
✓
MapGORM structs and queries
✓
Structurelayers and interfaces
✓
Wireinjection, errors, config

01 · The Domain

One clinic, one schema, all eleven sessions

Every page works on the same appointment-booking system. The tables you design in Session 01 are the structs you map in Session 05 and the repository you inject in Session 11.

THE REQUIREMENT

"Patients book appointments with doctors. A doctor has specialities, a patient has one medical record, and the same slot must never be sold twice."

REQUIREMENTOne paragraph from the clientplain English
▼
SCHEMAEntities, keys, relationshipssessions 01–04
▼
STRUCTSThe same tables, in Gosessions 05–06
▼
QUERIESReads, joins, transactionssessions 07–09
▼
LAYERSHandler · Service · Repositorysession 10
▼
OUTPOST /appointments — wired and testedsession 11

Nothing is thrown away between sessions. The double-booking problem is introduced as a constraint in Session 03, enforced in a transaction in Session 09, and returned as a clean 409 Conflict in Session 11.

02 · The Arc

From a paragraph of requirements to an endpoint

Entities→ Relationships→ Constraints→ ER diagrams→ GORM setup→ CRUD→ Queries→ Associations→ Transactions→ Layers→ Wire it up
→Sessions 01–04 never open a Go file. Get the schema wrong and every later session inherits it.
→Sessions 05–09 map that schema with GORM — and show where the ORM helps and where it quietly costs you.
→Sessions 10–11 put the code somewhere sensible, so the booking rule lives in exactly one place.

PostgreSQL throughout. Where MySQL differs in a way that matters — identity columns, RETURNING, the ON CONFLICT spelling — it is called out on the page.

03 · The 11 Sessions

Everything in this module

Part 1

Design the data

Part 2

Map it with GORM

Part 3

Structure the backend

"We'll fix the structure later"

Eleven sessions from now the booking rule lives in one function, the handler is nine lines, and swapping the database touches a single package.