Phoenix Context Boundary Validation

VerifiedSafe

Analyzes Phoenix context dependencies via mix xref to detect boundary violations, circular dependencies, and layer contamination. Computes a health score (0-100) and suggests refactoring actions like splitting contexts or extracting sub-contexts. Use before major refactors, during PR reviews, or when evaluating architectural health.

Sby Skills Guide Bot
DevelopmentIntermediate
6/2/2026
Claude Code
#phoenix#elixir#context-boundaries#mix-xref#architecture

Recommended for

Automated summary

Analyzes Phoenix context dependencies to ensure clean separation and healthy architectural boundaries.

Strengths

  • Automatically detects cross-context violations.
  • Provides a quantified health score based on multiple metrics.
  • Suggests concrete fixes to improve structure.

Limitations

  • Requires a properly set up Phoenix project.
  • Fix suggestions are generic and may need manual adjustment.
  • Does not analyze individual module-level dependencies beyond contexts.
When to use it

Use this skill when reviewing PRs, before major refactors, or when contexts feel tangled.

When not to use it

Do not use it for non-Phoenix projects or to analyze library dependencies.

Security analysis

Safe
Quality score92/100

The skill only uses safe read-only Bash commands (mix xref, find, grep) for static analysis. It does not execute destructive actions, download external content, or expose secrets.

No concerns found

How this analysis is made

Examples

Check context boundary violations
Run /phx:boundaries to check for violations in my Phoenix project.
Assess context health
Run /phx:boundaries --assess to score context health in my Phoenix app.
Fix boundary issues
Run /phx:boundaries --fix to suggest fixes for context boundary violations.

name: phx:boundaries description: Validate Phoenix context boundaries and dependencies using mix xref. Use when reviewing PRs, before major refactors, when contexts feel tangled, or when a module has too many cross-context dependencies. Also use when planning context splits or evaluating architecture health. argument-hint: [--assess|--fix] allowed-tools: Read, Grep, Glob, Bash

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

# Module count per context
for dir in lib/my_app/*/; do
  echo "$(basename $dir): $(find $dir -name '*.ex' | wc -l) modules"
done

# Public function count per context
for f in lib/my_app/*.ex; do
  echo "$(basename $f): $(grep -c '^  def ' $f 2>/dev/null || echo 0) public funcs"
done

# Dependency analysis
mix xref graph --format stats

# Circular dependencies
mix xref graph --format cycles

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

  1. Controllers call only contexts - No direct Repo access from web layer
  2. Schemas are pure data - No side effects, no Repo calls in schema modules
  3. Contexts own their schemas - Don't import schemas from other contexts
  4. Explicit dependencies only - Cross-context calls must be intentional

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

mix xref graph --label compile-connected

Find What Depends on a Context

mix xref graph --sink MyApp.Accounts --label compile

Find What a Module Calls

mix xref callers MyApp.Accounts.get_user!/1

Check for Circular Dependencies

mix xref graph --format cycles

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

  1. Run mix xref graph --label compile-connected for overview
  2. Check for context cross-contamination
  3. Verify no direct Repo calls from web layer
  4. Ensure schemas have no side effects
  5. 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:

  • references/context-design.md - Context design principles
  • references/refactoring-boundaries.md - Fixing boundary violations

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/phoenix-context-boundary-validation-mmlj2o2f/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/phoenix-context-boundary-validation-mmlj2o2f' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/phoenix-context-boundary-validation-mmlj2o2f/download' --output '.skill-downloads/phoenix-context-boundary-validation-mmlj2o2f/SKILL.md.part' && mv '.skill-downloads/phoenix-context-boundary-validation-mmlj2o2f/SKILL.md.part' '.skill-downloads/phoenix-context-boundary-validation-mmlj2o2f/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Tools declared by the author (check availability in your agent): Read, Grep, Glob, Bash

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

This file does not provide a usable name/description header for this native procedure. It remains available to download and inspect; use the manual method below.

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/phoenix-context-boundary-validation-mmlj2o2f/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills