phoenix-api-genGenerate a full Phoenix JSON API from an OpenAPI spec or natural language description. Creates contexts, Ecto schemas, migrations, controllers, JSON views/renderers, router entries, ExUnit tests with factories, auth plugs, and tenant scoping. Use when building a new Phoenix REST API, adding CRUD endpoints, scaffolding resources, or converting an OpenAPI YAML into a Phoenix project.
Install via ClawdBot CLI:
clawdbot install gchapim/phoenix-api-gensecuritySchemes.YYYYMMDDHHMMSS)JSON modules, or View for older)See references/phoenix-conventions.md for project structure, naming, context patterns.
Key rules:
Accounts, Billing, Notifications).MyApp.Accounts.User.{:ok, resource} or {:error, changeset}.FallbackController with action_fallback/1 to handle error tuples.See references/ecto-patterns.md for schema, changeset, migration details.
Key rules:
timestamps(type: :utc_datetime_usec).@primary_key {:id, :binary_id, autogenerate: true} + @foreign_key_type :binary_id.create_changeset/2 and update_changeset/2 when create/update fields differ.Add tenant_id :binary_id to every tenant-scoped table. Pattern:
# In context
def list_resources(tenant_id) do
Resource
|> where(tenant_id: ^tenant_id)
|> Repo.all()
end
# In plug ā extract tenant from conn and assign
defmodule MyAppWeb.Plugs.SetTenant do
import Plug.Conn
def init(opts), do: opts
def call(conn, _opts) do
tenant_id = get_req_header(conn, "x-tenant-id") |> List.first()
assign(conn, :tenant_id, tenant_id)
end
end
Always add a composite index on [:tenant_id, .
defmodule MyAppWeb.Plugs.ApiKeyAuth do
import Plug.Conn
def init(opts), do: opts
def call(conn, _opts) do
with [key] <- get_req_header(conn, "x-api-key"),
{:ok, account} <- Accounts.authenticate_api_key(key) do
assign(conn, :current_account, account)
else
_ -> conn |> send_resp(401, "Unauthorized") |> halt()
end
end
end
defmodule MyAppWeb.Plugs.BearerAuth do
import Plug.Conn
def init(opts), do: opts
def call(conn, _opts) do
with ["Bearer " <> token] <- get_req_header(conn, "authorization"),
{:ok, claims} <- MyApp.Token.verify(token) do
assign(conn, :current_user, claims)
else
_ -> conn |> send_resp(401, "Unauthorized") |> halt()
end
end
end
scope "/api/v1", MyAppWeb do
pipe_through [:api, :authenticated]
resources "/users", UserController, except: [:new, :edit]
resources "/teams", TeamController, except: [:new, :edit] do
resources "/members", MemberController, only: [:index, :create, :delete]
end
end
See references/test-patterns.md for ExUnit, Mox, factory patterns.
Key rules:
async: true on all tests that don't share state.Ecto.Adapters.SQL.Sandbox for DB isolation.ex_machina or hand-rolled build/1, insert/1.Mox ā define behaviours, set expectations in test.defmodule MyAppWeb.UserControllerTest do
use MyAppWeb.ConnCase, async: true
import MyApp.Factory
setup %{conn: conn} do
user = insert(:user)
conn = put_req_header(conn, "authorization", "Bearer #{token_for(user)}")
{:ok, conn: conn, user: user}
end
describe "index" do
test "lists users", %{conn: conn} do
conn = get(conn, ~p"/api/v1/users")
assert %{"data" => users} = json_response(conn, 200)
assert is_list(users)
end
end
describe "create" do
test "returns 201 with valid params", %{conn: conn} do
params = params_for(:user)
conn = post(conn, ~p"/api/v1/users", user: params)
assert %{"data" => %{"id" => _}} = json_response(conn, 201)
end
test "returns 422 with invalid params", %{conn: conn} do
conn = post(conn, ~p"/api/v1/users", user: %{})
assert json_response(conn, 422)["errors"] != %{}
end
end
end
defmodule MyAppWeb.UserJSON do
def index(%{users: users}), do: %{data: for(u <- users, do: data(u))}
def show(%{user: user}), do: %{data: data(user)}
defp data(user) do
%{
id: user.id,
email: user.email,
inserted_at: user.inserted_at
}
end
end
timestamps(type: :utc_datetime_usec){:error, changeset} and {:error, :not_found}Generated Mar 1, 2026
A startup building a multi-tenant SaaS platform for project management needs to quickly generate REST APIs for resources like projects, tasks, and users from an OpenAPI spec. This skill automates the creation of Phoenix contexts, controllers, and tests with built-in tenant scoping and authentication, reducing development time from weeks to days.
An e-commerce company wants to add new CRUD endpoints for inventory management and order tracking based on a natural language description of resources. The skill generates Ecto schemas, migrations, and JSON renderers following Phoenix conventions, ensuring consistency and maintainability across the codebase.
A healthcare provider needs to build a secure API for patient records and appointments, requiring strict validation and authentication. This skill parses an OpenAPI spec to create controllers with auth plugs for API keys and bearer tokens, along with ExUnit tests covering error cases and data integrity.
A FinTech firm is developing microservices for banking transactions and user accounts. Using this skill, they can convert OpenAPI YAML into Phoenix projects with contexts like Billing and Accounts, generating migrations with binary IDs and composite indexes for performance in multi-tenant environments.
An educational technology company needs to scaffold APIs for courses, enrollments, and assessments from a natural language description. The skill infers context boundaries, creates Ecto changesets with validation, and sets up router structures with nested resources, speeding up MVP deployment.
Companies offer API-driven services to other businesses on a subscription basis, using this skill to rapidly prototype and deploy new features. Revenue is generated through tiered pricing plans based on API usage, tenant limits, and support levels.
Developers sell access to specialized APIs, such as for data processing or integrations, built with Phoenix. This skill helps create scalable and well-tested endpoints, with revenue coming from pay-per-call models or usage-based billing.
Agencies use this skill to accelerate client projects by generating boilerplate code from specs, allowing them to focus on custom logic and integration. Revenue is earned through project-based contracts or hourly rates for development and maintenance.
š¬ Integration Tip
Integrate this skill into existing Phoenix projects by ensuring your OpenAPI spec or natural language descriptions clearly define resources and relationships, and review generated files for custom business logic before deployment.
Use the mcporter CLI to list, configure, auth, and call MCP servers/tools directly (HTTP or stdio), including ad-hoc servers, config edits, and CLI/type generation.
Connect to 100+ APIs (Google Workspace, Microsoft 365, GitHub, Notion, Slack, Airtable, HubSpot, etc.) with managed OAuth. Use this skill when users want to...
Build, debug, and deploy websites using HTML, CSS, JavaScript, and modern frameworks following production best practices.
YouTube Data API integration with managed OAuth. Search videos, manage playlists, access channel data, and interact with comments. Use this skill when users want to interact with YouTube. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway).
Scaffold, test, document, and debug REST and GraphQL APIs. Use when the user needs to create API endpoints, write integration tests, generate OpenAPI specs, test with curl, mock APIs, or troubleshoot HTTP issues.
Search for jobs across LinkedIn, Indeed, Glassdoor, ZipRecruiter, Google Jobs, Bayt, Naukri, and BDJobs using the JobSpy MCP server.