workflow:
  id: greenfield-fullstack
  name: Greenfield Full-Stack Application Development
  description: >-
    Agent workflow for building full-stack applications from concept to development.
    Supports both comprehensive planning for complex projects and rapid prototyping for simple ones.
    Includes Phase 0 environment bootstrap for proper tooling setup.
  type: greenfield
  version: "1.0"
  project_types:
    - web-app
    - saas
    - enterprise-app
    - prototype
    - mvp

  metadata:
    elicit: true
    confirmation_required: true

  phases:
    - phase_0: Environment Bootstrap
    - phase_1: Discovery & Planning
    - phase_2: Document Sharding
    - phase_3: Development Cycle

  sequence:
    # ═══════════════════════════════════════════════════════════════════════════
    # PHASE 0: ENVIRONMENT BOOTSTRAP
    # ═══════════════════════════════════════════════════════════════════════════
    - phase: 0
      name: Environment Bootstrap
      description: "Setup development environment before starting project planning"

    - id: devops-environment-bootstrap
      agent: devops
      action: environment_bootstrap
      duration_estimate: "15-30 min"
      creates:
        - .aiox/config.yaml
        - .aiox/environment-report.json
        - .gitignore
        - README.md
        - package.json
      task: environment-bootstrap.md
      optional: false
      notes: |
        CRITICAL FIRST STEP - Run before any planning:
        - @devops → *environment-bootstrap
        - Verifies/installs CLIs (git, gh, node, supabase, railway)
        - Authenticates services (GitHub, Supabase, Railway)
        - Creates Git repository locally and on GitHub
        - Scaffolds AIOX project structure
        - Generates environment report

        SKIP CONDITIONS:
        - Only skip if project already has .aiox/environment-report.json
        - Re-run if switching machines or team members join

    # ═══════════════════════════════════════════════════════════════════════════
    # PHASE 1: DISCOVERY & PLANNING
    # ═══════════════════════════════════════════════════════════════════════════
    - phase: 1
      name: Discovery & Planning
      description: "Create all planning artifacts (project brief, PRD, specs, architecture)"

    - id: analyst-project-brief
      agent: analyst
      creates: project-brief.md
      duration_estimate: "30-60 min"
      requires: environment_bootstrap_complete
      optional_steps:
        - brainstorming-session
        - market-research-prompt
      notes: "Can do brainstorming first, then optional deep research before creating project brief. SAVE OUTPUT: Copy final project-brief.md to your project's docs/ folder."

    - id: pm-create-prd
      agent: pm
      creates: prd.md
      duration_estimate: "30-60 min"
      requires: project-brief.md
      notes: "Creates PRD from project brief using prd-tmpl. SAVE OUTPUT: Copy final prd.md to your project's docs/ folder."

    - id: ux-create-frontend-spec
      agent: ux-design-expert
      creates: front-end-spec.md
      duration_estimate: "30-45 min"
      requires: prd.md
      optional_steps:
        - user-research-prompt
      notes: "Creates UI/UX specification using front-end-spec-tmpl. SAVE OUTPUT: Copy final front-end-spec.md to your project's docs/ folder."

    - id: ux-generate-v0-prompt
      agent: ux-design-expert
      creates: v0_prompt (optional)
      duration_estimate: "15-30 min"
      requires: front-end-spec.md
      condition: user_wants_ai_generation
      notes: "OPTIONAL BUT RECOMMENDED: Generate AI UI prompt for tools like v0, Lovable, etc. Use the generate-ai-frontend-prompt task. User can then generate UI in external tool and download project structure."

    - id: architect-create-architecture
      agent: architect
      creates: fullstack-architecture.md
      duration_estimate: "30-60 min"
      requires:
        - prd.md
        - front-end-spec.md
      optional_steps:
        - technical-research-prompt
        - review-generated-ui-structure
      notes: "Creates comprehensive architecture using fullstack-architecture-tmpl. If user generated UI with v0/Lovable, can incorporate the project structure into architecture. May suggest changes to PRD stories or new stories. SAVE OUTPUT: Copy final fullstack-architecture.md to your project's docs/ folder."

    - id: pm-update-prd
      agent: pm
      updates: prd.md
      duration_estimate: "15-30 min"
      requires: fullstack-architecture.md
      condition: architecture_suggests_prd_changes
      notes: "If architect suggests story changes, update PRD and re-export the complete unredacted prd.md to docs/ folder."

    - id: po-validate-artifacts
      agent: po
      validates: all_artifacts
      uses: po-master-checklist
      duration_estimate: "15-30 min"
      notes: "Validates all documents for consistency and completeness. May require updates to any document."

    - id: po-delegate-fixes
      agent: po
      action: delegate_fixes
      delegates_to: [analyst, pm, ux-design-expert, architect]
      updates: any_flagged_documents
      duration_estimate: "15-30 min"
      condition: po_checklist_issues
      notes: "If PO finds issues, PO delegates fixes to the relevant agent and re-validates updated documents in docs/ folder."

    - meta: guidance
      id: project-setup-guidance
      action: guide_project_structure
      condition: user_has_generated_ui
      notes: "If user generated UI with v0/Lovable: For polyrepo setup, place downloaded project in separate frontend repo alongside backend repo. For monorepo, place in apps/web or packages/frontend directory. Review architecture document for specific guidance."

    - meta: guidance
      id: development-order-guidance
      action: guide_development_sequence
      notes: "Based on PRD stories: If stories are frontend-heavy, start with frontend project/directory first. If backend-heavy or API-first, start with backend. For tightly coupled features, follow story sequence in monorepo setup. Reference sharded PRD epics for development order."

    # ═══════════════════════════════════════════════════════════════════════════
    # PHASE 2: DOCUMENT SHARDING
    # ═══════════════════════════════════════════════════════════════════════════
    - phase: 2
      name: Document Sharding
      description: "Break down PRD and architecture into development-ready chunks"

    - id: po-shard-documents
      agent: po
      action: shard_documents
      creates: sharded_docs
      duration_estimate: "15-30 min"
      requires:  # all validated artifacts must be saved in project docs/ folder
        - prd.md
        - front-end-spec.md
        - fullstack-architecture.md
      notes: |
        Shard documents for IDE development:
        - Option A: Use PO agent to shard: @po then ask to shard docs/prd.md
        - Option B: Manual: Drag shard-doc task + docs/prd.md into chat
        - Creates docs/prd/ and docs/architecture/ folders with sharded content
        - Generates: source-tree.md, tech-stack.md, coding-standards.md

    # ═══════════════════════════════════════════════════════════════════════════
    # PHASE 3: DEVELOPMENT CYCLE
    # ═══════════════════════════════════════════════════════════════════════════
    - phase: 3
      name: Development Cycle
      description: "Iterative story implementation with QA review"

    - id: sm-create-story
      agent: sm
      action: create_story
      creates: story.md
      duration_estimate: "15-30 min"
      requires: sharded_docs
      repeats: for_each_epic
      notes: |
        Story creation cycle:
        - SM Agent (New Chat): @sm → *create
        - Creates next story from sharded docs
        - Story starts in "Draft" status

    - id: pm-review-draft-story
      agent: pm
      action: review_draft_story
      alternative_agent: analyst
      updates: story.md
      duration_estimate: "10-20 min"
      requires: story.md
      optional: true
      condition: user_wants_story_review
      notes: |
        OPTIONAL: Review and approve draft story
        - NOTE: story-review task coming soon
        - Review story completeness and alignment
        - Update story status: Draft → Approved

    - id: dev-implement-story
      agent: dev
      action: implement_story
      creates: implementation_files
      duration_estimate: "1-4 hours"
      requires: story.md
      notes: |
        Dev Agent (New Chat): @dev
        - Implements approved story
        - Updates File List with all changes
        - Marks story as "Review" when complete

    - id: qa-review-implementation
      agent: qa
      action: review_implementation
      updates: implementation_files
      duration_estimate: "20-40 min"
      requires: implementation_files
      optional: true
      notes: |
        OPTIONAL: QA Agent (New Chat): @qa → review-story
        - Senior dev review with refactoring ability
        - Fixes small issues directly
        - Leaves checklist for remaining items
        - Updates story status (Review → Done or stays Review)

    - id: dev-address-qa-feedback
      agent: dev
      action: address_qa_feedback
      updates: implementation_files
      requires: implementation_files
      duration_estimate: "30-60 min"
      condition: qa_left_unchecked_items
      notes: |
        If QA left unchecked items:
        - Dev Agent (New Chat): Address remaining items
        - Return to QA for final approval

    - meta: repeat
      target_steps: [sm-create-story, dev-implement-story, qa-review-implementation]
      condition: stories_remaining
      notes: |
        Repeat story cycle (SM → Dev → QA) for all epic stories
        Continue until all stories in PRD are complete

    - id: po-epic-retrospective
      agent: po
      action: epic_retrospective
      creates: epic-retrospective.md
      duration_estimate: "15-30 min"
      condition: epic_complete
      optional: true
      notes: |
        OPTIONAL: After epic completion
        - NOTE: epic-retrospective task coming soon
        - Validate epic was completed correctly
        - Document learnings and improvements

    - meta: end
      action: project_complete
      notes: |
        All stories implemented and reviewed!
        Project development phase complete.
        Reference: .aiox-core/data/aiox-kb.md#IDE Development Workflow

  flow_diagram: |
    ```mermaid
    graph TD
        subgraph PHASE_0["PHASE 0: Environment Bootstrap"]
            A[Start: Greenfield Project] --> A1{Environment ready?}
            A1 -->|No| A2[devops: environment-bootstrap]
            A2 --> A3[CLIs installed + GitHub repo created]
            A1 -->|Yes| A3
        end

        subgraph PHASE_1["PHASE 1: Discovery & Planning"]
            A3 --> B[analyst: project-brief.md]
            B --> C[pm: prd.md]
            C --> D[ux-design-expert: front-end-spec.md]
            D --> D2{Generate v0 prompt?}
            D2 -->|Yes| D3[ux-design-expert: create v0 prompt]
            D2 -->|No| E[architect: fullstack-architecture.md]
            D3 --> D4[User: generate UI in v0/Lovable]
            D4 --> E
            E --> F{Architecture suggests PRD changes?}
            F -->|Yes| G[pm: update prd.md]
            F -->|No| H[po: validate all artifacts]
            G --> H
            H --> I{PO finds issues?}
            I -->|Yes| J[po: delegate fixes to relevant agent]
            I -->|No| K_GATE[Phase 1 Complete]
            J --> H
        end

        subgraph PHASE_2["PHASE 2: Document Sharding"]
            K_GATE --> K[po: shard documents]
            K --> K1[Creates: source-tree, tech-stack, coding-standards]
        end

        subgraph PHASE_3["PHASE 3: Development Cycle"]
            K1 --> L[sm: create story]
            L --> M{Review draft story?}
            M -->|Yes| N[pm/analyst: review & approve story]
            M -->|No| O[dev: implement story]
            N --> O
            O --> P{QA review?}
            P -->|Yes| Q[qa: review implementation]
            P -->|No| R{More stories?}
            Q --> S{QA found issues?}
            S -->|Yes| T[dev: address QA feedback]
            S -->|No| R
            T --> Q
            R -->|Yes| L
            R -->|No| U{Epic retrospective?}
            U -->|Yes| V[po: epic retrospective]
            U -->|No| W[Project Complete]
            V --> W
        end

        %% Optional paths
        B -.-> B1[Optional: brainstorming]
        B -.-> B2[Optional: market research]
        D -.-> D1[Optional: user research]
        E -.-> E1[Optional: technical research]

        %% Styling
        style A2 fill:#FF6B6B,color:#fff
        style A3 fill:#FF6B6B,color:#fff
        style W fill:#90EE90
        style K fill:#ADD8E6
        style K1 fill:#ADD8E6
        style L fill:#ADD8E6
        style O fill:#ADD8E6
        style D3 fill:#E6E6FA
        style D4 fill:#E6E6FA
        style B fill:#FFE4B5
        style C fill:#FFE4B5
        style D fill:#FFE4B5
        style E fill:#FFE4B5
        style N fill:#F0E68C
        style Q fill:#F0E68C
        style V fill:#F0E68C
    ```

  decision_guidance:
    when_to_use:
      - Building production-ready applications
      - Multiple team members will be involved
      - Complex feature requirements
      - Need comprehensive documentation
      - Long-term maintenance expected
      - Enterprise or customer-facing applications
    when_not_to_use:
      - Simple API-only project without frontend (use greenfield-service)
      - Frontend-only project without backend (use greenfield-ui)
      - Enhancing existing application (use brownfield-fullstack)
      - Technical debt assessment on existing project (use brownfield-discovery)

  handoff_prompts:
    # Phase 0 → Phase 1
    bootstrap_to_analyst: "Environment bootstrap complete! Git repo created, CLIs verified, project structure ready. Start a new chat with @analyst to create the project brief."

    # Phase 1 internal
    analyst_to_pm: "Project brief is complete. Save it as docs/project-brief.md in your project, then create the PRD."
    pm_to_ux: "PRD is ready. Save it as docs/prd.md in your project, then create the UI/UX specification."
    ux_to_architect: "UI/UX spec complete. Save it as docs/front-end-spec.md in your project, then create the fullstack architecture."
    architect_review: "Architecture complete. Save it as docs/fullstack-architecture.md. Do you suggest any changes to the PRD stories or need new stories added?"
    architect_to_pm: "Please update the PRD with the suggested story changes, then re-export the complete prd.md to docs/."
    updated_to_po: "All documents ready in docs/ folder. Please validate all artifacts for consistency."
    po_issues: "PO found issues with [document]. Please return to [agent] to fix and re-save the updated document."

    # Phase 1 → Phase 2
    phase1_to_phase2: "All planning artifacts validated. Now shard documents for development: @po → *shard-doc docs/prd.md"

    # Phase 2 → Phase 3
    phase2_to_phase3: "Documents sharded! source-tree.md, tech-stack.md, coding-standards.md created. Start development: @sm → *create-story"

    # Completion
    complete: "All stories implemented and reviewed. Project development phase complete!"
