Project Workshop — Library Management System
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important…
- What you are building
- Architecture
- Acceptance criteria
- Suggested repository structure
- Build plan: vertical slices
Python · OOP · dataclasses
Expected effort: 5–8 focused hours · Minimum meaningful tests: 12What you are building
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important design decision from the README.
Architecture
Critical interaction
Ownership table
| Boundary | Owns | Must not own |
|---|---|---|
| Interface | Parsing, protocol validation, identity extraction, status or presentation mapping | Core business invariants |
| Application/domain | Authorization inputs, state transitions, orchestration, transaction intent | Framework globals or raw transport objects |
| Repository/gateway | One persistence or external protocol, bounded retries, error translation | Product policy |
| Background/UI projection | Recoverable derived state and delivery progress | Hidden authoritative truth |
| Operations | Configuration, health, deployment, telemetry, recovery | Business decisions encoded only in dashboards |
Acceptance criteria
| ID | Required behavior | Evidence |
|---|---|---|
| AC-1.1 | __init__ and self produces the specified behavior inside Classes & objects | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.2 | instance vs class vs static attributes produces the specified behavior inside Classes & objects | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.3 | @classmethod and @staticmethod produces the specified behavior inside Classes & objects | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.4 | __repr__ vs __str__ produces the specified behavior inside Classes & objects | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.1 | single and multiple inheritance produces the specified behavior inside Inheritance & polymorphism | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.2 | MRO (Method Resolution Order) produces the specified behavior inside Inheritance & polymorphism | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.3 | super() usage produces the specified behavior inside Inheritance & polymorphism | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.4 | method overriding produces the specified behavior inside Inheritance & polymorphism | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.5 | duck typing produces the specified behavior inside Inheritance & polymorphism | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.1 | __len__/__getitem__/__setitem__ produces the specified behavior inside Dunder methods | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.2 | __eq__/__lt__/__gt__ for comparison produces the specified behavior inside Dunder methods | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.3 | __enter__/__exit__ for context managers produces the specified behavior inside Dunder methods | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.4 | __call__ and __slots__ produces the specified behavior inside Dunder methods | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.1 | @dataclass decorator produces the specified behavior inside Dataclasses | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.2 | field() with validators produces the specified behavior inside Dataclasses | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.3 | frozen=True for immutability produces the specified behavior inside Dataclasses | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.4 | nested dataclasses produces the specified behavior inside Dataclasses | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.1 | abc module and ABC produces the specified behavior inside Abstract Base Classes | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.2 | @abstractmethod produces the specified behavior inside Abstract Base Classes | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.3 | Protocol (structural subtyping, 3.8+) produces the specified behavior inside Abstract Base Classes | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
Suggested repository structure
1project/2├── src/3│ ├── __init__.py4│ ├── cli.py5│ ├── models.py6│ ├── services.py7│ ├── repository.py8│ └── errors.py9├── tests/{test_cli.py,test_services.py,test_repository.py}10├── pyproject.toml11├── README.md12└── .gitignoreBuild plan: vertical slices
| Milestone | Capability | First implementation | Exit condition |
|---|---|---|---|
| 1 | Classes & objects | __init__ and self; instance vs class vs static attributes; @classmethod and @staticmethod | Demonstration plus focused tests |
| 2 | Inheritance & polymorphism | single and multiple inheritance; MRO (Method Resolution Order); super() usage | Demonstration plus focused tests |
| 3 | Dunder methods | __len__/__getitem__/__setitem__; __eq__/__lt__/__gt__ for comparison; __enter__/__exit__ for context managers | Demonstration plus focused tests |
| 4 | Dataclasses | @dataclass decorator; field() with validators; frozen=True for immutability | Demonstration plus focused tests |
| 5 | Abstract Base Classes | abc module and ABC; @abstractmethod; Protocol (structural subtyping, 3.8+) | Demonstration plus focused tests |
| 6 | Hardening and delivery | Security, recovery, telemetry, performance, documentation | Full acceptance suite and recorded demonstration |
For each milestone, first create a failing acceptance test or a reproducible command. Implement the thinnest path to an observable result, add the nearest durable invariant, inject one expected failure, and refactor only after evidence protects the behavior.
Reference vertical slice
1from dataclasses import dataclass, field2from datetime import date, timedelta3from typing import Protocol4
5class FinePolicy(Protocol):6 def amount(self, due: date, returned: date) -> int: ...7
8@dataclass(frozen=True, slots=True)9class Book:10 isbn: str11 title: str12
13@dataclass(slots=True)14class Loan:15 book: Book16 issued_on: date17 due_on: date = field(init=False)18
19 def __post_init__(self) -> None:20 self.due_on = self.issued_on + timedelta(days=14)21
22 def __str__(self) -> str:23 return f"{self.book.title} due {self.due_on:%Y-%m-%d}"24
25print(Loan(Book("978-1", "Python Internals"), date(2026, 8, 28)))Expected result
1Python Internals due 2026-09-11Code reading
| Line | Code | Explanation |
|---|---|---|
| 1 | from dataclasses import dataclass, field | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 2 | from datetime import date, timedelta | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 3 | from typing import Protocol | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 5 | class FinePolicy(Protocol): | Creates a class namespace and binds the resulting class object to this name. |
| 6 | def amount(self, due: date, returned: date) -> int: ... | Defines a function; its parameters form the explicit input boundary. |
| 8 | @dataclass(frozen=True, slots=True) | Applies a decorator or framework annotation before the following definition is bound. |
| 9 | class Book: | Creates a class namespace and binds the resulting class object to this name. |
| 10 | isbn: str | Implements the next python statement in the example's data flow. |
| 11 | title: str | Implements the next python statement in the example's data flow. |
| 13 | @dataclass(slots=True) | Applies a decorator or framework annotation before the following definition is bound. |
| 14 | class Loan: | Creates a class namespace and binds the resulting class object to this name. |
| 15 | book: Book | Implements the next python statement in the example's data flow. |
| 16 | issued_on: date | Implements the next python statement in the example's data flow. |
| 17 | due_on: date = field(init=False) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 19 | def __post_init__(self) -> None: | Defines a function; its parameters form the explicit input boundary. |
| 20 | self.due_on = self.issued_on + timedelta(days=14) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 22 | def __str__(self) -> str: | Defines a function; its parameters form the explicit input boundary. |
| 23 | return f"{self.book.title} due {self.due_on:%Y-%m-%d}" | Returns the observable result to the caller and ends this invocation. |
| 25 | print(Loan(Book("978-1", "Python Internals"), date(2026, 8, 28))) | Emits the example's observable output. |
Risk register
| Area | Failure to reproduce | Required design response |
|---|---|---|
| Classes & objects | Including tokens, passwords, or personal data in either representation leaks them into logs and tracebacks. | Make repr identify the type and important fields while redacting secrets; keep str concise and domain-friendly. |
| Inheritance & polymorphism | Direct parent calls break cooperative MRO and deep hierarchies create fragile coupling. | Prefer composition or small protocols; use inheritance for a genuine substitutable abstraction. |
| Dunder methods | Slots complicate multiple inheritance, weak references, serialization, and migrations; they are not a universal speed switch. | Use callable objects for configured strategies with inspectable state and slots only after memory profiling or to enforce a closed attribute set. |
| Dataclasses | Use default_factory for mutable defaults and validate nested mutable state. | Use it for explicit records and domain values with validation in __post_init__. |
| Abstract Base Classes | Direct parent calls break cooperative MRO and deep hierarchies create fragile coupling. | Prefer composition or small protocols; use inheritance for a genuine substitutable abstraction. |
Engineering checklist for this stack
- To do: validate CLI inputs before domain operations
- To do: use explicit exit codes and deterministic output
- To do: close files, sessions, and network clients
- To do: separate domain logic from input/printing
- To do: measure large-input memory behavior
Test strategy
Implement at least 12 meaningful cases. A long list of shallow happy-path tests does not satisfy the requirement.
| Risk class | Minimum | Examples |
|---|---|---|
| Happy path and contract | 2 | Correct output, status/schema, durable state |
| Validation and boundaries | 2 | Empty, malformed, extreme, unsupported transition |
| Authorization or trust boundary | 1 | Missing identity, wrong tenant/role, injection or unsafe content |
| Failure and recovery | 2 | Timeout, retry, rollback, reconnect, dependency outage |
| Duplicate or concurrency | 1 | Same identity twice, racing update, redelivery |
| Performance and operations | 4 | Query bound, lag, p95, resource limit, telemetry |
Representative test scaffold
1@pytest.mark.parametrize(2 ("value", "expected"),3 [("valid", "success"), ("", "validation-error"), ("duplicate", "same-result")],4)5def test_contract(value, expected, service):6 result = service.execute(value)7 assert result.status == expected8
9def test_failure_rolls_back(repository, service):10 repository.fail_next_write()11 with pytest.raises(RepositoryError):12 service.execute("valid")13 assert repository.visible_changes() == []Failure drills
- Stop the primary external dependency during the critical path. Capture the failure, cleanup, telemetry, and recovery.
- Repeat the same operation with the same stable identity. Prove one logical outcome or document why repetition is forbidden.
- Crash after durable state changes but before the response, acknowledgement, or projection. Re-run and reconcile.
- Submit the largest supported input and one slightly larger input.
- Remove one permission and prove denial without state change or information leakage.
- Roll back the change or restore the dependency, then run a smoke test and reconciliation check.
Performance experiment
State the dataset, payload distribution, concurrency, rate, duration, cache state, and resource limits before measuring. Publish p50, p95, p99, throughput, error rate, and the technology-specific correctness signal such as query count, consumer lag, duplicate effects, rendered updates, token cost, or recall. Change one variable at a time and retain raw output.
Submission package
- Complete source with a locked/reproducible environment.
- README.md with problem, architecture, setup, commands, configuration, assumptions, and trade-offs.
- Acceptance and risk-focused tests with a short explanation of what mocks intentionally do not cover.
- One design record explaining the most consequential choice and a rejected alternative.
- Security notes, sample non-secret configuration, and cleanup commands.
- A demonstration record: terminal transcript, screenshots, trace, query plan, or metrics dashboard.
- A 5–8 minute walkthrough following input → validation → state → failure → evidence.
Grading rubric
| Dimension | Weight | Full-credit evidence |
|---|---|---|
| Product behavior | 25 | Acceptance criteria pass through real public boundaries |
| Architecture and ownership | 20 | Responsibilities and state authority are explicit |
| Tests and recovery | 20 | Important negative, duplicate, concurrent, and outage cases pass |
| Security and data correctness | 15 | Least privilege, validation, constraints, and secret handling are demonstrated |
| Performance and operations | 10 | Reproducible measurement, useful telemetry, and rollback/recovery |
| Documentation and explanation | 10 | A new reviewer can reproduce and defend the result |
Mastery check
How well can you recall this?
Finished this lesson?