Project Workshop — Dual-Interface Product Service
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
Django · FastAPI · GraphQL · PostgreSQL · WebSockets · pytest
Expected effort: 35–56 focused hours · Minimum meaningful tests: 24What 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 | REST resources vs GraphQL graph produces the specified behavior inside Interface selection | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.2 | request-response vs WebSocket push produces the specified behavior inside Interface selection | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.3 | Django vs FastAPI trade-offs produces the specified behavior inside Interface selection | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.4 | versioning and compatibility produces the specified behavior inside Interface selection | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.1 | transport-independent service layer produces the specified behavior inside Shared domain architecture | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.2 | Pydantic/serializer/domain model boundaries produces the specified behavior inside Shared domain architecture | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.3 | transaction and repository ownership produces the specified behavior inside Shared domain architecture | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.4 | consistent authentication and object authorization produces the specified behavior inside Shared domain architecture | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.1 | OpenAPI and GraphQL schema checks produces the specified behavior inside Contract verification | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.2 | consumer-driven contract tests produces the specified behavior inside Contract verification | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.3 | integration test database lifecycle produces the specified behavior inside Contract verification | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.4 | performance and security baseline produces the specified behavior inside Contract verification | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
Suggested repository structure
1project/2├── manage.py3├── config/{settings,urls,asgi,celery}.py4├── domain/5│ ├── models.py6│ ├── services.py7│ ├── selectors.py8│ ├── serializers-or-schema.py9│ ├── views-or-resolvers.py10│ ├── permissions.py11│ ├── tasks.py12│ └── consumers.py13├── templates/14├── tests/{unit,api,integration}/15├── pyproject.toml16└── compose.yamlBuild plan: vertical slices
| Milestone | Capability | First implementation | Exit condition |
|---|---|---|---|
| 1 | Interface selection | REST resources vs GraphQL graph; request-response vs WebSocket push; Django vs FastAPI trade-offs | Demonstration plus focused tests |
| 2 | Shared domain architecture | transport-independent service layer; Pydantic/serializer/domain model boundaries; transaction and repository ownership | Demonstration plus focused tests |
| 3 | Contract verification | OpenAPI and GraphQL schema checks; consumer-driven contract tests; integration test database lifecycle | Demonstration plus focused tests |
| 4 | 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 dataclass2
3@dataclass(frozen=True)4class CreateProduct:5 name: str6 price_cents: int7
8class ProductService:9 def __init__(self, repository):10 self.repository = repository11
12 def create(self, command: CreateProduct, actor) -> dict:13 if not actor.can('product:create'):14 raise PermissionError('product:create required')15 name = command.name.strip()16 if not name or command.price_cents <= 0:17 raise ValueError('valid name and positive price required')18 return self.repository.create(name=name, price_cents=command.price_cents)19
20# REST and GraphQL adapters both construct CreateProduct and call this service.Expected result
1Every interface reaches the same authorization and validation rules; protocol adapters only translate input and output.Code reading
| Line | Code | Explanation |
|---|---|---|
| 1 | from dataclasses import dataclass | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 3 | @dataclass(frozen=True) | Applies a decorator or framework annotation before the following definition is bound. |
| 4 | class CreateProduct: | Creates a class namespace and binds the resulting class object to this name. |
| 5 | name: str | Implements the next python statement in the example's data flow. |
| 6 | price_cents: int | Implements the next python statement in the example's data flow. |
| 8 | class ProductService: | Creates a class namespace and binds the resulting class object to this name. |
| 9 | def __init__(self, repository): | Defines a function; its parameters form the explicit input boundary. |
| 10 | self.repository = repository | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 12 | def create(self, command: CreateProduct, actor) -> dict: | Defines a function; its parameters form the explicit input boundary. |
| 13 | if not actor.can('product:create'): | Evaluates the condition and enters this branch only when it is truthy. |
| 14 | raise PermissionError('product:create required') | Stops the happy path with a deliberate exception carrying the boundary failure. |
| 15 | name = command.name.strip() | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 16 | if not name or command.price_cents <= 0: | Evaluates the condition and enters this branch only when it is truthy. |
| 17 | raise ValueError('valid name and positive price required') | Stops the happy path with a deliberate exception carrying the boundary failure. |
| 18 | return self.repository.create(name=name, price_cents=command.price_cents) | Returns the observable result to the caller and ends this invocation. |
| 20 | # REST and GraphQL adapters both construct CreateProduct and call this service. | Implements the next python statement in the example's data flow. |
Risk register
| Area | Failure to reproduce | Required design response |
|---|---|---|
| Interface selection | Changing meaning without changing a field name is still a breaking semantic change. | Add optional fields with defaults and test producer-consumer compatibility in CI. |
| Shared domain architecture | Checking only roles, hiding UI controls, or filtering in one adapter lets another interface expose the protected object. | Use one shared policy vocabulary and negative contract tests through REST, GraphQL, and WebSocket entry points. |
| Contract verification | A headline average without dataset, percentiles, warm-up, resource limits, authorization cases, or error rate cannot serve as a release gate. | Set budgets for critical endpoints and contracts, retain raw results by commit, and investigate statistically meaningful regressions rather than one local run. |
Engineering checklist for this stack
- To do: authenticate before object lookup where possible
- To do: authorize the action and object server-side
- To do: keep transactions in the application service
- To do: bound request, response, and query work
- To do: map typed domain failures to stable protocol errors
Test strategy
Implement at least 24 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 | 16 | Query bound, lag, p95, resource limit, telemetry |
Representative test scaffold
1def test_private_field_requires_owner(graphql_client, user, other_user, private_post):2 graphql_client.force_login(other_user)3 response = graphql_client.execute(4 "query($id: ID!) { post(id: $id) { id privateNotes } }",5 variables={"id": str(private_post.id)},6 )7 assert response["data"]["post"]["privateNotes"] is None8 assert response["errors"][0]["extensions"]["code"] == "FORBIDDEN"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?