Prompt Details
Model
(claude-4-7-opus)
Token size
525
Example input
[PROJECT_MONOLITH_STACK]: Node.js Express monolith sharing a single relational database instance
[TARGET_ARCHITECTURE]: Independent domain modules following Domain-Driven Design patterns
[MONOLITHIC_CODE_CONTEXT]: const UserService = require("./UserService"); class OrderManager { async createOrder(userId, orderValue) { const user = await UserService.getUserProfile(userId); if (user.isActive) { const order = await db.query("INSERT INTO orders VALUES ($1)", userId); return order; } return null; } }
[DECOUPLING_CONSTRAINTS]: Must eliminate hard file imports. Use dependency injection interfaces to ensure loose coupling.
Example output
# Architectural Decoupling Report
## PHASE 1: BOUNDED CONTEXT & COUPLING DIAGNOSIS
**Core Domain Identification:**
- Identity Domain: Manages profile metadata and user record updates.
- Transaction Domain: Manages checkout transactions and order summaries.
**Coupling Bottlenecks:**
1. **Direct Class Instantiation:** The ordering handler directly imports and calls internal methods from the user data service, preventing them from running on separate server instances.
2. **Shared Memory Context:** A single runtime error in the user profile verification block halts the entire execution stream of the payment processing sequence.
## PHASE 2: DECOUPLED ARCHITECTURE DESIGN
**Domain Separation Strategy:** Establish two distinct Bounded Contexts: IdentityContext and OrderContext. Each module must encapsulate its own data layer definitions and execute inside independent deployment runtimes.
**Inter-Service Communication:** Implement an asynchronous Event-Driven pattern. When an order completes, the Order service publishes an event notification to a messaging cluster, which the Identity service processes independently without blocking execution loops.
## PHASE 3: REFACTORING & DOMAIN SPLITTING
### Legacy Monolithic Implementation (Tightly Coupled Node.js)
```javascript
// Monolithic implementation linking user logic directly into order flows
const UserService = require("./UserService");
class OrderManager {
async createOrder(userId, orderValue) {
const user = await UserService.getUserProfile(userId);
if (user.isActive) {
const order = await db.query("INSERT INTO orders VALUES ($1)", userId);
return order;
}
return null;
}
}
```
### Decoupled Implementation (Isolated Domain Handlers)
```javascript
// Clean Domain Separation: Order Domain Module using independent interfaces
class OrderService {
constructor(userValidationService) {
this.userValidator = userValidationService;
}
async placeOrder(userId, orderValue) {
// Validation handled via injected abstract service interface
const isValid = await this.userValidator.isUserEligible(userId);
if (isValid) {
return db.query("INSERT INTO orders VALUES ($1)", userId);
}
throw new Error("Order creation rejected by domain validation rules");
}
}
```
## PHASE 4: MIGRATION PATH & DATA STRATEGY
- **Migration Risk:** Splitting code domains while they still reference a single shared SQL physical table can lead to data deadlocks during peak concurrent writes.
- **Programmatic Mitigation:** Introduce a logical API facade layer over the shared schema, forcing all data updates to route through explicit interface definitions before physically separating the database clusters.
By purchasing this prompt, you agree to our terms of service
CLAUDE-4-7-OPUS
Stop fighting with unmaintainable spaghetti monoliths. This prompt acts as a Principal Software Architect specializing in Domain-Driven Design (DDD), transforming tightly coupled monolithic logic into clean, decoupled microservices or modular domains. It maps bounded contexts, identifies domain boundaries, and provides refactored code splits. Designed to help engineering leaders plan safe, step-by-step decoupling strategies without disrupting business operations.
...more
Added 2 days ago
