Skip to content
Back to skills

1542 Contexts Fe0b2a88

ASecurity

```elixir lib/my_app/ ├── accounts/ # User identity & auth │ ├── user.ex │ └── accounts.ex ├── catalog/ # Product information │ ├── product.ex │ └── catalog.ex └── orders/ # Purchase workflow ├── order.ex └── orders.ex

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
testinggoapi

Works with

  • api

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 1542-contexts_fe0b2a88 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 1542 Contexts Fe0b2a88?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 1542 Contexts Fe0b2a88
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-1542-contexts-fe0b2a88/badge)](https://www.skillsdirectory.com/skills/tools-only-1542-contexts-fe0b2a88)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# Phoenix Contexts

## Bounded Contexts

### Domain Boundaries

```elixir
# GOOD - contexts bounded by domain
lib/my_app/
├── accounts/           # User identity & auth
│   ├── user.ex
│   └── accounts.ex
├── catalog/            # Product information
│   ├── product.ex
│   └── catalog.ex
└── orders/             # Purchase workflow
    ├── order.ex
    └── orders.ex

# BAD - contexts bounded by technical layer
lib/my_app/
├── models/
├── queries/
└── services/
```

### Public API Design

```elixir
# GOOD - domain-focused function names
defmodule MyApp.Accounts do
  def register_user(attrs)
  def authenticate_user(email, password)
  def reset_password(user, new_password)
end

# BAD - CRUD-focused names
defmodule MyApp.Accounts do
  def create_user(attrs)
  def get_user(id)
  def update_user(user, attrs)
end
```

## Ecto Integration

### Changesets in Contexts

```elixir
defmodule MyApp.Accounts do
  alias MyApp.Accounts.User

  def create_user(attrs) do
    %User{}
    |> User.registration_changeset(attrs)
    |> Repo.insert()
  end

  def update_user(%User{} = user, attrs) do
    user
    |> User.update_changeset(attrs)
    |> Repo.update()
  end
end
```

### Schema Definitions

```elixir
defmodule MyApp.Accounts.User do
  use Ecto.Schema
  import Ecto.Changeset

  schema "users" do
    field :email, :string
    field :password_hash, :string
    field :password, :string, virtual: true

    timestamps()
  end

  def registration_changeset(user, attrs) do
    user
    |> cast(attrs, [:email, :password])
    |> validate_required([:email, :password])
    |> validate_format(:email, ~r/@/)
    |> validate_length(:password, min: 8)
    |> unique_constraint(:email)
    |> hash_password()
  end
end
```

## Cross-Context Communication

```elixir
# GOOD - contexts communicate through public APIs
defmodule MyApp.Orders do
  alias MyApp.Accounts

  def create_order(user_id, items) do
    with {:ok, user} <- Accounts.get_user(user_id),
         :ok <- Accounts.verify_can_purchase(user) do
      # Create order
    end
  end
end

# BAD - reaching into another context's internals
defmodule MyApp.Orders do
  alias MyApp.Accounts.User
  alias MyApp.Repo

  def create_order(user_id, items) do
    user = Repo.get!(User, user_id)  # Bypasses Accounts context!
    # ...
  end
end
```

## Review Questions

1. Are contexts bounded by business domain, not technical layer?
2. Do public functions have domain-focused names?
3. Are changesets used for all data validation?
4. Do contexts communicate through public APIs only?

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.