AI's Top Blunder in Phoenix Context Modules

AGENT.md targets AI-generated code that fails to correctly organize business logic within Phoenix context modules, often leading to violations of separation of concerns and maintainability issues.

The top 3

  1. AI's Transactional Integrity Blind Spot: Ecto.Multi Omissions: AI often generates Phoenix context code that fails to use `Ecto.Multi` for atomic database operations, leading to potential data inconsistencies when multiple changes need to succeed or fail together.
  2. N+1 Queries: AI's Persistent Performance Blunder: AI commonly generates Ecto queries in Phoenix contexts that lead to N+1 problems, fetching associated data in multiple inefficient database calls instead of leveraging `Ecto.preload` or `Ecto.join` for optimal performance.
  3. AI's Changeset Gaps: Complex Validation & Association Failures: AI frequently struggles with generating robust Ecto changesets for Phoenix context modules, leading to missing `cast_assoc`, `put_assoc`, or custom validations essential for handling complex data structures and associations securely.

Sources

Open the full topic