- Alibaba Cloud Function Compute (Serverless, Custom Runtime Infrastructure)
- Alibaba Cloud DashScope API (Qwen Large Language Models Engine)
- TypeScript & Node.js (Core Backend Orchestration Router)
- Express.js (Endpoint Routing & Serving Frontend Pipelines)
- HTML5 / CSS3 / JavaScript (Glassmorphism Live-Timeline Client Dashboard)
- Mermaid.js (Dynamic Graphical Architecture Mapping)
RefactorBot Society is an autonomous, serverless multi-agent pipeline hosted on Alibaba Cloud Function Compute. Designed to modernize and secure legacy code, it triggers a "society" of specialized AI personas powered by Qwen Large Language Models to architect, write, and aggressively QA code before it ever reaches production.
Built by JemBuildz.
Legacy code modernization is usually a painful, manual process. While single-prompt LLMs can translate code from one language to another, they frequently hallucinate, introduce security vulnerabilities (like SSRF or CORS misconfigurations), and fail to grasp enterprise architecture. We wanted to build a system that doesn't just translate code, but engineers it.
When fed legacy monolithic code via the interactive Glassmorphism UI, it triggers a rigorous negotiation loop between five distinct personas:
- The Parser: Dissects the legacy logic and identifies deprecated patterns.
- The Architect: Designs a modern, asynchronous target framework (e.g., FastAPI).
- The Developer: Drafts the initial code based on the Architect's blueprint.
- The QA Engineer: A ruthless security and performance reviewer. It actively hunts for resource leaks, unhandled exceptions, and architectural flaws, rejecting the code until it meets enterprise standards.
- The Senior Reviewer: Mediates any QA rejections and provides actionable fix instructions back to the Developer.
Code is only output to the user once it survives this loop and passes the QA Engineer's strict approval.
graph TD
A --> B
%% Styling
classDef user fill:#3b82f6,stroke:#1e40af,stroke-width:2px,color:#fff;
classDef cloud fill:#f97316,stroke:#c2410c,stroke-width:2px,color:#fff;
classDef agent fill:#10b981,stroke:#047857,stroke-width:2px,color:#fff;
classDef qwen fill:#8b5cf6,stroke:#5b21b6,stroke-width:2px,color:#fff;
%% Nodes
A[User Frontend UI]:::user -->|POST /refactor| B(Alibaba Function Compute)
subgraph Serverless Backend [Alibaba Cloud Custom Runtime]
B:::cloud --> C{Orchestrator Loop}
C --> D[Parser Agent]:::agent
C --> E[Architect Agent]:::agent
%% Negotiation Loop
subgraph Agent Negotiation Loop
F[Developer Agent]:::agent --> G{QA Engineer}:::agent
G -- Rejects Code --> H[Senior Reviewer]:::agent
H -- Fix Instructions --> F
end
E --> F
G -- Approves Code --> I[Final Code Output]
end
%% API Calls
D -.->|API Call| Q[Qwen Cloud API]:::qwen
E -.->|API Call| Q
F -.->|API Call| Q
G -.->|API Call| Q
H -.->|API Call| Q
I -->|JSON Response| A
AI Brain: Alibaba Cloud DashScope API (Qwen Large Language Models)
Orchestration: Node.js / Express built with TypeScript
Infrastructure: Alibaba Cloud Function Compute (Custom Runtime, Serverless)
Frontend: HTML/CSS/JS Glassmorphism UI rendering real-time JSON timeline logs to visualize agent negotiations.
Prerequisites Node.js (v18+)
An Alibaba Cloud Account & DashScope API Key
TypeScript
Installation Clone the repository:
git clone [https://github.com/JemBuildz/RefactorBot](https://github.com/JemBuildz/RefactorBot)
cd refactorbot-societyInstall dependencies:
npm install
Create a .env file in the root directory:
Code snippet
QWEN_API_KEY=your_dashscope_api_key_here
PORT=9000
Build the TypeScript files:npm run build
Start the local server:
npm startThis project is configured specifically for Alibaba Cloud Function Compute (Custom Runtime).
Run npm run build to generate the updated dist folder.
Select the following 4 items in your file explorer:
dist/ (folder)
node_modules/ (folder)
package.json
.env
Compress these 4 items directly into a .zip file (Do not zip the parent folder, zip the items themselves).
Upload the deploy.zip file to your Alibaba Cloud Function Compute instance.
Ensure the Function Start Command is set to: node dist/server.js
By default, the RefactorBot Society is configured to allow a maximum of 3 negotiation cycles between the Developer and the QA Engineer. If the QA Engineer is not satisfied by the third attempt, the loop terminates to prevent infinite API calls and runaway cloud costs.
You can easily tune this limit to give the Developer agent more chances to fix highly complex legacy code.
- Adjusting the Cycle Limit Open src/orchestrator.ts and locate the MAX_ATTEMPTS constant in the runRefactorBot function:
TypeScript
// src/orchestrator.ts
let approved = false;
let attempts = 0;
const MAX_ATTEMPTS = 3; // Increase this number to allow more negotiation cycles
while (!approved && attempts < MAX_ATTEMPTS) {
// ... agent loop ...
}
- Synchronizing Cloud Timeouts If you increase the MAX_ATTEMPTS, you must also increase your Alibaba Cloud Function Compute execution timeout. An extended AI debate will trigger a serverless timeout if not properly configured.
Rule of Thumb: Allow approximately 90–100 seconds per cycle.
3 Cycles (Default): Set Alibaba Cloud Timeout to 300 seconds (5 minutes).
5 Cycles: Set Alibaba Cloud Timeout to 600 seconds (10 minutes).
To update the timeout in Alibaba Cloud:
Navigate to your Function Compute console.
Select your function and click Configurations.
Under Basic Settings, change the Execution Timeout Period.
Save and deploy the new configuration.
Jeremy Codjoe — Creator of JemBuildz
This project is licensed under the MIT License - see the LICENSE file for details.


