Claude-skill-registry facade-layer
Enforces project facade layer coding conventions when creating or modifying business logic facades. This skill ensures consistent patterns for transaction handling, error management, cache integration, query coordination, and cross-service orchestration.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/facade-layer" ~/.claude/skills/majiayu000-claude-skill-registry-facade-layer && rm -rf "$T"
manifest:
skills/data/facade-layer/SKILL.mdsource content
Facade Layer Skill
Purpose
This skill enforces the project facade layer coding conventions automatically during business logic development. It ensures consistent patterns for transaction handling, error management, cache integration, query coordination, and cross-service orchestration with Sentry monitoring.
Activation
This skill activates when:
- Creating new facade files in
src/lib/facades/ - Modifying existing facade files (
).facade.ts - Implementing business logic that coordinates multiple queries
- Working with database transactions
- Coordinating between multiple services or facades
Workflow
- Detect facade work (file path contains
or class name ends withfacades/
)Facade - Load
references/Facade-Layer-Conventions.md - Generate/modify code following all conventions
- Scan for violations of facade patterns
- Auto-fix all violations (no permission needed)
- Report fixes applied
Key Patterns (REQUIRED)
Naming Conventions (Strict)
- ALL async methods MUST use
suffix (e.g.,Async
,createAsync
,updateAsync
,deleteAsync
)getByIdAsync - No exceptions - this ensures consistent API across all facades
Structure Requirements
- Use static class methods (no instantiation needed)
- Define
at file top for error contextconst facadeName = '{Domain}Facade' - Accept optional
(DatabaseExecutor
) as last parameterdbInstance?: DatabaseExecutor - Create appropriate query context (
,createProtectedQueryContext
,createUserQueryContext
,createPublicQueryContext
)createAdminQueryContext
QueryContext and Automatic Filtering (IMPORTANT)
- Context drives filtering: Query methods automatically apply permission and soft-delete filters based on context flags
- Trust query methods: Don't manually add filters that queries handle via
buildBaseFilters() - Context factories set flags:
setscreatePublicQueryContext()
, etc.isPublic: true - Override when needed: Pass
for admin restore featuresshouldIncludeDeleted: true
Transaction Requirements (MANDATORY for mutations)
- ALL multi-step mutations MUST use transactions:
(dbInstance ?? db).transaction(async (tx) => { ... }) - Pass transaction executor (
) to all nested query callstx - Single-step reads do NOT need transactions
Caching Requirements (MANDATORY)
- ALL read operations MUST use domain-specific CacheService (
, etc.)CacheService.bobbleheads.byId() - ALL write operations MUST invalidate cache via
CacheRevalidationService - Never use generic
when domain helper existsCacheService.cached()
Error Handling (MANDATORY)
- ALL methods MUST wrap in try-catch with
createFacadeError(errorContext, error) - Use consistent return patterns (see Return Type Decision Matrix in conventions)
Sentry Monitoring (MANDATORY)
- Use
wrapper to add automatic entry/success/error breadcrumbs (recommended)withFacadeBreadcrumbs() - Alternatively, use
andtrackFacadeEntry()
for manual controltrackFacadeSuccess() - Use
for non-critical failures that shouldn't fail the operationtrackFacadeWarning() - Use
to capture non-critical exceptions with proper tags and warning levelcaptureFacadeWarning() - Never fail main operations due to monitoring failures
Documentation Requirements (MANDATORY)
- ALL public methods MUST have JSDoc with:
- Description of what the method does
for each parameter@param
describing the return value@returns- Cache behavior notes (TTL, invalidation triggers)
Method Complexity Limits
- Methods should not exceed 50-60 lines
- Extract helpers for complex transformations
- Use
for parallel independent data fetchingPromise.all
Anti-Patterns to Detect and Fix
- Missing
suffix on async methodsAsync - Missing transactions on multi-step mutations
- Missing cache invalidation after write operations
- Missing Sentry breadcrumbs in facade methods
- Missing JSDoc documentation on public methods
- Stub/incomplete methods that return hardcoded values
- Duplicate methods with different naming (e.g.,
andgetX
)getXAsync - Silent failures that log errors but don't handle them properly
- Raw SQL/Drizzle queries in facades - delegate to query classes that handle soft-delete
- Wrong operation constants - use semantically correct operations (add new ones if needed)
- Hardcoded cache keys - use
constantsCACHE_KEYS.* - Mixed executor/context usage - use single shared context for parallel queries
- Breadcrumbs only inside cache callbacks - add pre-operation breadcrumb outside for visibility
References
- Complete facade layer conventionsreferences/Facade-Layer-Conventions.md