DownloadMigration roadmap: legacy to adaptive persistence with AEM
A practical strategy for moving from a monolithic legacy system toward a maintainable, hexagonal architecture using Adaptive Entity Manager (AEM) as the persistence mapping layer.
AEM is not a temporary bridge you must leave. For many teams the stable target is AEM plus pluggable adapters?not a mandatory move to Doctrine ORM or DQL. If you later choose a relational core on Doctrine, see RFC-004: Optional Doctrine ORM exit path (adopter guidance only; not on the core product roadmap).
Migration timeline
flowchart LR
subgraph legacyStage [Legacy]
L1["Monolithic<br/>application"]
L2["Legacy DB"]
L3["Mixed<br/>codebase"]
L1 --> L2
L2 --> L3
end
subgraph aemStage [AEM integration]
A1["Adaptive<br/>Entity Manager"]
A2["Legacy DB<br/>adapter"]
A3["Value<br/>Objects"]
A1 --> A2
A2 --> A3
end
subgraph hybridStage [Hybrid architecture]
M1["Entity<br/>Manager"]
M2["Multiple<br/>sources"]
M3["APIs and<br/>files"]
M1 --> M2
M2 --> M3
end
subgraph stableStage [Stable adaptive target]
S1["Hexagonal<br/>boundaries"]
S2["Repositories<br/>behind ports"]
S3["AEM + adapters<br/>long term"]
S1 --> S2
S2 --> S3
end
L3 -.->|integrate| A1
A3 -.->|expand| M1
M3 -.->|stabilize| S1
Exit paths (choose deliberately)
| Path | When it fits | AEM role |
|------|----------------|----------|
| Stay on AEM | Mixed sources, uneven legacy schemas, DBAL/SQL you control, hexagonal ports | Long-term mapper; adapters per source |
| Hybrid long term | Some contexts on AEM, some on other stacks | Per bounded context |
| Optional Doctrine ORM | Single relational core, team standard on ORM, ready for entity mapping and migrations | Retire AEM for that context only; see RFC-004 |
There is no default requirement to reach DQL or Doctrine ORM.
Stages in detail
Stage 1: Legacy state
Typical duration: 0?2 weeks (analysis and planning)
What you usually have
-
Monolithic application ? one large codebase
-
Legacy database ? schemas full of historical decisions
-
Mixed code ? SQL scattered through business logic
Common pain points
-
Fear of change because everything depends on everything
-
Little or no automated tests
-
Documentation lives in people?s heads
-
?Do not touch it? culture (and it still breaks sometimes)
Goals for this stage
-
Map dependencies, inventory schemas, and name the riskiest hotspots first.
-
Do not plan a big-bang rewrite.
Practical advice: understand what you have before choosing adapters and bounded contexts.
Stage 2: AEM integration
Typical duration: 2?4 weeks depending on legacy size
What you do
-
Wire AEM to the existing legacy database
-
Build a legacy DB adapter that translates storage into entity operations
-
Introduce Value Objects so primitives gain validation and meaning (see VALUE_OBJECTS.md)
Why it matters
// Instead of unstructured arrays:
$result = mysql_query("SELECT user_id, user_email, user_balance FROM users WHERE user_id = $id");
$user_data = mysql_fetch_assoc($result);
$email = $user_data['user_email']; // nullable? valid?
$balance = $user_data['user_balance']; // cents? currency?
// You move toward typed access:
$user = $userRepository->find($id);
$email = $user->getEmail(); // Email value object
$balance = $user->getBalance(); // Money value object
AEM strengths here
-
Fast integration with a legacy database in days, not months
-
Incremental rollout ? one bounded context at a time
-
Low blast radius ? old paths can keep running in parallel
-
Richer data model via value objects and metadata
Things to watch
-
Temptation to rewrite everything immediately
-
Creative legacy schemas that fight elegant mapping
-
Team skepticism without a visible win
Practical advice: pick one module, prove the pattern, let the team feel the difference. Momentum beats big-bang plans.
Stage 3: Hybrid architecture
Typical duration: 1?3 months ? often the noisiest phase
What changes
-
Entity Manager becomes the coordination point inside infrastructure
-
Multiple sources coexist: old DB, new APIs, files, queues
-
Services split out while the UX stays stable
Example shape
$userRepository = $em->getRepository(User::class);
$user = $userRepository->find($userId); // legacy DB
$profileRepository = $em->getRepository(UserProfile::class);
$profile = $profileRepository->find($userId); // modern API
$documentsRepository = $em->getRepository(Document::class);
$documents = $documentsRepository->findByUser($userId); // filesystem or object storage
// Application code can stay similar even though storage differs.
Why hybrid helps
-
Old and new systems run side by side
-
Extract bounded contexts without freezing product work
-
Business rules stop caring which adapter answered the call
-
Roll back individual slices if something misbehaves
Hybrid risks
-
Debugging complexity ? data may live in many physical systems
-
Performance ? amplified N+1 patterns if fetch plans are naive
-
Consistency ? distributed transactions rarely come for free
-
Observability ? every source needs health checks
Practical advice: move low-risk data first, invest in logging and tracing, and design rollback paths before flipping traffic.
Stage 4: Stable adaptive target (recommended default)
Typical duration: ongoing ? this is where many teamsstop
Target outcome
-
Hexagonal (ports and adapters) layout ? domain and application do not depend on SQL, REST, or ORM details
-
Repositories expose aggregate-oriented or use-case-oriented APIs behind ports
-
AEM +
EntityDataAdapter implementations remain the persistence edge for each source you still need
-
Doctrine DBAL (or similar) for connections and query building where useful, without forcing full ORM entity mapping everywhere
End state example
// Application / domain port:
interface UserRepository
{
public function get(UserId $id): User;
}
// Infrastructure adapter (AEM-backed):
final class AemUserRepository implements UserRepository
{
public function __construct(
private readonly EntityManagerInterface $em,
) {}
public function get(UserId $id): User
{
return $this->em->find(User::class, $id->value())
?? throw new UserNotFound($id);
}
}
Why this is a valid finish line
-
Matches AEM positioning: adaptive mapper for legacy and mixed sources
-
Avoids a second large migration if Doctrine ORM does not solve your real constraints
-
Keeps one persistence story per adapter; metadata and value objects stay explicit
Optional later move
If a single bounded context later standardizes on Doctrine ORM (including DQL for complex reads), treat that as a separate, optional project?not the default end of this roadmap. See RFC-004.
Practical advice: optimize for operational clarity and team velocity, not for a specific vendor stack badge.
Progress signals
| Stage | Signal | Healthy | Concerning |
|-------|--------|---------|------------|
| Legacy | Time to fix typical bugs | 2?3 days | 1?2 weeks |
| AEM | Automated test coverage | 30%+ | under 10% |
| Hybrid | Deploy duration | ~30 minutes | 3+ hours |
| Stable adaptive | Time for medium feature | 2?3 days | 1?2 weeks |
When things go wrong
Red flags
-
A stage takes more than double the planned time
-
Team resistance grows instead of shrinking
-
Latency or throughput regresses without a mitigation plan
-
Defect rate climbs right after large mechanical changes
Response loop
-
Pause the slice that hurts.
-
Analyze (metrics, traces, data consistency checks).
-
Adjust the plan (smaller steps, rollback, more tests).
-
Communicate with the team and resume.
Practitioner tips
1. Record decisions
Use Architecture Decision Records so context survives turnover: why AEM, which bounded context next, dual-write windows, rollback triggers.
2. Automate health checks
Monitor legacy DB, APIs, and adapter error rates during cutover; alert on consistency drift between old and new paths.
3. Always keep a rollback path
Define rollback windows, backups before each stage, and explicit triggers (for example performance or error-rate thresholds).
Closing thoughts
Migration is a marathon, not a single sprint.
-
The goal is better operational reality, not vanity rewrites.
-
AEM as the long-term mapper is a first-class outcome.
-
Doctrine ORM / DQL is an optional exit for some contexts?not the implied destination of this document.
Good luck turning brittle legacy into a maintainable architecture.
|