Project Workshop — Task Management REST API
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 · DRF · JWT · PostgreSQL
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 | Serializer vs ModelSerializer produces the specified behavior inside Serializers | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.2 | field-level and object-level validation produces the specified behavior inside Serializers | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.3 | nested serializers (read vs write) produces the specified behavior inside Serializers | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.4 | SerializerMethodField produces the specified behavior inside Serializers | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.1 | APIView manual method handling produces the specified behavior inside APIView vs ViewSets | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.2 | GenericAPIView + mixins produces the specified behavior inside APIView vs ViewSets | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.3 | ModelViewSet full CRUD produces the specified behavior inside APIView vs ViewSets | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.4 | @action decorator for custom endpoints produces the specified behavior inside APIView vs ViewSets | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.1 | JWT with djangorestframework-simplejwt produces the specified behavior inside Authentication & permissions | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.2 | access + refresh tokens produces the specified behavior inside Authentication & permissions | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.3 | IsAuthenticated/IsAdminUser/custom permission_classes produces the specified behavior inside Authentication & permissions | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.1 | AnonRateThrottle/UserRateThrottle/ScopedRateThrottle produces the specified behavior inside Throttling & pagination | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.2 | custom Redis throttle produces the specified behavior inside Throttling & pagination | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.3 | PageNumber/LimitOffset/CursorPagination produces the specified behavior inside Throttling & pagination | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.1 | DefaultRouter and SimpleRouter produces the specified behavior inside Routers & custom authentication | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.2 | writable nested create/update transactions produces the specified behavior inside Routers & custom authentication | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.3 | custom BaseAuthentication contract produces the specified behavior inside Routers & custom authentication | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.4 | authentication vs permission vs object permission produces the specified behavior inside Routers & custom authentication | 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 | Serializers | Serializer vs ModelSerializer; field-level and object-level validation; nested serializers (read vs write) | Demonstration plus focused tests |
| 2 | APIView vs ViewSets | APIView manual method handling; GenericAPIView + mixins; ModelViewSet full CRUD | Demonstration plus focused tests |
| 3 | Authentication & permissions | JWT with djangorestframework-simplejwt; access + refresh tokens; IsAuthenticated/IsAdminUser/custom permission_classes | Demonstration plus focused tests |
| 4 | Throttling & pagination | AnonRateThrottle/UserRateThrottle/ScopedRateThrottle; custom Redis throttle; PageNumber/LimitOffset/CursorPagination | Demonstration plus focused tests |
| 5 | Routers & custom authentication | DefaultRouter and SimpleRouter; writable nested create/update transactions; custom BaseAuthentication contract | 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 rest_framework import serializers, viewsets2from rest_framework.permissions import IsAuthenticated3
4class TaskWriteSerializer(serializers.ModelSerializer):5 class Meta:6 model = Task7 fields = ("id", "project", "title", "status")8 read_only_fields = ("id",)9
10 def validate_project(self, project):11 if not project.members.filter(pk=self.context["request"].user.pk).exists():12 raise serializers.ValidationError("not a project member")13 return project14
15class TaskViewSet(viewsets.ModelViewSet):16 serializer_class = TaskWriteSerializer17 permission_classes = (IsAuthenticated,)18
19 def get_queryset(self):20 return Task.objects.filter(project__members=self.request.user).select_related("project")Expected result
1Authenticated users see and mutate only tasks in projects where they are members.Code reading
| Line | Code | Explanation |
|---|---|---|
| 1 | from rest_framework import serializers, viewsets | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 2 | from rest_framework.permissions import IsAuthenticated | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 4 | class TaskWriteSerializer(serializers.ModelSerializer): | Creates a class namespace and binds the resulting class object to this name. |
| 5 | class Meta: | Creates a class namespace and binds the resulting class object to this name. |
| 6 | model = Task | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 7 | fields = ("id", "project", "title", "status") | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 8 | read_only_fields = ("id",) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 10 | def validate_project(self, project): | Defines a function; its parameters form the explicit input boundary. |
| 11 | if not project.members.filter(pk=self.context["request"].user.pk).exists(): | Evaluates the condition and enters this branch only when it is truthy. |
| 12 | raise serializers.ValidationError("not a project member") | Stops the happy path with a deliberate exception carrying the boundary failure. |
| 13 | return project | Returns the observable result to the caller and ends this invocation. |
| 15 | class TaskViewSet(viewsets.ModelViewSet): | Creates a class namespace and binds the resulting class object to this name. |
| 16 | serializer_class = TaskWriteSerializer | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 17 | permission_classes = (IsAuthenticated,) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 19 | def get_queryset(self): | Defines a function; its parameters form the explicit input boundary. |
| 20 | return Task.objects.filter(project__members=self.request.user).select_related("project") | Returns the observable result to the caller and ends this invocation. |
Risk register
| Area | Failure to reproduce | Required design response |
|---|---|---|
| Serializers | SerializerMethodField can create N+1 queries and undocumented business logic. | Use separate read and write serializers when contracts diverge. |
| APIView vs ViewSets | Keep retries bounded and restricted to transient, idempotent operations. | Use it for orthogonal policy such as timing, authorization, validation, retry, or caching. |
| Authentication & permissions | Decoding is not validation, and a valid token does not grant every resource. | Enforce object ownership and roles on the server for every path. |
| Throttling & pagination | Application throttles are not a substitute for edge protection, and offset pagination drifts under concurrent writes. | Use deterministic unique ordering and return retry metadata. |
| Routers & custom authentication | Defining has_object_permission() is ineffective if custom view code never invokes the object-permission check. | Apply all three layers deliberately and test collection, detail, create, update, delete, and custom actions with the wrong user or tenant. |
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 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
1def test_list_is_authorized_and_query_bounded(api_client, member, project, django_assert_num_queries):2 api_client.force_authenticate(member)3 with django_assert_num_queries(3):4 response = api_client.get("/api/resources/")5 assert response.status_code == 2006 assert all(item["project_id"] == str(project.id) for item in response.data["results"])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?