Syntic
← All skills
LanguagesFreeCommunityv1.0.0

Elixir Expert

Use when building fault-tolerant, concurrent applications with Elixir, Phoenix, OTP supervision trees, LiveView, and BEAM.

About this skill

Use when building fault-tolerant, concurrent applications with Elixir, Phoenix, OTP supervision trees, LiveView, and BEAM.

SKILL.md

elixir-expert.SKILL.md

Place it in your Syntic skills folder. For Syntic Code, install in your local skills directory, review the contents and run it in a controlled environment first.

SKILL.md
---
name: Elixir Expert
description: Use when building fault-tolerant, concurrent applications with Elixir, Phoenix, OTP supervision trees, LiveView, and BEAM.
category: Languages
version: 1.0.0
tools: []
---

# Elixir and BEAM Development

Build fault-tolerant, concurrent applications using OTP, Phoenix, and the BEAM virtual machine.

## Core Principles

- **Let it crash.** Design supervision trees so individual process failures are isolated and automatically recovered.
- **Immutability enforced.** All data is immutable. Transformations create new data. State lives in processes.
- **Pattern matching** as primary control flow. Use in function heads, case expressions, and with clauses.
- **BEAM is your OS.** Use OTP GenServer, Supervisor, Registry instead of external tools for state and coordination.

## OTP Patterns

- **GenServer** for stateful processes: caches, rate limiters, connection pools.
- **Supervisor** with restart strategies: `:one_for_one` (independent children), `:one_for_all` (coordinated restart).
- **DynamicSupervisor** for on-demand processes: per-user sessions, per-room chat servers.
- **Registry** for process lookup by name. Avoid global names in distributed systems.
- **Task** and **Task.Supervisor** for fire-and-forget async work. Use `Task.async/await` for parallel computations.

## Phoenix Framework

- Phoenix 1.7+ with verified routes: `~p"/users/#{user}"` for compile-time route checking.
- **Contexts** (bounded contexts) organize business logic: `Accounts`, `Orders`, `Catalog`.
- Keep controllers thin. Controllers call context functions and render. Business logic in models/services.
- **Changesets** for data validation: `cast`, `validate_required`, `validate_format`, `unique_constraint`.
- **Ecto.Multi** for multi-step database transactions with named operations and rollback.

## Phoenix LiveView

- Maintains WebSocket connection, sends minimal diffs to client for real-time UI.
- `assign` and `assign_async` for state management. `stream` for large lists with efficient DOM patching.
- Implement `handle_event` (user interactions), `handle_info` (PubSub messages), `handle_async` (background tasks).
- Use `live_component` for reusable, stateful UI components with own event handling.
- Use `phx-debounce` and `phx-throttle` on form inputs to reduce server round-trips.

## Ecto and Data

- Schemas with explicit types. Use `embedded_schema` for non-database data structures.
- Use `Repo.preload` or `from(u in User, preload: [:posts])` to avoid N+1 queries.
- Database-level constraints (`unique_constraint`, `foreign_key_constraint`) and handle in changesets.
- `Repo.stream` with `Repo.transaction` for large datasets without loading all records.

## Distributed Systems

- **Phoenix.PubSub** for in-cluster message broadcasting. Works across nodes automatically.
- **libcluster** for automatic node discovery (Kubernetes, DNS, gossip strategies).
- **Horde** for distributed process registries and supervisors across nodes.
- Use `:rpc.call` sparingly. Prefer message passing via PubSub.

## Testing

- ExUnit with `async: true` for tests without shared state. BEAM handles true parallel test execution.
- `Ecto.Adapters.SQL.Sandbox` for concurrent database tests with automatic cleanup.
- **Mox** for behavior-based mocking. Define behaviors (callbacks) for external services.
- `Phoenix.LiveViewTest` with `live/2` and `render_click/2` for LiveView tests.
- **StreamData** for property-based testing on functions with wide input domains.

Install

Syntic App

  1. 1Create a dedicated folder for this skill in your local skills library.
  2. 2Place SKILL.md into that folder.
  3. 3Restart Syntic and invoke this skill on matching tasks.

Syntic Code (CLI)

  1. 1Save SKILL.md in your local Syntic Code skills directory.
  2. 2Keep related files in the same skill folder.
  3. 3Run in a safe environment and validate outputs.