home / skills / gilbertopsantosjr / fullstacknextjs / gs-evaluate-domain-module

gs-evaluate-domain-module skill

/skills/gs-evaluate-domain-module

This skill evaluates feature modules for Clean Architecture compliance, detecting dependency violations, layer separation issues, entity patterns, and DI

npx playbooks add skill gilbertopsantosjr/fullstacknextjs --skill gs-evaluate-domain-module

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.7 KB
---
description: Evaluates feature modules for Clean Architecture compliance including Dependency Rule violations, layer separation, Entity patterns, Use Case classes, and DI Container usage.
name: gs-evaluate-domain-module
---

# Feature Module Evaluator (Clean Architecture)

Evaluates features against Clean Architecture principles: Dependency Rule, layer separation, Entity patterns, Use Cases, Repository pattern, DI Container.

## Critical Checks (Must Pass)

| # | Check | Command | Expected |
|---|-------|---------|----------|
| 1 | Domain imports outer layers | `grep -rn "from '@/backend/application\|from '@/backend/infrastructure" src/backend/domain/` | Empty |
| 2 | Application imports Infrastructure | `grep -rn "from '@/backend/infrastructure" src/backend/application/` | Empty |
| 3 | Backend imports Next.js | `grep -rn "from 'next/\|from 'react\|'use server'" src/backend/` | Empty |
| 4 | Direct instantiation | `grep -rn "new.*UseCase(\|new.*Repository(" src/features/` | Empty |
| 5 | Fat server actions | Action files >30 lines | <30 lines each |

## Quick Evaluation Script

```bash
FEATURE="{feature-name}"

echo "=== P0: Dependency Rule Violations ==="
grep -rn "from '@/backend/application\|from '@/backend/infrastructure\|from '@/features/" src/backend/domain/$FEATURE/
grep -rn "from '@/backend/infrastructure" src/backend/application/$FEATURE/
grep -rn "from 'next/\|from 'react\|'use server'" src/backend/

echo "=== P0: Direct Instantiation ==="
grep -rn "new.*UseCase(\|new.*Repository(" src/features/$FEATURE/

echo "=== P1: Entity Pattern ==="
grep -n "private constructor" src/backend/domain/$FEATURE/entities/*.ts
grep -n "validate()" src/backend/domain/$FEATURE/entities/*.ts

echo "=== P1: Repository Pattern ==="
ls src/backend/domain/$FEATURE/repositories/I*.ts 2>/dev/null
ls src/backend/infrastructure/$FEATURE/repositories/*.ts 2>/dev/null

echo "=== P1: Action Sizes ==="
find src/features/$FEATURE/actions -name "*.ts" ! -name "index.ts" -exec wc -l {} \;

echo "=== P2: DI Container ==="
grep -n "$FEATURE" src/backend/infrastructure/di/tokens.ts
```

## Scoring

| Criterion | Weight | Good | Poor |
|-----------|--------|------|------|
| Dependency Rule | 30% | No violations | Any violations |
| Entity Pattern | 20% | Private constructor + validate() | Missing |
| Repository Pattern | 20% | Interface + Implementation | Direct access |
| DI Container | 15% | All registered | None |
| Thin Actions | 15% | <15 lines | >30 lines |

## Auto-Fail Conditions

| Violation | Max Score |
|-----------|-----------|
| Domain imports outer layers | 40% |
| Backend imports Next.js | 50% |
| Direct instantiation in actions | 60% |
| Entity without private constructor | 70% |

## Layer Checklist

### Domain (`src/backend/domain/<feature>/`)
- [ ] Entity with private constructor
- [ ] `static create()` and `fromPersistence()`
- [ ] `validate()` method
- [ ] Repository interface (I*Repository.ts)
- [ ] NO imports from outer layers

### Application (`src/backend/application/<feature>/`)
- [ ] Use Case classes with `execute()`
- [ ] Constructor injection
- [ ] DTOs with `static fromEntity()`
- [ ] NO imports from Infrastructure

### Infrastructure (`src/backend/infrastructure/<feature>/`)
- [ ] Repository implementation
- [ ] DI Container registration

### Presentation (`src/features/<feature>/`)
- [ ] Thin server actions (3-5 lines)
- [ ] Uses DI Container
- [ ] Zod for input shape only

## Output Format

```markdown
# Evaluation: {feature}

## Status: [PASS / FAIL]

### P0 Violations
- [ ] {violation + file}

### P1 Issues
- [ ] {issue}

### Score: {X}/100

## Fix Priority
1. {Highest priority}
2. {Second priority}
```

## References

- Feature Architecture: `skills/feature-architecture/SKILL.md`
- Create Domain Module: `skills/create-domain-module/SKILL.md`

Overview

This skill evaluates feature modules for compliance with Clean Architecture rules, focusing on dependency flow, layer separation, entity design, use case structure, repository patterns, and DI usage. It runs a set of deterministic checks and returns a pass/fail status, violation list, and remediation priorities. The goal is to make architectural defects visible and actionable for each feature module. Results map directly to scoring and auto-fail conditions so teams can prioritize fixes.

How this skill works

The evaluator scans the repository using grep, file listings, and simple heuristics to detect violations such as domain imports from outer layers, backend imports of Next.js/React, direct instantiation of use cases/repositories, and oversized server actions. It also verifies domain entity patterns (private constructor, validate()), repository interfaces and implementations, DI token registration, and thin presentation actions. Outputs include P0 violations, P1 issues, a numeric score, and a prioritized fix list based on defined auto-fail and weighted criteria.

When to use it

  • Before merging feature branches to ensure architectural integrity.
  • During code reviews for new or refactored feature modules.
  • When onboarding teams to enforce consistent Clean Architecture practices.
  • As part of CI to catch regressions in layer separation and DI registration.
  • When preparing a technical debt cleanup or refactor planning.

Best practices

  • Keep domain layer free of imports from application or infrastructure.
  • Implement entities with private constructors, static constructors, and validate().
  • Inject use cases and repositories via constructors; avoid 'new' inside actions.
  • Register all feature tokens in the DI container before runtime tests.
  • Keep server action files minimal (3–15 lines) and delegate logic to use cases.

Example use cases

  • Run the evaluator on a feature branch to block merges that violate the Dependency Rule.
  • Scan all features to build an architectural health dashboard and prioritize fixes.
  • Use as a pre-commit or CI gate to enforce thin presentation and DI registration.
  • Validate entity and repository patterns when implementing a new domain module.
  • Audit legacy features to quantify technical debt tied to layer violations.

FAQ

What constitutes an auto-fail?

Auto-fails include domain importing outer layers, backend importing Next.js, direct instantiation in actions, or missing private constructors on entities; each maps to a maximum allowed score in the evaluator.

Can I customize thresholds (like action size)?

Thresholds are configurable in the evaluation script; adapt the line limits and scoring weights to match your team's conventions.