Official SDK for CubeGen AI - Generate software architecture diagrams from text prompts
bash
npm install cubegen-ai
`
Quick Start
`javascript
import CubeGenAI from 'cubegen-ai';
// Initialize the client with your API key
// Get your API key from your CubeGen AI dashboard after subscribing to a Pro plan
const client = new CubeGenAI('your-api-key');
// Generate a diagram from a text prompt
try {
const diagram = await client.generateDiagram('A 3-tier web application on AWS with a load balancer, multiple EC2 instances in an auto-scaling group, and an RDS database.');
console.log('Generated diagram:', diagram);
} catch (error) {
console.error('Error generating diagram:', error.message);
}
`
API Reference
$3
`javascript
new CubeGenAI(apiKey[, baseUrl])
`
- apiKey (string, required): Your CubeGen AI API key. Get this from your dashboard after subscribing to a Pro plan.
- baseUrl (string, optional): The base URL for the API. Defaults to the production API.
$3
#### generateDiagram(prompt)
Generate a diagram from a text prompt.
- prompt (string, required): A text description of the architecture you want to generate.
- Returns: Promise - A promise that resolves to the generated diagram data.
Example:
`javascript
const diagram = await client.generateDiagram('A microservice architecture with API Gateway, Lambda functions, and DynamoDB.');
`
Diagram Data Structure
The generated diagram follows this structure:
`typescript
interface DiagramData {
title: string;
architectureType: string;
nodes: Array<{
id: string;
label: string;
type: string;
description: string;
x: number;
y: number;
width: number;
height: number;
}>;
links: Array<{
id: string;
source: string;
target: string;
label?: string;
}>;
containers?: Array<{
id: string;
label: string;
type: string;
childNodeIds: string[];
x: number;
y: number;
width: number;
height: number;
}>;
}
`
Error Handling
The SDK throws errors for API issues or invalid requests. Catch these errors to handle them appropriately:
`javascript
try {
const diagram = await client.generateDiagram(prompt);
} catch (error) {
console.error('API Error:', error.message);
// Handle the error appropriately
}
``