Project 34: Full-Stack Application Generator

Project 34: Full-Stack Application Generator

Build a comprehensive agent that generates entire full-stack applications from natural language specifications - database schema, API endpoints, frontend components, tests, and deployment configuration - all orchestrated through Kiro CLI.

Quick Reference

Attribute Value
Difficulty Master (Level 5)
Time Estimate 1 month+
Primary Language TypeScript
Alternative Languages Python, Go
Prerequisites Projects 1-20, deep understanding of full-stack architecture
Key Topics Domain-driven design, code generation, API design, schema design, orchestration
Kiro CLI Concepts Custom agents, PostgreSQL MCP, Docker MCP, hooks, subagents, steering
Main Book Reference โ€œDomain-Driven Designโ€ by Eric Evans

1. Learning Objectives

By completing this project, you will:

  1. Master natural language specification parsing: Extract entities, relationships, and business rules from prose descriptions
  2. Implement domain-driven design with AI: Use AI to identify bounded contexts, aggregates, and domain events
  3. Build sophisticated code generation pipelines: Create consistent, maintainable code across all layers of the stack
  4. Orchestrate multi-layer application scaffolding: Coordinate database, API, and frontend generation with proper dependencies
  5. Integrate real-world deployment infrastructure: Generate Docker, CI/CD, and infrastructure-as-code configurations

2. Deep Theoretical Foundation

2.1 The Challenge of Specification Interpretation

Generating applications from natural language requires bridging the gap between human intent and machine-executable code:

                    THE SPECIFICATION INTERPRETATION CHALLENGE

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   NATURAL LANGUAGE INPUT                                                โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                 โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   "Build a project management app where teams can create projects,      โ”‚
    โ”‚    assign tasks to members, track progress with status updates,         โ”‚
    โ”‚    and attach files to tasks. Teams should have owners and members      โ”‚
    โ”‚    with different permissions."                                          โ”‚
    โ”‚                                                                          โ”‚
    โ”‚                              โ”‚                                           โ”‚
    โ”‚                              โ–ผ                                           โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚                    INTERPRETATION LAYERS                         โ”‚   โ”‚
    โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚   LAYER 1: Entity Extraction                                    โ”‚   โ”‚
    โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                   โ”‚   โ”‚
    โ”‚   โ”‚   Entities: Team, Project, Task, Member, StatusUpdate, File     โ”‚   โ”‚
    โ”‚   โ”‚   Actors: Owner, Member                                         โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚   LAYER 2: Relationship Mapping                                 โ”‚   โ”‚
    โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                  โ”‚   โ”‚
    โ”‚   โ”‚   Team 1:N Projects                                             โ”‚   โ”‚
    โ”‚   โ”‚   Project 1:N Tasks                                             โ”‚   โ”‚
    โ”‚   โ”‚   Task N:1 Member (assignee)                                    โ”‚   โ”‚
    โ”‚   โ”‚   Task 1:N StatusUpdates                                        โ”‚   โ”‚
    โ”‚   โ”‚   Task 1:N Files                                                โ”‚   โ”‚
    โ”‚   โ”‚   Team N:M Members (through TeamMembership)                     โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚   LAYER 3: Business Rules                                       โ”‚   โ”‚
    โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                     โ”‚   โ”‚
    โ”‚   โ”‚   โ€ข Only team owners can delete projects                        โ”‚   โ”‚
    โ”‚   โ”‚   โ€ข Members can only be assigned tasks in their teams           โ”‚   โ”‚
    โ”‚   โ”‚   โ€ข Status updates are append-only (audit trail)                โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚   LAYER 4: Implicit Requirements                                โ”‚   โ”‚
    โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                โ”‚   โ”‚
    โ”‚   โ”‚   โ€ข Authentication required (implied by "permissions")          โ”‚   โ”‚
    โ”‚   โ”‚   โ€ข File storage needed (implied by "attach files")             โ”‚   โ”‚
    โ”‚   โ”‚   โ€ข Timestamps on all records (implied by "track progress")     โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.2 Domain-Driven Design with AI

Eric Evansโ€™ DDD provides the conceptual framework for understanding complex domains. AI can accelerate this process:

                    DDD CONCEPTS FOR CODE GENERATION

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   BOUNDED CONTEXTS                                                       โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                      โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   A large application should be divided into bounded contexts,          โ”‚
    โ”‚   each with its own ubiquitous language and models.                     โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                     โ”‚
    โ”‚   โ”‚    TEAM CONTEXT     โ”‚   โ”‚   PROJECT CONTEXT   โ”‚                     โ”‚
    โ”‚   โ”‚                     โ”‚   โ”‚                     โ”‚                     โ”‚
    โ”‚   โ”‚  โ€ข Team             โ”‚   โ”‚  โ€ข Project          โ”‚                     โ”‚
    โ”‚   โ”‚  โ€ข Member           โ”‚   โ”‚  โ€ข Task             โ”‚                     โ”‚
    โ”‚   โ”‚  โ€ข TeamMembership   โ”‚   โ”‚  โ€ข StatusUpdate     โ”‚                     โ”‚
    โ”‚   โ”‚  โ€ข Permission       โ”‚   โ”‚  โ€ข Attachment       โ”‚                     โ”‚
    โ”‚   โ”‚                     โ”‚   โ”‚                     โ”‚                     โ”‚
    โ”‚   โ”‚  Language:          โ”‚   โ”‚  Language:          โ”‚                     โ”‚
    โ”‚   โ”‚  "invite", "role"   โ”‚   โ”‚  "assign", "status" โ”‚                     โ”‚
    โ”‚   โ”‚  "owner", "member"  โ”‚   โ”‚  "progress", "due"  โ”‚                     โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                     โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   AGGREGATES                                                             โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                            โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   An aggregate is a cluster of entities treated as a unit.              โ”‚
    โ”‚   Changes to the aggregate go through the aggregate root.               โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
    โ”‚   โ”‚                      TASK AGGREGATE                              โ”‚  โ”‚
    โ”‚   โ”‚                                                                  โ”‚  โ”‚
    โ”‚   โ”‚      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                               โ”‚  โ”‚
    โ”‚   โ”‚      โ”‚   Task   โ”‚ โ—€โ”€โ”€โ”€ Aggregate Root                           โ”‚  โ”‚
    โ”‚   โ”‚      โ”‚  (root)  โ”‚                                               โ”‚  โ”‚
    โ”‚   โ”‚      โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜                                               โ”‚  โ”‚
    โ”‚   โ”‚           โ”‚                                                      โ”‚  โ”‚
    โ”‚   โ”‚     โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”                                               โ”‚  โ”‚
    โ”‚   โ”‚     โ”‚           โ”‚                                               โ”‚  โ”‚
    โ”‚   โ”‚     โ–ผ           โ–ผ                                               โ”‚  โ”‚
    โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                        โ”‚  โ”‚
    โ”‚   โ”‚  โ”‚ Status โ”‚  โ”‚ File   โ”‚                                        โ”‚  โ”‚
    โ”‚   โ”‚  โ”‚ Update โ”‚  โ”‚        โ”‚                                        โ”‚  โ”‚
    โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                        โ”‚  โ”‚
    โ”‚   โ”‚                                                                  โ”‚  โ”‚
    โ”‚   โ”‚  Operations:                                                    โ”‚  โ”‚
    โ”‚   โ”‚  โ€ข task.addStatusUpdate(status, author)                        โ”‚  โ”‚
    โ”‚   โ”‚  โ€ข task.attachFile(file)                                       โ”‚  โ”‚
    โ”‚   โ”‚  โ€ข task.assignTo(member)                                       โ”‚  โ”‚
    โ”‚   โ”‚                                                                  โ”‚  โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   DOMAIN EVENTS                                                          โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                         โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Events represent something that happened in the domain.               โ”‚
    โ”‚   They enable loose coupling and event sourcing.                        โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   TaskCreated { taskId, projectId, title, createdBy }                   โ”‚
    โ”‚   TaskAssigned { taskId, assigneeId, assignedBy }                       โ”‚
    โ”‚   TaskStatusChanged { taskId, oldStatus, newStatus, changedBy }         โ”‚
    โ”‚   FileAttached { taskId, fileId, fileName }                             โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.3 The Generation Pipeline Architecture

Full-stack generation requires a coordinated pipeline:

                    FULL-STACK GENERATION PIPELINE

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   PHASE 1: DOMAIN MODELING                                              โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                              โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Input: Natural language specification                                  โ”‚
    โ”‚   Output: Domain model (entities, relationships, rules)                 โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚  AI Analysis                                                     โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Extract entities and their properties                        โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Identify relationships (1:1, 1:N, N:M)                        โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Infer business rules from context                            โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Determine authentication/authorization needs                 โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                              โ”‚                                           โ”‚
    โ”‚                              โ–ผ                                           โ”‚
    โ”‚   PHASE 2: SCHEMA GENERATION                                            โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                            โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Input: Domain model                                                    โ”‚
    โ”‚   Output: Database schema (SQL migrations)                              โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚  [PostgreSQL MCP]                                               โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Generate CREATE TABLE statements                             โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Add proper indexes for relationships                         โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Create migration files                                       โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Generate seed data for development                           โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                              โ”‚                                           โ”‚
    โ”‚                              โ–ผ                                           โ”‚
    โ”‚   PHASE 3: API GENERATION                                               โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                               โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Input: Domain model + schema                                          โ”‚
    โ”‚   Output: REST/GraphQL endpoints                                        โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚  [API Subagent]                                                 โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Generate route handlers (CRUD)                               โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Add validation schemas (Zod)                                 โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Implement authentication middleware                          โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Create authorization checks                                  โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Generate OpenAPI spec                                        โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                              โ”‚                                           โ”‚
    โ”‚                              โ–ผ                                           โ”‚
    โ”‚   PHASE 4: FRONTEND GENERATION                                          โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                          โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Input: API spec + domain model                                        โ”‚
    โ”‚   Output: React/Vue components                                          โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚  [Frontend Subagent]                                            โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Generate page components                                     โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Create form components with validation                       โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Add data fetching hooks                                      โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Implement routing                                            โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Apply styling (Tailwind)                                     โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                              โ”‚                                           โ”‚
    โ”‚                              โ–ผ                                           โ”‚
    โ”‚   PHASE 5: TESTING GENERATION                                           โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                           โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Input: Generated code                                                  โ”‚
    โ”‚   Output: Test files                                                    โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚  [Test Subagent]                                                โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Generate unit tests for services                             โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Create integration tests for API                             โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Add component tests for frontend                             โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Generate E2E tests for critical flows                        โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                              โ”‚                                           โ”‚
    โ”‚                              โ–ผ                                           โ”‚
    โ”‚   PHASE 6: DEPLOYMENT GENERATION                                        โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                        โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Input: Application structure                                          โ”‚
    โ”‚   Output: Docker, CI/CD, infrastructure config                          โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚  [DevOps Subagent]                                              โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Create Dockerfile and docker-compose.yml                     โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Generate GitHub Actions workflows                            โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Add environment configuration                                โ”‚   โ”‚
    โ”‚   โ”‚  โ€ข Create deployment scripts                                    โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.4 Code Generation Patterns

Consistent code generation requires well-defined patterns:

                    CODE GENERATION PATTERNS

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   TEMPLATE-BASED GENERATION                                             โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                             โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Templates provide consistent structure while AI fills in specifics.   โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Template: api/routes/[entity].ts                                      โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚  import { Router } from 'express';                              โ”‚   โ”‚
    โ”‚   โ”‚  import { {{Entity}}Service } from '../services/{{entity}}';    โ”‚   โ”‚
    โ”‚   โ”‚  import { validate{{Entity}} } from '../validators/{{entity}}'; โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚  const router = Router();                                        โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚  router.get('/', async (req, res) => {                          โ”‚   โ”‚
    โ”‚   โ”‚    const items = await {{Entity}}Service.findAll(req.query);    โ”‚   โ”‚
    โ”‚   โ”‚    res.json(items);                                              โ”‚   โ”‚
    โ”‚   โ”‚  });                                                             โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚  router.post('/', validate{{Entity}}, async (req, res) => {     โ”‚   โ”‚
    โ”‚   โ”‚    const item = await {{Entity}}Service.create(req.body);       โ”‚   โ”‚
    โ”‚   โ”‚    res.status(201).json(item);                                   โ”‚   โ”‚
    โ”‚   โ”‚  });                                                             โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚  // ... more CRUD operations                                    โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   AI-AUGMENTED GENERATION                                               โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                               โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   AI adds domain-specific logic that templates can't capture.           โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Entity: Task with status transitions                                  โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚  // AI-generated business logic                                 โ”‚   โ”‚
    โ”‚   โ”‚  class TaskService {                                             โ”‚   โ”‚
    โ”‚   โ”‚    async updateStatus(taskId: string, newStatus: Status) {      โ”‚   โ”‚
    โ”‚   โ”‚      const task = await this.findById(taskId);                  โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚      // AI understands valid state transitions                  โ”‚   โ”‚
    โ”‚   โ”‚      const validTransitions = {                                  โ”‚   โ”‚
    โ”‚   โ”‚        'todo': ['in_progress'],                                 โ”‚   โ”‚
    โ”‚   โ”‚        'in_progress': ['review', 'blocked'],                    โ”‚   โ”‚
    โ”‚   โ”‚        'review': ['done', 'in_progress'],                       โ”‚   โ”‚
    โ”‚   โ”‚        'blocked': ['in_progress'],                              โ”‚   โ”‚
    โ”‚   โ”‚        'done': []  // Terminal state                            โ”‚   โ”‚
    โ”‚   โ”‚      };                                                          โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚      if (!validTransitions[task.status].includes(newStatus)) { โ”‚   โ”‚
    โ”‚   โ”‚        throw new InvalidTransitionError(task.status, newStatus);โ”‚   โ”‚
    โ”‚   โ”‚      }                                                           โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚      return this.update(taskId, { status: newStatus });         โ”‚   โ”‚
    โ”‚   โ”‚    }                                                             โ”‚   โ”‚
    โ”‚   โ”‚  }                                                               โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   COMPOSITION PATTERNS                                                   โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                  โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Generated code should follow composition patterns for maintainability.โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
    โ”‚   โ”‚                                                                  โ”‚  โ”‚
    โ”‚   โ”‚   Controller Layer                                              โ”‚  โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ Handles HTTP request/response                             โ”‚  โ”‚
    โ”‚   โ”‚       โ”‚                                                          โ”‚  โ”‚
    โ”‚   โ”‚       โ–ผ                                                          โ”‚  โ”‚
    โ”‚   โ”‚   Service Layer                                                 โ”‚  โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ Business logic, validation                                โ”‚  โ”‚
    โ”‚   โ”‚       โ”‚                                                          โ”‚  โ”‚
    โ”‚   โ”‚       โ–ผ                                                          โ”‚  โ”‚
    โ”‚   โ”‚   Repository Layer                                              โ”‚  โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ Data access, queries                                      โ”‚  โ”‚
    โ”‚   โ”‚       โ”‚                                                          โ”‚  โ”‚
    โ”‚   โ”‚       โ–ผ                                                          โ”‚  โ”‚
    โ”‚   โ”‚   Database                                                      โ”‚  โ”‚
    โ”‚   โ”‚                                                                  โ”‚  โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.5 The 80/20 Rule of Code Generation

AI can generate 80% of boilerplate, but 20% requires human refinement:

                    THE 80/20 GENERATION BOUNDARY

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   AI CAN GENERATE (80%)                   HUMANS MUST REFINE (20%)      โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€      โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โœ“ CRUD operations                       โœ— Complex business rules      โ”‚
    โ”‚   โœ“ Basic validations                     โœ— Edge case handling          โ”‚
    โ”‚   โœ“ Standard UI components                โœ— Custom UI interactions      โ”‚
    โ”‚   โœ“ Database schema                       โœ— Performance optimization    โ”‚
    โ”‚   โœ“ Authentication boilerplate            โœ— Security hardening          โ”‚
    โ”‚   โœ“ Basic test structure                  โœ— Meaningful test assertions  โ”‚
    โ”‚   โœ“ Docker configuration                  โœ— Production tuning           โ”‚
    โ”‚   โœ“ API routing                           โœ— API design decisions        โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   THE REFINEMENT WORKFLOW                                               โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                               โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   1. AI generates initial scaffolding                                   โ”‚
    โ”‚      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚      โ”‚  Generated: src/services/TaskService.ts                      โ”‚   โ”‚
    โ”‚      โ”‚  Status: SCAFFOLD - needs review                             โ”‚   โ”‚
    โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   2. Human reviews and identifies gaps                                  โ”‚
    โ”‚      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚      โ”‚  TODO: Add concurrent update handling                        โ”‚   โ”‚
    โ”‚      โ”‚  TODO: Implement soft delete                                 โ”‚   โ”‚
    โ”‚      โ”‚  TODO: Add audit logging                                     โ”‚   โ”‚
    โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   3. AI assists with refinements                                        โ”‚
    โ”‚      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚      โ”‚  Human: "Add optimistic locking for concurrent updates"      โ”‚   โ”‚
    โ”‚      โ”‚  AI: Adds version column and conflict detection              โ”‚   โ”‚
    โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   4. Human validates final implementation                               โ”‚
    โ”‚      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚      โ”‚  Status: REVIEWED - ready for production                     โ”‚   โ”‚
    โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

3. Complete Project Specification

3.1 What You Will Build

A Kiro CLI agent that:

  1. Accepts natural language application specifications
  2. Parses and models the domain (entities, relationships, rules)
  3. Generates complete database schema with migrations
  4. Creates REST API with authentication and authorization
  5. Scaffolds frontend with components and routing
  6. Generates comprehensive tests
  7. Creates deployment configuration

3.2 Functional Requirements

Requirement Description
Spec Parsing Extract entities, relationships, and rules from natural language
Domain Modeling Create bounded contexts and aggregates
Schema Generation Produce PostgreSQL schema with migrations
API Generation Create REST endpoints with validation
Frontend Scaffolding Generate React/Next.js components
Test Generation Create unit, integration, and E2E tests
Deploy Config Generate Docker and CI/CD files
Documentation Produce API docs and README

3.3 Non-Functional Requirements

  • Maintainability: Generated code follows best practices
  • Consistency: Uniform patterns across all generated files
  • Extensibility: Easy to add custom code without conflicts
  • Type Safety: Full TypeScript support throughout

4. Solution Architecture

4.1 System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      FULL-STACK APPLICATION GENERATOR                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                           CLI INTERFACE                                  โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ”‚   kiro-cli --agent app-generator                                        โ”‚ โ”‚
โ”‚  โ”‚   > "Generate a SaaS application for project management..."             โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                       โ”‚                                       โ”‚
โ”‚                                       โ–ผ                                       โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                      SPECIFICATION ANALYZER                              โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Entity         โ”‚  โ”‚ Relationship   โ”‚  โ”‚ Business Rule  โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Extractor      โ”‚  โ”‚ Mapper         โ”‚  โ”‚ Detector       โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚                โ”‚  โ”‚                โ”‚  โ”‚                โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Parse nouns  โ”‚  โ”‚ โ€ข 1:1, 1:N, N:Mโ”‚  โ”‚ โ€ข Permissions  โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Properties   โ”‚  โ”‚ โ€ข Join tables  โ”‚  โ”‚ โ€ข Constraints  โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Types        โ”‚  โ”‚ โ€ข Foreign keys โ”‚  โ”‚ โ€ข Workflows    โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                 โ”‚                                             โ”‚
โ”‚                                 โ–ผ                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                        GENERATION ORCHESTRATOR                           โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
โ”‚  โ”‚  โ”‚                     SUBAGENT COORDINATOR                           โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚                                                                    โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚   Phase 1        Phase 2        Phase 3        Phase 4            โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”          โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚   โ”‚ Schema  โ”‚โ”€โ”€โ–ถโ”‚  API    โ”‚โ”€โ”€โ–ถโ”‚Frontend โ”‚โ”€โ”€โ–ถโ”‚  Test   โ”‚          โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚   โ”‚ Agent   โ”‚   โ”‚ Agent   โ”‚   โ”‚ Agent   โ”‚   โ”‚ Agent   โ”‚          โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜          โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚        โ”‚             โ”‚             โ”‚             โ”‚                โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚        โ–ผ             โ–ผ             โ–ผ             โ–ผ                โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚   migrations/   src/api/      src/app/      __tests__/           โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚                                                                    โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                 โ”‚                                             โ”‚
โ”‚                                 โ–ผ                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                          MCP INTEGRATIONS                                โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ PostgreSQL   โ”‚  โ”‚ Docker MCP   โ”‚  โ”‚ File System  โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ MCP          โ”‚  โ”‚              โ”‚  โ”‚              โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚              โ”‚  โ”‚ โ€ข Dockerfile โ”‚  โ”‚ โ€ข Write filesโ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ โ€ข Schema     โ”‚  โ”‚ โ€ข Compose    โ”‚  โ”‚ โ€ข Create dirsโ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ”‚ โ€ข Migrations โ”‚  โ”‚ โ€ข Networks   โ”‚  โ”‚ โ€ข Templates  โ”‚                 โ”‚ โ”‚
โ”‚  โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                                                               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

4.2 Domain Model Schema

// Core types for application specification

interface ApplicationSpec {
  name: string;
  description: string;
  entities: EntitySpec[];
  relationships: RelationshipSpec[];
  features: FeatureSpec[];
  auth: AuthSpec;
  deployment: DeploymentSpec;
}

interface EntitySpec {
  name: string;
  pluralName: string;
  properties: PropertySpec[];
  isAggregate: boolean;
  aggregateRoot?: string;
  timestamps: boolean;
  softDelete: boolean;
}

interface PropertySpec {
  name: string;
  type: DataType;
  required: boolean;
  unique: boolean;
  default?: string | number | boolean;
  validation?: ValidationRule[];
}

type DataType =
  | 'string'
  | 'text'
  | 'integer'
  | 'float'
  | 'boolean'
  | 'date'
  | 'datetime'
  | 'json'
  | 'enum'
  | 'uuid';

interface RelationshipSpec {
  from: string;
  to: string;
  type: '1:1' | '1:N' | 'N:M';
  throughTable?: string;
  onDelete: 'cascade' | 'set-null' | 'restrict';
  required: boolean;
}

interface FeatureSpec {
  name: string;
  type: 'auth' | 'file-upload' | 'search' | 'notifications' | 'audit-log';
  config: Record<string, unknown>;
}

interface AuthSpec {
  type: 'jwt' | 'session' | 'oauth';
  providers?: ('google' | 'github' | 'email')[];
  roles: RoleSpec[];
}

interface RoleSpec {
  name: string;
  permissions: PermissionSpec[];
}

interface PermissionSpec {
  entity: string;
  actions: ('create' | 'read' | 'update' | 'delete')[];
  conditions?: string;  // e.g., "own" or "team"
}

interface DeploymentSpec {
  platform: 'docker' | 'kubernetes' | 'vercel' | 'railway';
  database: 'postgresql' | 'mysql' | 'sqlite';
  storage?: 's3' | 'local';
  ci: 'github-actions' | 'gitlab-ci';
}

interface GenerationContext {
  spec: ApplicationSpec;
  outputDir: string;
  framework: {
    backend: 'express' | 'fastify' | 'nestjs';
    frontend: 'nextjs' | 'react' | 'vue';
    orm: 'prisma' | 'drizzle' | 'typeorm';
    styling: 'tailwind' | 'css-modules' | 'styled-components';
  };
  options: {
    generateTests: boolean;
    generateDocs: boolean;
    generateDocker: boolean;
  };
}

4.3 Generated File Structure

                    GENERATED APPLICATION STRUCTURE

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   project-management-app/                                               โ”‚
    โ”‚   โ”‚                                                                      โ”‚
    โ”‚   โ”œโ”€โ”€ prisma/                          # Database layer                 โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ schema.prisma               # Schema definition               โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ migrations/                 # Migration files                 โ”‚
    โ”‚   โ”‚       โ”œโ”€โ”€ 001_create_users.sql                                     โ”‚
    โ”‚   โ”‚       โ”œโ”€โ”€ 002_create_teams.sql                                     โ”‚
    โ”‚   โ”‚       โ””โ”€โ”€ ...                                                       โ”‚
    โ”‚   โ”‚                                                                      โ”‚
    โ”‚   โ”œโ”€โ”€ src/                                                              โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ api/                        # API layer                       โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ routes/                                                   โ”‚
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ users.ts            # User CRUD                      โ”‚
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ teams.ts            # Team CRUD                      โ”‚
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ projects.ts         # Project CRUD                   โ”‚
    โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ tasks.ts            # Task CRUD                      โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ middleware/                                               โ”‚
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.ts             # Authentication                 โ”‚
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ authorize.ts        # Authorization                  โ”‚
    โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ validate.ts         # Validation                     โ”‚
    โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ index.ts                # API entry                      โ”‚
    โ”‚   โ”‚   โ”‚                                                                  โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ services/                   # Business logic                 โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ UserService.ts                                           โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ TeamService.ts                                           โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ProjectService.ts                                        โ”‚
    โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ TaskService.ts                                           โ”‚
    โ”‚   โ”‚   โ”‚                                                                  โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ validators/                 # Input validation               โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ user.ts                                                   โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ team.ts                                                   โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ project.ts                                               โ”‚
    โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ task.ts                                                   โ”‚
    โ”‚   โ”‚   โ”‚                                                                  โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ types/                      # TypeScript types               โ”‚
    โ”‚   โ”‚       โ””โ”€โ”€ index.ts                                                  โ”‚
    โ”‚   โ”‚                                                                      โ”‚
    โ”‚   โ”œโ”€โ”€ app/                            # Frontend (Next.js)             โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ (auth)/                                                       โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ login/page.tsx                                           โ”‚
    โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ register/page.tsx                                        โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ (dashboard)/                                                  โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ projects/                                                 โ”‚
    โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx           # Project list                   โ”‚
    โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [id]/page.tsx      # Project detail                 โ”‚
    โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ tasks/                                                    โ”‚
    โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ [id]/page.tsx      # Task detail                    โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ layout.tsx                                                    โ”‚
    โ”‚   โ”‚                                                                      โ”‚
    โ”‚   โ”œโ”€โ”€ components/                     # UI components                   โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ ui/                         # Base components                โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Button.tsx                                               โ”‚
    โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Input.tsx                                                โ”‚
    โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Card.tsx                                                 โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ features/                   # Feature components             โ”‚
    โ”‚   โ”‚       โ”œโ”€โ”€ ProjectCard.tsx                                          โ”‚
    โ”‚   โ”‚       โ”œโ”€โ”€ TaskList.tsx                                             โ”‚
    โ”‚   โ”‚       โ””โ”€โ”€ TeamSelector.tsx                                         โ”‚
    โ”‚   โ”‚                                                                      โ”‚
    โ”‚   โ”œโ”€โ”€ __tests__/                      # Tests                          โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ api/                        # API tests                      โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ services/                   # Service tests                  โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ e2e/                        # End-to-end tests              โ”‚
    โ”‚   โ”‚                                                                      โ”‚
    โ”‚   โ”œโ”€โ”€ docker-compose.yml              # Local dev environment          โ”‚
    โ”‚   โ”œโ”€โ”€ Dockerfile                      # Production build               โ”‚
    โ”‚   โ”œโ”€โ”€ .github/workflows/              # CI/CD                          โ”‚
    โ”‚   โ”‚   โ”œโ”€โ”€ ci.yml                                                        โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€ deploy.yml                                                    โ”‚
    โ”‚   โ”‚                                                                      โ”‚
    โ”‚   โ””โ”€โ”€ docs/                           # Documentation                   โ”‚
    โ”‚       โ”œโ”€โ”€ api.md                      # API documentation              โ”‚
    โ”‚       โ””โ”€โ”€ architecture.md             # Architecture overview          โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

5. Phased Implementation Guide

Phase 1: Specification Parser (Days 1-7)

Goals:

  • Parse natural language into structured spec
  • Extract entities and properties
  • Identify relationships

Tasks:

  1. Create ApplicationSpec schema
  2. Build entity extraction prompts
  3. Implement relationship detection
  4. Add validation for parsed spec
  5. Create spec preview for user approval

Milestone Checkpoint:

$ kiro-cli --agent app-generator
> "Create a blog app with posts, comments, and users"

[Parser] Analyzing specification...

[Entities Detected]
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Entity   โ”‚ Properties                        โ”‚ Type              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ User     โ”‚ id, email, name, password, avatar โ”‚ Aggregate Root    โ”‚
โ”‚ Post     โ”‚ id, title, content, published     โ”‚ Aggregate Root    โ”‚
โ”‚ Comment  โ”‚ id, content, author_id, post_id   โ”‚ Entity (of Post)  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

[Relationships]
โ€ข User 1:N Posts (user writes many posts)
โ€ข Post 1:N Comments (post has many comments)
โ€ข User 1:N Comments (user writes many comments)

[Inferred Features]
โ€ข Authentication (email/password)
โ€ข Timestamps on all entities
โ€ข Soft delete for posts

Proceed with this model? [Y/n]

Hint 1: Use few-shot prompting with example specifications to improve entity extraction accuracy.

Phase 2: Schema Generation (Days 8-14)

Goals:

  • Generate Prisma schema from spec
  • Create migration files
  • Add seed data generation

Tasks:

  1. Map entities to Prisma models
  2. Generate relationships (1:1, 1:N, N:M)
  3. Add proper indexes
  4. Create migration SQL files
  5. Generate seed data script

Milestone Checkpoint:

> "Generate database schema"

[PostgreSQL MCP] Generating schema...

Created: prisma/schema.prisma
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ model User {                                                     โ”‚
โ”‚   id        String   @id @default(uuid())                       โ”‚
โ”‚   email     String   @unique                                    โ”‚
โ”‚   name      String                                               โ”‚
โ”‚   password  String                                               โ”‚
โ”‚   avatar    String?                                              โ”‚
โ”‚   posts     Post[]                                               โ”‚
โ”‚   comments  Comment[]                                            โ”‚
โ”‚   createdAt DateTime @default(now())                             โ”‚
โ”‚   updatedAt DateTime @updatedAt                                  โ”‚
โ”‚ }                                                                โ”‚
โ”‚                                                                  โ”‚
โ”‚ model Post {                                                     โ”‚
โ”‚   id        String    @id @default(uuid())                      โ”‚
โ”‚   title     String                                               โ”‚
โ”‚   content   String                                               โ”‚
โ”‚   published Boolean   @default(false)                           โ”‚
โ”‚   author    User      @relation(fields: [authorId], ...)        โ”‚
โ”‚   authorId  String                                               โ”‚
โ”‚   comments  Comment[]                                            โ”‚
โ”‚   createdAt DateTime  @default(now())                           โ”‚
โ”‚   updatedAt DateTime  @updatedAt                                โ”‚
โ”‚ }                                                                โ”‚
โ”‚ ...                                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Created: prisma/migrations/001_initial.sql
Created: prisma/seed.ts

Hint 2: Generate @map and @@map annotations for snake_case database columns while keeping camelCase in TypeScript.

Phase 3: API Generation (Days 15-21)

Goals:

  • Generate CRUD endpoints for all entities
  • Add authentication and authorization
  • Create validation schemas

Tasks:

  1. Create route files for each entity
  2. Generate service layer with business logic
  3. Implement Zod validation schemas
  4. Add authentication middleware
  5. Generate OpenAPI documentation

Milestone Checkpoint:

> "Generate API layer"

[API Subagent] Generating endpoints...

Created API routes:
โ”œโ”€โ”€ src/api/routes/users.ts (6 endpoints)
โ”œโ”€โ”€ src/api/routes/posts.ts (6 endpoints)
โ”œโ”€โ”€ src/api/routes/comments.ts (5 endpoints)
โ””โ”€โ”€ src/api/routes/auth.ts (3 endpoints)

API Summary:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Method โ”‚ Endpoint           โ”‚ Auth   โ”‚ Description                โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ GET    โ”‚ /api/posts         โ”‚ No     โ”‚ List all posts             โ”‚
โ”‚ GET    โ”‚ /api/posts/:id     โ”‚ No     โ”‚ Get post by ID             โ”‚
โ”‚ POST   โ”‚ /api/posts         โ”‚ Yes    โ”‚ Create new post            โ”‚
โ”‚ PUT    โ”‚ /api/posts/:id     โ”‚ Yes    โ”‚ Update post (owner only)   โ”‚
โ”‚ DELETE โ”‚ /api/posts/:id     โ”‚ Yes    โ”‚ Delete post (owner only)   โ”‚
โ”‚ ...    โ”‚ ...                โ”‚ ...    โ”‚ ...                        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Created: docs/api.md (OpenAPI specification)

Phase 4: Frontend Generation (Days 22-28)

Goals:

  • Generate page components
  • Create form components
  • Implement data fetching

Tasks:

  1. Create page routes (Next.js app router)
  2. Generate list and detail views
  3. Build form components with validation
  4. Add data fetching with React Query
  5. Apply Tailwind styling

Milestone Checkpoint:

> "Generate frontend"

[Frontend Subagent] Generating components...

Created pages:
โ”œโ”€โ”€ app/(auth)/login/page.tsx
โ”œโ”€โ”€ app/(auth)/register/page.tsx
โ”œโ”€โ”€ app/(dashboard)/posts/page.tsx
โ”œโ”€โ”€ app/(dashboard)/posts/[id]/page.tsx
โ”œโ”€โ”€ app/(dashboard)/posts/new/page.tsx
โ””โ”€โ”€ app/(dashboard)/profile/page.tsx

Created components:
โ”œโ”€โ”€ components/features/PostCard.tsx
โ”œโ”€โ”€ components/features/PostForm.tsx
โ”œโ”€โ”€ components/features/CommentList.tsx
โ”œโ”€โ”€ components/ui/Button.tsx
โ”œโ”€โ”€ components/ui/Input.tsx
โ””โ”€โ”€ components/ui/Card.tsx

Created hooks:
โ”œโ”€โ”€ hooks/usePosts.ts
โ”œโ”€โ”€ hooks/usePost.ts
โ””โ”€โ”€ hooks/useAuth.ts

Phase 5: Test and Deploy (Days 29-35)

Goals:

  • Generate comprehensive tests
  • Create Docker configuration
  • Set up CI/CD

Tasks:

  1. Generate API integration tests
  2. Create service unit tests
  3. Add component tests
  4. Build Dockerfile and docker-compose
  5. Create GitHub Actions workflows

Hint 3: Generate test fixtures from the seed data to ensure consistency between development and testing.


6. Testing Strategy

6.1 Generated Test Structure

// Example generated test
describe('PostService', () => {
  beforeEach(async () => {
    await db.post.deleteMany();
    await db.user.deleteMany();
  });

  describe('create', () => {
    it('should create a post for authenticated user', async () => {
      const user = await createTestUser();
      const post = await PostService.create({
        title: 'Test Post',
        content: 'Test content',
        authorId: user.id
      });

      expect(post.title).toBe('Test Post');
      expect(post.authorId).toBe(user.id);
    });

    it('should require authentication', async () => {
      await expect(PostService.create({
        title: 'Test',
        content: 'Test',
        authorId: 'invalid-id'
      })).rejects.toThrow('Unauthorized');
    });
  });
});

6.2 Validation Tests

Aspect Test Pass Criteria
Schema Migrations apply cleanly No SQL errors
API All endpoints respond correctly 2xx responses for valid requests
Auth Protected routes require auth 401 for unauthenticated
Frontend Pages render without errors No React errors
E2E Full user flow works Create, read, update, delete

7. Common Pitfalls and Debugging

7.1 Common Issues

Pitfall Symptom Solution
Circular dependencies Import errors Separate entity types into base module
Missing relationships Foreign key errors Review spec for implicit relationships
Auth scope issues Unauthorized errors Check permission rules in spec
Type mismatches TypeScript errors Regenerate types from schema
Migration conflicts Database errors Reset and regenerate migrations

7.2 Debugging Strategies

1. Validate spec before generation:

> "Show me the parsed specification"

[Spec Validation]
โ”œโ”€โ”€ Entities: 4 (User, Post, Comment, Tag)
โ”œโ”€โ”€ Relationships: 5
โ”œโ”€โ”€ Business Rules: 3
โ”œโ”€โ”€ Warnings:
โ”‚   โ”œโ”€โ”€ Post.published has no default - assuming false
โ”‚   โ””โ”€โ”€ Comment.content has no max length - assuming 1000
โ””โ”€โ”€ Status: Valid (with warnings)

2. Incremental generation:

> "Generate only the User entity first"

# Verify User works before generating all entities

3. Test isolation:

> "Run tests for the API layer only"

[Test Runner]
โ”œโ”€โ”€ src/api/__tests__/users.test.ts โœ“ (12 tests)
โ”œโ”€โ”€ src/api/__tests__/posts.test.ts โœ— (1 failure)
โ”‚   โ””โ”€โ”€ FAIL: should require auth for create
โ”‚       Expected 401, got 200
โ””โ”€โ”€ Fix: Authentication middleware not applied to POST /posts

8. Extensions and Challenges

8.1 Beginner Extensions

  • Add GraphQL API as alternative to REST
  • Generate Storybook stories for components
  • Add i18n support with generated translation files

8.2 Intermediate Extensions

  • Support for real-time features (WebSockets)
  • Generate mobile app with React Native
  • Add multi-tenant architecture support

8.3 Advanced Extensions

  • AI-powered spec refinement through conversation
  • Generate microservices architecture
  • Support for event sourcing and CQRS patterns

9. Real-World Connections

9.1 Industry Tools

Tool Similar Pattern Company
Blitz.js Full-stack scaffolding Blitz
RedwoodJS Full-stack framework Redwood
Amplication Backend generation Amplication
Supabase Database + API Supabase

9.2 Production Considerations

  • Customization: Generated code should be clearly marked and easy to extend
  • Regeneration: Changes to spec should not overwrite custom code
  • Testing: Generated tests are starting points, not complete coverage
  • Security: Generated auth is basic - always add security hardening

10. Self-Assessment Checklist

Understanding Verification

  • I can explain domain-driven design concepts
  • I understand the 80/20 rule for code generation
  • I can identify aggregates and bounded contexts
  • I know when to use 1:1, 1:N, and N:M relationships
  • I understand the generation pipeline phases

Implementation Verification

  • Spec parser extracts entities correctly
  • Relationships are detected and modeled
  • Schema generates valid Prisma models
  • API endpoints work with authentication
  • Frontend renders and fetches data
  • Tests pass for generated code

Integration Verification

  • Full application runs with docker-compose
  • CI/CD pipeline builds and deploys
  • Generated code is maintainable
  • Custom code can be added without conflicts

11. Completion Criteria

Minimum Viable Completion

  • Parse specification and extract entities
  • Generate database schema
  • Create basic CRUD API
  • Scaffold simple frontend pages
  • Docker configuration works

Full Completion

  • Complete authentication with roles
  • Authorization on all endpoints
  • Full frontend with forms and validation
  • Comprehensive test coverage
  • CI/CD pipeline

Excellence (Going Above and Beyond)

  • AI-powered spec refinement
  • Multiple framework support
  • Real-time feature generation
  • Custom code protection on regeneration
  • Visual spec editor

This guide was expanded from LEARN_KIRO_CLI_MASTERY.md. For the complete learning path, see the README.