When a shared capability is ready to leave the project

Use a journal and a catalogue to build a keep/extract map: shared semantics, permitted differences, change cost and reasons to reject an overly broad package.

A shared component makes sense when two different products need the same behavior.
A shared component makes sense when two different products need the same behavior.

Similar code has appeared in two sites. Both display a list of cards, shorten a title, choose a language and build links. The first response is understandable: move everything into a shared package so the next fix only needs to be made once. Yet similar lines do not answer the main question: should these sites change together?

A journal and a catalogue can have the same card HTML while having different reasons to change it. The journal cares about the author's title and editorial state; the catalogue cares about an item's availability and characteristics. If we combine these rules because they look alike, the next requirement will introduce a “for the catalogue” parameter, followed by more exceptions.

I suggest making the extraction decision through a concrete requirements map. The journal and catalogue below are hypothetical examples created for this discussion. This is not a description of the platform's internal packages or a report of a completed migration. The goal is to identify a small shared behaviour that can be named, explained and checked without knowing the first site.

The decision map contains eight elements and three alternatives: extract the entire card, retain duplication or extract a narrow contract. It compares requirements of two hypothetical products. It measures no time savings; a practical exercise can check two adapters’ behavior without automatically proving lower maintenance costs.

Compare the reasons for change first

Identical program text can be a coincidence. Two lists may be ordered by date today, but tomorrow the journal may need an author's selection while the catalogue needs available items first. A shared sorting function called “standard” would conceal two different product decisions.

Conversely, different implementations can provide the same promise. One site reads a localised title from an array and another from storage, yet both must return only the explicitly requested locale and report its absence. Here the candidate for sharing is the title lookup contract; the data retrieval methods remain separate.

Before moving code, I therefore write down three things: which rule is the same, which real requirement could change it, and whether that change should reach both consumers. “This method was copied twice” describes the history of the code, but does not establish shared semantics.

The danger of accumulating parameters for different cases is illustrated in Sandi Metz's original essay The Wrong Abstraction. The practical inference for our task is to assess temporary duplication alongside the cost of an unsuitable dependency. This is an argument for testing the boundary, rather than a general prohibition on shared code.

Map two independent consumers

Suppose the journal publishes learning notes and the catalogue lists reusable workshop equipment. The data is fictional. Both sites need short localised titles, but their pages, availability rules and display order differ.

Element Journal Catalogue Decision in this example
Title lookup by key and exact locale Note title or absence Item title or absence Extract a narrow reading contract
Locale validation Accept only an agreed code The same requirement Extract the same validation rule
Fallback language Do not display an untranslated note The supplier's language may be needed Keep the policy in the sites
Permission to see a record Editorial state and reader access Item visibility in this catalogue Keep in the sites
Card order Author's selection Item availability and priority Keep in the sites
URL Note reading route Equipment detail route Keep routes in the sites
HTML and branding Concise journal card Card with specifications Keep templates in the sites
Storage Array for demonstration A different data set Separate adapters to the shared contract

This table does not assign permanent status to the elements. It records a decision under the current requirements. If both products later deliberately adopt the same fallback language policy, that policy can be considered separately. Merely adding a third site is insufficient.

The precision of “title” matters too. The shared contract must not suddenly return an HTML card, price, editorial state and ready-made URL. Every additional field expands the promise. If the second consumer has to invent empty values for half the fields, the boundary already needs reconsideration.

What can actually be extracted

For this discussion, the operation “find title text by key and locale” is enough. The key is an opaque string within one source's namespace. The locale is explicit. An unknown key or missing translation produces an absent result. A known translation returns text without adding HTML, a route or the site's name.

This definition still needs clarification. Is an empty translation invalid data or an available title? Are spaces allowed in a key? May callers request an unsupported locale? Can storage errors be disguised as absence? The answers must be the same for both consumers, or explicitly remain outside the shared boundary.

Our hypothetical decision is that the key is not empty, the contract defines the allowed locales, absence is a normal distinct result, and source unavailability is an error. Each site handles visibility before or inside its adapter. The existence of a title does not grant permission to display the record. This gives us a small contract that can be checked against two different data sets.

Dependency registration does not require the shared code to know the first application's container. Symfony allows dependencies to be passed through constructors and interface implementations to be selected explicitly; these capabilities are described in the service container documentation. In our model, each site connects its own adapter. A full bundle becomes useful when framework integration must be delivered, rather than simply to hold a few PHP types.

Describe variation in product terms

A useful setting names a real difference: maximum length, allowed locales or loading method. A questionable setting names a client: “second site mode”, “journal behaviour” or “old catalogue”. Such names suggest that the package is controlling other applications' scenarios instead of fulfilling a shared promise.

The number of parameters alone proves nothing, however. Two independent parameters can create four combinations, some of which make no sense. Ten formatting settings can sometimes form a clear model. The allowed combinations need to be checked, with responsibility for each explained.

For localised title lookup, we deliberately leave fallback language out of the first contract. The journal may want to hide a missing translation, while the catalogue may display a separate label identifying the original language. Both behaviours can be built around the same “translation absent” result. Embedding a complete policy in the package would remove that choice from consumers.

The opposite risk also exists: a shared contract can be so empty that all substantive behaviour is repeated in adapters. If both adapters contain the same lengthy normalisation, the same exceptions and the same text checks, a separate shared mechanism may be appropriate. The boundary is not settled forever; the next meaningful change tests it.

The cost extends beyond moving files

Extraction introduces work that line counts cannot show. Supported versions must be named, dependencies declared, installation documented and isolation checked. Consumers also need to know how to adopt a new release. These are among the concerns covered by Symfony's reusable bundle recommendations. A plain library has less integration to supply, but its maintenance promise remains.

Before moving code, it helps to compare concrete actions instead of invented hours saved. A local implementation requires two checks and two changes for a fix. A package requires the fix, a release, compatibility checks and two consumer updates. A shared implementation reduces the number of places where a rule is corrected, but does not remove each site's acceptance work.

Question before extraction Sufficient answer Reason to keep it local
Which rule is shared? It can be described without naming a site There is only similar code
Why does it change? One requirement should reach both consumers Product reasons diverge
What may vary? A small list of explicit dependencies A collection of exception flags
How is a second consumer checked? Different data and independent configuration The first application must be copied
Who maintains the contract? A decision owner and change procedure exist The package has no assigned responsibility
Can adoption be gradual? One site can update independently All sites must be rewritten together

This is not a scoring system. No total makes an architecture automatically correct. One unresolved question about the meaning of a result may outweigh all the organisational conveniences combined.

Test the decision with two future changes

Imagine the first requirement: a translation containing only spaces no longer counts as a title. If both sites agree that such a record is invalid, a shared validation rule earns its place. We need to decide whether this means absence or invalid data, and record the same behaviour in contract checks.

The second requirement is that the catalogue wants to append a capacity label while the journal wants to preserve the author's title. This does not justify adding a catalogue flag to the shared reader. The catalogue can construct its own presentation after receiving the text. Its page change then does not force the journal to change behaviour.

A useful negative check is to imagine that a new site must pass its router, menu configuration, Entity and access service into the library even though the declared task is title lookup. This collection of foreign concepts does not automatically prove an error. It does show where a discussion of the contract became a discussion of the entire application.

If the shared implementation has already accumulated incompatible branches, narrowing it or returning some behaviour to consumers may be the right response. That changes the boundary of responsibility. It should preserve behaviour through deliberate checks, rather than treating all duplication as a flaw and keeping everything in one class.

A completed decision using this map

For the learning example, assume three observable requirements: both consumers request one specific locale; their sources have different keys and titles; and the catalogue needs its own addition to the displayed text. These are inputs to the scenario, rather than measurements from running sites. They allow us to reject two initially convenient options.

Move the entire card. This immediately ties the title to a route, HTML and specifications. The catalogue gets a convenient starting point, but the journal has to accept fields that do not describe its material. We reject this option: a future presentation change for one consumer would pass through a shared release without serving the other.

Keep everything duplicated. This preserves independence and remains valid if the cost of maintaining a package is too high. In our scenario, it means agreeing exact locale selection, empty keys and source errors twice. We choose to extract only this small promise because one set of examples can describe it for both sites. This choice does not prove time savings.

Extract the contract and keep composition local. This is the selected option. Initial costs include a separate dependency name, input and result documentation, shared contract checks and two adapter integrations. Ongoing costs include compatibility assessment and acceptance by each site. The expected benefit is one version of the reading rules; it still needs verification by the second consumer. If that verification requires knowledge of the first site, the decision returns for review.

Record a decision instead of promising universality

For our pair of sites, the decision reads as follows: extract the exact localised title lookup contract and its common input rules; leave data, visibility, routes, sorting, fallback language and presentation with consumers. Check the contract through two independent adapters. Do not promise suitability for every future product.

The record should also name a reason to revisit the decision: a new consumer needs a different meaning of absence, another localisation policy starts repeating, or an adapter must reproduce a substantial part of the shared mechanism. There is then a concrete reason to reconsider the boundary instead of extending it indefinitely in anticipation.

A capability is ready for extraction when a clear promise repeats and there is a way to check it outside the first site. Copy counts help identify a candidate. The decision rests on behavioural meaning, permitted differences and a willingness to maintain changes for every consumer.

  1. Symfony Core Two profiles, one contract: testing the boundary of reuse
  2. Architecture Configuration or a new implementation: when to stop adding settings
  3. Architecture The cost of a shared foundation: assessing changes without invented savings percentages
  4. Symfony Core Independent sites with a shared Symfony foundation

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article