Stack & Architecture
How SupplyMars Is Built
The design, the stack, the checks and the delivery as they stand today, and why each was chosen.
SupplyMars is a working e-commerce back office – catalogue, pricing, multi‑supplier purchasing, fulfilment and reporting – with a simulated business trading through it around the clock.
Strictly typed, modern PHP and Symfony, built around a rich domain model, rendered on the server and shipped as one container image. Three choices run through all of it: few moving parts, the framework before custom code, and rules the build enforces rather than rules people have to remember.
This page is the overview. The documentation holds the detail, the decision records the reasoning, and the engineering log how it got here.
Core
- PHP 8.5
- Symfony 8.1
- Doctrine ORM 3
- Twig 3
Data
- MySQL 8.4
- Redis 8.8
- Amazon S3
- Flysystem
Runtime
- FrankenPHP
- Docker
- AWS Lightsail
- Sentry
Frontend
- Turbo & Stimulus
- Asset Mapper
- Tailwind CSS 4
- Shadcn kit
Async & live
- Messenger
- Scheduler
- Lock
- Mercure
Quality
- PHPUnit & ParaTest
- Foundry & Zenstruck Browser
- PHPStan & Rector
- Deptrac & PHP CS Fixer
Architecture
A Modular Monolith
One deployable application, divided into bounded contexts that each own their part of the business. A monolith keeps transactions, refactoring and deployment simple; the boundaries stop it from turning into one tangled codebase where everything depends on everything else. Should a context ever need to stand alone, its edges are already drawn.
- Catalog
- Pricing
- Purchasing
- Order
- Customer
- Review
- Note
- Reporting
- Audit
- Home
- Shared
Domain
Entities, value objects, typed IDs, enums, events and repository interfaces. The business rules.
Application
Commands, handlers, listeners and search criteria. Loads the model, asks it to change, reports back.
Infrastructure
Doctrine repositories, security, mail, storage. The parts that can be swapped.
UI
Controllers, forms, the REST API, console commands and Twig. Thin, and calls the layer below.
The rules between contexts are short. A context may use another context's domain (its entities, enums, events and repository interfaces) but never its handlers, services, Doctrine classes or controllers, and the shared kernel imports from no business context at all. Deptrac checks this on every change and the build fails on a new breach (ADR 014).
The domain is deliberately not framework-free. Entities carry Doctrine mapping and validation attributes, because a second, separate description of every entity would cost more than it saves for an extraction that isn't planned. The business rules themselves stay in plain methods.
Domain-Driven Design
A Model That Owns Its Rules
The business is complicated: products sourced from several suppliers, an order line's status derived from the purchase order items beneath it, markups that cascade from category to product. That complexity lives in the entities, where it can be tested directly, rather than spread across services and listeners.
Rich entities
An order knows when it can be cancelled; a product knows where its markup comes from. Handlers ask the model rather than decide for it, so a web form, the API and a console command all get the same answer.
Built whole
Entities are created through named constructors, such as CustomerOrder::createFromCustomer() and Product::create(). Orders, purchase orders and reviews have private constructors, so there is no other way to build one, and the test factories go through the same constructors.
Typed public IDs
Every entity behind a URL has a ULID public ID with its own type, set in the constructor. Auto-increment keys stay internal, URLs reveal no counts, and an order's ID cannot be passed where a purchase order's is expected.
Value objects
Immutable values for each kind of change: a status change, a cost change, a stock change, a price model. Prices are calculated with bcmath on decimal strings, never floats.
Domain events
Aggregates raise immutable events that carry IDs, not live entities. Other contexts react to them: the audit trail, price recalculation, live pages. What must succeed at once is sync; what can lag or retry goes on the queue.
Repository interfaces
Each context declares the queries it offers as an interface in its domain; the Doctrine class behind it is a detail. When another context needs a query, the method is added to the interface.
Application Layer
One Path for Every Write
A consistent shape makes the codebase predictable. Once you have read one feature, you know where to find the pieces of every other.
Commands and handlers
Every form, action and API write takes the same path. A form fills a form model, never an entity; a mapper turns it into a readonly command DTO; one handler loads the entity, calls a method on it and returns Result::ok() or Result::fail() with a message. Inline edits are the one shortcut: they check the entity's rules, call its method and flush.
Search criteria
Reads are separate. Each index page has a criteria object with its allowed sorts and defaults, passed to a repository that returns a paginated query. Lightweight CQRS: separate models for reading and writing, one database.
FormFlow
Controllers are thin orchestrators built from five flows: form, action, confirm, search and inline edit. CSRF, flashes, redirects and Turbo responses are handled once, in an open-source package of my own, myvars/form-flow.
A REST API on the same handlers
Versioned JSON endpoints call the same handlers and repositories as the web, so they add no business logic. Errors are RFC 7807 Problem Details, the OpenAPI docs are generated from attributes, and Bearer tokens are stored only as SHA-256 hashes.
Symfony
Leaning on the Framework
Symfony 8.1 does most of the infrastructure work. Before anything is hand-built or another library is added, the first question is which Symfony component already does it. The code that remains is the business.
- Attributes & autowiring
- Routes, commands, listeners and message handlers are declared on the class itself, and services are autowired. Configuration in YAML is the last resort.
- Request mapping
- A value resolver turns the ULID in a URL into the entity, and the API maps JSON bodies and query strings straight into validated DTOs.
- Forms & Validator
- Forms fill form models carrying constraint attributes, and one form theme renders every field.
- Security
- Form login with remember-me and throttling, access tokens for the API, a role hierarchy and voters.
- Doctrine
- Attribute mapping, repositories behind domain interfaces, and every schema change as a migration.
- EventDispatcher
- Domain events are dispatched once the change is saved. Sync listeners react straight away, in any context; async events go on to Messenger.
- Messenger & Scheduler
- The async queue and the recurring jobs, both consumed by one worker.
- Lock & RateLimiter
- Locks for scheduled jobs and live refreshes; rate limits on sign-in, registration and password reset.
- Symfony UX
- Twig Components, Turbo, Stimulus, Icons and Chart.js, served by Asset Mapper.
Async & Live
Work That Happens Off the Request
Mail, recurring jobs, live refreshes and the simulation all run off the request, through one queue and one worker.
Messenger on a database queue
Async work is a row in MySQL, consumed by a worker. The workload doesn't need a broker, so there isn't one to run, secure and back up. RabbitMQ stays one setting away, behind a Compose profile, and the code doesn't change because Messenger hides the transport.
ADR 013Symfony Scheduler, not cron
Every scheduled job is listed in one class and runs inside the Messenger worker, one at a time, with its state in Redis and a lock against double runs. No cron daemon in the application image, and no jobs colliding on the same minute.
ADR 015Live pages with Mercure
FrankenPHP's built-in Mercure hub pushes changes to the browser. A page refresh is a public signal with no data, so each viewer reloads through their own access check; toasts to a user are private. Refreshes are queued and deduplicated, one per order however many events a change raises.
ADR 017A simulated business
Console commands simulate the business with realistic timing: customers place orders at random through the day, purchase orders are raised and accepted, suppliers ship and deliver, stock and prices move. The live site always has fresh data, and the order, purchasing and fulfilment lifecycle runs around the clock.
ADR 003Frontend
HTML Over the Wire
A staff tool lives on forms, tables and state changes, and Symfony handles those well. Rendering on the server keeps one source of truth and one language for the rules; Turbo and Stimulus (Hotwire) make it feel like a single-page app.
Server-rendered, not an SPA
Twig renders every page and Symfony Forms validate on the server. There is no second application in JavaScript, no client state to keep in sync and no API written only for the UI.
ADR 008Turbo and Stimulus
Turbo gives app-like navigation: frames for the main content and for modals in a native <dialog>, streams for flashes, morphing for live refreshes. Small Stimulus controllers add behaviour where HTML alone isn't enough.
ADR 007Asset Mapper, no bundler
JavaScript is served as native ES modules through an import map, and Tailwind is compiled by its standalone binary. No Node toolchain, no Webpack or Vite build, no node_modules to keep patched.
Tailwind and the Shadcn kit
UI primitives come from the Shadcn kit of Symfony UX Toolkit, copied into the project as Twig components. The project owns the files and edits them freely, with no dependency on the toolkit at runtime; in-house components are built from the kit's pieces.
ADR 012Charts and icons
Chart.js through Symfony UX for the dashboards and reports, and UX Icons with every icon committed to the repository as SVG.
Dark by default
A dark Martian theme, a light mode beside it, and every screen responsive from a phone to a wide monitor.
Runtime & Infrastructure
Containerised, End to End
Development, CI and production are built from one Dockerfile on the same pinned base and described by the same Compose files, so what works on a laptop works in production.
One FrankenPHP image
One Dockerfile on an exactly pinned FrankenPHP base, with development and production stages. FrankenPHP is the web server and PHP in one, so nginx and PHP-FPM are gone; the same production image runs the Messenger worker as a second container. Worker mode keeps the booted kernel in memory, restarting each worker after 500 requests.
ADR 016Docker Compose
One set of Compose files describes the app, the worker, MySQL 8.4 and Redis 8.8, with an override for each environment. CI runs the checks in it, production runs it from pulled images, and development can run all of it or only the services behind symfony serve.
One small host
Two stacks, the live site and the public playground, share one small AWS Lightsail instance behind a host Caddy that terminates TLS. Product images and backups live in S3. Sized to the load, not to a diagram.
MySQL and Redis
MySQL holds the data and the queue; schema changes go through Doctrine migrations only. Redis holds the cache, sessions, the scheduler's state and the locks that deduplicate live refreshes.
Monitoring
Sentry reports uncaught exceptions in production, and Sentry Uptime checks the site from outside. /health checks the database, Redis and the queue for the container healthcheck and the uptime monitor.
Backups and the playground
A nightly database backup goes to S3. The public playground, where anyone can sign in as staff and try it out, is rebuilt every night from live's backup, so nothing a visitor does there lasts.
Worker mode has one rule above the rest: a service must never keep a request's data in a property, because the same service object serves the next request too. Services read the user or the request when they need them, a service that caches on purpose clears itself between requests, and a test fails the build if one doesn't (state between requests).
Security
Rules in the App, Not the Web Server
Security that lives in application code is tested with everything else and behaves the same in every environment. The security guide has the full list.
Roles and voters
Staff and super-admin roles in a hierarchy, always checked through isGranted() so the hierarchy applies. The most destructive actions are for super admins only, and a voter guards the rule that depends on the record.
No state change on a GET
Every state-changing action is a POST with its own CSRF token, including one-button actions such as approving a review. Apart from signing out and the signed links in emails, no link changes anything, so prefetching and crawlers are harmless.
Headers, limits and proxies
The app sends its own CSP and security headers, so development, tests and production share one policy. Rate limits, login throttling and trusted proxies live in Symfony rather than the web server, and Cloudflare Turnstile protects sign-up and the playground sign-in.
Testing & Code Quality
The Same Checks, Locally and in CI
make check runs every check CI runs, with the same commands in the same container. If it passes on a laptop, it passes on the pull request.
PHP CS Fixer
Symfony coding standard, strict_types in every file, no Yoda conditions.
Rector
PHP, Symfony, Doctrine and PHPUnit sets, dead code, type declarations, early returns. Run in dry-run mode, so the code must already comply.
PHPStan, level 7
Static analysis over the application and the tests, with an empty baseline kept empty by rule.
Deptrac
The rules between bounded contexts.
Lint
The service container, every Twig template and every YAML file in config/.
Composer audit
Known vulnerabilities in any installed package.
Migrations
The migrations must produce exactly the schema the entities describe.
Production config
The production Compose files and the Caddyfile, in each of its modes, must validate before anything is built.
Tests
The full suite, in parallel.
PHPUnit and ParaTest
Over 1,300 tests run in parallel with ParaTest, one database per process. A feature is done when a test exercises it the way a caller would: an HTTP request for a page, a handler call for a handler.
Foundry and DAMA
Zenstruck Foundry factories build test data through the entities' own constructors, and DAMA rolls each test back in a transaction, so tests are fast and independent. Queued messages go to an in-memory transport that serialises them, so a test can read what was sent.
Browser flow tests
Zenstruck Browser drives whole flows through the kernel: sign in, submit a form, follow the redirect, read the flash. When one fails in CI, the page it was on is saved as an artifact.
CI/CD
Merge Is Deploy
GitHub Actions takes every merge to main through to production with no manual step.
-
1
Test
On every pull request and every push to main: builds the image with a layer cache, then runs each step of make check.
-
2
Publish
On main only: builds the production images and pushes them to the GitHub Container Registry, tagged with the commit SHA.
-
3
Deploy
Connects to the server, checks out that commit, pulls its images and restarts the live and playground stacks; one container runs the migrations on start. The job then checks that /health answers and no migration is pending. If a newer commit is already live, an older job stops rather than roll it back.
The server never builds anything. CI builds the production images from the commit that passed the tests, the server only pulls them, and the commit that is checked out decides which images run, so a rollback is a checkout of the previous commit and a restart. Application secrets live in env files on the server, outside the repository; GitHub holds only what it needs to reach the server, and third-party actions are pinned to commit SHAs.
Ways of Working
How the Work Is Done
I run it as if it were a team project, because the habits are what make a codebase easy to hand over.
Issues and pull requests
Work is planned as GitHub issues, and every change arrives as a pull request from its own branch, saying what changed and why. Nothing is published or deployed without passing CI.
Decisions written down
The architecture decision records explain the choices that shape the system, with the alternatives and their costs. A non-obvious area isn't changed until its ADR has been read.
Docs as the source of truth
The docs describe the system as it is today, and each entry in their index says when to read it. They are updated with the code they describe.
AI under review
For most of its life SupplyMars was written by hand, with AI for the occasional question. Since early 2026 Claude Code has written most of the code and tests, working from a CLAUDE.md that sets out the rules and points to the docs. I set the direction, review every change and remain responsible for the result.
Direction
The Principles That Carry Forward
The tools will change; these are the choices each new feature is measured against.
-
1
Use the framework first
Before building infrastructure or adding a library, look for the Symfony component that already does it: locks, rate limits, scheduling, queues, HTTP.
-
2
Keep the rules in the model
Business rules belong in the entities, behind one path for every write, so no caller can go around them.
-
3
Let the build enforce the rules
A rule that matters is checked by a tool on every change, not left to code review.
-
4
Render on the server
Add JavaScript for behaviour, never for business logic or to duplicate state.
-
5
Keep the moving parts few
One image, one database, one queue, one worker, until the load says otherwise.
-
6
Run the same everywhere
Development, CI and production share one Dockerfile, one set of Compose files and the same checks, so surprises surface early.
-
7
Write it down
Decisions in ADRs, behaviour in the docs, the story in the log.
Go Deeper
Read the Code
The repository is public: the code, the tests, the ADRs and the infrastructure behind everything on this page.