/agent-engineering-system:code-qualityfrom agent-engineering-system
Detailed engineering quality and design rules for non-trivial implementation, refactors, debugging, integration, and migration work.
Ships in agent-engineering-system. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Use this skill for any non-trivial implementation, refactor, debugging task, integration change, performance work, migration, concurrency change, persistence change, or substantial review.
Read this skill completely before substantial implementation. Then apply the sections relevant to the task.
This skill contains engineering/design quality rules only. Repository-wide operating behavior such as
instruction precedence, completion discipline, source-control workflow, evidence claims, and handoff rules
lives in .agents/core/AGENT_RULES.md.
When pstack is available:
Identify the concepts involved before writing framework glue.
Look for:
Prefer project-owned domain types over loosely structured bags of framework data.
Example:
type InvitationStatus =
| { type: "pending"; expiresAt: Date }
| { type: "accepted"; acceptedAt: Date }
| { type: "expired" }
rather than combinations of unrelated booleans:
{
accepted: boolean
expired: boolean
pending: boolean
}
Use the type system to make impossible states difficult or impossible to represent.
Do not create domain types that merely rename primitives without adding meaning, constraints, or clarity.
Prefer modules with:
small, stable interface
↓
substantial cohesive behavior
over:
many small interfaces
→ many thin wrappers
→ many forwarding layers
→ unclear responsibility
A good module:
Do not maximize:
Abstraction has a cost.
Every abstraction should reduce complexity somewhere else.
Introduce interfaces or protocols when they separate genuine replacement or effect boundaries.
Good candidates:
Poor candidates:
Do not confuse testability with interface proliferation.
If an implementation is deterministic and local, test it directly.
A healthy dependency shape is usually:
UI / HTTP / framework
↓
application orchestration
↓
domain
↓
effect contracts
external provider SDK
↓
adapter
↓
project-owned values
Domain and application logic should generally not depend directly on:
Translate at boundaries.
Third-party SDK types should not become your application’s domain language.
Bad:
async function decideRenewal(
subscription: Stripe.Subscription
): Promise<RenewalDecision>
Better:
interface SubscriptionSnapshot {
id: SubscriptionId
status: SubscriptionStatus
renewalDate: Date | null
}
The adapter is responsible for converting provider data into project-owned values.
This applies to:
This containment makes provider changes, SDK upgrades, testing, and refactoring substantially safer.
TypeScript protects compiled code from many developer mistakes.
It does not validate runtime data.
All untrusted boundary data must be validated.
Examples:
Preferred flow:
unknown external value
↓
runtime schema validation
↓
project-owned typed value
↓
application/domain logic
Use the repository’s established validation library when available.
Do not use:
value as SomeType
as a substitute for runtime validation.
anyany turns off the compiler.
Prefer:
unknown;If an unavoidable untyped dependency requires any, contain it within the smallest possible adapter and convert immediately to safe types.
Do not spread any into application or domain code.
Do not weaken types merely to get the build passing.
Prefer discriminated unions and explicit state machines over loosely related flags.
Example:
type UploadState =
| { type: "idle" }
| { type: "uploading"; startedAt: number }
| { type: "failed"; error: UploadError }
| { type: "complete"; assetId: AssetId }
This is usually safer than:
{
isUploading: boolean
didFail: boolean
isComplete: boolean
}
Ask:
What combinations of state are actually legal?
Encode that answer into the model.
Every important mutable resource needs one identifiable owner.
Examples:
Avoid architectures where multiple unrelated modules can independently mutate the same resource.
Prefer:
one owner
↓
explicit commands
↓
readers / observers
Shared mutation creates hidden coupling.
For every long-running operation, know:
Use tools such as:
AbortSignal;try/finally;Do not leave behind:
Lifecycle behavior is part of correctness.
Do not accidentally create unlimited concurrency.
For concurrent work, explicitly consider:
Be careful with:
await Promise.all(items.map(processItem))
when items may be unbounded or processItem has external effects.
Use bounded concurrency where appropriate.
Separate decision-making from execution where doing so improves clarity.
Prefer:
validated input
↓
decision / transformation
↓
explicit effect
Example:
const decision = decideRefund(order, policy)
await refundExecutor.execute(decision)
This is particularly valuable for:
The module that decides what should happen does not always need to own how the outside world is changed.
Coordinators should connect modules rather than absorb their algorithms.
Good:
load
→ validate
→ invoke domain operation
→ execute effect
→ return result
Warning sign:
A large “service” that:
When orchestration becomes algorithmic, move cohesive behavior into the module that owns it.
Validate invariants where data enters the trusted system.
Once converted to a valid project-owned type, internal modules should generally be able to trust those invariants.
Avoid repeatedly validating the same condition throughout the call graph.
This improves:
Validation should belong somewhere specific.
Do not rely on arbitrary strings or raw provider exceptions as application behavior.
Represent meaningful failures explicitly.
Example:
type CreateAccountError =
| { type: "email_taken" }
| { type: "invalid_input"; issues: ValidationIssue[] }
| { type: "dependency_unavailable"; dependency: string }
Translate infrastructure/provider failures at the adapter boundary.
A caller should not need to understand a vendor SDK’s entire error model.
Preserve useful causal information for diagnostics without leaking implementation detail across the architecture.
Do not scatter direct environment access through the system.
Bad:
process.env.API_URL
throughout many modules.
Prefer:
interface AppConfig {
apiUrl: URL
port: number
environment: Environment
}
Validate configuration once during startup.
Missing or malformed required configuration should fail loudly and early.
Pass modules only the configuration they require.
Never commit or production-log:
Tests use fake credentials.
Live integration tests may read secrets from the approved environment but must never:
When reviewing a diff, explicitly check for accidental secret exposure.
Logs exist for humans and machines trying to understand what happened.
Prefer structured logging.
Example:
logger.info("invoice processed", {
invoiceId,
durationMs,
result: "paid",
})
Prefer useful identifiers and outcome fields over giant serialized payloads.
Avoid logging full:
unless explicitly necessary, protected, and approved.
Do not debug by permanently adding excessive logging.
Default testing hierarchy:
pure unit test
↓
module contract test
↓
integration test
↓
end-to-end test
Do not prove simple deterministic logic through slow E2E tests.
Do not claim a real integration works because a unit mock was green.
Choose the layer based on what must actually be proven.
For every meaningful module, be able to answer:
How do we know this works?
Examples:
Deterministic input/output tests.
Contract tests against an isolated real database.
Stubbed transport tests plus live integration where meaningful.
Deterministic message handling tests plus real queue integration when required.
Component behavior tests.
End-to-end verification through the actual surface.
If a module is extremely difficult to verify independently, inspect whether its responsibilities are too broad or its boundaries unclear.
Prefer tests of observable behavior.
Avoid tests whose primary purpose is to assert:
A safe internal refactor should usually not require rewriting most tests.
Tests are part of the module contract.
Useful fakeable dependencies include:
Avoid manufacturing interfaces merely so every internal collaborator can be mocked.
Too much mocking results in tests that prove:
The code called the mock the way the test expected.
rather than:
The product behavior is correct.
When logic depends on time, avoid scattering:
Date.now()
through domain logic.
Prefer a clock seam where deterministic behavior matters:
interface Clock {
now(): Date
}
This is especially useful for:
Avoid:
await sleep(500)
as a correctness mechanism.
Prefer waiting for a real observable condition:
Always use bounded waits.
If a test needs an arbitrary sleep to avoid a race, investigate the missing synchronization or ownership boundary.
For meaningful bugs:
Do not patch symptoms based on a guess.
Do not add performance complexity because something “might be slow.”
Before a performance-oriented change:
Keep durable evidence for important performance decisions.
Performance abstractions without measurements are speculation.
Do not casually introduce:
Before adding infrastructure, explain:
Future flexibility alone is usually insufficient justification.
Use current repository conventions and mature libraries where they meet the requirement.
A new dependency should earn its place.
Evaluate:
Do not replace working technology solely because another tool is newer or fashionable.
For React or similar UI systems, components should primarily:
receive state
→ render
→ emit user intent
Keep domain and application logic outside large UI components where practical.
Avoid components that simultaneously own:
Use composition.
Do not invent a private UI framework unless the repository has a demonstrated need.
Preferred HTTP flow:
HTTP request
↓
authenticate / parse / validate
↓
project-owned command/query
↓
application/domain
↓
project-owned result
↓
map to HTTP response
Do not pass request/response framework objects deep into domain logic.
Route/controller layers should be understandable without knowing the full business implementation.
Keep database-specific representations close to persistence modules.
Avoid leaking:
into domain logic.
Transactions require explicit ownership.
Avoid hidden database calls triggered by arbitrary getters or model methods.
Watch for:
Schema changes require migration verification.
When modifying a consumed API, event schema, package interface, or persisted format:
Do not silently break externally relied-upon contracts.
Prefer:
one useful behavior
↓
test
↓
implementation
↓
integration
↓
verification
↓
commit
over:
design complete architecture
→ build many layers
→ connect everything at the end
Vertical slices expose architectural mistakes sooner.
Each slice should leave the repository coherent.
Refactoring means intentionally preserving externally observable behavior.
Before a significant refactor:
Prefer improving a specific module boundary over repository-wide abstraction campaigns.
Useful comments explain:
Bad:
// Increment counter
counter++
Good:
// Delivery is at-least-once, so the idempotency record must
// be persisted before executing the external side effect.
Prefer self-explanatory code for “what.”
Use comments for “why.”
Prefer:
InvoiceReconciliation
AccessPolicy
DocumentRevision
RetryBudget
SubscriptionRenewal
over:
Manager
Helper
Common
Utils
Processor
ThingService
Generic names often reveal unclear responsibility.
A module should usually be nameable by what it owns.
Do not split files merely because they cross an arbitrary line count.
Split when responsibilities diverge.
A cohesive 300-line module can be healthier than six 50-line forwarding wrappers.
Likewise, an 80-line file with unrelated concepts may need separation.
Optimize for cohesion and locality, not file-count aesthetics.
Inject real effect boundaries where it improves:
Plain explicit construction is often enough:
const repository = new PostgresOrderRepository(db)
const gateway = new StripePaymentGateway(stripe)
const checkout = new CheckoutService(repository, gateway)
Do not build a dependency-injection framework unless the system genuinely requires one.
Prefer visible dependencies over global service locators.
Mutable globals obscure:
When a process-wide resource is necessary, give it:
Do not use singleton state as a shortcut around dependency design.
Security should be verifiable, not aspirational.
Consider:
Security-sensitive rules belong at clear boundaries and should have tests where practical.
Never weaken a security boundary merely to simplify a test or make CI green.
If the product handles user-sensitive or business-sensitive information:
Prefer derived, minimal diagnostic information over copying full sensitive payloads into logs/evidence.
Treat privacy as an architectural property.
For user-facing interfaces, accessibility is not optional polish.
Use:
Critical workflows should remain usable without a mouse.
When changing UI behavior, include accessibility in verification.
Avoid speculative layers such as:
Design clean seams where actual external effects exist.
Do not build hypothetical systems.
When requirements are evolving:
Make cheap decisions easy to change.
Spend architectural complexity where reversal would otherwise be expensive.
When modifying a subsystem, identify what should remain locally understandable.
A developer working on one module should ideally not need to understand the entire system.
If a small behavioral change requires edits across many unrelated packages, investigate whether:
Locality of change is a signal of architectural health.
When adding a dependency, ask:
Avoid adding packages for trivial utilities.
Record significant dependency choices when the rationale will matter later.
For schema/data migrations:
Where possible:
expand
→ migrate
→ switch
→ contract
rather than an atomic breaking migration.
Operations that may be retried or delivered more than once should define idempotency behavior.
Especially:
Do not assume exactly-once delivery unless the underlying system truly guarantees it.
Test duplicate delivery when relevant.
Retries are not generic error handling.
Before retrying, determine:
Do not retry validation errors, authorization failures, or deterministic bad input.
Retry policy belongs at a clear ownership boundary.
If adding or changing caching, define:
“Add a cache” is incomplete architecture.
Incorrect cached data can be worse than slow correct data.
Prefer no cache until requirements justify one.
When using event-driven architecture, define:
Do not use an event bus merely to avoid direct dependencies inside a single process.
Events are useful when temporal decoupling is actually required.
Long-running/background work should expose enough state to understand:
Do not create jobs that disappear into invisible async execution.
Make operational failure diagnosable.
If using a feature flag, define:
Do not allow dead flags to become permanent branches.
Test both paths while both are supported.
Remove obsolete flags promptly.
What SKILL.md sets; muted values are Claude Code's defaults
3 skills in this plugin
/semantic-architectureMaintains a hierarchical semantic model of system responsibilities, ownership, relationships, invariants, and architectural decisions./technical-communicationWrite clear, concrete engineering communication for comments, commits, pull requests, documentation, RFCs, diagrams, and specifications.Other plugins' skills for the same job
npx claudepluginhub lalitkapoor/agent-starter --plugin agent-engineering-system