with one click
builderx-api-contexts
Guide to Context logic structure in builderx_api.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Guide to Context logic structure in builderx_api.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Phoenix Channel patterns in landing_page_backend — real-time collaboration, WebSocket topics, broadcasting, and channel structure.
Guide to Context module patterns in landing_page_backend — Ecto queries, dynamic query building, Ecto.Multi, and Outbox messaging.
Guide to Phoenix Controller structure in landing_page_backend using FallbackController, tuple responses, and permission plugs.
Patterns for creating Oban background workers in landing_page_backend — queue configuration, job arguments, retry strategies, and dynamic query processing.
Custom Plug middleware patterns in landing_page_backend — authentication (JWT/Passport), authorization, permission checking, and rate limiting.
Guidelines for creating Ecto Schemas in landing_page_backend, including binary UUID primary keys, virtual fields, custom json/1 function, and multiple changeset patterns.
| name | builderx_api-contexts |
| description | Guide to Context logic structure in builderx_api. |
| metadata | {"author":"Vũ Lưu","version":"2026.03.25","source":"Source code builderx_api"} |
Conventions and structure for Ecto Contexts in the builderx_api project.
| Topic | Description | Reference |
|---|---|---|
| Transactions and Outbox | Using Ecto.Multi for complex logic and logging Outbox messages | core-multi-outbox |
defmodule BuilderxApi.SomeContext do
alias BuilderxApi.Citus, as: Repo
alias BuilderxApi.{Tools, Outbox}
alias Ecto.Multi
def create_something(attrs \\ %{}) do
multi =
Multi.new()
|> Multi.run(:changeset, fn _, _ ->
# Generate changeset
{:ok, Something.changeset(%Something{}, attrs)}
end)
|> Multi.run(:insert, fn _, %{changeset: changeset} ->
# Handle insert
Repo.insert(changeset, returning: true)
end)
|> Multi.run(:changelog, fn _, %{changeset: changeset, insert: insert_res} ->
# Write outbox log
%{
queue: "sync_to_questdb",
args: %{
action: "something_changelog",
data: %{
id: Ecto.UUID.generate(),
action: "CREATE",
changes: changeset.changes,
record_id: insert_res.id,
site_id: insert_res.site_id,
}
}
}
|> Outbox.new()
end)
case Repo.transaction(multi) do
{:ok, res} -> {:ok, res.insert}
err -> {:error, err}
end
end
end