- Home
- Skills
- Thebushidocollective
- Han
- Phoenix Patterns
phoenix-patterns_skill
- TypeScript
88
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill thebushidocollective/han --skill phoenix-patterns- SKILL.md4.9 KB
Overview
This skill provides a concise, practical guide to applying Phoenix Framework best practices for context design, controller patterns, and application architecture. It focuses on structuring code for maintainability, using plugs and pipelines effectively, and handling errors consistently. Use it to make Phoenix apps predictable, testable, and easy to evolve.
How this skill works
The skill explains how to organize domain logic into contexts that expose clear CRUD and query functions while keeping controllers thin. It demonstrates controller patterns including action_fallback for centralized error handling, RESTful routes, and response rendering. It also covers router pipelines and custom plugs for authentication and cross-cutting concerns so you can compose behavior cleanly across scopes.
When to use it
- When designing or refactoring a Phoenix application to improve structure and separation of concerns.
- When you need a consistent pattern for CRUD controllers and API responses.
- When implementing authentication, authorization, or other cross-cutting concerns via plugs.
- When configuring router pipelines to separate browser and API behavior.
- When standardizing error handling with a fallback controller.
Best practices
- Keep controllers thin and delegate business logic to contexts.
- Group related functions in contexts to define clear boundaries and public APIs.
- Use action_fallback to centralize HTTP error responses and status codes.
- Compose authentication and authorization as plugs in router pipelines.
- Follow RESTful routing and separate browser and API pipelines for different concerns.
Example use cases
- Create an Accounts context that exposes list, get, create, update, delete, and change functions for user management.
- Implement a UserController that uses with/ok tuples and action_fallback for clean success/error flows.
- Add an Authenticate plug that extracts a Bearer token, verifies it, and assigns current_user or returns 401.
- Define :api and :browser pipelines in the router and mount admin routes under an :admin pipeline.
- Replace ad-hoc controller logic with context calls to make the codebase more testable and modular.
FAQ
Put validations in schemas/changesets and run them inside context functions; controllers should only handle parsing params and returning responses.
When should I create a new context versus adding to an existing one?
Create a new context when functionality serves a distinct domain or set of responsibilities; avoid overly large contexts by grouping only closely related behavior.