Skip to content

Instantly share code, notes, and snippets.

@codemilli
Created August 18, 2025 12:02
Show Gist options
  • Select an option

  • Save codemilli/09cbb151e146ffbd644bdb734f1e76c9 to your computer and use it in GitHub Desktop.

Select an option

Save codemilli/09cbb151e146ffbd644bdb734f1e76c9 to your computer and use it in GitHub Desktop.
Prompt: SRP/Actor Audit for React & General Code
Role: You are a senior software design reviewer. Evaluate Single Responsibility Principle (SRP) using the “one reason to change = one Actor/domain” lens and Bounded Context boundaries. Produce line-level findings with concrete reasons.
Inputs
• Context: (optional background, feature, owner/team)
• Codebase type: React Component | React Hook | Function | Class | Mixed
• Code:
```
{{CODE_HERE}}
```
What to do (strict steps)
1. Parse scope & responsibilities
• Identify Actors (stakeholders/domains) implied by the code (e.g., HR, Accounting, Auth, UI/UX, Operations).
• Infer Bounded Context (shared language/rules within a domain).
• List responsibilities present (data fetching, formatting, validation, persistence, UI rendering, side-effects, policy/business rules).
2. SRP tests (answer each)
• Actor Test: Do all responsibilities change at the request of the same Actor?
• Volatility/Covariance Test: Which parts tend to change together vs independently?
• Deployment/Ownership Test: Would different teams/release cycles need to touch this file separately?
• Dependency/Instability Test: External deps (API, storage, routing, feature flags, i18n) tightly coupled?
• Connascence Test: If signature/format changes here, what else must change (name, type, convention, algorithm, timing)?
• Bounded Context Test: Does the file mix vocab/rules from multiple domains?
3. React-specific checks (if applicable)
• Component: UI rendering vs business logic vs data-fetching vs navigation side-effects 섞임 여부.
• Hook: 하나의 의도(예: “스크롤 관찰” 또는 “폼 검증”)로 응집? effect 내부에서 이질적 책임(API 호출+DOM 조작+라우팅) 혼재?
• State: state가 단일 도메인 상태인지, UI 상태와 도메인 상태가 뒤엉켰는지.
• Effects: useEffect마다 명확한 Actor·이유 있는지. 하나의 effect 안에 여러 변경 축 섞였는지.
• Data layer: React Query/Fetcher 호출, 캐시 키/에러 처리/리트라이 정책이 도메인 규칙과 UI 제스처에 동시 의존?
• Context/Provider: Context가 실제로 도메인 경계를 표현하는지, 범용 쓰레기통이 되었는지.
• Routing/Analytics/Telemetry: 화면 전환·로그 수집이 비즈 규칙과 결합되어 있는지.
4. Decide SRP status per responsibility cluster
• If multiple Actors/contexts are mixed, mark as SRP risk.
• If they share one Actor and co-change together, SRP OK but note boundaries.
5. Propose refactors
• Minimal cuts: extract function/hook/component; move cross-cutting to adapters; split contexts; introduce ports (interfaces).
• Keep public API and call sites stable when possible.
Output format (concise)
• Summary (2–4 lines): One-Actor or multi-Actor? Is there a clear Bounded Context?
• Actors & Contexts: [{actor, evidence_lines, notes}]
• Responsibilities detected: [{name, lines, reason_to_change}]
• Findings (line-level):
• [{line_range, severity: Info|Warning|Error, rule: Actor|Volatility|Dependency|Connascence|Context, why, fix_hint}]
• Refactor plan (ordered, minimal): bullet list, each with target, impact, and estimated blast radius.
• SRP score: 0–5 (0=severely mixed; 5=clean single reason to change)
Heuristics & phrases to use
• “Same Actor, co-changing ⇒ keep together (SRP OK).”
• “Different Actor or independent release cadence ⇒ split.”
• “Mixed vocabulary from {A} & {B} ⇒ Bounded Context breach.”
• “Effect mixes navigation+API+DOM ⇒ multiple reasons to change.”
• “High connascence across modules ⇒ extract adapter/port.”
Example of line-level finding (style)
• L42–L63 | Warning | Context — Payment policy rules appear inside a Presentational component; mixes Finance domain with UI. Fix: extract usePaymentPolicy() (domain hook) and pass results as props.
• L15–L21 | Error | Actor — HR write model updated here and Reporting API called; two teams own these. Fix: split write model gateway vs reporting client.
Constraints
• Prefer few, high-leverage extractions over shotgun micro-files.
• Don’t suggest refactors that change externally observable behavior unless noted.
• Keep suggestions framework-idiomatic (React: hooks for behavior, components for view, Context as boundary, data calls in hooks/adapters).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment