Table of content
Phoenix Framework skills for building web applications
Installation
npx claude-plugins install @TheBushidoCollective/han/jutsu-phoenix
Contents
Folders: hooks, skills
Files: CHANGELOG.md, README.md
Documentation
Phoenix Framework skills for building web applications in Elixir.
Skills
This plugin provides the following skills:
- Phoenix Controllers - Building RESTful and LiveView controllers
- Phoenix Routing - Defining routes and pipelines
- Phoenix Views Templates - Creating views and templates
- Phoenix Patterns - Best practices for Phoenix applications
Usage
Once enabled, Claude will automatically apply these skills when working with relevant code. The plugin provides context and expertise that Claude uses to:
- Write idiomatic code following best practices
- Suggest appropriate patterns and architectures
- Catch common mistakes and anti-patterns
- Provide framework-specific guidance
Installation
Install with npx (no installation required):
han plugin install jutsu-phoenix
License
Licensed under MIT - see repository for details.
Included Skills
This plugin includes 4 skill definitions:
phoenix-controllers
Handle HTTP requests with Phoenix controllers including actions, parameters, rendering, flash messages, and redirects
View skill definition
Phoenix Controllers
Phoenix controllers are the intermediary modules between the router and views in a Phoenix application. They handle HTTP requests, process parameters, interact with contexts, and determine what response to send back to the client. Controllers are stateless and receive a connection struct (conn) that represents the current HTTP request.
Basic Controller Structure
The simplest Phoenix controller uses the HelloWeb, :controller macro and defines actions as functions that receive the connection and parameters:
defmodule HelloWeb.PageController do
use HelloWeb, :controller
def home(conn, _params) do
render(conn, :home, layout: false)
end
end
Each controller action receives:
conn- ThePlug.Connstruct representing the HTTP request/responseparams- A map containing request parameters from the URL, query string, and request body
Controller Actions and Parameter Handling
Extracting Specific Parameters
Use pattern matching to extract specific parameters from the params map:
defmodule HelloWeb.HelloController do
use HelloWeb, :controller
def show(conn, %{"messenger" => messenger}) do
render(conn, :show, messenger: messenger)
end
end
Accessing Full Parameter Map
To access both a specific parameter and the full params map, use pattern matching with the = operator:
def show(conn, %{"messenger" => messenger} = params) do
# Access to both messenger and the full para
...(truncated)
</details>
### phoenix-patterns
> Use when applying Phoenix Framework best practices including context design, controller patterns, and application architecture. Use when building Phoenix applications.
<details>
<summary>View skill definition</summary>
# Phoenix Patterns
Master Phoenix Framework patterns to build well-structured, maintainable web applications in Elixir.
## Context Design
Contexts are dedicated modules that expose and group related functionality:
```elixir
defmodule MyApp.Accounts do
@moduledoc """
The Accounts context handles user management and authentication.
"""
alias MyApp.Repo
alias MyApp.Accounts.User
def list_users do
Repo.all(User)
end
def get_user!(id), do: Repo.get!(User, id)
def get_user_by_email(email) do
Repo.get_by(User, email: email)
end
def create_user(attrs \\ %{}) do
%User{}
|> User.changeset(attrs)
|> Repo.insert()
end
def update_user(%User{} = user, attrs) do
user
|> User.changeset(attrs)
|> Repo.update()
end
def delete_user(%User{} = user) do
Repo.delete(user)
end
def change_user(%User{} = user, attrs \\ %{}) do
User.changeset(user, attrs)
end
end
Controller Patterns
defmodule MyAppWeb.UserController do
use MyAppWeb, :controller
alias MyApp.Accounts
alias MyApp.Accounts.User
action_fallback MyAppWeb.FallbackController
def index(conn, _params) do
users = Accounts.list_users()
render(conn, :index, users: users)
end
def create(conn, %{"user" => user_params}) do
with {:ok, %User{} = user} <- Accounts.create_user(user_params) do
conn
|> put_status(:created)
|> put_resp_header("location", ~p"/api/users/#{user}")
|> render(:show, user:
...(truncated)
</details>
### phoenix-routing
> Define routes and URL helpers in Phoenix applications including resources, scopes, pipelines, and verified routes
<details>
<summary>View skill definition</summary>
# Phoenix Routing
Phoenix routing maps incoming HTTP requests to controller actions. The router is the entry point for all web requests and determines which controller action should handle each request. Phoenix provides powerful routing macros for RESTful resources, scopes, pipelines, and verified routes.
## Basic Route Declaration
### Single Routes
Define individual routes using HTTP verb macros:
```elixir
get "/", PageController, :home
Phoenix supports all standard HTTP verbs:
get "/users", UserController, :index
post "/users", UserController, :create
patch "/users/:id", UserController, :update
put "/users/:id", UserController, :update
delete "/users/:id", UserController, :delete
Routes with Dynamic Segments
Capture URL parameters using the :param_name syntax:
get "/hello/:messenger", HelloController, :show
The :messenger segment becomes available in the controller’s params map.
Resource Routes
Basic Resource Declaration
Generate all standard RESTful routes with the resources macro:
resources "/users", UserController
This generates eight routes:
GET /users UserController :index
GET /users/:id/edit UserController :edit
GET /users/new UserController :new
GET /users/:id UserController :show
POST /users UserController :create
PATCH /users/:id UserController :update
PUT /users/:id UserController :update
DELETE /users/:id
...(truncated)
</details>
### phoenix-views-templates
> Render views and templates in Phoenix using HEEx templates, function components, slots, and assigns
<details>
<summary>View skill definition</summary>
# Phoenix Views and Templates
Phoenix uses HEEx (HTML+EEx) templates for rendering dynamic HTML content. HEEx provides compile-time validation, security through automatic escaping, and a component-based architecture. Views in Phoenix are modules that organize template rendering logic and house reusable function components.
## View Module Structure
Phoenix view modules use the `embed_templates` macro to load HEEx templates from a directory:
```elixir
defmodule HelloWeb.HelloHTML do
use HelloWeb, :html
embed_templates "hello_html/*"
end
This automatically creates functions for each .html.heex file in the hello_html/ directory.
HEEx Templates
Basic Template Structure
HEEx templates combine HTML with embedded Elixir expressions:
<section>
<h2>Hello World, from Phoenix!</h2>
</section>
Interpolating Dynamic Content
Use <%= ... %> to interpolate Elixir expressions into HTML:
<section>
<h2>Hello World, from <%= @messenger %>!</h2>
</section>
The @ symbol accesses assigns passed from the controller.
Multi-line Expressions
For expressions without output, omit the =:
<% # This is a comment %>
<% user_name = String.upcase(@user.name) %>
<p>Welcome, <%= user_name %>!</p>
Working with Assigns
Assigns are key-value pairs passed from controllers to templates:
# Controller
def show(conn, %{"messenger" => messenger}) do
render(conn, :show, messenger: messenger, receiver: "Dweezil")
end
...(truncated)
</details>
## Source
[View on GitHub](https://github.com/TheBushidoCollective/han)