Shared model, different use cases: public reading and editorial writes
One Symfony application: a read contract, editorial JSON snapshot writes, and a separate minimal PHP experiment without editorial classes.
A public page reads an already prepared article, yet starting the application suddenly requires an editor form class. Perhaps that class entered the shared package alongside the article entity. Perhaps the container automatically discovered every service in the neighbouring application. The distinction matters little to the reader: changing the administration interface can break an ordinary read.
Splitting the code into two repositories does not resolve this by itself. We need to identify the dependency that the public application acquires with the shared model and check whether its use case actually needs it. The shared meaning of an article can survive without installing an editorial interface in every consumer.
Continue the same article_demo on Symfony 8.1 and PHP 8.4+. An editorial module prepares a JSON snapshot of an approved card, and a reading module returns public fields. Both routes run in one Kernel; a separate minimal Composer experiment checks only copied read files without the editorial module.
One article, two different operations
The read operation starts with an identifier and ends with a public card or a clear absence. The write operation starts with editorial data, checks whether the article is suitable, and creates a new snapshot. Their inputs, dependencies, and reasons for refusal differ.
| Part | Public reader | Editorial module |
|---|---|---|
| Input | Card identifier | Selected draft and a new snapshot path |
| Source | Prepared JSON | Synthetic draft catalogue |
| Result | Public fields or absence | New file containing an approved card |
| Own interface | Read route | Draft screen and console operation |
The editor screen only displays fictional drafts. A console command starts publication. Forms, accounts, and authentication are not implemented: they are unnecessary for asking this narrow question about the reader's dependencies.
The shared contract describes the available result
A small contract module contains CardId, PublishedCard, and a read interface. The identifier has a defined format, the title cannot consist solely of ordinary whitespace characters, and the revision starts at 1. A card contains only id, title, and revision.
<?php
declare(strict_types=1);
namespace App\PublicationSnapshot\Contract;
interface PublishedCardReader
{
/** Null means absent from a valid snapshot; source failure must throw. */
public function find(CardId $id): ?PublishedCard;
}
This contract contains no save method, editorial note, or reference to a form. null means that a card is absent from a valid snapshot. An unreadable source must not become the same answer; otherwise a fault starts looking like a missing article.
Draft approval is not a property of the reader either. A DTO alone does not prove that somebody had permission to publish a record. The editorial operation selects the data, while the shared type defines the permitted shape of the already prepared result.
The boundary must be visible in dependencies
The contract lives in src/PublicationSnapshot/Contract, writes in Editing, and reads in Read. These are module boundaries in one application, rather than two installed Symfony projects or a released package. The DTO does not import an editorial interface; data crosses the boundary through a snapshot. Directory separation alone does not prove the independence of arbitrary production code.
A separate experiment copied five Contract/Read files byte for byte into a minimal PHP Composer consumer. Its requirements contained only PHP; a fresh offline installation added no packages. 29 checks confirmed card reading, unchanged snapshot bytes, the distinction between absence and source failure, and the absence of editorial classes. This is not a Symfony cold boot, a release-package installation, or a complete transitive dependency audit.
Editorial writes do not travel with the DTO
The editor's catalogue contains an approved paper-boat card, an unapproved review-card, and an intentionally invalid article with a blank title. The approved card has revision 2. Its editorial note belongs on the demonstration screen but is excluded from the reader's JSON.
The PublishDraft operation obtains a draft, checks its synthetic approval flag, and creates a PublishedCard. Only then does it open a new file. An unknown, unapproved, or invalid card must be refused without creating a snapshot.
Writing uses xb mode: according to the fopen documentation, this mode does not open an existing file for overwriting. That is a useful property of the teaching command, but it is not a complete publication update protocol. There is no atomic switch of the current snapshot or guarantee of preservation after power failure; a partial file remains available for diagnosis after a write error.
Each generated snapshot contains one selected card. It is not a full journal export and does not merge with an earlier file. This constraint keeps attention on the boundary between the editorial operation and reading, without hiding another algorithm behind the word publication.
The public container builds its own composition
Add these entries under the existing services: in config/services.yaml, preserving earlier services and routes. Do not replace the whole file. JsonPublishedCards receives var/publication-snapshot.json; the reading interface explicitly points to the adapter. Do not automatically register DTOs as services.
services:
App\PublicationSnapshot\Editing\DraftCatalog:
arguments:
$file: '%kernel.project_dir%/fixtures/publication-drafts.json'
App\PublicationSnapshot\Editing\PublishDraft: ~
App\PublicationSnapshot\Read\JsonPublishedCards:
arguments:
$file: '%kernel.project_dir%/var/publication-snapshot.json'
App\PublicationSnapshot\Contract\PublishedCardReader:
alias: App\PublicationSnapshot\Read\JsonPublishedCards
App\Controller\PublicationSnapshotController: ~
App\Controller\PublicationDraftsController: ~
App\Command\PublishSnapshotCommand: ~
From the same article_demo root, create a snapshot at a new, unused path:
php bin/console app:publication-snapshot:publish paper-boat var/publication-snapshot.json
The command refuses an existing file: preserve existing data when repeating the example. GET /publication-demo/cards/paper-boat reads the card; GET /publication-demo/drafts displays synthetic drafts in the same application. The draft page has no authentication and is unsuitable for production.
What the Kernel and separate PHP consumer check
The module was checked with 19 tests and 40 assertions. HTTP requests pass through one Symfony Kernel without a network server. Separate cases cover overwrite refusal, unchanged bytes after reading, and the distinction between a valid empty source and a damaged file.
| Situation | Example behaviour |
|---|---|
| Approved card in a valid snapshot | 200 and exact public fields |
| Absent or unapproved card | 404 |
| Draft screen in the same application | 200 |
| POST to the reading route | 405 |
| Missing, damaged, or unsupported snapshot | 503 |
Independent reading still needs data
Independent reading still needs an available snapshot, a compatible schema, and its own dependencies. The minimal PHP experiment checks the narrow boundary of five files; the shared Kernel checks HTTP-module behaviour. These are different forms of evidence. Neither establishes server availability, a complete package graph, or current data.
A real product needs separate decisions about delivering changes, withdrawing articles, filesystem permissions, and acceptable delay. The teaching operation creates a new file without implementing an atomic switch of the current snapshot. The useful criterion remains concrete: does the reader need a new dependency, or does that dependency belong only to writing?