rea-analysis-optimization
MOmorluto/rea485k近 7 天新增 7,690 个 star
Use when multiple workflows duplicate the same operational logic, when deciding what belongs in actions vs shared services, or when refactoring repeated operational blocks across domain flows. Use when adding new features that share mechanics with existing ones.
This collection prefers a two-layer separation: actions orchestrate domain rules, while services implement reusable operations. Use it where the project has no established convention. Preserve existing domain services, repositories, transaction boundaries, and framework patterns when they already fit the task.
This prevents duplicated code, inconsistent behavior, and bugs fixed in one path but not others.
Avoid extraction that adds indirection without a concrete benefit. Repetition is a useful signal, but a single caller can justify a boundary for testing, provider isolation, transactions, or complex logic.
Orchestration Layer (Actions) Service Layer (Shared Mechanics)
├── owns business rules ├── owns reusable operations
├── owns state transitions ├── owns provider/SDK interactions
├── owns auth/ownership checks ├── owns command execution details
├── owns failure classification ├── owns health checks / readiness
├── owns retries / user-facing errors └── returns structured results
└── calls service functions
Rule of thumb:
| Design Principle | Do | Don't |
|---|---|---|
| API shape | Composable capability blocks | One giant "do everything" method |
| Inputs/outputs | Explicit dependencies and meaningful results | Hidden global state or undocumented side effects |
| Migration | Extract one block, replace one caller, verify, then migrate rest | Refactor everything at once |
| Domain logic | Put policy and transactions in the project's established owner | Scatter the same policy across callers |
| Extraction trigger | Repeated mechanics or a concrete boundary benefit | Speculative abstractions with no current benefit |
Design as capability blocks, not monoliths:
// Good: composable, each caller chooses what to use
createManagedSandbox(...)
prepareRepo(...)
detectPackageManager(...)
installDependencies(...)
runBuildCommand(...)
startSandboxRuntime(...)
Each function should:
{ ready, previewUrl, proxyPort })This lets callers choose strict vs relaxed behavior per flow.
When extracting shared logic:
| Anti-Pattern | Problem |
|---|---|
| God service | One huge function hides all control flow |
| Leaky service | Hidden state changes or unclear transaction ownership |
| Inconsistent API | Each function uses different argument styles and error semantics |
| Over-abstraction | Indirection with no reuse, testability, or boundary benefit |
// emailService.ts — shared mechanics
export async function sendWelcomeEmail(params: { to: string; name: string }) {
const html = `<h1>Welcome ${params.name}</h1>`;
await emailProvider.send(params.to, "Welcome", html);
}
// userSignup.ts — orchestration (owns WHEN to send)
if (user.marketingOptIn) {
await sendWelcomeEmail({ to: user.email, name: user.name });
}
// adminInvite.ts — orchestration (different business rule, same mechanic)
await sendWelcomeEmail({ to: invitee.email, name: invitee.name });
Existing architecture? → Follow its boundaries
No convention? → Prefer actions for orchestration and services for operations
Extraction? → Name its concrete benefit before adding another layer
Keep responsibilities clear, dependencies explicit, and side effects visible.
MOmorluto/rea485k近 7 天新增 7,690 个 star
MAmattpocock/skills336k近 7 天新增 4,217 个 star
MAmattpocock/skills336k近 7 天新增 4,217 个 star
MAmattpocock/skills336k近 7 天新增 4,217 个 star
MAmattpocock/skills336k近 7 天新增 4,217 个 star