practical capstone projects
Small MVC-Style App
A small MVC-style app separates HTTP handling, application decisions, persistence, and templates. Refactor the catalog app you already built; do not start again from an abstract folder diagram.
Move One Vertical Slice First
Start with the product list:
request
-> router
-> ProductController::index()
-> ProductRepository::list()
-> templates/products/index.php
-> response
Once the list works, move create, edit, and delete flows one at a time. Keep each change runnable before moving the next flow.
Use A Small Directory Shape
src/
Controller/ProductController.php
Repository/ProductRepository.php
Service/CreateProduct.php
templates/products/
public/index.php
tests/
The repository owns SQL. The controller translates HTTP input and chooses a response. A focused service is useful when a use case has rules or several collaborators; do not add a service that merely forwards one method call.
Build Dependencies Once
Create dependencies near the front controller:
<?php
$repository = new ProductRepository($pdo);
$controller = new ProductController($repository);
Pass dependencies explicitly. This is enough for the learning project and prepares you to recognize a framework container later.
Verify Common Changes
Ask where you would add a product field, a validation rule, a new SQL filter, an authorization check, and a markup change. Each answer should have an obvious home.
Practice
Practice: Sketch A Small MVC Product App
Refactor the working catalog app into the small MVC-style shape from the lesson.
Requirements
- Route requests to controllers.
- Keep repository code responsible for database access.
- Prepare view data before rendering templates.
- Keep validation and authorisation visible.
- Avoid thin layers that only pass values through without adding clarity.
- Do not place SQL in controllers or templates.
- Keep framework conventions distinct from PHP language rules.
Move one vertical slice at a time and keep the app runnable after each move. Record where five common changes belong: product field, validation rule, SQL filter, authorization check, and markup change.
Show solution
Refactor the list page first, then create, edit, and delete. Keep SQL in ProductRepository, request translation in ProductController, HTML in templates, and reusable use-case rules in focused services only when they earn their place.
Common changes should land predictably:
product field -> migration, repository mapping, validation, template
validation rule -> input validator or use-case service
SQL filter -> repository
authorization check -> controller guard or middleware boundary
markup change -> template
Construct the PDO connection, repository, and controller once near the entry point and pass dependencies explicitly.