phoenix-contexts
/phoenix-contexts
Pomaga projektować konteksty Phoenix, czyli ich tworzenie, dzielenie i Scope, przy edycji kontekstów i routerów.
- Autor
- oliver-kriska ↗
- Repozytorium
- claude-elixir-phoenix ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 22.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 6
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 22.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Pomaga projektować konteksty Phoenix, czyli ich tworzenie, dzielenie i Scope, przy edycji kontekstów i routerów.
Oryginalny opis (EN)
Phoenix context design — creating/splitting contexts, Scope (1.8+); Use when editing contexts, routers, or designing…
Jak działa
- Iron Laws — Never Violate These
- Context Structure
- Phoenix 1.8+ Scopes (CRITICAL)
- Quick Decisions
- Anti-patterns
- Version Notes
- References
Podgląd SKILL.md
---
name: phoenix-contexts
description: Phoenix context design — creating/splitting contexts, Scope (1.8+); Use
when editing contexts, routers, or designing…
---
# Phoenix Contexts Reference
> **Ash projects**: `Ash.Domain` replaces Phoenix contexts for data access — use the `ash-framework` skill. Context boundary and PubSub patterns still apply.
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)
Context functions take the scope as their first parameter, so queries are filtered to the caller:
```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 excessive cross-context calls
### Cross-Context References
```elixir
# ✅ Reference by ID, convert at boundary
def create_order(%Scope{} = scope, user_id, product_ids) do
with {:ok, user} <- Accounts.fetch_user(scope, user_id) do
do_create_order(scope, user.id, product_ids)
end
end
# ❌ Reaching into other context's internals
alias MyApp.Accounts.User # Don't do this
Repo.all(from o in Order, join: u in User, ...) # Don't query other schemas
```
## Anti-patterns
| Wrong | Right |
|-------|-------|
| Service objects (`UserCreationService`) | Context functions (`Accounts.create_user/2`) |
| Repository pattern wrapping Repo | Repo IS the repository |
| Direct Repo calls in controllers | Delegate to context |
| Schema callbacks with side effects | Use Ecto.Multi |
## Version Notes
- **Phoenix 1.8+**: Uses built-in `%Scope{}` struct for authorization context
- **Phoenix 1.7**: Requires manual authorization context (see `references/scopes-auth.md` "Pre-Scopes Patterns")
## References
For detailed patterns, see:
- `references/context-patterns.md` - Full context module, PubSub, Multi, cross-boundary
- `references/scopes-auth.md` - Scope struct, multi-tenant, authorization, plugs
- `references/routing-patterns.md` - Verified routes, pipelines, API auth
- `references/plug-patterns.md` - Function/module plugs, placement, guards
- `references/json-api-patterns.md` - JSON controllers, FallbackController, API auth
Pliki w paczce (6)
- SKILL.md 3 KB
- references/context-patterns.md 6 KB
- references/json-api-patterns.md 4 KB
- references/plug-patterns.md 4 KB
- references/routing-patterns.md 3 KB
- references/scopes-auth.md 8 KB
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · oliver-kriska/claude-elixir-phoenix | 100 | MIT |
| oliver-kriska/claude-elixir-phoenix | 100 | MIT |
Identyczna treść występuje jeszcze w 1 innych folderach na GitHubie. Tu pokazujemy jedną, najlepiej ocenioną kopię.
Migawka bazy z 13.11.2026 · wersja paczki 0bb6f1d1ff67 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100phoenix-code-review
Przegląda kod Phoenix pod kątem wzorców kontrolerów, granic kontekstów, routingu i plugów, w kontrolerach, routerach i modułach kontekstów. - 100phoenix
Prowadzi przez budowę aplikacji webowych w Phoenix: LiveView, projektowanie kontekstów, kanały i integracja narzędzi deweloperskich Tidewave MCP. - 100phoenix-patterns
Stosuje dobre praktyki frameworku Phoenix: projektowanie kontekstów, wzorce kontrolerów i architektura aplikacji. - 100phoenix-pubsub-patterns
Dodaje aktualizacje na żywo do LiveView przez Phoenix.PubSub: tematy z zakresem, broadcast z kontekstów i Presence. - 100phoenix-scopes-and-generators
Pomaga uruchamiać generatory phx.gen z zakresami, rozbudowywać strukturę %Scope{} o organizację i konfigurować :scopes. - 100phx-boundaries
Analizuje granice kontekstów Phoenix i sprzężenia modułów przez mix xref, przy sprawdzaniu wywołań między kontekstami.