Chapter 18 · Practice · Migrating from CRUD to DDD

Migrating from CRUD to DDD

Moving a CRUD application to DDD in Symfony without rewriting it from scratch: the Strangler Fig Pattern, pulling out the domain layer, introducing repositories, and adopting CQRS step by step. With examples in PHP.

Author M. Katuščák
Reading time ≈ 34 min
Difficulty advanced
Published · Updated ·
In this chapter

18.01 When and why to migrate from CRUD to DDD#

A CRUD architecture (Create, Read, Update, Delete) is the default choice for most applications, and it holds up for a long time. For managing data without complex logic, such as contacts, product catalogs, or administration screens, the DDD layers would only be extra weight. The trouble starts when the application grows more complex and domain logic begins to settle in the wrong places.

When DDD adds value and when CRUD is enough

The decision to migrate rests on an analysis of domain complexity, not on trends. In Patterns of Enterprise Application Architecture, Martin Fowler describes Transaction Script as the natural choice for applications with little logic. As the rules grow more complex, he argues, such code gets harder and harder to maintain, and Domain Model gains the advantage [1].

The economics of migration: what it costs and when it pays back

Depending on the size of the codebase, a migration from CRUD to DDD takes months to years, and on its own it delivers nothing to the customer. The benefit arrives once the team starts adding features with a lower risk of regressions.

An incremental migration of a mid-sized CRUD application (50–100 tables, 3–5 years of development) usually takes 12 to 24 months. That figure is an order-of-magnitude estimate from experience, not a measurement. It assumes that the migration runs alongside the development of new features and has no full-time team of its own. The timeline stretches with poor testability of the existing code, weak domain knowledge in the team, and domain experts who are not available.

The decision criterion is not technical. The investment pays back only when the benefit over the remaining lifetime of the system exceeds the cost of the migration with a margin to spare. The cost model, as well as the situations in which the investment never pays back, is covered in the section Migration cost paradox. Management accepts a migration more readily as ongoing work alongside new features than as an isolated refactoring project.

When not to start a migration and when a rewrite is cheaper

Three situations argue against migrating at all:

  • The system has less lifetime left than the migration itself would take. An application that is due to be shut down in two years will not pay back the investment.
  • The domain is being discontinued or replaced by a purchased solution. Modeling rules that will disappear within a year is wasted work.
  • Nobody within the team's reach understands the domain. Without a domain expert, the result is a renamed CRUD, not a domain model. This trap is described in the chapter When Not to Use DDD.

A rewrite from scratch, on the other hand, comes out cheaper where the system is smaller than the cost of introducing seams and characterization tests, or where there are no production users and data yet. Martin Fowler has a name for this, Sacrificial Architecture [6]: an architecture designed with the expectation that it will be thrown away in a few years is a reasonable choice. It comes with a condition, though: the decision to throw it away belongs to the team that wrote the system, not to a new team that arrives from outside and wants to rewrite the old code because it does not like it.

18.02 Strangler Fig Pattern – gradual replacement#

The Strangler Fig Pattern was named by Martin Fowler [2]. The pattern replaces an old system piece by piece, without a “big bang” rewrite. The name comes from the tropical fig that grows around a host tree and gradually strangles it.

The original article came out on June 29, 2004, under the title Strangler Application. On April 29, 2019, Fowler renamed the pattern Strangler Fig Application: the shortened “strangler” had come loose from the botanical metaphor and started to sound violent. The older name persists to this day in articles and in the names of libraries.

FIG. 18.2-A Strangler Fig: four phases of a CRUD → DDD migration

Advantages over a big bang rewrite

Rewriting a whole system at once (a “big bang rewrite”) is among the biggest risks in software development. In his article “Things You Should Never Do” [3], Joel Spolsky describes how companies lost their competitive edge by completely rewriting working systems. With the Strangler Fig Pattern, by contrast:

  • The customer keeps getting new features during the migration.
  • The risk goes down: the system is never completely “broken.”
  • Rolling back is possible: if the new implementation fails, the old one keeps working.
  • The team learns DDD gradually, on real production code.
  • Refactoring can stop at any time, and the system stays in a consistent, working state.

What the pattern does not solve

The original article was a short reflection on a metaphor. In 2024, Fowler rewrote it and adopted four activities from Ian Cartwright, Rob Horn, and James Lewis: understand the desired outcomes, break the problem into smaller parts, deliver them incrementally, and change the organization. According to Fowler, the order does not imply a sequence. Changing the organization runs through all the other activities: without it, the new system ends up as brittle as the one it replaced, only on newer technology [2].

The pattern does not remove complexity; it spreads it out over time. The price is a transitional architecture: a routing layer, double writes, translation adapters. Ian Cartwright, Rob Horn, and James Lewis have a name of their own for it: Transitional Architecture [7]. They add a warning: part of the work will be thrown away in the end. Whoever does not throw the transitional layer away inherits it as a permanent part of the system.

Data migration with Strangler Fig

Code can be replaced piece by piece, data cannot – at any given moment, a table has one shape. Strangler Fig therefore needs a plan for moving data into the new model without downtime and with a way back. A proven procedure has four phases.

1. Dual-write with comparison. The application starts writing to both the old and the new model at once. The old write stays primary; the new one runs in addition, and its failure is isolated (e.g., with a savepoint) so it does not roll back the whole transaction. An asynchronous job compares the two sources and logs the differences. Every difference found means a bug in the mapping, and it has to be fixed before the switchover.

A note on the term. “Dual-write” here means writing to two data models in a single database transaction, that is, an operation that either completes entirely or not at all. The chapter Outbox Pattern uses the same term for writing to a database and to a broker without a shared transaction – that is, for the problem the outbox solves.

Dual-write from the application assumes that you can intervene in the write path of the old system. That does not hold for code nobody understands, or for writes that bypass the ORM. The substitute is Event Interception [8]: changes are captured by a layer below the application (a database trigger or a CDC tool such as Debezium), and the new model consumes them. One criterion drives the choice. If the code has a single place through which every write flows, dual-write is enough. If there is no such place, the layer below the application is what remains.

2. Backfill. Only after dual-write is switched on does a one-off script fill the new tables with historical data. The reverse order is broken. An UPDATE to a legacy row that the backfill has already processed would be lost before dual-write is switched on, because the WHERE id > checkpoint condition does not read it a second time. The script must be idempotent: running it again must not create duplicates or overwrite a newer record that dual-write has written in the meantime. It runs in batches by id or updated_at, the newer record wins on conflict, and it saves a checkpoint of the last processed row, so after a crash it picks up where it left off.

3. Shadow reads. Reads go to both sources: the old model builds the response for the user, while the result of the new one is only compared, and a mismatch raises an alert. Only a zero mismatch rate over days to weeks of operation gives confidence that the new model is complete and correct.

4. Cutover. The switch to the new model is controlled by a feature flag, not by a deploy. Traffic moves over gradually: 1%, 10%, 50%, all of it. The metrics from the shadow-read phase stay on throughout. A rollback means flipping the flag back; thanks to dual-write, the old model is still up to date. That holds only if dual-write continues in the reverse direction after the primary is switched, that is, if the new model writes back to the old one. The old write is turned off as the very last step, after several weeks of quiet operation. Symfony has no component of its own for feature flags; PHP projects use third-party libraries, typically flagception/flagception-bundle or the unleash/client SDK.

The schema changes the same way. A column or a table is not renamed with a single ALTER TABLE. Pramod Sadalage and Martin Fowler describe a transition phase for this [9]. The new structure is created next to the old one, both are populated for the duration of the migration, and the original name remains available as a view or through a trigger. Dependent systems can then migrate at their own pace, and the DROP comes only at the end. In Symfony, DoctrineMigrationsBundle carries this sequence: each phase is its own versioned migration, not a manual intervention in the production database.

18.03 Anti-Corruption Layer between legacy and the new model#

The weak spot of two coexisting architectures is the data. The new model reaches into a legacy table for users, takes over its columns one to one, and a month later looks exactly like what it was supposed to replace. The Anti-Corruption Layer is the layer that prevents this: it translates the foreign model into the domain model and back, and does nothing else. The full treatment of the pattern, including its place on the Context Map, is in the chapter Bounded Context and Context Mapping; this section covers its migration form.

Cartwright, Horn, and Lewis describe the same thing under the name Legacy Mimic [10]: the new system talks to the old one in such a way that the old one does not know about the change. The difference lies in the point of view. Legacy Mimic protects the old system from the new one; the ACL protects the new model from the shape of the old one. When migrating from CRUD, you need both, usually in the same class.

Three rules keep the ACL in check:

  1. The layer belongs to the infrastructure of the new Bounded Context, never to its domain. The domain code does not know that the legacy table exists.
  2. The translation is an explicit contract. Whatever the legacy model cannot express gets a default value or fails loudly. The domain model does not bend to accommodate it.
  3. The ACL has an expiry date. Once the legacy writes end, the layer is deleted.

It also makes sense to guard the boundary statically: a rule that forbids the App\<BC>\Domain\* namespace from referencing App\<BC>\Infrastructure\Legacy\* catches a leak earlier than code review does. The procedure is described in the Architecture tests section of the Testing DDD chapter.

18.04 Techniques for safe incremental change#

Strangler Fig says what to do at the scale of the system. About a single concrete refactoring, though, it is silent: how to swap out the implementation of a class called from forty places while still deploying every day. Three named techniques serve that purpose.

Branch by Abstraction

Fowler described it in 2014 [11]; the term was introduced by Paul Hammant, who credits Stacy Curl with the idea. The procedure has five steps:

  1. Over the interface between the caller and the old implementation, create an abstraction, in PHP usually an interface.
  2. Move all callers over to it. Behavior does not change, and the system stays deployable.
  3. Behind the same abstraction, build the new implementation (a domain repository instead of a direct EntityManager).
  4. Switch callers over in parts, through a feature flag or an alias in services.yaml.
  5. Delete the old implementation.

No branch is created in version control along the way. Both implementations live side by side on the main branch, and the difference between them is held by the abstraction, not by a merge.

Parallel Change: expand – migrate – contract

The article on Fowler's site is by Danilo Sato [12]; Joshua Kerievsky described the technique itself as early as 2006. It concerns a change to a single interface, not to the whole system:

  • Expand – the interface is extended so that it can carry both the old and the new variant. The method setEmail(string $email) gets a sibling, changeEmail(Email $email).
  • Migrate – the callers are moved over. Inside the application this is a matter of hours; for external API clients, months. This phase tends to be the longest.
  • Contract – the old variant is removed. Its departure is announced with the #[\Deprecated] attribute (PHP 8.4) or trigger_error(..., E_USER_DEPRECATED).

The value of the pattern is that the code can be deployed in each of the three phases. The same triad applies to the database schema too; the four-phase data migration in the section Strangler Fig Pattern – gradual replacement describes it.

Mikado Method

The method was created by Ola Ellnestam and Daniel Brolund, and Matthias Noback popularized it in the PHP world [13]. It works top down: the target change is made right away and allowed to fail. From the error messages and failed tests, the prerequisites are derived, the change is thrown away (git checkout .), and the leaves of the resulting graph are handled first. The graph thus emerges from the reality of the compiler and the tests, not from guesses at a whiteboard.

Noback adds a rule to it: it must be possible to stop a refactoring at any time, and at that moment the project must be in a better state than at the start [14]. A migration that becomes usable only once it is finished is a big bang spread out over sprints.

18.05 Step 1: Analyzing the existing domain#

Understanding the domain comes before moving code. The most common mistake is jumping straight into refactoring. The result is a DDD architecture that copies the structure of the old database tables and does not reflect the real domain model.

Identifying Bounded Contexts in existing CRUD code

In an existing CRUD application, Bounded Contexts can be recognized by their natural boundaries:

  • Groups of entities and tables that are tightly connected to each other but loosely coupled to other groups. These are the candidates for one Bounded Context.
  • God Services – large service classes are, paradoxically, a good guide. If OrderService contains the logic of orders, payments, and delivery, one class is hiding three Bounded Contexts.
  • The same word with different meanings. If “customer” means something different in sales than in customer support, that is where the boundary between two Bounded Contexts runs.

Event Storming as an analysis tool

Event Storming was invented by Alberto Brandolini [4]. The workshop technique models the domain through domain events and brings people from outside the development team into the design, above all domain experts. In a migration from CRUD, it uncovers logic hidden in controllers and service classes, names state transitions from the point of view of the domain rather than the database, and shows the natural boundaries of Bounded Contexts. The notation, the course of the workshop, and its three levels are covered in the chapter Event Storming and Domain Storytelling.

What not to migrate

The analysis should produce two lists: what exists and what will end. Feature parity, that is, the requirement that the new system do exactly what the old one did, is something Cartwright, Horn, and Lewis advise against [15]. The cost of replicating existing functionality is consistently underestimated, and part of the replicated behavior is not used by anyone anyway. In a CRUD application with ten years of history, a typical find is an export screen that two people used to operate, one of whom left three years ago. There is no point in modeling such a feature. It gets dropped.

The team does not hand down the verdict on its own, though. The list of features to drop is decided by the product side together with a domain expert; developers contribute data on actual usage from logs and metrics.

18.06 Step 2: Extracting the domain layer#

Extraction moves domain rules out of controllers and service classes into the objects they belong to. Those objects guard their invariants themselves, and nobody can get around them from the outside.

Moving domain rules into domain objects

The refactoring has two steps. First, Value Objects are created for primitives that carry domain rules. Then the logic moves into entities and domain services.

Value Objects instead of primitive types

A domain concept hidden in a string or an int is a symptom called Primitive Obsession. A Value Object replaces the primitive with an object that keeps validation and behavior together.

18.07 Step 3: Introducing repositories#

A CRUD application typically calls EntityManagerInterface or Doctrine repositories directly from controllers and service classes. DDD puts a domain repository interface between the domain and persistence. The domain code knows neither the EntityManager nor SQL, and the implementation can be swapped without touching it.

Creating a domain repository interface

The repository interface belongs to the domain layer and describes operations the way the domain needs them.

18.08 Step 4: Introducing CQRS gradually#

Command Query Responsibility Segregation (CQRS) builds on DDD, but its turn comes only after the domain model has settled. If it comes earlier, it moves complexity from the domain into the handler, where it is invisible and harder to test.

Starting with the command side (write side)

On the write side, for operations that change the state of the system, the domain model already exists, and a command only names the intent. Reads can stay on direct Doctrine queries at first; optimized SQL as a read model is a fully valid permanent state in a DDD system, not a stopgap.

A read model over the legacy schema as the first step

The fact that the query side may stay as it is at first does not mean that reads are postponed to the end. The opposite order tends to be even safer. A read model built over the old schema does not change a single write, so it cannot damage data. It is verified by comparing its output with the old screen. And the projection created for it is later ready to consume domain events from the new model.

Concretely: the query from OrderRepository::findAllForListing() moves into OrderListQuery with its own handler and read DTO, while the SQL itself stays unchanged. Once the write model is switched over, only the body of the handler changes; neither the controller nor the template knows about it. Read models, their projections, and eventual consistency are covered in the chapter CQRS.

18.09 Testing during migration#

Tests decide whether a migration succeeds. Without them, refactoring introduces regressions that show up only in production. A migration from CRUD to DDD needs two techniques: characterization tests, which capture the existing behavior, and unit tests of the new domain layer.

Characterization tests

The term “characterization tests” comes from Michael Feathers's book Working Effectively with Legacy Code [5]. A characterization test does not describe how the system should behave, but how it currently behaves. During refactoring, it catches unintended changes in behavior. Feathers also defines legacy code as code without tests – not as code that is old or ugly.

Seams: how a test gets into legacy code

A characterization test is the result; a seam is its precondition. According to Feathers, a seam is a place where you can change the behavior of a program without editing the code in that place. Each seam comes with an enabling point: the place where the decision is made about which variant of the behavior is used [16]. Introducing seams into an established system takes considerable effort. It is an investment, not a by-product of refactoring.

Three kinds recur in Symfony CRUD code:

  • Constructor injection instead of new. A line like $mailer = new SmtpMailer(); inside a method has no seam. A dependency passed through the constructor creates one, and the enabling point ends up in the service configuration.
  • An interface instead of a concrete class. A type hint on UserRepository instead of on DoctrineUserRepository moves the enabling point into services.yaml, where the test overrides it.
  • An event listener instead of inline code. A side effect pulled out of a method into a listener can be detached in the test environment; the enabling point is the listener's registration.

When a characterization test is not necessary

Nobody writes full characterization test coverage for a legacy system, and whoever waits for it never starts. Matthias Noback argues that behavior-preserving structural transformations are safe even without tests, as long as they are backed by static analysis and pair programming [17]. The following gradation builds on his reasoning; Noback does not lay it out this way in the article:

  1. An automated refactoring from the IDE (rename, extract method, move class) goes ahead without a test.
  2. A manual structural change under PHPStan at level 8, with one high-level smoke test.
  3. An intervention in decision logic – only here a characterization test, and only on the affected path.

The line between the second and third points is a judgment call, not a rule. When the team is not sure, the change belongs in the third category.

Language models also help with extracting logic from legacy code: they generate a first set of characterization tests or describe what a convoluted method does. The context is covered in the chapter DDD and Artificial Intelligence.

Unit tests of the domain layer

A domain object that knows neither the database nor HTTP is tested without them. The test runs in milliseconds, does not depend on its surroundings, and reads like a statement of the domain rule. The chapter Testing DDD analyzes the techniques that cover this layer in depth: InMemory repositories, testing domain events, and architecture tests.

18.10 Risks and recommendations#

The most common migration mistakes

  • Anemic domain model – The most common trap. Classes get DDD-style names (User, Order) but contain only getters and setters, and the logic stays in service classes. The result is DDD terminology over a CRUD implementation.
  • Bounded Contexts that are too fine-grained – Too many small contexts lead to distributed complexity, because every integration between them costs something. Larger contexts are a safer start; they get split once the reason is clear.
  • The ORM dictating the shape of the model – Attribute mapping in itself is not the anti-pattern; both Step 2: Extracting the domain layer and Recipe 2 accept it as a pragmatic choice. The problem starts when the ORM determines the shape of the model: public setters for hydration, an anemic entity, flush() called from a controller. Projects that need strict separation of the domain from persistence meet the same need through the Persisted Object Pattern.
  • CQRS without a domain model – Introducing a CommandBus and a QueryBus without a refactored domain model adds layers of complexity with no benefit. CQRS is an amplifier: it magnifies both the strengths and the problems of the existing architecture.
  • A missing Anti-Corruption Layer – Integrating the new DDD layer with the old CRUD code needs a translation layer. Without it, concepts from the old model seep into the new one.

Why migrations fail

The list above is technical; the reasons for failure tend to be organizational. Four keep recurring:

  • A migration without a mandate. The team does it “on the side,” nobody in leadership knows about it, and the first deadline pressure stops it halfway. Arguing in the language of business value is covered in the section The business case for a DDD refactoring.
  • A team without a domain expert. The model then copies the database, because no other source of truth is available.
  • No decision about what not to migrate. Without it, the scope equals the whole legacy system, and the end recedes faster than the work progresses.
  • A migration carried by one person. If that person leaves, half-finished work remains that nobody understands. Bus factor and knowledge silos are covered in the section Knowledge silos and the bus factor.

The fifth reason is quieter than the others: a transitional architecture nobody threw away. The routing layer and the double writes were meant to live for months. Two years later they are parts of the system, and the migration ended with a third architecture added next to the two original ones.

DDD concepts and their implementation in Symfony are covered in the follow-up chapters Implementation in Symfony 8 and CQRS. The specific friction points a migration runs into in production are summarized in the chapter DDD in Practice – Where It Hurts: Doctrine, asynchronous infrastructure, and the team.

18.11 Refactoring cookbook – short recipes#

Strangler Fig is the strategic view of the whole migration. In day-to-day practice, small situations keep recurring; the cookbook summarizes the nine most common ones, each in the format “symptoms → step 1, 2, 3.” The recipes are deliberately short; the referenced chapters carry the more thorough analysis.

Recipe 1: An anemic Doctrine entity

Symptoms: the entity has only getters/setters, and all the logic is in a Service class.

  1. Identify the entity's invariants (what must never be violated).
  2. For each invariant, find the method in *Service that enforces it today.
  3. Move the method into the entity, and narrow the getter/setter to private or remove it.
  4. The service shrinks to a thin coordinator (Application Service): it loads the entity, calls its method, and passes on the events.

Related: Anti-pattern: anemic domain model · Domain Services vs. Application Services.

Recipe 2: Doctrine attributes in a domain class – when it is a problem

Symptoms: App\Domain\Order has #[ORM\Entity], and the domain depends on Doctrine.

The pragmatic default in this book accepts attributes: they are metadata, not behavior, and the Symfony ecosystem works with them idiomatically (see the mapping decision). When a project really does need strict separation (Hexagonal, a long-term ORM swap, a high-value core domain), the procedure is:

  1. Introduce the Persisted Object Pattern: the domain class stays a POPO, and the persistence model + mapper go into App\<BC>\Infrastructure\Persistence\Doctrine\.
  2. Have the mapper hydrate from persistence through a reconstitution factory (like User::reconstitute() in Step 2: Extracting the domain layer) that emits no domain events.
  3. Guard the boundary statically: composer require --dev phparkitect/phparkitect + the rule App\<BC>\Domain\* must not depend on Doctrine\* (the book uses phparkitect in several chapters; deptrac is an alternative).

Recipe 3: Primitive IDs as string / int

Symptoms: Order::$id: string, and only a string is passed around everywhere.

  1. Introduce an OrderId VO (final readonly class OrderId { public function __construct(public string $value) {} }, generated via Uuid::v7()).
  2. Add a Doctrine custom type for OrderId (mapping DB string ↔ VO). The VO must implement __toString(); the UnitOfWork assumes the identifier can be converted to a string, and without it the mapping does not work.
  3. Adjust the signatures in handlers step by step. PHPStan at level 8 reveals every forgotten string.

Recipe 4: A Doctrine table shared by several BCs

Symptoms: the users table is used in the Ordering BC and the Billing BC, and both write to it.

  1. Determine the BC that owns the table (typically Identity).
  2. The other BCs must not write to it – only read. Move the reads into read models (each BC has its own projection).
  3. Replace the writes with calls to the Identity API (sync HTTP or async event publishing with an outbox).

Related: Outbox Pattern.

Recipe 5: Domain logic in a controller

Symptoms: a 200-line controller with an if-else tree of domain decisions.

  1. Create a command DTO (e.g., CancelOrder) and its handler (CancelOrderHandler) in the Application layer.
  2. The controller shrinks to three steps: input validation → dispatching the command → the response.
  3. Move authorization into a Voter (related: Authorization in DDD).

Recipe 6: A bloating aggregate (1000+ lines)

Symptoms: Order has 30 methods and 15 fields.

  1. Find the fields that change independently (different invariants, different use cases).
  2. Consider splitting it into two aggregates (e.g., Order + OrderShipment). They are connected by a shared OrderId, with no strong reference.
  3. Extract the specification logic into Specification classes (related: Specification Pattern).

Recipe 7: eventDispatcher->dispatch() inside a domain method

Symptoms: the aggregate calls the Symfony EventDispatcher directly.

  1. The aggregate extends AggregateRoot and records events by calling record($event).
  2. After repository->save(), the application handler calls $order->releaseEvents() and writes the events to the outbox in the same transaction.
  3. The domain loses its dependency on the Symfony EventDispatcher, and the test runs without the framework.

Related: The aggregate publishes, the handler stores to the outbox.

Recipe 8: The state is a string $status column

Symptoms: Order::$status: string, with conditions like if ($order->status === 'PLACED') everywhere.

  1. Introduce an enum with the states the domain knows: enum OrderStatus: string { case Draft = 'draft'; case Confirmed = 'confirmed'; /* … */ case Cancelled = 'cancelled'; }. The ACL translator translates the legacy value 'PLACED' to Confirmed.
  2. State transitions are performed by the aggregate's methods: $this->status = OrderStatus::Cancelled.
  3. For complex transition rules, consider a state machine (Symfony Workflow or a domain representation).

Recipe 9: A legacy table that cannot be changed

Symptoms: the users table is also written to by a script outside the application or by a third-party system; ALTER TABLE is out of the question.

  1. The new model does not take ownership of the table. It reads through the ACL translator, which translates the legacy columns into domain terms.
  2. Store the missing attributes in a separate table of the new context, linked by a foreign key. The legacy schema stays untouched.
  3. If the column names are unbearable, create a view over the table with domain naming and map the entity onto it.

Related: Mapping complex Value Objects.

Frequently asked questions

What signs show that a CRUD application is ready for migration?

The typical signals are God Services hundreds of lines long and controllers that contain domain rules. Others are domain logic mixed into Doctrine repositories, recurring regressions after small changes, and the growing time it takes to onboard new developers. If the application shows none of these signs and remains a plain mapping of forms onto tables, a migration will not pay for itself. The more general question of which projects DDD suits is answered in the separate chapter When Not to Use DDD. See also the When and why to migrate from CRUD to DDD section.

What is the Strangler Fig Pattern?

Strangler Fig is a migration pattern described by Martin Fowler in which the new architecture gradually “grows around” the old system and replaces it piece by piece. New functionality is built in the DDD style from the start, while the old CRUD part stays in operation and shrinks with every iteration. Both parts exist in parallel and are connected through an Anti-Corruption Layer. A detailed analysis is in the Strangler Fig Pattern – gradual replacement section.

How do you start analyzing the existing domain?

You start with Event Storming or a similar collaborative technique with domain experts: the main events, commands, and actors get mapped. The design of Bounded Contexts and the Ubiquitous Language follows from this map. In parallel, you look for implicit model boundaries in the existing code: modules, tables, or functional areas that are loosely connected. The goal of the first iteration is a rough map, not a complete model. The practical procedure is in the Step 1: Analyzing the existing domain section.

How do you extract the domain layer from existing CRUD code?

The migration starts with one selected Bounded Context, for which a new domain layer is created, separate from the Doctrine entities. Domain logic from service classes and controllers moves into the methods of the aggregate, while the original CRUD code remains as an adapter for the API and persistence. The Anti-Corruption Layer comes first, then the individual use cases are refactored. Characterization tests against the original behavior keep regressions to a minimum. A detailed analysis is in the Step 2: Extracting the domain layer section.

What are the main risks of migrating from CRUD to DDD, and how do you mitigate them?

The most common trap is the anemic model: the new classes have DDD names, but the logic stays in service classes. Other risks are overly fine-grained Bounded Contexts, the ORM dictating the shape of the model (public setters for hydration, flush from a controller), and introducing CQRS without a reworked model. The biggest risk is a Big Bang Rewrite, which rarely gets finished. The migration should proceed incrementally through Strangler Fig, with a realistic estimate of 12–24 months for a mid-sized application. The risks and mitigations are analyzed in the Risks and recommendations section.