LiveView Best Practices
AI can help with:
- Optimizing assigns updates
- Reducing data over wire
- Client-side hooks
- JavaScript interop
- SEO considerations
Master Elixir and Phoenix development with Cursor IDE and Claude Code. These patterns cover functional programming, OTP principles, LiveView, concurrent systems, and the unique features that make Elixir perfect for building fault-tolerant, real-time applications.
claude "Initialize Phoenix app with umbrella architecture"
# Phoenix architecture prompt:"Set up Phoenix application with:- Contexts for domain logic- LiveView for real-time UI- PubSub for messaging- Ecto schemas and migrations- Background jobs with Oban- Telemetry for monitoring"
# Generated structure:lib/ my_app/ accounts/ # Context catalog/ # Context mailer/ repo.ex my_app_web/ live/ controllers/ components/ router.ex
# LiveView component prompt:"Create a LiveView for real-time dashboard with:- Multiple chart components- Live data updates via PubSub- User interactions- Optimistic UI updates- Error recovery"
# Stateful component:"Create LiveComponent for:- File upload with progress- Drag and drop support- Image preview- Validation feedback"
# Real-time features prompt:"Implement real-time chat with:- Phoenix Channels- Presence tracking- Message history- Typing indicators- Read receipts- Push notifications"
LiveView Best Practices
AI can help with:
# GenServer prompt:"Create GenServer for:- Rate limiting service- State persistence- Crash recovery- Dynamic supervision- Telemetry events- Backpressure handling"
# Ecto schema prompt:"Design Ecto schemas for e-commerce:- Multi-tenant architecture- Polymorphic associations- Soft deletes- Audit logging- Full-text search- Database views"
Complex Queries
# Prompt: "Create Ecto query with:# - Window functions# - CTEs# - Lateral joins# - Aggregations"
Performance
# Prompt: "Optimize queries with:# - Preloading strategies# - Batch loading# - Query fragments# - Raw SQL when needed"
# Concurrency patterns prompt:"Implement concurrent system for:- Parallel data processing- Task supervision- Flow-based programming- GenStage pipelines- Broadway integration- Back-pressure handling"
# Actor pattern:"Design actor system with:- Message protocols- State machines- Event sourcing- Process registry- Distributed actors"
# Pool management:"Create process pool for:- Worker allocation- Load balancing- Health monitoring- Dynamic scaling"
# Test suite prompt:"Create test suite with:- Unit tests with ExUnit- LiveView testing- Channel testing- Integration tests- Property-based tests with StreamData- Mox for mocking"
# Auth system prompt:"Implement authentication with:- Pow or Guardian- Multi-factor auth- OAuth providers- Session management- Password policies- Account lockout"
Security Checklist
AI can implement:
# GraphQL API prompt:"Create GraphQL API with Absinthe:- Schema design- Resolvers with dataloader- Subscriptions- Authentication middleware- Error handling- Schema stitching"
# REST API design:"Create JSON API with:- Resource controllers- Pagination- Filtering- API versioning- OpenAPI docs"
# API auth:"Implement API auth with:- JWT tokens- API keys- Rate limiting- Token refresh"
# Performance optimization:"Optimize Phoenix app for:- Response time reduction- Memory usage- Database query optimization- Caching strategies- CDN integration- Load testing"
ETS Caching
# Prompt: "Implement ETS cache:# - TTL support# - Cache warming# - Invalidation# - Memory limits"
Redis Integration
# Prompt: "Add Redis caching:# - Connection pooling# - Pub/sub support# - Distributed cache# - Cache aside pattern"
# Deployment prompt:"Set up deployment with:- Elixir releases- Config providers- Runtime configuration- Health checks- Rolling updates- Kubernetes manifests"
# Distributed Elixir prompt:"Implement distributed system with:- libcluster for discovery- Global process registry- Distributed PubSub- CRDTs for state- Split-brain handling- Network partitions"
# Event sourcing implementation:"Create event-sourced system with:- Commanded framework- Event store- Projections- Process managers- Saga orchestration- Snapshot strategies"
# Structure prompts like:"Create [module/function] in Elixir that:- Follows OTP principles- Handles these failure cases: [list]- Includes @spec and @doc- Has property-based tests- Uses pattern matching effectively"
# Macro development:"Create macro for:- DSL implementation- Compile-time validation- Code generation- AST manipulation- Hygiene considerations"
# NIF/Port integration:"Implement native integration:- Rustler for NIFs- Error handling- Resource management- Async NIFs- Port drivers"
Avoid These Issues
When using AI for Elixir: