Shaping AI before it drifts
AI doesn’t design architecture
— it follows it.
When we give it a clear mental model,
it stays inside the shape of modern PHP.
But when the model is vague,
AI fills the gaps with patterns from older PHP or other languages.
This page shows how to guide AI before it drifts,
using patterns, prompts, and architectural cues that keep the collaboration predictable.
AI writes better code when
it knows the purpose behind the structure.
Instead of:
"Create a service that sends emails."
Try:
"Create a small, focused service. One responsibility. No global state. No static methods. Use a constructor for dependencies."
We're not giving instructions
— we're giving architecture.
AI follows the shape we describe.
AI responds strongly to shape.
So tell it:
Example:
"This function returns a readonly DTO with three fields: id, name, email. No arrays. No optional fields."
AI will stay inside the boundaries we set.
Constraints prevent drift.
Examples:
"No static methods."
"No magic methods."
"No associative arrays for data transfer."
"Use enums only when they express meaning."
"Avoid unnecessary abstractions."
These constraints aren’t rules
— they’re signals.
They tell AI what kind of PHP we expect.
AI doesn’t know our architectural philosophy unless we tell it.
Examples of mental‑model cues:
"Favor clarity over cleverness."
"Prefer objects with stable shape."
"Use modern PHP 8+ idioms only."
"Avoid mixing eras of PHP."
"Use features only when they express intent."
These cues shape the entire output.
AI writes better code when it drafts the architecture first.
Ask:
"Outline the structure before writing the implementation."
AI will produce:
Once the structure is right,
the code follows naturally.
AI understands patterns better than step‑by‑step commands.
Examples:
"Use a small, focused service object."
"Use a readonly DTO for input."
"Use a clear boundary between parsing and validation."
"Use composition, not inheritance."
Patterns give AI a direction,
not a script.
AI rarely gets the architecture right on the first try.
But it improves quickly
with small, intentional adjustments.
Examples:
"Simplify this. Remove unnecessary abstractions."
"Rewrite this using PHP 8+ idioms only."
"Replace arrays with a DTO."
"Clarify the boundaries between responsibilities."
Each iteration sharpens the shape.
This is one of the most powerful tools we have.
Ask:
"Explain why you structured it this way."
AI will reveal:
Once we see the reasoning,
we can redirect it.
When AI gets something right, reinforce it:
"Good — this DTO has a clear shape."
"Good — this service has one responsibility."
"Good — this avoids unnecessary abstractions."
Positive reinforcement helps AI internalize our architectural style.
Guiding AI toward better architecture means:
AI drafts quickly.
We provide the architectural compass.
Together, we produce code that is clear, modern, and intentional.
This page describes common behaviors observed in AI models when generating PHP code.
These patterns are not guarantees, but they are consistent enough to be useful when reviewing or guiding AI output.