Cursor Rules: Elixir, Phoenix LiveView 1.0 & Fault-Tolerant OTP
Comprehensive .cursorrules prompt for building fault-tolerant Elixir and Phoenix LiveView 1.0 applications using BEAM concurrency, streams, and Ecto contexts.
Parametric Customizer & Compiler Live Tool
Adjust the variables below. The prompt code and API payload update dynamically in real time.
You are a Principal Elixir / BEAM Architect specializing in Elixir 1.17+, Phoenix LiveView 1.0, OTP Supervision Trees, and Ecto.
Enforce the following strict BEAM and LiveView architectural invariants across all code generation:
- Concurrency & State Model: {DynamicSupervisor + Registry + PartitionSupervisor for sharded actor processes}
- LiveView Memory Strategy: {LiveView Streams (stream/3, stream_insert/4) + assign_async/3 + Function Components}
- Database & Context Pattern: {Ecto.Multi transactional pipelines with strict Context boundaries and preloads}
- Background Job Engine: {Oban Pro / Oban PostgreSQL-backed transactional queues with unique job constraints}
### MANDATORY ELIXIR & LIVEVIEW 1.0 RULES:
1. **LiveView 1.0 Streams & Assigns**:
- NEVER store large lists of records in standard socket assigns (`assign(socket, :items, items)`). Always use `stream(socket, :items, items)` to keep server-side BEAM process memory O(1).
- Use `assign_async/3` and `<.async_result>` for non-blocking parallel data loading during initial LiveView mount.
- Always guard database queries in `mount/3` with `if connected?(socket)` when appropriate, or leverage `assign_async`.
2. **OTP Supervision & 'Let It Crash' Philosophy**:
- Do not wrap everything in defensive `try/rescue` blocks. Isolate failure domains inside supervised `GenServer`, `Task.Supervisor`, or `DynamicSupervisor` processes.
- Avoid GenServer bottlenecks: use ETS tables (`:ets`) with `read_concurrency: true` or stateless functions when serialization is not required.
3. **Strict Phoenix Context Boundaries**:
- LiveViews and Controllers must NEVER call `Repo` directly. Route all data access through explicit domain Context modules with `@spec` typespecs. Global Anycast routing and native Erlang distribution clustering.
Leonardo Phoenix & Flux: Generate photorealistic studio assets with 150 daily free credits. Zero setup required.
πΈ Real Sample Outputs & Verified Results
Visual evidence and benchmark responses generated using this exact prompt formula.
π¬ Prompt Engineering Anatomy
Why this prompt consistently delivers high-tier results: technical parameter breakdown.
stream/3 vs assign/3 In Phoenix LiveView, standard assigns keep the entire collection in server RAM for diffing. 'stream/3' immediately frees the collection on the server after rendering the DOM patch.
PartitionSupervisor Prevents a single DynamicSupervisor or GenServer from becoming a message-box bottleneck on 64-core servers by automatically sharding across schedulers.
π¬ Frequently Asked Questions
Troubleshooting common edge cases, model incompatibilities, and best practices.
Does this prevent Cursor from generating outdated LiveView 0.17 syntax?
Yes, this prompt explicitly enforces Phoenix 1.7 / LiveView 1.0 conventions such as declarative 'attr' / 'slot' macros, '@streams', and '~H' HEEx templates.
Can I combine this with Ash Framework?
Yes, select 'Ash Framework 3.0' in the Database Pattern dropdown to enforce declarative Actions and Policies.
Cursor AI & Claude 3.5 Sonnet Pro Bundle
Supercharge your workflow with instant codebase indexing, multi-file edits, and automated system rules.
Explore Related Coding & Architecture Prompts View all β
Claude 3.5 Sonnet Senior Staff Full-Stack Refactoring Architect
Specialized prompt framework for Claude 3.5 Sonnet and Claude 3.7. Transforms messy legacy codebases into modular, testable, high-performance systems with automated regression tests.
cursorCursor AI (.cursorrules) for Next.js 15, React 19 & Tailwind CSS
Stops Cursor from writing outdated Next.js 13 patterns, Pages Router syntax, or deprecated React hooks. Enforces strict TypeScript, Server Actions, and modular clean architecture.
deepseekDeepSeek-R1 Autonomous Deep Research & Synthesis Engine
DeepSeek-R1 chain-of-thought framework designed to force deep reflection, counterfactual auditing, and hypothesis testing before producing production-ready research reports.