Greenfield project from a specification π±
A greenfield project is the greatest temptation and the highest risk. The agent can generate hundreds of lines of code in seconds β but if you do not have a clear specification, you will get hundreds of lines of wrong code in seconds. The difference between a successful greenfield and an architectural disaster is not the tool: it is the quality of the specification you put in front of it.
The specification is not a preliminary step: it is the contract that outlives the code.
When to use the agent for this case π―
- Completely new project β no existing code, stack to define.
- Rapid prototype from spec β you have a requirements document and want a working MVP.
- Initial scaffolding β project structure, README, CI, base tests.
- Complete rewrite β rewriting a legacy system as a new project from scratch.
When NOT to use the agent β
- You do not have a specification β if the idea is vague, do not delegate the definition to the agent. Write what you want first, then ask how to do it.
- The stack is critical and undefined β the agent will choose the most common solution, not the best one for your case.
- The project requires hardware or physical integration β the agent cannot test what does not exist in its environment.
Opening prompt π
“Starting from this specification [link/block], build [project]. Stack: [x]. Constraints: [y]. Process: plan first, then tasks, then TDD. Do not generate everything in one step.”
Concrete example:
“Starting from this specification: ‘REST API for order management with JWT authentication, rate limiting, and PostgreSQL integration’, build the project in the current folder. Stack: Go + Chi + sqlx. Constraints: test coverage >= 80%, no unapproved dependencies. Process: architectural plan first, then incremental tasks with TDD.”
Context setup π§
- Create
AGENTS.mdimmediately β define stack, versions, approved libraries, and test commands. This is the contract that will guide the agent for the entire project duration. - Write the specification formally β objectives, users, scenarios, acceptance criteria. Not a vague idea: a document a colleague could read and understand.
- Define the “constitution” β stack, coding standards, non-negotiable constraints (e.g., “no GPL dependencies”, “tests for every public function”).
Workflow π‘
The spec-driven flow is as follows:
- Specify: write what you want the system to do (not how).
- Clarify: the agent asks questions about ambiguities. Answer before proceeding.
- Plan: the agent proposes module architecture, interfaces, data schema.
- Approve: review the plan. This is where you stop architectural drift.
- Implement incrementally: MVP first, expansion later. Each increment with green tests.
Do not generate the entire architecture in one step. Every unvalidated line is potential architectural debt.
Use lightweight models for initial phases (architecture, interfaces, data schema) and reserve the most powerful model for complex logic.
Greenfield architecture choice ποΈ
Architecture choice is the most impactful decision you make before delegating. Agents work better with certain structures than others.
| Pattern | Success Rate | Note |
|---|---|---|
| Modular Monolith | 85-95% | Default recommended for agents |
| Monorepo | 75-85% | OK if tooling is adequate |
| Polyrepo Microservices | 30-50% | “Frequent cross-boundary schema hallucinations” |
The modular monolith is making a comeback in the agent era. Microservices require coordination overhead that agents do not handle well.
Practical rule: start with a modular monolith. Select modules along clear domain boundaries. Allow modules the possibility of being extracted into separate services in the future β but do not do it now.
The clarify phase: 5 question archetypes π¬
The clarification phase is where the agent analyzes the specification and asks questions about ambiguities. There are 5 recurring archetypes:
| Archetype | Typical question | Why it matters |
|---|---|---|
| Scope boundary | “Should it handle only orders or also payments?” | Defines what the system does NOT do |
| State concurrency | “Do two users modify the same resource simultaneously?” | Impacts data design and locking |
| Authentication | “JWT, session, OAuth2? Who manages the token?” | Cross-cutting infrastructure, hard to change later |
| Failure mode | “What happens if payment fails midway?” | Defines error handling and rollback |
| Depth calibration | “Do we need E2E tests or just unit tests?” | Determines testing effort |
If the agent does not ask questions during the clarify phase, it is an alarming signal: it means the specification is too vague or the agent is skipping a critical step.
Template: ADR Agent-Optimized π
Architecture Decision Records (ADRs) document architectural decisions. This template is optimized for use with agents, with executable “Agent Execution Rules”:
|
|
The “Alternatives rejected” section is the most skipped and the most valuable: it documents not only what you chose, but why you discarded the alternatives. Without it, a future developer (or agent) might resurface a solution already evaluated and discarded.
Anti-pattern table π«
| Anti-pattern | Symptom | Remediation |
|---|---|---|
| Vague Intent | Agent invents DB schema or architecture | Specification with Given-When-Then + Zod/JSON Schema |
| Bypassing Clarify | Massive rewrites after first prompt | Pre-commit hooks: do not proceed without clarify |
| Ephemeral Specs | Future prompts break previous code | Specs in git with PR review, versioning |
| Over-Specification | Spec = pseudo-code, 200 pages | Separation: spec.md (what) vs implementation (how) |
| Specification Rot | Document diverges from actual code | Spec-anchored tests in CI |
| Spec Theater | Process is slower than coding without agents | Minimal Viable Specs (MVS): only what is necessary |
Acceptance criteria β
- Architectural plan approved before writing code.
-
AGENTS.mdpresent with stack, versions, and commands defined. - Green tests for every increment.
- No architectural drift from the approved plan.
- README,
.gitignore, and CI scaffolding present from the first release.
Further reading π
- Writing prompts that work β how to structure the specification in the prompt.
- Configuring the repository β
AGENTS.mdas a project contract. - Blog: Question-driven specification β the method for turning questions into executable specifications.
- Blog: Unknowns-driven development β how to manage uncertainty in development.