phoenix-contexts

Solid

Phoenix context design — creating/splitting contexts, Scope (1.8+), Ecto.Multi, PubSub, routers, plugs, controllers. Use when editing contexts, routers, or designing boundaries.

AI & Automation 384 stars 25 forks Updated 4 days ago MIT

Install

View on GitHub

Quality Score: 92/100

Stars 20%
86
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Phoenix Contexts Reference Reference for designing and implementing Phoenix contexts (bounded contexts). ## Iron Laws — Never Violate These 1. **CONTEXTS OWN THEIR DATA** — Never query another context's schema directly via Repo 2. **SCOPES ARE MANDATORY (Phoenix 1.8+)** — Every context function MUST accept scope as first parameter 3. **THIN CONTROLLERS/LIVEVIEWS** — Controllers translate HTTP, business logic stays in contexts 4. **NO SIDE EFFECTS IN SCHEMAS** — Use `Ecto.Multi` for transactions with side effects ## Context Structure ``` lib/my_app/ ├── accounts/ # Context directory │ ├── user.ex # Schema │ ├── scope.ex # Scope struct (Phoenix 1.8+) ├── accounts.ex # Context module (public API) ``` ## Phoenix 1.8+ Scopes (CRITICAL) All context functions MUST accept scope as first parameter: ```elixir def list_posts(%Scope{} = scope) do from(p in Post, where: p.user_id == ^scope.user.id) |> Repo.all() end def create_post(%Scope{} = scope, attrs) do %Post{user_id: scope.user.id} |> Post.changeset(attrs) |> Repo.insert() |> broadcast(scope, :created) end ``` ## Quick Decisions ### When to SPLIT contexts? - Module exceeds ~400 lines - Functions don't share domain language - Could theoretically be a separate microservice - Team member could own it independently ### When to KEEP together? - Resources share vocabulary and domain concepts - Functions frequently operate on same data together - Splitting would create exces...

Details

Author
oliver-kriska
Repository
oliver-kriska/claude-elixir-phoenix
Created
3 months ago
Last Updated
4 days ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

API & Backend Listed

ecto-thinking

This skill should be used when the user asks to "add a database table", "create a new context", "query the database", "add a field to a schema", "validate form input", "fix N+1 queries", "preload this association", "separate these concerns", or mentions Repo, changesets, migrations, Ecto.Multi, has_many, belongs_to, transactions, query composition, or how contexts should talk to each other.

2 Updated today
ahmedxx99
API & Backend Listed

phoenix-thinking

This skill should be used when the user asks to "add a LiveView page", "create a form", "handle real-time updates", "broadcast changes to users", "add a new route", "create an API endpoint", "fix this LiveView bug", "why is mount called twice?", or mentions handle_event, handle_info, handle_params, mount, channels, controllers, components, assigns, sockets, or PubSub. Essential for avoiding duplicate queries in mount.

2 Updated today
ahmedxx99
Code & Development Solid

phxboundaries

Analyze Phoenix context boundaries and module coupling via mix xref. Use when checking cross-context calls, validating dependencies, before splitting modules, or reviewing architecture.

384 Updated 4 days ago
oliver-kriska
Code & Development Solid

phxexamples

Provide examples and walkthroughs for Phoenix, LiveView, Ecto, OTP patterns. Use when "how do I...", "show me an example", or "what does X look like".

384 Updated 4 days ago
oliver-kriska
AI & Automation Listed

context-fundamentals

Foundational theory of context engineering — what context IS, how attention works, progressive disclosure principles, and context budgeting basics. Use when the user asks to "understand context", "explain context windows", "learn context engineering", or discusses context components, attention mechanics, or context budgets. NOT for fixing broken context or diagnosing failures (use context-degradation), NOT for compressing or summarizing context (use context-compression), NOT for KV-cache or partitioning performance optimization (use context-optimization), NOT for file-based context patterns or scratch pads (use filesystem-context).

9 Updated 2 days ago
viktorbezdek