Business Apps: Why Spec, Not Generated Code
In this article
- Background: The Rise of Code Generation
- How a Spec Prevents Costly Rework
- Generated Code Lacks Business Context
- The Role of the Spec in Team Alignment
- How to Choose: When to Use Generated Code vs. a Spec
- Common Problems and Misconceptions
- Costs and Safety of Skipping the Spec
- Alternatives to a Full Specification
- Frequently Asked Questions
The reason you should start with a written specification, not generated code, is that the specification captures the business logic and intent that code generation cannot infer, and it serves as the single source of truth for stakeholders, developers, and future maintenance. Generated code, while useful for scaffolding, lacks the context, constraints, and decision rationale that a spec encodes, leading to rework and misalignment. In short, a spec leads because it defines the 'what' and 'why' before the 'how' is ever coded.
Background: The Rise of Code Generation
Code generation tools have evolved from simple template-based CRUD (Create, Read, Update, Delete) generators to AI-assisted development environments. These tools can produce functional code from database schemas, API definitions, or even natural language prompts. However, the promise of 'instant apps' often clashes with reality: business applications are not just about data entry forms and list views. They embed workflows, validation rules, approval chains, and complex state transitions that are rarely explicit in a prompt or a schema.
The specification—whether a formal document, a set of user stories, or a structured requirements document—exists precisely to make those implicit rules explicit. It forces stakeholders to agree on what the system must do, under what conditions, and with what exceptions. This is a human communication exercise, not a technical one, and it cannot be skipped without consequences.
How a Spec Prevents Costly Rework
Consider a typical inventory management app. A code generator might produce a product table, a stock level field, and a quantity adjustment form. But the business rule 'stock cannot go negative unless the item is on backorder and the user has manager approval' is a rule that lives in the domain, not in the schema. Without a spec, a developer might implement a simple check that blocks negative stock entirely, or worse, allow it without any audit trail. When the business discovers the discrepancy, the rework involves not just changing a validation function but rethinking the data model, the UI flow, and the reporting.
A well-written spec would have stated this rule upfront, along with the rationale ('we allow backorders for high-priority clients to avoid losing sales'), the approval workflow, and the audit requirements. That single paragraph in a spec can save days of development and testing. The cost of fixing a requirement error after code is written is often 10 to 100 times higher than fixing it during specification, a principle long recognized in software engineering.
Generated Code Lacks Business Context
Generated code is inherently generic. It follows patterns: CRUD operations, standard validations, and typical UI layouts. It does not understand that a 'customer' in your business has a credit limit, a preferred shipping method, and a history of late payments. It does not know that a 'sales order' must be frozen once invoiced, or that a 'project task' cannot be deleted if it has time entries. These are domain rules, and they come from business analysis, not from code generation.
Furthermore, generated code often lacks the 'why' behind decisions. A developer reading generated code can see that a field is required, but not why it is required, or what the consequence of making it optional would be. A spec, on the other hand, can explain that the field is required for regulatory compliance, which changes how the validation error is displayed and what the fallback behavior should be if the field is missing.
The Role of the Spec in Team Alignment
A specification is a communication tool. It bridges the gap between business stakeholders—who think in terms of processes and outcomes—and developers—who think in terms of data structures and algorithms. When a spec is written, it forces the business to articulate its own processes clearly. This often reveals ambiguities or contradictions that would otherwise surface only after the app is built.
For example, a spec for a leave management system might state that 'employees can request up to 20 days of annual leave per year.' A stakeholder might then ask: 'Does that include unpaid leave? Does it include public holidays? What happens if an employee joins mid-year?' These questions, answered during specification, prevent the developer from making arbitrary assumptions. The spec becomes the agreed-upon contract between the business and the development team, and it is also the basis for test cases and acceptance criteria.
How to Choose: When to Use Generated Code vs. a Spec
Generated code is not useless; it is a powerful accelerator when used correctly. The key is to understand when it adds value and when it creates debt.
- Use generated code for scaffolding: Initial project structure, database migration scripts, and basic CRUD endpoints can be generated to save time. This gives you a working skeleton that you can then refine.
- Use a spec for business logic: Any rule that involves money, compliance, user roles, or multi-step workflows must be specified in detail. Do not rely on a generator to infer these.
- Use a spec for integration points: If your app must talk to an external system (payment gateway, CRM, ERP), the exact data mapping, error handling, and retry logic must be specified. Generated code cannot know the quirks of your legacy system.
- Use generated code for prototypes: When you need a clickable demo to gather feedback, generated code is fast. But treat it as disposable; do not build the production system on top of it without a spec.
Common Problems and Misconceptions
A common misconception is that a specification is a one-time document that is written and then forgotten. In reality, a spec is a living artifact that evolves as the business changes. It should be versioned, reviewed, and updated just like code. Another problem is the 'analysis paralysis' where teams spend months writing a 200-page spec that nobody reads. The solution is to use a 'just enough' approach: specify the critical rules and constraints, and leave implementation details to the developers.
Another issue is the belief that a spec must be a formal, text-heavy document. It can be a set of user stories, a process flow diagram, or even a structured spreadsheet of rules. The format matters less than the content. The goal is to capture the decisions that must be made before code is written, so that the code generation tool is simply translating a clear blueprint, not guessing at requirements.
Costs and Safety of Skipping the Spec
The immediate cost of skipping the spec is faster initial development, but the long-term costs are significant. These include:
- Rework: Features built on incorrect assumptions must be rebuilt, often from scratch.
- Technical debt: Quick fixes to accommodate missed requirements lead to brittle code that is hard to maintain.
- Testing gaps: Without a spec, testers do not know what the expected behavior is, so they test what the code does, not what it should do.
- Stakeholder dissatisfaction: The final app may not match the business's mental model, leading to a lack of adoption.
From a safety perspective, a spec is critical in regulated industries. If your app handles financial transactions, health records, or personal data, you need to demonstrate that the system behaves as intended. A spec provides the audit trail for that demonstration. Generated code, by itself, does not prove that you considered privacy, security, or data retention requirements.
Alternatives to a Full Specification
If a full specification seems too heavy, there are lighter-weight alternatives that still capture the essential business logic:
- User story mapping: A visual exercise that organizes user activities into a narrative flow, highlighting gaps and dependencies.
- Behavior-driven development (BDD): Writing executable specifications in a language like Gherkin (Given/When/Then) that can be automated. This bridges the gap between spec and test.
- Domain-driven design (DDD): A modeling approach that focuses on the core domain and its logic, producing a shared language between business and developers.
- Prototyping with review cycles: Build a rough prototype, review it with stakeholders, and iterate. This is a form of specification, but it is based on concrete examples rather than abstract text.
These alternatives still require the same discipline: capturing the rules and rationale before code is finalized. They just use different formats.
Frequently Asked Questions
Can't AI generate code that understands my business rules?
AI can generate code that appears to understand rules if you describe them in a prompt, but it does not truly understand the business context. It can only translate what you explicitly tell it. If you forget to mention a rule, the AI will not infer it. The spec is the place to ensure all rules are stated, so the AI (or a human developer) has complete information.
Isn't a spec just a waste of time when we need to move fast?
In the short term, writing a spec seems slower. But the speed you gain by skipping it is often lost when you have to rework features, fix bugs, or handle missed requirements. A focused spec that captures the critical rules can be written in days, and it prevents weeks of rework later.
What if the business doesn't know what it wants?
That is exactly why you need a spec. The process of writing a spec forces the business to think through its processes and make decisions. If the business cannot articulate its requirements, then no code generation tool can help. The spec is a tool for discovery, not just documentation.
Can we use generated code as the spec itself?
No. Generated code is an implementation, not a specification. It shows what the system does, but not why it does it. A spec explains the intent behind the behavior, which is essential for future changes, debugging, and onboarding new team members.
How detailed should a spec be?
As detailed as needed to avoid ambiguity on the critical rules. Focus on business logic, data constraints, workflows, and integration points. Leave UI layout and code architecture to the developers. A good rule of thumb is: if a rule is not written down, it will be implemented incorrectly.