From BEAM Fundamentals to Production-Ready Systems
Introduction: Why Elixir, Why Phoenix
- The Problems Modern Web Applications Face
- What Makes This Stack Different
- Who This Book Is For
- How This Book Is Structured
- Conventions Used in This Book
- What Comes Next
Chapter 1: Elixir Fundamentals for Web Development
- The BEAM Virtual Machine and Why It Matters
- Immutability, Pattern Matching, and Data Flow
- Functions as First-Class Citizens
- Modules, Structs, and Protocols
- Error Handling with the Let It Crash Philosophy
- The Elixir Toolchain: Mix, Hex, and Dependencies
- Summary
Chapter 2: OTP Patterns for Resilient Applications
- Processes: Lightweight Concurrency Explained
- GenServer: Stateful Process Pattern
- Supervisors and Supervision Trees
- Fault Tolerance and Let It Crash in Practice
- Task and Agent: Simpler OTP Behaviors
- How Phoenix Uses OTP Under the Hood
- Summary
Chapter 3: Phoenix Architecture and Project Structure
- Installing Elixir, Erlang, and Phoenix
- Creating Your First Phoenix Application
- Directory Structure Explained File by File
- The Request Lifecycle from Start to Finish
- Configuration Layers: Config Files and Environments
- Generators and When to Use Them
- Summary
Chapter 4: Routing, Controllers, Plugs, and Request Handling
- The Router: Routes, Scopes, Pipelines, and Constraints
- Controllers: Actions, Views, and Separation of Concerns
- Plugs: Building Reusable Middleware
- Request and Response Objects in Detail
- Error Handling at the HTTP Layer
- Custom Pipelines for Authentication and Logging
- Summary
Chapter 5: Templates, HEEx, Components, and Forms
- EEx vs HEEx: Template Systems Compared
- The View Layer: Views, Helpers, and Layouts
- Phoenix Components: Reusable UI Building Blocks
- Form Helpers: Phoenix.HTML.Form in Practice
- Displaying Validation Errors Gracefully
- Asset Pipeline: Tailwind, JavaScript, and Compilation
- Summary
Chapter 6: Ecto Fundamentals : Schemas, Changesets, and Migrations
- Ecto Architecture: Repo, Schema, Query, Changeset
- Designing Schemas with Types and Defaults
- Migrations: Creating and Evolving Database Tables
- Changesets: Safe Data Validation and Transformation
- Basic Queries with Ecto.Query DSL
- Working with PostgreSQL: The Default Choice
- Summary
Chapter 7: Advanced Ecto : Associations, Joins, Transactions, and Database Design
- Association Types: BelongsTo, HasMany, HasOne, ManyToMany
- Preloading vs Eager Loading Strategies
- Joins and Complex Query Patterns
- Transactions and Data Integrity
- Database Indexing and Query Performance
- Schema Design Patterns for Domain Modeling
- Summary
Chapter 8: Authentication, Authorization, Sessions, and Security
- Session Management and Cookies in Phoenix
- Password Hashing with Comeonin/Bcrypt
- Building an Authentication System from Scratch
- Token-Based Authentication for APIs
- Authorization Patterns: Roles, Permissions, Contexts
- Security Hardening: CSRF, XSS, Content Security Policy
- Summary
Chapter 9: Building APIs with Phoenix : JSON, RESTful Design, and Versioning
- JSON Responses and Serialization Patterns
- RESTful Route Design and Conventions
- API Controllers vs Web Controllers
- Error Handling and Standardized Response Formats
- API Versioning Strategies
- Documentation with OpenAPI/Swagger
- Summary
Chapter 10: Phoenix LiveView Fundamentals : Interactive Pages Without JavaScript
- How LiveView Works: The Server-Side Rendering Model
- Your First LiveView Component
- State Management with Assigns
- Handling Events: Clicks, Inputs, and Lifecycle Callbacks
- LiveView Forms: Real-Time Validation
- When to Use LiveView vs Traditional Controllers
- Summary
Chapter 11: Advanced LiveView : Uploads, Components, Nested Views, and Real-Time Features
- File Uploads with LiveView
- LiveComponents: Encapsulated Interactive Elements
- Nested LiveViews and Component Composition
- Optimizing Performance: Diffing and Lazy Loading
- Real-Time Data Updates with PubSub Integration
- Complex Form Patterns: Dynamic Fields and Multi-Step Forms
- Summary
Chapter 12: Phoenix Channels, WebSockets, and PubSub
- WebSockets in Phoenix: The Channel Layer
- Topics, Joins, and Message Handling
- Authorization and Authentication in Channels
- Phoenix.PubSub: In-Process and Distributed Messaging
- Presence Tracking: Knowing Who Is Online
- Building a Real-Time Chat Application
- Summary
Chapter 13: Background Jobs, Scheduled Tasks, and OTP Integration
- Why Background Jobs Matter in Phoenix
- Oban: Production-Grade Job Processing
- Designing Job Workers with OTP Patterns
- Scheduled Tasks and Recurring Jobs
- Handling Failures, Retries, and Dead Letters
- Integrating Long-Running Operations with LiveView
- Summary
Chapter 14: Configuration, Secrets Management, and Environment Strategy
- Phoenix Configuration File Structure
- Runtime vs Compile-Time Configuration
- Secret Management Strategies
- Environment-Specific Configuration Patterns
- Feature Flags and Toggles
- Configuration Validation and Defaults
- Summary
Chapter 15: Testing Phoenix Applications : Unit, Integration, and System Tests
- The ExUnit Framework and Test Organization
- Unit Testing Business Logic and Contexts
- Integration Testing Controllers and Plugs
- Testing LiveViews: Assertions and Simulated Events
- System Tests with Headless Browsers
- Test Factories, Fixtures, and Data Management
- Summary
Chapter 16: Debugging, Logging, Observability, and Production Monitoring
- Logging in Phoenix: Levels, Formatters, and Destinations
- IEx and Remote Debugging Techniques
- Error Tracking with Sentry and Similar Tools
- Metrics Collection: Telemetry and Prometheus
- Distributed Tracing for Microservices
- Health Checks and Readiness Probes
- Summary
Chapter 17: Performance Optimization : Caching, Database Tuning, and Scaling
- Profiling Phoenix Applications
- Caching Strategies: Memory, Redis, and CDN
- Database Connection Pooling with Ecto
- Query Optimization and N+1 Problem Prevention
- Load Testing and Benchmarking
- Horizontal Scaling and State Management
- Summary
Chapter 18: Deployment : Releases, Docker, CI/CD, and Production Operations
- Mix Releases: Building Self-Contained Applications
- Dockerizing Phoenix Applications
- CI/CD Pipelines for Phoenix Projects
- Zero-Downtime Deployment Strategies
- Production Configuration Checklist
- Database Migrations in Production
- Summary
Chapter 19: Architectural Patterns for Maintainable Phoenix Applications
- The Context Pattern: Organizing by Domain
- Boundary Design and Dependency Rules
- When to Use Microservices vs a Monolith
- Code Organization at Scale
- Refactoring Legacy Phoenix Applications
- Making Architectural Decisions Systematically
- Summary
Conclusion: Your Path Forward with Elixir and Phoenix
- Key Principles to Remember
- Community Resources and Learning Paths
- The Future of Phoenix and the BEAM Ecosystem
- Final Thoughts