Course map
Every module and lesson
Each lesson ends in a runnable state and is tagged lesson/<id> in the reference repository. Effort estimates come from the amount of reading, code and commands in each lesson.
0 Orientation and environment setup
See the finished application, meet the scenario, and prepare a working toolchain.
- What we are buildingA tour of the finished Caretaker application, the people in it, and the route we take from an empty folder to Cedar.
- Install and verify your toolsInstall Node.js, npm, Git, Docker and an editor, and prove each one works before you write any code.
- Terminal, folders and environment variablesCreate the empty project folder, learn the few terminal ideas the course relies on, and see how environment variables reach a Node.js process.
1 Our first Express application
HTTP, routing, middleware, errors, EJS views and the first tests, with data kept in memory.
- npm init and a first Express serverTurn the empty folder into a Node.js project, install a pinned Express version, start a server and read a raw HTTP response.
- Routes, requests and responsesReturn maintenance issues as JSON, read route parameters and query strings, choose status codes, and let Node restart the server for you.
- Middleware, JSON bodies and errorsAccept new issues with POST, learn what middleware is by writing one, validate input, and make errors safe and predictable.
- HTML pages with EJSRender real pages with EJS templates and shared partials, serve a stylesheet, accept an HTML form, redirect after a successful POST, and see why output escaping matters.
- First tests, and the limits of memorySeparate the app from the server so tests can import it, write HTTP tests with node:test and Supertest, and watch in-memory data disappear.
2 Persistence and the relational data model
PostgreSQL in Docker, tables and constraints, migrations, seed data, and an app that reads and writes with parameterized SQL.
- PostgreSQL with Docker ComposeDescribe a database server in compose.yaml, start it, connect with psql, and learn where the data actually lives.
- Tables, keys and constraintsDesign the first three tables, write them as SQL, and let PostgreSQL reject bad data with primary keys, foreign keys, CHECK constraints and deletion rules.
- Migrations you can run twiceInstall the pg driver, keep connection settings in .env, and write a small migration runner that records which SQL files have run, each inside a transaction.
- Seed data and reading it with SQLLoad the Caretaker scenario with fixed IDs, fix the identity sequences, and practise the joins, filters and grouping our pages will need.
- Connect Express to PostgreSQLLoad configuration from the environment, share a connection pool, move SQL into small data-access functions, replace the in-memory array, and trace one request from route to SQL to HTML.
- Safe writes and a test databaseGive the tests their own database that resets before every test file, turn constraint violations into form errors, and see exactly what SQL injection does and why placeholders stop it.
3 Build real CRUD features
Organisations, buildings, issues and inspections with forms, validation, safe deletes, paging, sorting, filters and transactions.
- Routers, and organisations you can create and editSplit routes into Express routers before app.js becomes unreadable, then build list, view, create and update for organisations with a shared form.
- Buildings, unique names and safe deletesCreate buildings inside an organisation, turn unique and restrict violations into clear messages, and add delete buttons that confirm before they act.
- Edit, move and delete issuesComplete the issue lifecycle with an edit form shared with create, a status field, a UTC date-time input, updated timestamps, and delete.
- Paging, sorting and filteringBuild a list that pages with LIMIT and OFFSET, filters with parameterized WHERE clauses, and sorts through an allowlist, after watching a sort parameter turn into SQL injection.
- Inspections, a state machine and transactionsAdd inspections with a draft → submitted → approved workflow, enforce valid transitions with a conditional UPDATE, and record history atomically in a transaction.
- A dashboard, and the CRUD app as a wholeSummarise issues and inspections with aggregate SQL and FILTER clauses, run independent queries in parallel, and review what the application can do before we add users.
4 Authentication and user management
Users, argon2id password hashing, sessions in PostgreSQL, login and logout, session fixation, cookie settings, CSRF and login throttling.
- Users and password hashingAdd a users table and ownership columns, hash passwords with argon2id, seed the six scenario users, and see what a stored password actually looks like.
- Registration, login and sessionsStore sessions in PostgreSQL, sign the session cookie, register and log users in and out, and follow the cookie from Set-Cookie to the session row to req.user.
- Require login, and keep sessions safeDeny anonymous access by default, add one-time flash messages, fix session fixation by regenerating the session at login, set cookie attributes deliberately, and record who did what from the trusted identity.
- CSRF tokens, login throttling, and "logged in" is not "allowed"Write a synchronizer-token CSRF middleware, put the token in every form, limit failed logins per client, and finish authentication by showing what it does not do.
5 Authorization before Cedar
Memberships and building roles, permission checks in plain JavaScript, tenant isolation for every list, and the point where hand-written rules stop scaling.
- Memberships, building roles and the access matrixStore who belongs to which organisation and who holds which role at which building, load it for every request, and write down the exact access matrix we will enforce.
- Authorizing issues in plain JavaScriptWrite a can(user, action, resource) function for issues, enforce it in every issue route, choose between 404 and 403, hide buttons the user cannot use, and test the issue rows of the access matrix.
- Lists and tenant isolationScope every list, count and dropdown to the buildings the user can see, in SQL, with one shared condition that must agree with the JavaScript rules.
- Buildings, organisations and inspectionsExtend can() to every remaining action, enforce it in the organisations, buildings and inspections routers, make the creator of an organisation its admin in one transaction, and close the last local-only gaps.
- Role explosion and the access matrix as a testTurn the access matrix into one table-driven test, add a separation-of-duties rule, and measure where authorization logic now lives and what the next requirement would cost.
6 Introduce Cedar
Install the real Cedar engine, make the smallest real decision, add a schema, map database rows to entities, and move every route behind Cedar without changing behaviour.
- The first Cedar decisionCheck a package before you trust it, install the official Cedar WebAssembly engine, and make the smallest real authorization request, seeing every byte that goes in and comes out.
- A schema, and policies that are checked before they runDescribe Caretaker's entities and actions in a Cedar schema, keep one policy per file, and validate every policy against the schema in a script and a test.
- From database rows to Cedar entitiesBuild Cedar entities from the rows the app already loads, assemble a complete authorization call, trace one request with real values, and prove the Cedar answer matches the JavaScript rules for every user and issue.
- Cedar behind can(): the first routeLoad and validate the policy store at startup, wrap the engine so that it fails closed, log decisions, and let Cedar decide ViewIssue inside the running app without changing a route, a template or a test.
- Every route on CedarGrow the schema and the entity mapper to cover organisations, buildings, issues and inspections, write twelve small policies, and replace the whole JavaScript switch with one line, keeping all 89 tests green.
- Forbid, precedence, errors and failuresExpress separation of duties as a forbid policy that overrides every permit, see why an evaluation error in a forbid policy is dangerous, and test how the app handles a normal deny, an evaluation error and a failure.
7 RBAC, ABAC, scoped roles and policy management
Roles as facts, parents and action groups, templates as a comparison, controlled onboarding, and grant/revoke that is itself authorized.
- Facts, parents and action groupsStop computing inherited rights in JavaScript. Give Cedar raw role facts, let parent relationships carry organisation inheritance, group actions, and replace twelve policies with nine that read like the role table.
- Policy templates, comparedBuild a real template-linked version of the read and admin rights, check that it decides exactly like our attribute policies, and see what happens to each design when a role is revoked.
- Members and controlled onboardingLet organisation admins add registered users as members or admins, authorize the change with a Cedar context, forbid changes to your own membership, and record every change in an audit log.
- Grant and revoke building rolesBuild the building access page, authorize every grant and revoke with Cedar and a context, limit who may hand out building_admin, keep history, and watch a revocation take effect on the next request.
8 Lists, writes and multi-tenant isolation
Keep SQL list filters and Cedar policies aligned and prove it, make per-item checks fast, authorize creates and moves against the right parents, and test isolation everywhere.
- Lists and policies, kept alignedUnderstand why Cedar cannot filter a list for you, prove that the SQL list filter and the Cedar policies agree for every user and record, add a per-item guard, make per-item decisions fast, and look at partial evaluation honestly.
- Creates and movesAuthorize a create against the parent it will belong to, using trusted data about that parent, and add a move feature that needs permission at both the source and the destination.
- An isolation test suiteAttack every route with another tenant's identifiers, as two different users, and prove that every request is refused and that the database does not change by a single byte.
9 Trust boundaries and architecture
Forged input, what Cedar cannot detect, PDP/PIP/PEP/PAP, an optional authorization service, and defence in depth in the database.
- Forged input, and what Cedar cannot knowSend forged roles, user IDs, building IDs and attributes in every place a client controls, show that Caretaker ignores them, and then show exactly what Cedar would do if the server believed them.
- PDP, PIP, PEP and PAP, and a separate decision serviceName the four parts of Caretaker's authorization with the standard terms, then build an optional decision service that loads its own facts, authenticates its callers, and ignores attributes they send.
- Defence in depth, stale data and racesSee what PostgreSQL itself can refuse (least-privilege roles, an append-only log, row-level security), why Cedar cannot do this, and how stale data, caches and races affect any authorization design.
10 Complete, test and operate the application
Hardening and safe logging, the whole application as six users, a run from a clean checkout, production considerations, and a capstone feature.
- Hardening, logging and configurationRemove the framework banner, add security headers and request IDs, keep decision logs useful and safe, refuse unsafe production settings at startup, and add a guarded reset command.
- The whole application, as six usersWalk through the finished Caretaker as Alice, Bob, Carol, Dave, Nora and Ravi, compare each screen with the access matrix, and read the complete test suite as a specification.
- From a clean checkout, and what production needsDocument how to run Caretaker, prove the instructions work on a fresh clone with its own database, and list honestly what separates this learning application from a production one.
- Recap, and your capstone featureRetell the whole course as one request, then build a feature on your own: work orders for maintenance issues, with their own data, pages, Cedar policies, a forbid, and tests.
- Capstone solution: work ordersA complete, replay-verified solution to the capstone, with the reasoning behind each choice. Open it after you have tried the feature yourself.