Master

The project structure is the contract

A server that grows keeps its routes in one place and its logic in another. The structure is what makes the two findable, and findable is what makes a large server reviewable.

What you will see

3. Three reads is the whole review, and three is small enough to be a rule.

About 1 min of reading

Try It

Check the table against the files

1

Write the table and the files

printf 'ping\nping_body\nhealth\n' > /tmp/t.txt; printf 'ping\nhealth\n' > /tmp/files.txt; comm -23 <(sort -u /tmp/t.txt) <(sort -u /tmp/files.txt)

Before you run it, say out loud what it will print. Then open the answer.

What it prints
ping_body. A name in the table with no file is a route that does not exist.
2

Write the shared declaration

printf 'counter writers=1 mechanism=atomic\n' > /tmp/s.txt; grep -c writers /tmp/s.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
1. One declaration for the value, which is the rule.
3

Count the reads of a review

printf 'table\nhandler\nlogic\n' > /tmp/r.txt; wc -l < /tmp/r.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
3. Three reads is the whole review, and three is small enough to be a rule.

Data Flow

A large server to three reads
1 The route table is read
↓
2 The handler is read for its shape
↓
3 The logic is read for its rules
↓
4 The shared declaration is checked against uses
Why this works
Why the shared state is declared once

One place declares what is shared and how many writers it has. A declaration per use is a claim that will disagree with itself.

The shape of a review

The table, then the handler, then the logic. Three reads, and the three reads are the whole review.

Examples

One file per route

The route table is the index. An index that lists every file is a structure that cannot hide a route.

Logic has no HTTP in it

The logic takes a value and returns a value. The handler is the only place that speaks bytes.

Why the split is not style

The logic is tested without a server. A test that needs a server is a test that tests the transport.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Profiling a server
Previous Lesson
Profiling a server
Next Lesson
Testing a server without a client
Testing a server without a client →