CHAPTER FIVE
Six-part pre-release for review, with eight figures, seven tables, and worked exercises. ADR-001 is proposed, not accepted. No Django application is implemented.
Milestone reached in this chapter: Plan ready. A product brief, written requirements, web vocabulary, a checked Python setup, and a proposed architecture. Django is not installed yet. All milestones
Why This Matters
We have described Otahque’s needs, followed a web request, and practised the Python underneath the application. Before we install Django, we need to answer a question that every later chapter depends on: what will Django do for us, and what must Otahque’s own code still decide?
Getting that wrong is expensive in both directions. Expect too little of the framework and we rebuild what it already offers. Expect too much and we assume that Sam’s private draft is protected, or that the last place cannot be taken twice, just because we used Django. Sam has prepared an event that should stay private until publication; Soni visits the public event list. The server must decide which events belong in that response, and that decision is ours, not the framework’s.
So this chapter separates Django’s mechanisms from Otahque’s rules, follows one request through Django’s main parts, sketches the whole system and the line where trust changes, compares three ways to build it, and writes the choice down as a decision record that someone can review a year from now. Chapter 6 then creates the project these decisions describe.
By the end of the chapter, you will be able to:
- distinguish framework capabilities from Otahque’s product rules;
- follow a request through Django’s main components;
- sketch the browser, application, and storage boundaries;
- compare an architecture choice against requirements and trade-offs;
- record a decision with its reasons, consequences, and status.
You can complete this chapter on paper. Project creation begins in Chapter 6.
Found an error or something unclear? Report an issue with this chapter (GitHub, opens in a new tab)
PAGE 001What You Need to Know
What a framework contributes
New Concept: web framework
What problem exists? Every web application repeats the same machinery: connecting addresses to code, building pages, storing records, checking forms, and identifying people. Written by hand each time, that machinery is slow to build and easy to get subtly wrong.
What did people do before? Teams wrote that machinery themselves, or assembled separate libraries and decided how they fitted together.
What is a web framework? Reusable software that supplies structure and tools for building web applications. Django is a Python web framework. We write application code that works with its components and conventions; a convention is an agreed way of arranging or naming things so that the pieces work together predictably.
Why a framework? Because more of our effort can go on the shared registration record, clear outcomes, and ownership boundaries our people need, rather than on plumbing.
Now let’s separate what it supplies from what we decide.
In the small programs from Chapter 4, we started a file and followed its statements to the end. In a web application, incoming requests repeatedly trigger application work, and Django calls our code when a request needs it. Reusing a framework does not remove Python from the picture. Functions still receive inputs and return results; objects still hold attributes and provide methods. Some of the objects and calling conventions come from Django, while the application supplies its own behaviour.
Que. 1 Does choosing Django mean that we no longer need the Python skills from Chapter 4?
Flip to check your answerFold answer back
Answer. No. Django application code still uses Python. Reading a function call, a returned value, an import, or an error message helps us understand how our code works with the framework. Django adds tools and conventions; it does not replace those language concepts.
Chapter 3 separated the browser from the server-side application, and that separation still applies. The browser sends a request and interprets the response. Our Python application uses Django on the server side to help produce that response. Installing Django on the development computer does not install Python inside each visitor’s browser.

The diagram shows responsibilities, not a deployment plan. It does not say how many computers we need or which hosting service to use. The two parts inside the application cooperate; they are not two independently deployed services.
Que. 2 Soni opens an Otahque page. Does her browser run the Django code shown inside the application box?
Flip to check your answerFold answer back
Answer. No. Django runs as part of the server-side Python application in this design. Soni’s browser sends the request and receives the response. For a normal page response, the browser interprets the returned HTML, together with the page’s styling and any browser-side scripts.
Reusable mechanisms and product rules
Django brings several reusable mechanisms into one framework. For the registration problem in Chapter 1, their value is concrete:
- URL routing connects an address to the view that handles its request; a view is the Python code that returns the response.
- Templates turn supplied event details into HTML pages for visitors and members.
- The object-relational mapper, or ORM, lets Python code work with database records. We will use it to read and change events and registrations.
- Forms and account tools help process input and identify members. Otahque must still decide when registration is allowed and who may change each record.
- The admin site provides a starting interface for trusted staff to manage records. Attendees and organizers will need pages designed for their own tasks.
- Security mechanisms help protect common web interactions. We must still configure them correctly and enforce Otahque’s access and capacity rules.
Table 5.1 separates framework support from product responsibilities; it describes future work, not features already built.
| Need | Framework support | Otahque responsibility |
|---|---|---|
| Show an event page | Connect an address to response-handling code. | Decide which event details this visitor may see. |
| Display event information | Build page content using templates. | Choose the content, wording, and accessible page structure. |
| Keep event records | Provide Python tools for database access. | Define the records and enforce the required data rules. |
| Accept registration details | Provide form and validation tools. | Define valid input and when a registration may succeed. |
| Restrict editing | Provide account and permission mechanisms. | Check that this organizer may edit this particular event. |
For example, knowing which account is signed in does not answer whether that account may edit Sam’s event. Our requirements assign organizers responsibility for particular events; the implementation must enforce that relationship, and our tests must show that a different organizer cannot bypass it. Likewise, a page can display a Register button while the server must still reject a registration that violates the rules. The button is a way to request an action, not proof that the action is allowed.
Que. 3 If an edit button is hidden from another organizer, have we proved that Sam’s event is protected?
Flip to check your answerFold answer back
Answer. No. Hiding the button changes the interface. A request could still reach the server through another route. The server-side operation must check whether the account may edit that event, and later verification must include a request from an account that lacks that permission.
Common Error: “Django handles security”
Django supplies protections against several common web attacks, but their effectiveness depends on how we use and configure the framework. An application-specific rule, such as keeping an unpublished event out of a public response, still needs an implementation and a check. For every feature, ask two questions: what mechanism can the framework supply, and what result must our application guarantee?
A review of a finished feature asks the same two questions.
In practice: reviewing a framework-based feature
Situation. A team uses Django’s account tools and is ready to review who may edit an event.
Application. Ask separately whether the requester is signed in and whether that account may edit this particular event. Use the requirements to define the second answer.
Consideration. Framework support does not establish event ownership rules automatically. A review must include an account that should be refused, as well as the permitted organizer.
Try it yourself
On paper, consider this proposed check: Sam has one published event and one unpublished draft. Soni opens the public event list. State the expected result, identify one task Django can help with, and identify the rule Otahque must enforce. Then explain why seeing the published event alone would be an incomplete check if you had never created a draft for the test.
Que. 4 What should the responsibility split and check show?
Flip to check your answerFold answer back
Answer. Soni should see the published event and should not receive the private draft’s details. Django can help handle the request and produce the page response. Otahque must apply the visibility rule when choosing what data the response contains. Including both kinds of event in the test lets us check inclusion and exclusion; a test containing only published events cannot expose accidental disclosure of a draft. Private data should not be included in a public response and then merely hidden on screen.
Following a request through Django
Soni follows a link to the Python workshop’s detail page. In Chapter 3 we traced that request as far as “the server”. Now we look inside the server-side application. Django divides the work of answering a request among a few kinds of component, each with one job. Learning their names now means that the files you meet in Chapter 6 and the code you write from Chapter 9 will look familiar rather than arbitrary.
The first job is choosing which code should answer. A URL configuration, often shortened to URLconf, is an ordered list of address patterns, each connected to a view. Django compares the requested path, such as /events/42/, with the patterns in order and uses the first one that matches. A pattern can capture part of the path, such as the number 42, and pass it on. If no pattern matches, Django answers with a “not found” response, the 404 status from Chapter 3.
A view is a Python function, or a class, that receives the request and returns a response. It is where the application decides what this request should produce: which event is wanted, whether it is published, and which page to show. In Django, a view is the code that prepares a response, not the screen the visitor sees.
A model is a Python class that describes one kind of stored record, such as an event, and gives the view a way to read and change those records. Django translates model operations into database queries, so a view can ask for “the published event numbered 42” in Python rather than in the database’s own language. We design Otahque’s models in Chapters 15 and 16.
A template is a text file, usually HTML, with marked places where values are inserted. The view chooses a template and supplies the values; Django fills in the template, and the result becomes the body of the response. By default, Django’s templates escape inserted values, so text typed by a member and placed in ordinary HTML text is displayed as text rather than treated as part of the page’s code. Values placed in other contexts, such as scripts or addresses, and values deliberately marked as safe need separate care; Chapter 11 explains the limits.
Finally, the view returns a response: a status code, headers, and a body, the same parts introduced in Chapter 3. Django hands it back to the web server, which sends it to the browser.

Read the figure as one possible path for a reading request. Not every view uses every component. A view that redirects after a registration may use no template, and a page of fixed text may need no model. What stays constant is the order of decisions: match the address, run the view, gather what it needs, and return a response.
Under the Hood: how Django finds the view
Each request enters a handler, BaseHandler in django/core/handlers/base.py, which passes it through the middleware chain. The handler’s resolve_request() asks the root URL resolver to resolve() the request’s path. The resolver, in django/urls/resolvers.py, tries the patterns in order and stops at the first match, returning a ResolverMatch that carries the view and the captured values, such as 42. Django then calls that view with the request and those values. If nothing matches, the resolver raises Resolver404, which becomes the “not found” response.
Que. 5 Soni’s request is for /events/42/. Which component decides which Python function handles it?
Flip to check your answerFold answer back
Answer. The URL configuration. Django compares the path with its patterns in order and calls the view connected to the first match, passing the captured value 42. The URL configuration chooses the code; it does not decide whether event 42 is published. That is the view’s job.
Where Otahque’s rules run
The view, together with the model code it uses, is where Otahque decides whether event 42 is published, whether Sai may see a registration, or whether a registration request may succeed. The template displays the result of those decisions. A template that hides a Register button is still presentation.
Django also runs shared steps, called middleware, on the way into a request and on the way out with its response. Middleware handles concerns common to many pages, such as attaching the signed-in account to the request or adding security headers to the response. We use it with accounts in Chapter 27 and study it directly in Chapter 39. A middleware step can also return a response itself, in which case the view never runs. It does not replace a view’s event-specific checks.
| Part | Job in the request | Otahque example | Built in |
|---|---|---|---|
| URL configuration | Match the path to a view. | /events/42/ calls the event view with 42. | Ch. 9 |
| View | Receive the request, decide, and return a response. | Find event 42; refuse it if it is a draft. | Ch. 10 |
| Model | Describe stored records and query them. | Read the event’s title, time, and place. | Ch. 15–16 |
| Template | Turn supplied values into HTML. | Show the event details as a page. | Ch. 11 |
| Middleware | Process requests and responses around the view. | Attach the signed-in account to the request. | Ch. 27, 39 |
| Response | Carry the status, headers, and body back. | 200 with the page, or 404 for an unknown event. | Ch. 10 |
Prefer the model, view, controller names?
If you have met the model, view, controller pattern elsewhere, Django’s names can seem shuffled. Django’s own documentation describes its division as model, template, and view: Django’s view does much of what other descriptions call a controller, while the framework’s routing machinery does the rest, and the template is the presentation. We use Django’s names, because they are the ones in its files and documentation. The names matter less than the jobs.
Que. 6 A template contains a condition that hides draft events. Is that enough to keep drafts private?
Flip to check your answerFold answer back
Answer. No. The template shows whatever the view supplies. If the view passes a draft’s details, private data has already been selected for a public response, and one mistake in the template would reveal it. The view should select only published events for a public page, and a test should check that a draft is absent from the response.
Que. 7 Does every Django view need a model and a template?
Flip to check your answerFold answer back
Answer. No. A view must return a response. It may build that response from stored records and a template, but a redirect, a short message, or a “not found” response may need neither. The components are tools a view can use, not a checklist every view must follow.
In practice: tracing an unexpected page
Situation. An organizer reports that the address for one event shows a different event’s details.
Application. Follow the request trace: which URL pattern matched, what value it captured, which record the view asked the model for, and which template displayed it. Each step narrows the investigation to one job.
Consideration. The visible page shows only the final result. Confirm each step with the application’s own evidence, such as a test or a log entry, rather than guessing from the screen.
Try it yourself
On paper, write the trace for Raj opening his registration page at the illustrative address /registrations/7/. For each of the URL configuration, view, model, template, and response, write one line saying what it does in this request. Then add the Chapter 2 rule the view must check, and say what Raj should receive if registration 7 belongs to someone else.
Que. 8 What should the trace and the refusal show?
Flip to check your answerFold answer back
Answer. URL configuration: matches /registrations/7/ and calls the registration view with 7. View: identifies the signed-in member, asks the model for registration 7, and checks that it belongs to Raj. Model: reads registration 7 and its event from the database. Template: shows Raj’s status and the event details. Response: 200 with his page. The rule is ownership: a member may see only their own registration. If registration 7 belongs to someone else, the view must refuse without showing any of its details, either as 403 or as a not-found response that does not reveal that the registration exists; Chapter 30 chooses between them. The address is an illustration, not a chosen route.
Found an error or something unclear? Report an issue with this chapter (GitHub, opens in a new tab)
PAGE 002How We Build It
This chapter builds design documents rather than code. Starting point: Chapter 2’s requirements and the responsibilities and request trace from What You Need to Know. Work on paper or in a text file. The steps produce three artefacts: a sketch of the system with its trust boundary, a comparison of three options, and a draft decision record.
The Custom Way: deciding in conversation
Most small projects make their first architecture choice in a chat thread or a meeting. Someone suggests a framework, someone else suggests a different one, and whoever has the most time starts building. That works until a year later, when a new contributor asks why, and the answer is “I think we discussed it once”. The reasons, the options that were rejected, and the conditions under which the choice should change have all gone. The steps below do the same thinking, but leave a record.
The Recorded Way: sketch, compare, record
Step 1: Sketch the application boundaries
A volunteer developer offers to help Sam maintain Otahque and asks: “What are the pieces, and what talks to what?” A high-level design, often shortened to HLD, answers that question. It describes a system’s main parts, how they communicate, and where responsibility and trust change, without the detail of individual functions or tables. More detailed documents follow when decisions need them: an entity-relationship diagram for stored data in Chapter 15, and low-level designs for particular features from Chapter 24. A sketch is a proposal: drawing a box does not build it, choose a hosting service, or prove that the parts will cope with any amount of traffic.
A useful way to sketch is to name each separately running part. The C4 model, a widely used approach to architecture diagrams created by Simon Brown, calls such a part a container: an application or data store that must be running for the system to work. The word has nothing to do with Docker containers. Otahque’s first release needs three, plus the files it serves:
- The visitor’s browser runs on the visitor’s own device. It displays pages and sends requests, and it is outside our control.
- The Otahque web application is our Django project: the URL configuration, views, models, templates, and Otahque’s rules, running as one Python application on a server.
- The database stores events, accounts, and registrations so that they survive between requests and restarts. During development we use SQLite, the database a new Django project is configured to use by default and which is included with Python. Chapter 32 moves Otahque to PostgreSQL.
- Static files are the stylesheets, images, and scripts that are the same for every visitor. The application delivers them alongside its pages in this first sketch; production hosting may serve them differently, a decision for Chapter 63.

Name each connection. Between the browser and the application travel the HTTPS requests and responses from Chapter 3. Between the application and the database travel queries made through Django’s models; the browser never connects to the database directly. Other routes, such as the admin site, maintenance commands, or background work, can also change records later, so every operation that changes a registration must apply the relevant rules.
Then mark where trust changes. A trust boundary is a line in a design where data passes between parts under different control. Everything arriving from a browser crosses one: form fields, addresses, cookies, and headers can be changed by whoever controls the browser. The application must treat that data as untrusted input and check it before relying on it. The database sits inside the boundary because only our application connects to it, but its contents are still text from people, which is why templates escape it when it is displayed.
Que. 9 Sai changes the event number in a registration form before submitting it. Which side of the trust boundary is that change on, and what should happen?
Flip to check your answerFold answer back
Answer. The browser side: everything in the submitted form is untrusted input. The application must check the requested event like any other: that it exists and is published, that registration is open and a place remains, and that Sai has no active registration for it. Editing the form changes what is requested, not what is allowed.
Finally, say what the sketch leaves out. This one leaves out email delivery (Chapter 43), background tasks (Chapter 44), an application programming interface, or API, through which other software could use Otahque (Chapters 47 to 54), and the production arrangement of servers, certificates, and backups (Chapters 62 and 63). It does not say how many copies of the application run or how much traffic they can serve.
Que. 10 Does the sketch show that Otahque can handle a busy event with hundreds of simultaneous registrations?
Flip to check your answerFold answer back
Answer. No. It shows parts and connections, not capacity. Chapter 2 left performance targets open until a workload is agreed, and Chapter 33 protects the last place with database transactions. A sketch can show where a check will run; only measurement and tests can show that it works.
In practice: onboarding with a design sketch
Situation. A new contributor wants to fix a bug and asks where to start reading.
Application. Walk through the sketch first: browser, application, database, and the trust boundary. Then point to where each request component lives in the project. The sketch tells them which part a bug report is likely to concern.
Consideration. Update the sketch when a chapter adds a part, such as email delivery. An out-of-date diagram misleads more than a missing one.
Try it yourself
Copy Figure 5.3 onto paper. Add one future part: reminder emails sent through an outside email service. Draw its connection, label what crosses it, and decide whether the connection crosses a trust boundary. Then name one Otahque rule that must still be applied inside the application rather than by the email service.
Que. 11 What should the extended sketch show?
Flip to check your answerFold answer back
Answer. Draw the email service outside the server-side boundary, with an arrow from the application labelled with what it sends: a recipient address, a subject, and the message. The service is an external system we do not control, so the connection crosses a trust boundary. The application should send only what the message needs and treat delivery as uncertain. The rule that stays inside the application is choosing recipients: only members with an active registration for that event receive a reminder. Reminders remain deferred from the first release.
Step 2: Compare the architecture choices
Sam asks a fair question: “Why build an application at all? A form and a spreadsheet already work for most of our events.” A volunteer suggests the opposite: a separate JavaScript application that talks to Django through an API. Both deserve a reasoned answer rather than an appeal to habit or popularity.
An architecture choice is a decision about a system’s main structure that would be expensive to change later. We judge it by the requirements it must serve and the constraints we work under, not by how fashionable a technology is. Our criteria come from earlier chapters. Organizers and attendees need one current registration record. Ownership and capacity rules must hold whatever a browser sends. The main journeys must work with a keyboard and on narrow screens. A small volunteer team, and a reader learning Django, must be able to build, test, and maintain the result. One constraint is fixed by the book itself: the application uses Django. The open question is its shape.
Option A keeps the simple workflow from Chapter 1: a hosted form and a spreadsheet, perhaps with automatic copying between them. There is no application code to write or host, but capacity and ownership depend on what the chosen tools allow. We have not evaluated a particular product, so the comparison describes the basic workflow rather than every hosted service.
Option B is a server-rendered Django application. Server-side rendering means producing complete HTML pages on the server, as traced in What You Need to Know, with a database behind the application. The rules run in one place, and pages work with ordinary links and forms. JavaScript can later improve particular interactions without becoming necessary, an approach called progressive enhancement that Chapter 45 develops.
Option C uses Django only to provide data through an API, while a separate JavaScript application builds the pages in the browser, which is called client-side rendering. It suits highly interactive screens and products with several kinds of client, such as a website and a mobile app. It also means two applications, an agreed data format between them, and pages that depend on JavaScript running correctly on each visitor’s device.
| Criterion | A: Form and spreadsheet | B: Server-rendered Django | C: API and JavaScript client |
|---|---|---|---|
| One current registration record | Partly: separate tools still need reconciling. | Yes: one database behind one application. | Yes: one database behind the API. |
| Ownership and capacity checked on the server | Depends on the tools; not shown for our rules. | In the views and models. | In the API; the client cannot be trusted to check. |
| Works with links, forms, and a keyboard | Depends on the tools. | Yes, before any added JavaScript. | Depends on the client code working. |
| Parts to build, test, and host | Configuration only. | One application and a database. | Two applications, an API, and a database. |
| API for other software | Depends on the tools. | Can be added later (Ch. 47–54). | Available from the start. |
The table does not award points, because its rows are not equally important. The first two rows are requirements; the last is not, because nothing in the first release’s scope needs other software to use Otahque. Option A, in the basic form described here, has not shown that it meets the first two requirements, which is the problem that started the book; it remains a sensible choice for a community without that problem. Options B and C can both satisfy the essential rules if built carefully. Option B does so with fewer moving parts, and its pages work before any JavaScript runs. Option C pays now for capabilities the first release does not need and doubles the places where a beginner must keep data formats in step.
Option B has limits too. Without enhancement, each action loads a new page, and a highly interactive feature, such as a live seating map, would need extra work. Choosing B now does not rule out an API: Chapters 47 to 54 add one while the HTML pages remain.
Que. 12 Is “most new websites use a JavaScript framework” a good reason to choose Option C?
Flip to check your answerFold answer back
Answer. No. It describes other projects, not ours. A reason must connect to our requirements or constraints, such as a need for an app that works offline. If a requirement like that appears, it becomes part of the context for a new decision.
Que. 13 Option A needs the least coding effort at the start. Why is it not chosen?
Flip to check your answerFold answer back
Answer. Because, in the basic form we described, it has not shown that it meets an essential requirement: one current registration record with capacity and ownership enforced. Less coding at the start is not the same as lower total cost, which also includes reconciling records and handling mistakes. Effort and cost decide only between options that meet the requirements.
Try it yourself
A new requirement is proposed: organizers must be able to check attendees in at the venue on a phone with a poor signal. Add it to Table 5.3 as a criterion. For each option, write a short note on how it might cope. Then say whether the new requirement changes the decision for the first release.
Que. 14 How might the options cope, and does the decision change?
Flip to check your answerFold answer back
Answer. The new criterion is working with an unreliable connection. A: depends on whether the form tool works offline, and its records still need reconciling later. B: each page needs a connection, so a poor signal means slow or failed requests; offline support would need extra work. C: a client application can store check-ins and send them later, at the cost of handling duplicated or conflicting records. Check-in is deferred from the first release, so the decision stands; the requirement should prompt a review when check-in is planned in Chapter 46.
Step 3: Record the decision
In a year, someone will ask why Otahque renders its pages on the server. The volunteers who compared the options may have moved on. A short written record keeps the reasoning available. An architecture decision record, or ADR, is a short document that captures one significant decision, the situation that led to it, and its consequences. Michael Nygard proposed the form in 2011 so that teams would stop losing the reasons behind their designs. A record is usually a page or two, numbered in sequence, and kept with the project’s code.
A useful ADR states a title that names the decision; its status; the context, meaning the requirements, constraints, and pressures at the time; the options considered; the decision; its consequences, both helpful and costly; and the changes that would justify revisiting it. It summarizes the comparison and points to where the detail lives.
The status tells a reader whether to rely on the record. A proposed record is written for review and not yet agreed. An accepted record has been agreed by the people responsible. A rejected record was considered and not adopted; keeping it saves repeating the discussion. A superseded record has been replaced by a later one that links back to it. An accepted record is not rewritten to match a later choice; a new record supersedes it, so the history of the design stays visible.

Que. 15 The team later adds an API so that a partner’s app can list Otahque events. Should they edit the accepted record for the first release so that it seems to have included an API all along?
Flip to check your answerFold answer back
Answer. No. Write a new record for the API decision and link it to the earlier one. If the new decision replaces the old one, mark the old record superseded. If it adds to it, as the planned API in Chapters 47 to 54 would, both records remain valid. Editing the old record would erase the reasoning a future reader needs.
Table 5.4 is our draft. As the project’s first decision record, it is numbered ADR-001. Its status is proposed, because no one responsible for a real Otahque project has reviewed it, and this book does not invent an approval. The following chapters build on this proposal as the working design; if review changes it, a new record will say so.
| Part | Content |
|---|---|
| Status | Proposed, October 2026. Not yet reviewed or accepted. |
| Context | Organizers and attendees need one current registration record. Ownership and capacity rules must hold whatever a browser sends. Main journeys must work with a keyboard and on narrow screens. A small volunteer team must be able to build and maintain the application, and the book’s readers are learning Django. |
| Options | A: connected form and spreadsheet. B: a server-rendered Django application with a database. C: a Django API with a separate JavaScript client. Compared in Table 5.3. |
| Decision | Build the first release as one Django application that renders HTML pages on the server, stores records in a relational database, and applies Otahque’s rules in its views and models. |
| Consequences | One application to build, test, and host. Rules run in one place. Pages work with links and forms before any JavaScript. Highly interactive screens need extra work, and other software has no API until one is added. |
| Revisit if | A mobile or partner application needs Otahque’s data; check-in or other work must continue offline; measurement shows that server rendering cannot meet an agreed performance target. |
| Related | BR-1 to BR-3 and PR-1 to PR-6 (Chapter 2); the high-level sketch in Figure 5.3. |
Notice what the record does not decide: which database runs in production, how the application is hosted, or how pages are styled. Each is a separate decision, recorded when its chapter needs it. One decision per record keeps each record short, reviewable, and easy to supersede. Once the project exists, keep decision records as numbered Markdown files in a folder such as docs/adr/ inside the repository, so that they are versioned with the code; Chapter 8 introduces Git for that purpose.
For you as a reader, the decision means that you begin with one Django project and follow an event request through Python code to a complete HTML page, learning routing, views, templates, and stored records one step at a time, without first building a separate JavaScript application.
In practice: making a disagreement reviewable
Situation. Two contributors disagree about rebuilding the event list with client-side rendering.
Application. Ask the proposer to write a short decision record: context, options, and consequences. The disagreement becomes specific: which requirement does the change serve, and what does it cost?
Consideration. Writing the record does not settle the question. Someone responsible for the project still has to accept or reject it, and the status should say which.
When something goes wrong
Revise a copy of each artefact and keep the first version beside it. Table 5.5 lists the problems these documents most often have.
| Problem | Check | Recovery |
|---|---|---|
| A product rule is credited to Django | Is it a mechanism the framework supplies, or a result Otahque must guarantee? | Move the rule to the Otahque column, and name the check that will prove it. |
| The sketch has a connection with no label | What travels along it, and who controls each end? | Label it, and mark a trust boundary where control changes. |
| An option is rejected by preference | Which requirement or constraint does it fail? | State the criterion; if there is none, keep the option open. |
| The record reads as approved | Has anyone responsible accepted it? | Set its status to Proposed until someone does. |
Found an error or something unclear? Report an issue with this chapter (GitHub, opens in a new tab)
PAGE 003Verify Your Work
There is no code to test in this chapter. Check your paper artefacts against Table 5.6 instead. Each one should be specific enough that someone else could review it.
| Check | What to look at | Expected result |
|---|---|---|
| Responsibility map | Your version of Table 5.1 | Each need has a framework part and an Otahque rule, and they are different |
| Request trace | Your Raj trace | URL configuration, view, model, template, and response each have one job; the view checks ownership |
| Design sketch | Your copy of Figure 5.3 | Browser, application, and database, with labelled connections and a trust boundary |
| Omissions | Under your sketch | Email, background tasks, an API, and hosting are named as left out |
| Comparison | Your Table 5.3 | Options judged against requirements, with costs and limits stated |
| Decision record | Your ADR-001 | Title, status proposed, context, options, decision, consequences, and revisit conditions |
If any artefact merely restates a technology name, such as “Django handles it”, add the rule or reason it stands for.
Found an error or something unclear? Report an issue with this chapter (GitHub, opens in a new tab)
PAGE 004Checkpoint: Quiz and Challenge
Quiz
Que. 16 Name one thing Django supplies and one thing Otahque must decide for the event page.
Flip to check your answerFold answer back
Answer. Django supplies a way to connect the address to a view and to build the page from a template. Otahque decides which event details this visitor may see, such as excluding an unpublished draft.
Que. 17 Which component chooses the view, and which decides whether event 42 is published?
Flip to check your answerFold answer back
Answer. The URL configuration chooses the view by matching the path. The view, with the model code it uses, decides whether event 42 is published.
Que. 18 What is a trust boundary, and where does the main one sit in Figure 5.3?
Flip to check your answerFold answer back
Answer. A line where data passes between parts under different control. The main one sits between the visitor’s browser and the server side: everything arriving from a browser is untrusted input.
Que. 19 Why does Table 5.3 not add up points for each option?
Flip to check your answerFold answer back
Answer. Its rows are not equally important. The first two are requirements an option must meet; the others only help choose between options that meet them.
Que. 20 What are the four statuses of a decision record?
Flip to check your answerFold answer back
Answer. Proposed, accepted, rejected, and superseded. An accepted record is never rewritten; a later record supersedes it and links back.
Mini-Challenge
On paper, write a second, smaller record: should Otahque show event dates and times in the event’s own timezone or in each visitor’s device timezone? Use the parts of Table 5.4. Base the context on Chapter 2’s expectation that times are clear wherever a person acts on them, give at least two options, and choose an honest status.
Que. 21 What would a useful practice record contain?
Flip to check your answerFold answer back
Answer. Title: show event times in the event’s stated timezone. Status: proposed, because nobody responsible has accepted it. Context: Chapter 2 requires a date and timezone wherever a person acts on a time; members may view from devices set to other timezones; a deadline must refer to one instant. Options: the event’s timezone, always labelled; the visitor’s device timezone, converted; or both together. Decision: show the event’s timezone, labelled, everywhere, and consider adding the visitor’s local time later. Consequences: organizers and attendees share one unambiguous time; a remote attendee must convert it until a local equivalent is added. Revisit if: online events with attendees in many timezones become common. Another decision is acceptable if its context and consequences support it.
What We Learned
- Django supplies reusable web mechanisms; Otahque’s rules, such as who may see or change an event, remain ours to implement and test.
- A request passes through middleware, the URL configuration, a view, and often a model and a template, before the view’s response returns.
- Rules belong in views and models; templates only display the result of decisions.
- A high-level sketch names the running parts, their connections, the trust boundary, and what it leaves out.
- Architecture options are compared against requirements and constraints, not popularity, and the comparison states each option’s costs.
- ADR-001 records the proposal for a server-rendered Django application, with its context, consequences, and conditions for revisiting it.
Key terms
Use Table 5.7 to check the vocabulary from this chapter before Chapter 6.
| Term | Meaning in this book |
|---|---|
| Web framework | Reusable software that supplies structure and tools for building web applications. |
| Convention | An agreed way of arranging or naming things so that parts work together predictably. |
| URL configuration (URLconf) | Django’s ordered list of address patterns, each connected to a view. |
| View | A Python function or class that receives a request and returns a response. |
| Model | A Python class that describes one kind of stored record and how to query it. |
| Template | A text file, usually HTML, with places where supplied values are inserted. |
| Middleware | Shared steps that process requests on the way in and responses on the way out; a step may return a response before the view runs. |
| High-level design (HLD) | A system’s main parts, their connections, and where responsibility and trust change. |
| Container (C4 model) | An application or data store that must be running for the system to work. |
| Trust boundary | A line where data passes between parts under different control. |
| Server-side rendering | Producing complete HTML pages on the server. |
| Client-side rendering | Building pages in the browser with JavaScript, usually from API data. |
| API | Application programming interface: a way for other software to use an application. |
| Architecture decision record (ADR) | A short record of one significant decision, its context, options, consequences, and status. |
| Proposed, accepted, rejected, superseded | The statuses that tell a reader whether to rely on a decision record. |
Readiness checkpoint: without looking back, trace a request for an event page through Django’s components and name each one’s job; draw the three-part sketch with its trust boundary; explain why Option B was proposed over Options A and C; and list the parts of a decision record and its four statuses. If one of these is difficult, return to that step’s exercise and model answer.
Git Commit
There is nothing to commit yet: no project exists until Chapter 6, and Git is set up for it in Chapter 8. Keep your paper ADR-001; once the repository exists, it belongs in docs/adr/ as the project’s first committed decision.
Found an error or something unclear? Report an issue with this chapter (GitHub, opens in a new tab)
PAGE 005Test Your Knowledge: Interview Questions
These five questions rehearse the chapter at interview level, one at each of five levels from junior to lead. L1 and L2 check what you have just learned. L3 asks how it works underneath. L4 and L5 ask about the design and leadership decisions that later chapters build on: attempt them now, and return to them when you reach those chapters. Django is not installed until Chapter 6, so the code proofs here are for you to run once it is. Use the readiness checkpoint to decide whether to continue. If an answer is difficult, revisit its worked example and explain the result in your own words. L4 and L5 are extension questions, not a gate to the next chapter.
L1 (Junior): What does Django provide, and what must Otahque’s own code still decide?
What the interviewer is testing: Can you separate a framework’s mechanisms from a product’s rules?
Flip to check your answerFold answer back
Perfect answer: Django provides common web mechanisms: matching addresses to views, request and response objects, templates that escape inserted values, models and queries for the database, forms and validation, accounts and sessions, an administration site, protections such as defence against cross-site request forgery, and a development server. It does not know Otahque’s rules: who may register, how many places an event has, when registration closes, or what cancelling releases. Our code expresses those rules using Django’s tools.
| Area | Django supplies | Otahque decides |
|---|---|---|
| Addresses | Matching /events/42/ to a view | Which events a visitor may see |
| Records | Models and queries | What makes a registration valid |
| Accounts | Who is signed in | Who may edit this event |
| Forms | Parsing and validating input | When registration is open |
| Security | CSRF protection, escaping | That every route applies the rules |
Behind the scenes:
# Django: calls the view and passes the captured event number.
# Otahque: decides what the response may contain, for example
# events = Event.objects.filter(status='published')
# Chapter 16 defines the model; Chapter 19 writes the query.Evidence: Table 5.1 and Figure 5.1 show the split for each first-release need.
Common mistakes:
- “Django handles security, so we need not think about it.”
- Expecting the framework to define product behaviour.
- Treating a hidden button as an enforced permission.
Follow-up the interviewer might ask:
- “Name a rule that Django cannot enforce for you.”
- “Which Django feature saves Otahque the most work?”
L2 (Mid-Level): Trace a request for /events/42/ through Django.
What the interviewer is testing: Can you name each component a request meets and what each one is responsible for?
Flip to check your answerFold answer back

Perfect answer: The request first passes through middleware, the shared steps every request takes. The URL configuration compares the path with its patterns in order and calls the matching view with 42. The view asks the model for event 42 and checks that it is published; the model queries the database. The view passes the event to a template, which produces the HTML, and returns a response with status 200. The response passes back through middleware on its way to the browser. If no pattern matches, Django returns 404 Not Found, and the view itself decides what to return when the event cannot be shown.
Behind the scenes:
# get_response(request) runs the middleware chain, then
# _get_response(request):
# callback, args, kwargs = self.resolve_request(request)
# response = callback(request, *args, **kwargs)
# resolve_request() asks the URL resolver for the first match.Code proof (after Chapter 6): the new project’s only route is the admin, so /events/42/ matches nothing yet. In PowerShell, a macOS shell, or Linux/WSL Bash, beside manage.py:
uv run --no-project --python .venv python manage.py shell -c "
from django.urls import resolve, Resolver404
print(resolve('/admin/').view_name)
try:
resolve('/events/42/')
except Resolver404:
print('no pattern matches /events/42/')"12 objects imported automatically (use -v 2 for details).
admin:index
no pattern matches /events/42/Common mistakes:
- Saying that the template fetches the data.
- Forgetting that middleware also handles the response.
- Assuming every view uses a model and a template.
Follow-up the interviewer might ask:
- “Where would you check that event 42 is published?”
- “What happens when no URL pattern matches?”
L3 (Senior): Django describes itself as model, template, view rather than model, view, controller. What do the parts mean, and where is the controller?
What the interviewer is testing: Do you know how responsibilities are divided, rather than only the labels?
Flip to check your answerFold answer back

Perfect answer: The model describes stored records and their rules. The template describes presentation. Django’s view decides which data is presented and returns the response, so it is not the presentation layer that MVC calls a view. Django’s own FAQ suggests that the controller is the framework itself: the machinery that sends each request to the right view according to the URL configuration. What matters is that each kind of decision has one home: rules with models and views, presentation in templates.
Behind the scenes:
# model: "an event's capacity can never be below zero"
# view: "this public page shows published events only"
# template: "show the date in the event's own timezone"
# routing: "/events/<number>/ goes to the event view"Evidence: Table 5.2 assigns each part one job, and the “Prefer the model, view, controller names?” callout explains the naming.
Common mistakes:
- Mapping Django’s view onto MVC’s view.
- Putting business rules in templates.
- Arguing about labels instead of responsibilities.
Follow-up the interviewer might ask:
- “Where should the capacity rule live: the view, the model, or the template?”
- “What goes wrong when templates start making decisions?”
L4 (Staff): Compare server-rendered pages with a separate JavaScript application and an API for Otahque’s first release. Defend a choice.
What the interviewer is testing: Can you weigh options against requirements and constraints instead of fashion?
Flip to check your answerFold answer back

Perfect answer: Server-rendered pages give one application to build, test, and host, keep the rules in one place, and work with ordinary links and forms before any JavaScript, which helps keyboard and narrow-screen use. A separate JavaScript application with an API allows richer interaction, offline work, and reuse by mobile apps, but adds a second codebase, an API to design and secure, and more for a small volunteer team to learn. For the first release’s requirements, server rendering fits better, as ADR-001 proposes. Record when to revisit: a partner or mobile application needs the data, work must continue offline, or measurements miss an agreed performance target.
Behind the scenes:
# must meet: one current record; rules enforced on server
# A form + spreadsheet -> not shown
# B server-rendered -> yes, one application
# C API + JS client -> yes, two applications
# then cost: B has fewer parts for a small teamEvidence: Table 5.3 and the consequences row of Table 5.4.
Common mistakes:
- Choosing by popularity.
- Claiming server-rendered pages can never be interactive.
- Ignoring the team’s skills and the cost of maintenance.
Follow-up the interviewer might ask:
- “What evidence would make you revisit the decision?”
- “How could you add an API later without rewriting the application?”
L5 (Lead): How do you use architecture decision records across a team, and what makes one useful a year later?
What the interviewer is testing: Can you make decisions reviewable and durable, and lead the habit?
Flip to check your answerFold answer back

Perfect answer: Write a record when a decision is significant and costly to reverse. Keep it short: title, status, context, options, decision, consequences, and when to revisit. Store records as numbered files beside the code and review them as you would review code. The status tells readers whether to rely on a record. Never rewrite an accepted record; write a new one that supersedes it and links back. A record is useful a year later because it keeps the context and the options not chosen, so a newcomer understands why the decision was made and can tell when it should be reopened. A lead makes this the normal way to settle significant disagreements and names who accepts each record.
Behind the scenes:
# ADR-001: Build the first release as a server-rendered
# Django application
Status: Proposed
Context: ... Options: A, B, C (Table 5.3)
Decision: ... Consequences: ...
Revisit if: ... Supersedes: noneEvidence: ADR-001 in Table 5.4 and the status flow in Figure 5.4.
Common mistakes:
- Writing records afterwards to justify a decision.
- Recording the decision without the options.
- Editing an accepted record, or writing records for trivial choices.
Follow-up the interviewer might ask:
- “Who should accept a decision record?”
- “How would you notice that a record’s revisit condition has been met?”
Next: Chapter 6 creates the Otahque project and opens Django’s development page in your browser, your first running result.
Found an error or something unclear? Report an issue with this chapter (GitHub, opens in a new tab)
PAGE 006Found an error or something unclear? Report an issue with this chapter (GitHub, opens in a new tab)