Phoenix Context Validator
Phoenix Context Boundary Validation

Analyze Phoenix context boundaries and module coupling via mix xref. Use when checking cross-context calls, validating dependencies, before splitting modules, or reviewing architecture.
--- name: boundaries description: Analyze Phoenix context boundaries and module coupling via mix xref. Use when checking cross-context calls, validating dependencies, before splitting modules, or reviewing architecture. effort: medium argument-hint: "[--assess|--fix]" --- # Phoenix Context Boundary Validation Analyze module dependencies to ensure clean context separation and proper architectural boundaries. ## Usage ``` /phx:boundaries # Check for violations /phx:boundaries --assess # Score context health (0-100) /phx:boundaries --fix # Suggest fixes for violations ```
Overview
Analyze module dependencies to ensure clean context separation and proper architectural boundaries.
Manual install (npx, ZIP)
npx skills add oliver-kriska/claude-elixir-phoenix --skill boundaries -g -a claude-codenpx degit oliver-kriska/claude-elixir-phoenix/plugins/elixir-phoenix/skills/boundaries#main ~/.claude/skills/boundariesConnects with Agent Alley MCP · agentalley.io/mcp
Files included
SKILL.md4.5 KB
Read SKILL.md here
Show the full text138 lines
Phoenix Context Boundary Validation
Analyze module dependencies to ensure clean context separation and proper architectural boundaries.
Usage
/phx:boundaries # Check for violations
/phx:boundaries --assess # Score context health (0-100)
/phx:boundaries --fix # Suggest fixes for violations
--assess Mode: Context Health Score
Evaluate overall boundary health with a quantified score.
Metrics Calculated
| Metric | Healthy Range | Red Flag | Weight |
|---|---|---|---|
| Modules per context | 3-15 | >20 or <2 | 20% |
| Public API surface | 5-30 funcs | >40 funcs | 15% |
| Fan-out (contexts called) | 1-4 | >6 | 20% |
| Fan-in (called by contexts) | 1-6 | >10 | 15% |
| Circular dependencies | 0 | >0 | 15% |
| Boundary violations | 0 | >0 | 15% |
Commands for Assessment
Use Glob to count .ex files per context directory under lib/my_app/*/.
Use Grep to count public function definitions per context file under lib/my_app/*.ex.
Run mix xref graph --format stats for dependency analysis.
Run mix xref graph --format cycles --label compile for compile-time circular dependencies.
Output Format
## Context Health Assessment
### Overall Score: 82/100 (Good)
| Context | Modules | API | Fan-Out | Fan-In | Score |
|---------|---------|-----|---------|--------|-------|
| Accounts | 5 | 12 | 2 | 4 | 95 |
| Orders | 18 | 45 | 8 | 3 | 62 |
| Shared | 2 | 8 | 0 | 12 | 78 |
### Issues Found
1. **Orders** - Too large (18 modules, 45 funcs)
- Consider: Extract Fulfillment, Invoicing sub-contexts
2. **Orders** - High fan-out (8 contexts)
- Consider: Review if all dependencies necessary
### Recommendations
- Split Orders into Orders + Fulfillment
- Review Accounts ← Billing dependency
Iron Laws - Never Violate These
- Controllers call only contexts - No direct Repo access from web layer
- Schemas are pure data - No side effects, no Repo calls in schema modules
- Contexts own their schemas - Don't import schemas from other contexts
- Explicit dependencies only - Cross-context calls must be intentional
- DO NOT refactor context boundaries without running
mix xreffirst — Refactoring without dependency data creates new violations; always map the dependency graph before moving modules
Dependency Rules
| Layer | Can Call | Cannot Call |
|---|---|---|
| Controllers | Contexts, Plug, Conn | Repo, Schemas directly |
| LiveViews | Contexts, Components, PubSub | Repo, Schemas directly |
| Contexts | Own schemas, Repo, other contexts | Web layer modules |
| Schemas | Ecto types, validations | Contexts, Repo |
Analysis Commands
Check Compile Dependencies
Run mix xref graph --label compile-connected.
Find What Depends on a Context
Run mix xref graph --sink MyApp.Accounts --label compile.
Find What a Module Calls
Run mix xref callers MyApp.Accounts.get_user!/1.
Check for Circular Dependencies
Run mix xref graph --format cycles --label compile.
Red Flags to Detect
| Issue | Detection Command | Fix |
|---|---|---|
| Repo in web layer | grep -r "Repo\." lib/my_app_web/ |
Move to context |
| Schema with queries | grep -r "import Ecto.Query" lib/my_app/**/schemas/ |
Move queries to context |
| Cross-context schema import | grep -r "alias MyApp.Other.Schema" lib/my_app/ctx/ |
Call context API |
| Business logic in LiveView | grep -r "Repo\.|Ecto\.Multi" lib/my_app_web/live/ |
Extract to context |
Boundary Verification Process
- Run
mix xref graph --label compile-connectedfor overview - Check for context cross-contamination
- Verify no direct Repo calls from web layer
- Ensure schemas have no side effects
- Validate explicit cross-context dependencies
Next Steps
Always end with actionable follow-up — findings without a plan get lost:
- `/phx:plan` — Create a plan to fix violations (recommended for 3+ issues)
- `/phx:quick` — Fix a single boundary violation directly
- `/phx:review` — Review specific modules for deeper issues
References
For detailed patterns, see:
${CLAUDE_SKILL_DIR}/references/context-design.md- Context design principles${CLAUDE_SKILL_DIR}/references/refactoring-boundaries.md- Fixing boundary violations
| 1 | |
| 2 | name boundaries |
| 3 | description Analyze Phoenix context boundaries and module coupling via mix xref. Use when checking cross-context calls, validating dependencies, before splitting modules, or reviewing architecture. |
| 4 | effort medium |
| 5 | argument-hint "[--assess|--fix]" |
| 6 | |
| 7 | |
| 8 | # Phoenix Context Boundary Validation |
| 9 | |
| 10 | Analyze module dependencies to ensure clean context separation and proper architectural boundaries. |
| 11 | |
| 12 | ## Usage |
| 13 | |
| 14 | |
| 15 | /phx:boundaries # Check for violations |
| 16 | /phx:boundaries --assess # Score context health (0-100) |
| 17 | /phx:boundaries --fix # Suggest fixes for violations |
| 18 | |
| 19 | |
| 20 | ## `--assess` Mode: Context Health Score |
| 21 | |
| 22 | Evaluate overall boundary health with a quantified score. |
| 23 | |
| 24 | ### Metrics Calculated |
| 25 | |
| 26 | | Metric | Healthy Range | Red Flag | Weight | |
| 27 | |--------|---------------|----------|--------| |
| 28 | | Modules per context | 3-15 | >20 or <2 | 20% | |
| 29 | | Public API surface | 5-30 funcs | >40 funcs | 15% | |
| 30 | | Fan-out (contexts called) | 1-4 | >6 | 20% | |
| 31 | | Fan-in (called by contexts) | 1-6 | >10 | 15% | |
| 32 | | Circular dependencies | 0 | >0 | 15% | |
| 33 | | Boundary violations | 0 | >0 | 15% | |
| 34 | |
| 35 | ### Commands for Assessment |
| 36 | |
| 37 | Use Glob to count `.ex` files per context directory under `lib/my_app/*/`. |
| 38 | Use Grep to count public function definitions per context file under `lib/my_app/*.ex`. |
| 39 | Run `mix xref graph --format stats` for dependency analysis. |
| 40 | Run `mix xref graph --format cycles --label compile` for compile-time circular dependencies. |
| 41 | |
| 42 | ### Output Format |
| 43 | |
| 44 | |
| 45 | ## Context Health Assessment |
| 46 | |
| 47 | ### Overall Score: 82/100 (Good) |
| 48 | |
| 49 | | Context | Modules | API | Fan-Out | Fan-In | Score | |
| 50 | |---------|---------|-----|---------|--------|-------| |
| 51 | | Accounts | 5 | 12 | 2 | 4 | 95 | |
| 52 | | Orders | 18 | 45 | 8 | 3 | 62 | |
| 53 | | Shared | 2 | 8 | 0 | 12 | 78 | |
| 54 | |
| 55 | ### Issues Found |
| 56 | |
| 57 | 1. **Orders** - Too large (18 modules, 45 funcs) |
| 58 | - Consider: Extract Fulfillment, Invoicing sub-contexts |
| 59 | |
| 60 | 2. **Orders** - High fan-out (8 contexts) |
| 61 | - Consider: Review if all dependencies necessary |
| 62 | |
| 63 | ### Recommendations |
| 64 | |
| 65 | - Split Orders into Orders + Fulfillment |
| 66 | - Review Accounts ← Billing dependency |
| 67 | |
| 68 | |
| 69 | ## Iron Laws - Never Violate These |
| 70 | |
| 71 | **Controllers call only contexts** - No direct Repo access from web layer |
| 72 | **Schemas are pure data** - No side effects, no Repo calls in schema modules |
| 73 | **Contexts own their schemas** - Don't import schemas from other contexts |
| 74 | **Explicit dependencies only** - Cross-context calls must be intentional |
| 75 | **DO NOT refactor context boundaries without running `mix xref` first** — Refactoring without dependency data creates new violations; always map the dependency graph before moving modules |
| 76 | |
| 77 | ## Dependency Rules |
| 78 | |
| 79 | | Layer | Can Call | Cannot Call | |
| 80 | |-------|----------|-------------| |
| 81 | | Controllers | Contexts, Plug, Conn | Repo, Schemas directly | |
| 82 | | LiveViews | Contexts, Components, PubSub | Repo, Schemas directly | |
| 83 | | Contexts | Own schemas, Repo, other contexts | Web layer modules | |
| 84 | | Schemas | Ecto types, validations | Contexts, Repo | |
| 85 | |
| 86 | ## Analysis Commands |
| 87 | |
| 88 | ### Check Compile Dependencies |
| 89 | |
| 90 | Run `mix xref graph --label compile-connected`. |
| 91 | |
| 92 | ### Find What Depends on a Context |
| 93 | |
| 94 | Run `mix xref graph --sink MyApp.Accounts --label compile`. |
| 95 | |
| 96 | ### Find What a Module Calls |
| 97 | |
| 98 | Run `mix xref callers MyApp.Accounts.get_user!/1`. |
| 99 | |
| 100 | ### Check for Circular Dependencies |
| 101 | |
| 102 | Run `mix xref graph --format cycles --label compile`. |
| 103 | |
| 104 | ## Red Flags to Detect |
| 105 | |
| 106 | | Issue | Detection Command | Fix | |
| 107 | |-------|------------------|-----| |
| 108 | | Repo in web layer | `grep -r "Repo\." lib/my_app_web/` | Move to context | |
| 109 | | Schema with queries | `grep -r "import Ecto.Query" lib/my_app/**/schemas/` | Move queries to context | |
| 110 | | Cross-context schema import | `grep -r "alias MyApp.Other.Schema" lib/my_app/ctx/` | Call context API | |
| 111 | | Business logic in LiveView | `grep -r "Repo\.\|Ecto\.Multi" lib/my_app_web/live/` | Extract to context | |
| 112 | |
| 113 | ## Boundary Verification Process |
| 114 | |
| 115 | Run `mix xref graph --label compile-connected` for overview |
| 116 | Check for context cross-contamination |
| 117 | Verify no direct Repo calls from web layer |
| 118 | Ensure schemas have no side effects |
| 119 | Validate explicit cross-context dependencies |
| 120 | |
| 121 | ## Next Steps |
| 122 | |
| 123 | Always end with actionable follow-up — findings without a plan |
| 124 | get lost: |
| 125 | |
| 126 | |
| 127 | - `/phx:plan` — Create a plan to fix violations (recommended for 3+ issues) |
| 128 | - `/phx:quick` — Fix a single boundary violation directly |
| 129 | - `/phx:review` — Review specific modules for deeper issues |
| 130 | |
| 131 | |
| 132 | ## References |
| 133 | |
| 134 | For detailed patterns, see: |
| 135 | |
| 136 | `${CLAUDE_SKILL_DIR}/references/context-design.md` - Context design principles |
| 137 | `${CLAUDE_SKILL_DIR}/references/refactoring-boundaries.md` - Fixing boundary violations |
| 138 |
Details
- License
- MIT
- Stars on the repo
- ★ 560
- Checked
- Source
- oliver-kriska/claude-elixir-phoenix ↗
- Creator
- oliver-kriska · 7 listings
Similar skills
See all →
SkillCross-Platform Reverse Engineer
SkillBrainstorm Ideas
SkillCode Review Feedback Analyzer
SkillBug Diagnosis Framework
SkillImplement Spec
SkillPR Description WriterMore from oliver-kriska
SkillAsync Return Briefing
SkillHex Dependency Security Audit
SkillCatchup Briefing
SkillLiveView Memory Auditor
SkillN+1 Query Detector
SkillPlugin Development Workflow