> ## Documentation Index
> Fetch the complete documentation index at: https://docs.scriptonia.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# execution-process

> What happens during Execution, how agents are coordinated, how progress is shown, and how long it typically takes.

## What Happens During Execution

***

### 1. Entry

After **Payment**, you are redirected to\
`/execution?sessionId=...&platform=...&signature=...`\
(or without `signature` when paying with Dodo).

* The Execution page loads
* After a short **“Preparing...”** delay (\~2 seconds)
* Calls `POST /api/execute` with:
  * `sessionId`
  * `transactionSignature` (if Solana)
  * `platform`

***

### 2. Execute API

The `/api/execute` handler:

1. **Loads workflow context**
   * From database (or in-memory) using `sessionId`
   * If missing, may rebuild from `Workflow` table or fail with a clear error
2. **Validates**
   * Ensures `selectedPlatform` exists
   * Ensures `refinedRequirements` exist
   * If Solana payment, may verify transaction on-chain
3. **Resolves agents**
   * From `platformOptions.agents_required`
   * Or defaults (ProductManager, FrontendDev, BackendDev)
   * For Android / iOS, DevOpsEngineer usually included
   * **ReviewAgent** always runs after main agents
4. **Runs the X402 workflow**
   * Calls `executeX402Workflow`
   * Inputs: platform, requirements, `sessionId`, agent list
5. **Saves the result**
   * Writes `executionResult` to workflow:
     * `agents_executed`
     * `deliverables`
     * `review_passed`
     * `review_issues`
   * Returns the result

***

### 3. X402 Workflow (server-side)

Inside `executeX402Workflow`:

1. **Platform config**
   * Selects template (Website, Web Application, Android, iOS)
   * Gets expected folder structure and file list
2. **Platform deliverables**
   * `generatePlatformDeliverables` creates real file content:
     * PRD
     * PLAN
     * Specs
     * Prompts
     * Infra
   * Files assigned to agents and generated via AI
3. **A2A setup**
   * Initializes **A2A (Agent-to-Agent)** for the session
   * Sends “Execution started”
   * Shares requirements with all agents
4. **Agent run**
   * Agents run in parallel:
     * ProductManager
     * FrontendDev
     * BackendDev
     * DevOpsEngineer
     * ToolManager (as applicable)
   * Each agent:
     * Receives requirements
     * Produces outputs
     * Shares `execution_result` via A2A
   * **ReviewAgent does not run here**
5. **Aggregation**
   * Platform deliverables are merged
   * Deduplication may regenerate identical files
6. **Folder structure**
   * Adds `project_structure` deliverable
   * Example: `FOLDER_STRUCTURE.md`
7. **Review**
   * **ReviewAgent** checks:
     * Required files exist
     * Each file has path and non-empty content
   * Returns:
     * `review_passed` (true/false)
     * `review_issues` (list)
8. **Response**
   * Returns:
     * `agents_executed`
     * `deliverables`
     * `integration_points`
     * `review_passed`
     * `review_issues`
     * `execution_time_seconds`

***

### 4. Projects Generate (ZIP)

When Execute API returns **success** and `review_passed = true`:

* Execution page calls `POST /api/projects/generate`
* Inputs:
  * `sessionId`
  * `executionResult`

That API:

* Builds project file tree
* Writes files to disk or in-memory
* Creates a **ZIP**
* Stores ZIP in `ZipFile` (and/or `Workflow.zipFile`)

***

### 5. Execution Page After Completion

* **Review**
  * “Review Passed” or “Review Failed”
  * Shows `review_issues` if failed
* **Structure**
  * Renders **Project Structure** preview
* **ZIP**
  * Progress bar during:
    * “Generating ZIP file...”
    * “Preparing your document...”
  * Shows **“Download Project ZIP”** when ready
* **GitHub**
  * If OAuth configured:
    * Connect to GitHub
    * Upload to GitHub
    * Create repo and push files

***

## Agent Coordination

***

### Roles in Execution

| Agent              | Role                                                       |
| :----------------- | :--------------------------------------------------------- |
| **X402Agent**      | Orchestrator; shares requirements via A2A; coordinates run |
| **ProductManager** | PRD, user stories, acceptance criteria, feature specs      |
| **FrontendDev**    | Frontend components, pages, styles, specs                  |
| **BackendDev**     | API, data models, DB schema, auth                          |
| **DevOpsEngineer** | Docker, CI/CD, deployment, infra                           |
| **ToolManager**    | Integrations, `.env.example`, configs, folder structure    |
| **ReviewAgent**    | Post-run review; sets `review_passed` and `review_issues`  |

**CEO** appears in UX copy, but real orchestration is done by **X402Agent**.

***

### A2A (Agent-to-Agent)

* **Initialize**
  * A2A initialized at start of X402 run
* **Notifications**
  * “Execution started”
  * “Starting \<Agent>”
  * “\<Agent> completed”
* **Data sharing**
  * Requirements shared to all agents
  * Agents share `execution_result` when done
* **Parallel run**
  * Agents run via `Promise.all`
  * No fixed sequence

***

### Integration Points

Inferred from agents run:

* Frontend–Backend
* Backend–AI
* ProductManager–Frontend
* DevOps–Backend

Reported in execution result.

***

### Who Produces What

* **Platform-specific content**
  * Produced by `generatePlatformDeliverables`
* **Parallel agent run**
  * Provides status and high-level outputs
* **Final deliverables**
  * Platform deliverables
  * `FOLDER_STRUCTURE.md`
  * `REVIEW_REPORT.md`

***

## Progress Tracking

***

### On the Execution Page

| Phase                  | What you see                           |
| :--------------------- | :------------------------------------- |
| **Preparing**          | “Preparing... Setting up your project” |
| **Executing**          | “Executing Workflow” + messages        |
| **Execution complete** | “Execution complete!”                  |
| **Review**             | “Review Passed” or “Review Failed”     |
| **Generating ZIP**     | Progress bar (0–100%)                  |
| **Ready**              | “ZIP file ready!” + download button    |

***

### Progress Messages (in order)

1. “Validating payment...”
2. “CEO Agent: Analyzing request and routing to X402Agent...”
3. “X402Agent: Orchestrating simultaneous multi-agent execution...”
4. “Executing agents simultaneously: ProductManager, FrontendDev, BackendDev...”
5. “ReviewAgent: Reviewing deliverables for quality and uniqueness...”

**Note**

* `/api/execute` is a **single HTTP request**
* Messages are **client-side placeholders**
* Server work runs in one pass
* ZIP progress reflects `/api/projects/generate`

***

### If Review Fails

* “Review Failed” shown
* `review_issues` displayed
* ZIP generation not started
* Download button hidden

***

## Expected Timelines

***

### By Platform (typical)

| Platform            | Typical execution time |
| :------------------ | :--------------------- |
| **Website**         | \~45 s                 |
| **Web Application** | \~75 s                 |
| **Android**         | \~100 s                |
| **iOS**             | \~100 s                |

***

### Additional Time

| Step                    | Typical duration |
| :---------------------- | :--------------- |
| Preparing (client)      | \~2 s            |
| Execute API             | \~45–100+ s      |
| Projects Generate (ZIP) | \~5–30+ s        |
| Client UX placeholders  | A few seconds    |

***

### End-to-End (Payment → Download)

* **Website:** \~1–2.5 min
* **Web Application:** \~1.5–3 min
* **Android / iOS:** \~2–3.5 min

***

### What Affects Duration

* Platform
* Deduplication
* ReviewAgent overhead
* AI model and RPC latency
* ZIP size and file count
