cubegen-ai
v1.0.4
Published
Official SDK for CubeGen AI - Generate software architecture diagrams from text prompts
Maintainers
Readme
CubeGen AI SDK
The official SDK for integrating CubeGen AI into your applications. Generate beautiful software architecture diagrams from simple text prompts.
Installation
npm install cubegen-aiQuick Start
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
Constructor
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.
Methods
generateDiagram(prompt)
Generate a diagram from a text prompt.
prompt(string, required): A text description of the architecture you want to generate.- Returns:
Promise<DiagramData>- A promise that resolves to the generated diagram data.
Example:
const diagram = await client.generateDiagram('A microservice architecture with API Gateway, Lambda functions, and DynamoDB.');Diagram Data Structure
The generated diagram follows this structure:
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:
try {
const diagram = await client.generateDiagram(prompt);
} catch (error) {
console.error('API Error:', error.message);
// Handle the error appropriately
}How It Works
The CubeGen AI SDK communicates with our backend service which leverages advanced AI models (including Gemini, GPT, and others) to generate architecture diagrams from natural language descriptions. The backend handles the complex process of:
- Interpreting architectural descriptions
- Generating appropriate visual representations
- Creating node-link diagrams with proper layouts
- Providing structured JSON data that can be rendered in various formats
Prerequisites
- A CubeGen AI Pro or Business subscription to generate API keys
- Node.js version 12 or higher
Support
Need help? Visit our documentation or contact support.
License
MIT
