Estimated Effort: 4 weeks / 5 days
Impacted Subsystems / Files:
app/api/forge-agent/route.ts
lib/forge/payment-verifier.ts
lib/forge/ai-pipeline.ts
lib/forge/ipfs-publisher.ts
Context & Problem Statement:
app/api/forge-agent/route.ts is a 1,072-line monolithic handler managing HTTP 402 challenges, Soroban XDR verification, Gemini lore generation, Nano Banana API orchestration, Pollinations fallbacks, Pinata IPFS uploads, and on-chain mint calls in a single synchronous execution path.
Technical Requirements & Scope:
- Decompose route handler into isolated pipeline steps (
verifyPaymentStep, generateLoreStep, generateImageStep, publishIpfsStep, mintNftStep).
- Implement async job status tracking with UUID correlation IDs.
- Refactor fallback logic so Nano Banana timeouts cleanly cascade to Pollinations without failing the response.
- Extract AI lore prompt construction into
lib/forge/prompt-builder.ts.
Multi-File Change Surface:
Refactors app/api/forge-agent/route.ts completely and creates modular sub-libraries in lib/forge/.
Acceptance Criteria:
Suggested Approach / Investigation Steps:
- Map state payload transitions across current 1,072-line route file.
- Create isolated module pipeline files in
lib/forge/.
- Implement integration test suite mocking external API failures.
Estimated Effort: 4 weeks / 5 days
Impacted Subsystems / Files:
app/api/forge-agent/route.tslib/forge/payment-verifier.tslib/forge/ai-pipeline.tslib/forge/ipfs-publisher.tsContext & Problem Statement:
app/api/forge-agent/route.tsis a 1,072-line monolithic handler managing HTTP 402 challenges, Soroban XDR verification, Gemini lore generation, Nano Banana API orchestration, Pollinations fallbacks, Pinata IPFS uploads, and on-chain mint calls in a single synchronous execution path.Technical Requirements & Scope:
verifyPaymentStep,generateLoreStep,generateImageStep,publishIpfsStep,mintNftStep).lib/forge/prompt-builder.ts.Multi-File Change Surface:
Refactors
app/api/forge-agent/route.tscompletely and creates modular sub-libraries inlib/forge/.Acceptance Criteria:
Suggested Approach / Investigation Steps:
lib/forge/.