Rewriting Phoenix for Agent-Driven Development

A thought experiment I’m interested in people’s thoughts on: If we were designing Phoenix specifically for agents rather than humans, how would we approach it?

Some ideas:

Kill the macro DSLs, or make them introspectable.
router.ex with pipe_through, resources, scope are compact for humans but opaque for agents — you can’t grep for the actual URL /users/:id/posts because it’s synthesized at compile time. Instead use explicit route definitions:

route "GET", "/users/:id/posts", UserController, :list_posts,
  pipeline: [:browser, :authenticated]

An agent editing this never has to simulate macro expansion in its head. Same treatment for Ecto.Schema, use MyAppWeb, :controller, and the LiveView lifecycle macros — either eliminate them or require that every macro emit a .expanded.ex sibling file that agents can read.

Make use statements concrete.
use MyAppWeb, :controller is the single biggest source of “where does this function come from?” confusion. Replace it with explicit imports listing every symbol brought into scope.

One behavior per file, predictable paths.
Current Phoenix scatters a single feature across lib/my_app/accounts.ex, lib/my_app/accounts/user.ex, lib/my_app_web/controllers/user_controller.ex, lib/my_app_web/live/user_live.ex, templates, and tests. Agents do much better when a feature is a directory they can load entirely, ie features/users/

LiveView assigns as a declared struct.
Currently assigns are a loose map and you discover what’s in them by reading every assign/3 call in the module. Declaring defassigns as a typed struct up front means an agent editing a template knows exactly what’s available.

Deterministic generators with reversible diffs.
For agents, generators should produce a manifest so a later “regenerate with these options” command produces a clean diff rather than conflicts.

Eliminate the MyApp / MyAppWeb split, or formalize it.
The convention that business logic lives in MyApp and web concerns in MyAppWeb is real but unenforced. Either make it a hard compile-time boundary (web modules cannot be called from business modules, full stop) or drop it. Agents waste tokens figuring out which side of the line they’re on.

2 Likes