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 version
Canvas controls
Level
State
Overlay
Request path
View

Turn on JavaScript to pan, zoom and open notes. The text version below has everything on the canvas.

Drag 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

Calls between containers

Request paths

Legacy route

  1. Legacy views with jQuery → Front controller and routes: page request
  2. Front controller and routes → Legacy page controllers: routes to the page controller, which does its own checks
  3. Legacy page controllers → Legacy views with jQuery: renders the PHP view

Through the Symfony seam

  1. Vue.js SPA → Front controller and routes: JSON request
  2. Front controller and routes → Symfony kernel: the seam: boots Symfony
  3. Symfony kernel: the seam → Request listeners: runs the listeners: session, entity, JSON body
  4. Request listeners → MySQL: reads the shared sessions table
  5. Request listeners → Controllers: validated request
  6. Controllers → Handlers: business rules, owns the transaction
  7. Handlers → Repositories: reads and writes
  8. Repositories → MySQL: DTO collections
  9. 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

AreaNowTargetState in target
Reports and exportsCodeIgniterSymfonyACTIVE, PORTED
Item listsSymfonySymfonyALREADY ON SYMFONY
Users and accountsCodeIgniterCodeIgniterIDLE LEGACY
Area ASymfonySymfonyALREADY ON SYMFONY
Area BCodeIgniterSymfonyACTIVE, PORTED
Area CCodeIgniterCodeIgniterIDLE 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

SidePHPUnitHTTP integration / characterisationEnd-to-end
CodeIgniterhard to write hereyesthe main level here (pyramid partly inverted)
Symfonyyesyesyes
Vue.js SPAnot givenn/ayes
jQuery viewsnot givenn/athe main level here
Workers, console commands, cron, storesnot givennot givennot given

Line coverage, measured by a tool: about 20 % on the CodeIgniter code, about 80 % on the Symfony code.

← All fundamentals