Spec-Driven Development: A Practical AI Coding Workflow
AI coding tools have evolved from line completion to generating entire scaffolds from a single prompt, yet teams still struggle with drifting requirements, duplicated implementations, and regressions. This article explains spec-driven development, a workflow that separates specification design from implementation: maintain a structured "project dictionary" of requirements, domain models, and capability inventories, then let AI generate code under those constraints with TDD, automated review, and change proposals. Using a pet feeding system as a concrete example, it covers the workflow's lifecycle, repository structure, and practical lessons for long-term, complex projects.
Why AI Coding Needs Specs First
Over the past two years, AI-assisted programming has evolved significantly: from completing single lines, to generating individual functions, to producing entire scaffolds from a one-sentence requirement. Capabilities keep growing, but a core contradiction has become increasingly apparent: limited context versus unlimited requirements.
When developers hand requirements directly to AI and ask it to generate a complete system in one shot, common problems include results that deviate from the original intent, large amounts of duplicated or conflicting implementations, and small follow-up fixes triggering widespread regressions. The root cause is not insufficient model capability but the absence of a persistent anchor for requirements and design that can be continuously updated.
As a result, a new consensus has emerged in the industry: instead of letting AI “improvise,” first use AI to generate and maintain a set of structured specification documents, and then have AI implement code within the constraints of those specifications. This is the basic idea of spec-driven development: specifications first, implementation second; documents as contracts, process as the gatekeeper.
Division of Labor: Separate Design and Implementation Tracks
A mature spec-driven workflow typically splits the development process into two parallel tracks:
1. The Design Track: Maintaining a “Project Dictionary”
The design track produces and continuously maintains a set of structured documents, which can be thought of as a “project dictionary.” It typically includes:
- Requirement specifications: what problems the system should solve, its boundaries, and acceptance criteria;
- Domain model: core entities (e.g., pets, feeding plans, records) and the definitions of their relationships;
- Capability inventory: the functional modules exposed externally, along with the business behaviors and invariants for each module.
The value of the project dictionary lies in establishing a consistency-checking layer between requirements and code. Whenever a new feature is proposed, first check whether it conflicts with the existing capability inventory; whenever a behavior changes, first determine whether it breaks existing invariants. In this way, the risk of requirements and code drifting apart is intercepted at the design stage.
2. The Implementation Track: Quality Control Through Process
The implementation track turns specifications into code and ensures quality through a series of standardized steps:
- Requirement clarification and brainstorming: before implementation, repeatedly align with the user on intent and clarify ambiguities, avoiding “unauthorized” technical decisions;
- Task planning and decomposition: break specifications into execution units with clear dependency ordering that can be independently verified;
- Test-driven development (TDD): write failing tests first, then implement, using tests as the executable expression of the specification;
- Code review and automated checks: after implementation, verify behavior against the specification item by item, run static checks and the test suite, and merge in a controlled manner once everything passes.
The collaboration between the two tracks can be summarized as: the design track answers “what and why,” while the implementation track answers “how and whether it’s correct.” Any change in conclusions on either side must be written back into the specifications rather than communicated verbally.
A Concrete Scenario: A Pet Feeding System
Using a common pet feeding system as an example, the overall process looks like this:
- Specification generation: first produce the document directory (e.g.,
docs/specs/) and create draft requirement specifications for capabilities such as feeding plan management and feeding record tracking; - Iterative confirmation: review the drafts section by section with the user, and once confirmed, commit them to the repository, forming standard assets protected by the project dictionary;
- Feature implementation: when a new requirement arrives — “support multiple feedings at different times of day” — the implementation track starts with a clarifying dialogue to confirm details, then plans tasks on an isolated branch;
- Test-first: write failing tests for edge cases of multi-time feeding (overlapping time slots, cross-day plans);
- Implementation and review: code until the tests pass; automated review checks the work item by item against the specification and merges only if there are no deviations;
- Specification write-back: once the implementation is confirmed correct, update the capability changes back into the project dictionary as “change proposals.”
The first few iterations will feel noticeably “slow” — a lot of time goes into writing documents, aligning on intent, and following the process. But from the second or third feature onward, because the specifications have stabilized, every AI implementation has clear boundaries to work within, rework rates plummet, and overall speed surpasses the “fast and loose” approach of skipping specs.
Proposal-Based Changes: The Key to Keeping Teams in Sync
The most far-reaching discipline in spec-driven development is this: all behavioral changes must go through update proposals or specification documents; directly modifying code outside the specifications is forbidden. At the repository level, this usually looks like:
project/├── docs/│ ├── specs/ # Capability specs (protected assets)│ └── changes/ # Change proposals (in progress)└── src/
The lifecycle of a change proposal is: draft → review and revision → approval and commit → spec-driven implementation → archived after the updated spec becomes the official standard. This brings three direct benefits:
- Reusable context: any developer or AI can read the specifications to understand the system as a whole, without relying on oral memory;
- Traceable changes: every behavioral change has a record; when regressions occur, it’s easy to identify which proposal introduced them;
- Coordinated multi-agent collaboration: when multiple developers or multiple AI sessions work in parallel, the specifications are the single source of truth, preventing the fragmentation of “everyone going their own way.”
Three Practical Lessons
- Accept the slow start, and beware of skipping clarification to save time. The ten minutes saved by skipping brainstorming often costs ten times as much in rework later.
- Keep specifications lean, not bloated. Only record verifiable, testable behavioral constraints; avoid writing lyrical requirement prose. An ambiguous specification is more dangerous than no specification at all.
- Treat TDD as the executable projection of the specification. The specification is the static contract and tests are the dynamic contract; when the two disagree, suspect that the specification’s wording is imprecise first.
Conclusion
Spec-driven development does not deny AI’s creativity; rather, it establishes a “bounded, verifiable, collaborative” working environment for it. Once the process is running smoothly, AI is no longer the most uncontrollable variable but a high-throughput productivity engine executing within clear contracts — the better approach for long-term, complex projects and intelligent programming workflows.
