Elixir Project
Language: Elixir October 1, 2025
Instruction file for Elixir projects with Phoenix and OTP.
---
applyTo: "**/*.ex, **/*.exs"
---
# Elixir Development Instructions (2025)
_Last updated: October 2025_
- Always use the fetch tool to look up the latest Elixir documentation: https://elixir-lang.org/docs.html
- Use Elixir 1.15+ for new projects
- Leverage functional programming patterns and immutability
- Use Phoenix framework for web applications
- Implement OTP principles for fault-tolerant systems
- Follow Elixir style guide and naming conventions
**Core Principles:**
- Embrace immutability - data cannot be changed
- Use pattern matching for control flow and function dispatch
- Implement pipe operator |> for data transformation pipelines
- Use atoms for constant values and keys
- Follow functional programming principles
- Understand processes and message passing
**Phoenix Framework:**
- Use Phoenix 1.7+ with LiveView for real-time web apps
- Implement context-based architecture
- Use Ecto for database operations
- Leverage channels for WebSocket communication
- Use generators for scaffolding (mix phx.gen)
- Implement proper routing with Phoenix Router
**Pattern Matching:**
- Use pattern matching in function heads
- Implement guard clauses for additional conditions
- Match on data structures for destructuring
- Use = operator for matching, not assignment
- Pattern match in case and with expressions
**Concurrency:**
- Use processes for concurrent operations (spawn, Task)
- Implement GenServer for stateful processes
- Use Supervisor for fault tolerance
- Leverage Task.async for concurrent operations
- Implement proper message passing between processes
**Ecto (Database):**
- Use Ecto schemas for data validation
- Implement changesets for data validation and casting
- Use Ecto Query for database queries
- Leverage Ecto migrations for schema changes
- Implement associations (belongs_to, has_many)
**Error Handling:**
- Use {:ok, result} and {:error, reason} tuples
- Implement with expressions for happy path
- Use case for pattern matching on results
- Let it crash - embrace OTP supervision
- Use try/rescue sparingly
**LiveView:**
- Use Phoenix LiveView for real-time server-rendered apps
- Implement mount and handle_event callbacks
- Use assigns for state management
- Leverage PubSub for real-time updates
- Implement form handling with changesets
**Testing:**
- Use ExUnit for testing
- Write doctests for function documentation
- Implement proper test setup with setup/setup_all
- Use Mox for mocking
- Test GenServers and processes properly
**Performance:**
- Use ETS for in-memory storage
- Implement caching strategies
- Leverage BEAM's concurrency model
- Use :telemetry for monitoring
- Profile with :observer and :fprof
**Summary:**
> For all Elixir work, always use the fetch tool to look up the latest documentation from https://elixir-lang.org/docs.html. Build scalable, fault-tolerant applications with functional programming. Elixir Phoenix Backend Functional Programming Programming Language