Sheet 02 — Architecture
Two frameworks, one app
A PHP application where CodeIgniter and Symfony share one codebase, shown now and in its target state, with generic names.
The canvas shows the containers of the application, then the components inside them, with two request paths: one through the legacy route and one through the Symfony seam. Every name on it is generic: no company, product or real module names.
The canvas
Skip to the text versionDrag to move the canvas. Turn off Move map to scroll the page with a swipe.
Which areas sit on which side is illustrative. It shows the rule (an area moves to Symfony when a project touches it, and idle legacy stays), not the real split.
Text version of the canvas
Front end
A Vue.js SPA that calls Symfony JSON endpoints, and legacy PHP views with jQuery, rendered by CodeIgniter. The SPA is fully separate from the back end.
Legacy views with jQuery jQuery
Server-rendered PHP views from CodeIgniter, with jQuery in the page.
Tests: PHPUnit not given; HTTP integration / characterisation n/a; End-to-end main.
Calls out
- Front controller and routes: page requests
Vue.js SPA Vue.js
The modern front end. It calls Symfony JSON endpoints and is fully separate from the back end.
Tests: PHPUnit not given; HTTP integration / characterisation n/a; End-to-end yes.
Calls out
- Front controller and routes: JSON requests
- Symfony kernel: the seam: JSON requests, own entry point
PHP application
CodeIgniter and Symfony in one codebase. Symfony can be booted from anywhere in the legacy app, and the session is the remaining legacy dependency. Line coverage: about 20 % on the CodeIgniter code, about 80 % on the Symfony code.
Front controller and routes CodeIgniter
Requests enter the legacy app here. A route either runs a legacy page controller or boots Symfony: the seam. Some Symfony JSON endpoints are reached through here; others have their own entry point.
Tests: PHPUnit hard; HTTP integration / characterisation yes; End-to-end main.
Calls out
- Legacy page controllers: routes legacy pages
- Symfony kernel: the seam: boots Symfony
Related essay: adding to legacy
Legacy page controllers CodeIgniter
Long controllers with a lot of logic. Each one has to check the signed-in user, access to the data and the input itself. Some don’t, and a lower layer turns the problem into a 500.
Tests: PHPUnit hard; HTTP integration / characterisation yes; End-to-end main.
Calls out
- Legacy views with jQuery: renders PHP views
- Big shared classes: calls
- Shared globals: reads
- Legacy session: reads the session (proposed)
- RabbitMQ: publishes jobs
Related essay: validate at the edge
Big shared classes CodeIgniter
Large classes that do many things and are used in many places. Hard to unit test, with a lot of coupling.
Tests: PHPUnit hard; HTTP integration / characterisation yes; End-to-end main.
Calls out
- Shared globals: reads
- MySQL: queries (proposed)
Related essay: adding to legacy
Shared globals CodeIgniter
Globals reused in many places: one reason the CodeIgniter code is hard to test.
Tests: PHPUnit hard; HTTP integration / characterisation yes; End-to-end main.
Legacy session CodeIgniter
The session, stored in a sessions table in MySQL. Symfony reads the same table, and that is the one legacy dependency left on the Symfony side.
Tests: PHPUnit hard; HTTP integration / characterisation yes; End-to-end main.
Calls out
- MySQL: sessions table
Symfony kernel: the seam Symfony
Can be booted from anywhere in the legacy app, and some routes reach it through their own entry point. Behind it, code follows Symfony’s conventions and tests, and modules stay reusable and inside their domain.
Tests: PHPUnit yes; HTTP integration / characterisation yes; End-to-end yes.
Calls out
- Request listeners: runs before the controller
Related essay: adding to legacy
Request listeners Symfony
They run before the controller. They load the user from the session, load the entity and validate the JSON body with Symfony Validator constraints. Bad input stops here.
Tests: PHPUnit yes; HTTP integration / characterisation yes; End-to-end yes.
Calls out
- MySQL: reads the shared sessions table
- Controllers: validated request
- Exception mapping: throws on bad input
Related essay: validate at the edge
Controllers Symfony
Thin: each one calls one handler per action and returns plain JSON. Controllers moved to the listeners one at a time, so feature work went on.
Tests: PHPUnit yes; HTTP integration / characterisation yes; End-to-end yes.
Calls out
- Handlers: one handler per action
- Vue.js SPA: returns JSON
Handlers Symfony
One per action, with business rules only, because their input is already valid. A top-level handler owns the transaction, so there are no partial writes. The same handler can be called from a controller, an API endpoint or a CLI command.
Tests: PHPUnit yes; HTTP integration / characterisation yes; End-to-end yes.
Calls out
- Repositories: reads and writes
- Exception mapping: throws on a broken rule
- RabbitMQ: publishes jobs
Repositories Symfony
Organised reads: collections that are easy to retrieve, returned as DTOs with an expected structure.
Tests: PHPUnit yes; HTTP integration / characterisation yes; End-to-end yes.
Calls out
- MySQL: collections as DTOs
Exception mapping Symfony
Exceptions are mapped centrally and generically, so controllers never deal with them.
Tests: PHPUnit yes; HTTP integration / characterisation yes; End-to-end yes.
Calls out
- Vue.js SPA: mapped error response
Calls from the container (component not given)
- File storage: writes exports and other files
- Redis: cache: longer-lived, larger data
- APCu: short-lived keys, per server
- Third-party API: calls
Scheduled jobs and CLI
Cron jobs and console commands, for example scheduled report exports to CSV.
Cron schedule No framework
Starts console commands on a schedule.
Tests: PHPUnit not given; HTTP integration / characterisation not given; End-to-end not given.
Calls out
- Console commands: starts on a schedule
Console commands Symfony
Symfony Console commands such as the scheduled report export. An unbuffered query and a generator stream each row straight to a CSV file on disk.
Tests: PHPUnit not given; HTTP integration / characterisation not given; End-to-end not given.
Calls out
- MySQL: reads rows, unbuffered
- File storage: streams CSV rows
Related essay: streaming large results
Queue and workers
RabbitMQ with background workers. CodeIgniter and Symfony code both publish jobs, and the workers run on Symfony.
RabbitMQ No framework
The message broker. Both CodeIgniter and Symfony code publish jobs to it.
Tests: PHPUnit not given; HTTP integration / characterisation not given; End-to-end not given.
Calls out
- Background workers: delivers jobs
Background workers Symfony
Consume jobs from RabbitMQ and run on Symfony: report and CSV exports, and emails and notifications.
Tests: PHPUnit not given; HTTP integration / characterisation not given; End-to-end not given.
Stores and externals
- File storage (store): Where exports and other files land. Used mostly by the Symfony side.
- MySQL (store): The main database. It also holds the sessions table, which both frameworks read.
- Redis (store): Cache for data that must persist longer than APCu, and for larger data. Used mostly by the Symfony side.
- APCu (store): Short-lived, small keys on each server, so a server does not refetch them from other servers. Used mostly by the Symfony side.
- Third-party API (external): One generic node for the external APIs the app calls, mostly from the Symfony side.
Calls between containers
- Front end → PHP application: page and JSON requests
- PHP application → Front end: renders PHP views, returns JSON
- PHP application → MySQL: queries and the sessions table
- PHP application → Queue and workers: publishes jobs
- Scheduled jobs and CLI → MySQL: reads rows, unbuffered
- Scheduled jobs and CLI → File storage: streams CSV rows
- PHP application → File storage: writes exports and other files
- PHP application → Redis: cache: longer-lived, larger data
- PHP application → APCu: short-lived keys, per server
- PHP application → Third-party API: calls
Request paths
Legacy route
- Legacy views with jQuery → Front controller and routes: page request
- Front controller and routes → Legacy page controllers: routes to the page controller, which does its own checks
- Legacy page controllers → Legacy views with jQuery: renders the PHP view
Through the Symfony seam
- Vue.js SPA → Front controller and routes: JSON request
- Front controller and routes → Symfony kernel: the seam: boots Symfony
- Symfony kernel: the seam → Request listeners: runs the listeners: session, entity, JSON body
- Request listeners → MySQL: reads the shared sessions table
- Request listeners → Controllers: validated request
- Controllers → Handlers: business rules, owns the transaction
- Handlers → Repositories: reads and writes
- Repositories → MySQL: DTO collections
- Controllers → Vue.js SPA: JSON
On error
- Request listeners → Exception mapping: throws on bad input
- Handlers → Exception mapping: throws on a broken rule
- Exception mapping → Vue.js SPA: mapped error response
Areas, now and target
| Area | Now | Target | State in target |
|---|---|---|---|
| Reports and exports | CodeIgniter | Symfony | ACTIVE, PORTED |
| Item lists | Symfony | Symfony | ALREADY ON SYMFONY |
| Users and accounts | CodeIgniter | CodeIgniter | IDLE LEGACY |
| Area A | Symfony | Symfony | ALREADY ON SYMFONY |
| Area B | CodeIgniter | Symfony | ACTIVE, PORTED |
| Area C | CodeIgniter | CodeIgniter | IDLE LEGACY |
Which areas sit on which side is illustrative. It shows the rule (an area moves to Symfony when a project touches it, and idle legacy stays), not the real split.
Test levels per side
| Side | PHPUnit | HTTP integration / characterisation | End-to-end |
|---|---|---|---|
| CodeIgniter | hard to write here | yes | the main level here (pyramid partly inverted) |
| Symfony | yes | yes | yes |
| Vue.js SPA | not given | n/a | yes |
| jQuery views | not given | n/a | the main level here |
| Workers, console commands, cron, stores | not given | not given | not given |
Line coverage, measured by a tool: about 20 % on the CodeIgniter code, about 80 % on the Symfony code.