"""Diagram templates for quick-start examples."""
# Templates organized by format, then by category
PLANTUML_TEMPLATES = {
'class': {
'Basic Class Diagram': {
'description': 'Simple class with attributes and methods',
'code': '''@startuml
title Basic Class Diagram
class User {
+id: int
+name: String
+email: String
--
+login()
+logout()
}
class Order {
+id: int
+date: Date
+total: float
--
+addItem(item)
+removeItem(item)
+calculateTotal(): float
}
User "1" --> "*" Order : places
@enduml'''
},
'Inheritance Example': {
'description': 'Class hierarchy with inheritance and interfaces',
'code': '''@startuml
title Inheritance and Interfaces
interface Drawable {
+draw()
+resize(scale)
}
abstract class Shape {
#x: int
#y: int
+move(dx, dy)
{abstract} +area(): float
}
class Circle {
-radius: float
+area(): float
+draw()
}
class Rectangle {
-width: float
-height: float
+area(): float
+draw()
}
Drawable <|.. Shape
Shape <|-- Circle
Shape <|-- Rectangle
@enduml'''
},
},
'sequence': {
'Basic Sequence': {
'description': 'Simple request-response flow',
'code': '''@startuml
title Basic API Request Flow
actor User
participant "Web App" as App
participant "API Server" as API
database "Database" as DB
User -> App: Click Login
activate App
App -> API: POST /auth/login
activate API
API -> DB: SELECT user
activate DB
DB --> API: user data
deactivate DB
API --> App: JWT token
deactivate API
App --> User: Show dashboard
deactivate App
@enduml'''
},
'Authentication Flow': {
'description': 'OAuth2 authentication sequence',
'code': '''@startuml
title OAuth2 Authentication Flow
actor User
participant "Client App" as Client
participant "Auth Server" as Auth
participant "Resource Server" as Resource
User -> Client: Login request
Client -> Auth: Authorization request
Auth -> User: Login page
User -> Auth: Credentials
Auth -> Auth: Validate credentials
alt successful login
Auth --> Client: Authorization code
Client -> Auth: Exchange code for token
Auth --> Client: Access token + Refresh token
Client -> Resource: API request + Access token
Resource --> Client: Protected resource
Client --> User: Display data
else invalid credentials
Auth --> Client: Error
Client --> User: Show error
end
@enduml'''
},
},
'component': {
'System Architecture': {
'description': 'High-level system components',
'code': '''@startuml
title System Architecture
package "Frontend" {
[Web Application] as Web
[Mobile App] as Mobile
}
package "Backend Services" {
[API Gateway] as Gateway
[User Service] as UserSvc
[Order Service] as OrderSvc
}
package "Data Layer" {
database "PostgreSQL" as PG
database "Redis Cache" as Redis
}
Web --> Gateway
Mobile --> Gateway
Gateway --> UserSvc
Gateway --> OrderSvc
UserSvc --> PG
OrderSvc --> PG
Gateway --> Redis
@enduml'''
},
},
'state': {
'Order State Machine': {
'description': 'Order lifecycle states',
'code': '''@startuml
title Order State Machine
[*] --> Draft : create order
Draft --> Pending : submit
Draft --> Cancelled : cancel
Pending --> Confirmed : payment received
Pending --> Cancelled : payment failed
Confirmed --> Processing : begin fulfillment
Processing --> Shipped : dispatch
Shipped --> Delivered : delivery confirmed
Delivered --> [*]
Cancelled --> [*]
@enduml'''
},
},
'activity': {
'Checkout Process': {
'description': 'E-commerce checkout flow',
'code': '''@startuml
title Checkout Process
start
:View Cart;
if (Cart empty?) then (yes)
:Show empty cart message;
stop
endif
:Enter Shipping Address;
:Select Shipping Method;
:Enter Payment Details;
:Validate Payment;
if (Payment valid?) then (yes)
:Process Payment;
:Create Order;
:Send Confirmation Email;
:Show Success Page;
else (no)
:Show Payment Error;
endif
stop
@enduml'''
},
},
'mindmap': {
'Project Planning': {
'description': 'Project breakdown structure',
'code': '''@startmindmap
title Project Planning
* Project Launch
** Planning
*** Define scope
*** Set milestones
*** Allocate resources
** Development
*** Backend
**** API endpoints
**** Database layer
*** Frontend
**** Components
**** Styling
** Testing
*** Unit tests
*** Integration tests
** Deployment
*** CI/CD setup
*** Production release
@endmindmap'''
},
},
}
MERMAID_TEMPLATES = {
'flowchart': {
'Basic Flowchart': {
'description': 'Simple decision flowchart',
'code': '''flowchart TD
A[Start] --> B{Is it working?}
B -->|Yes| C[Great!]
B -->|No| D[Debug]
D --> B
C --> E[End]'''
},
'Process Flow': {
'description': 'Business process with multiple paths',
'code': '''flowchart LR
subgraph Input
A[User Request] --> B[Validate]
end
subgraph Processing
B --> C{Valid?}
C -->|Yes| D[Process]
C -->|No| E[Return Error]
D --> F[Store Result]
end
subgraph Output
F --> G[Send Response]
E --> G
end'''
},
'Top-Down Flow': {
'description': 'Vertical flowchart with conditions',
'code': '''flowchart TB
Start([Start]) --> Input[/Get Input/]
Input --> Validate{Valid Input?}
Validate -->|Yes| Process[Process Data]
Validate -->|No| Error[Show Error]
Error --> Input
Process --> Save[(Save to DB)]
Save --> Output[/Display Result/]
Output --> End([End])'''
},
},
'sequence': {
'Basic Sequence': {
'description': 'Simple API request flow',
'code': '''sequenceDiagram
actor User
participant App as Web App
participant API as API Server
participant DB as Database
User->>App: Click Login
activate App
App->>API: POST /auth/login
activate API
API->>DB: Query user
DB-->>API: User data
API-->>App: JWT Token
deactivate API
App-->>User: Show Dashboard
deactivate App'''
},
'Async Messaging': {
'description': 'Asynchronous message flow with loops',
'code': '''sequenceDiagram
participant Client
participant Server
participant Queue
participant Worker
Client->>+Server: Submit Job
Server->>Queue: Enqueue Job
Server-->>-Client: Job ID
loop Process Queue
Worker->>Queue: Poll for jobs
Queue-->>Worker: Job data
Worker->>Worker: Process
Worker->>Queue: Mark complete
end
Client->>Server: Check Status
Server-->>Client: Job Complete'''
},
},
'class': {
'Basic Class Diagram': {
'description': 'Classes with relationships',
'code': '''classDiagram
class Animal {
+String name
+int age
+makeSound()
}
class Dog {
+String breed
+bark()
+fetch()
}
class Cat {
+bool indoor
+meow()
+scratch()
}
Animal <|-- Dog
Animal <|-- Cat'''
},
'E-commerce Model': {
'description': 'Domain model with associations',
'code': '''classDiagram
class Customer {
+String id
+String name
+String email
+placeOrder()
}
class Order {
+String id
+Date date
+String status
+calculateTotal()
}
class Product {
+String id
+String name
+float price
}
class OrderItem {
+int quantity
+float unitPrice
}
Customer "1" --> "*" Order : places
Order "1" *-- "*" OrderItem : contains
OrderItem "*" --> "1" Product : references'''
},
},
'state': {
'Order States': {
'description': 'Order lifecycle state machine',
'code': '''stateDiagram-v2
[*] --> Draft
Draft --> Pending: submit
Draft --> Cancelled: cancel
Pending --> Confirmed: payment
Pending --> Cancelled: timeout
Confirmed --> Shipped: dispatch
Shipped --> Delivered: arrive
Delivered --> [*]
Cancelled --> [*]'''
},
'Traffic Light': {
'description': 'Simple state transitions',
'code': '''stateDiagram-v2
[*] --> Red
Red --> Green: timer
Green --> Yellow: timer
Yellow --> Red: timer
state Red {
[*] --> Waiting
Waiting --> Pedestrian: button
Pedestrian --> Waiting: timer
}'''
},
},
'er': {
'Blog Database': {
'description': 'Blog entity relationships',
'code': '''erDiagram
USER ||--o{ POST : writes
USER ||--o{ COMMENT : writes
POST ||--o{ COMMENT : has
POST }o--o{ TAG : has
USER {
uuid id PK
string username
string email
string password_hash
}
POST {
uuid id PK
uuid author_id FK
string title
text content
datetime published_at
}
COMMENT {
uuid id PK
uuid post_id FK
uuid user_id FK
text content
}
TAG {
uuid id PK
string name
}'''
},
},
'pie': {
'Simple Pie Chart': {
'description': 'Distribution pie chart',
'code': '''pie title Project Time Distribution
"Development" : 45
"Testing" : 25
"Documentation" : 15
"Meetings" : 15'''
},
},
'gantt': {
'Project Timeline': {
'description': 'Project schedule with dependencies',
'code': '''gantt
title Project Timeline
dateFormat YYYY-MM-DD
section Planning
Requirements :a1, 2024-01-01, 7d
Design :a2, after a1, 14d
section Development
Backend API :b1, after a2, 21d
Frontend UI :b2, after a2, 21d
Integration :b3, after b1, 7d
section Testing
QA Testing :c1, after b3, 14d
Bug Fixes :c2, after c1, 7d
section Deployment
Release :d1, after c2, 3d'''
},
},
}
OPENSCAD_TEMPLATES = {
'primitives': {
'Basic Shapes': {
'description': 'Cube, sphere, and cylinder primitives',
'code': '''// Basic 3D Primitives
$fn = 32; // Smoothness
// Cube
translate([-30, 0, 0])
cube([15, 15, 15], center=true);
// Sphere
sphere(r=10);
// Cylinder
translate([30, 0, 0])
cylinder(h=20, r=8, center=true);'''
},
'2D Shapes': {
'description': 'Circle, square, and polygon',
'code': '''// 2D Shapes (for extrusion)
$fn = 32;
// Circle
translate([-30, 0, 0])
circle(r=10);
// Square
square([15, 15], center=true);
// Polygon
translate([30, 0, 0])
polygon(points=[
[0, 15],
[-13, -7.5],
[13, -7.5]
]);'''
},
},
'operations': {
'Boolean Operations': {
'description': 'Union, difference, and intersection',
'code': '''// Boolean Operations Demo
$fn = 32;
// Difference: cube with spherical hole
translate([-35, 0, 0])
difference() {
cube([20, 20, 20], center=true);
sphere(r=12);
}
// Union: combined shapes
union() {
cube([15, 15, 15], center=true);
sphere(r=10);
}
// Intersection: overlapping volume
translate([35, 0, 0])
intersection() {
cube([20, 20, 20], center=true);
sphere(r=14);
}'''
},
'Extrusions': {
'description': 'Linear and rotational extrusion',
'code': '''// Extrusion Examples
$fn = 32;
// Linear extrude a shape
translate([-25, 0, 0])
linear_extrude(height=20, twist=45)
square([10, 10], center=true);
// Rotate extrude (lathe)
translate([25, 0, 0])
rotate_extrude()
translate([10, 0, 0])
circle(r=5);'''
},
},
'transforms': {
'Transformations': {
'description': 'Translate, rotate, and scale',
'code': '''// Transformation Examples
$fn = 32;
// Original
color("red")
cube([10, 10, 10], center=true);
// Translated
color("green")
translate([20, 0, 0])
cube([10, 10, 10], center=true);
// Rotated
color("blue")
translate([40, 0, 0])
rotate([45, 0, 45])
cube([10, 10, 10], center=true);
// Scaled
color("yellow")
translate([60, 0, 0])
scale([1.5, 0.5, 1])
cube([10, 10, 10], center=true);'''
},
'Mirror and Hull': {
'description': 'Mirror and convex hull operations',
'code': '''// Mirror and Hull Examples
$fn = 32;
// Mirror operation
translate([-30, 0, 0]) {
sphere(r=5);
mirror([1, 0, 0])
translate([15, 0, 0])
sphere(r=5);
}
// Hull: convex wrapper around shapes
translate([20, 0, 0])
hull() {
sphere(r=5);
translate([20, 0, 0])
sphere(r=5);
translate([10, 15, 0])
sphere(r=5);
}'''
},
},
'modules': {
'Custom Module': {
'description': 'Reusable parametric module',
'code': '''// Parametric Module Example
$fn = 32;
// Define a rounded box module
module rounded_box(size, radius) {
hull() {
for (x = [-1, 1])
for (y = [-1, 1])
for (z = [-1, 1])
translate([
x * (size[0]/2 - radius),
y * (size[1]/2 - radius),
z * (size[2]/2 - radius)
])
sphere(r=radius);
}
}
// Use the module
rounded_box([30, 20, 15], 3);
translate([40, 0, 0])
rounded_box([20, 20, 20], 5);'''
},
'Gear Module': {
'description': 'Simple parametric gear',
'code': '''// Simple Gear Module
$fn = 64;
module gear(teeth, tooth_size, thickness, hole_r) {
difference() {
union() {
// Base cylinder
cylinder(h=thickness, r=teeth*tooth_size/6.28, center=true);
// Teeth
for (i = [0:teeth-1]) {
rotate([0, 0, i * 360/teeth])
translate([teeth*tooth_size/6.28, 0, 0])
cylinder(h=thickness, r=tooth_size/2, center=true);
}
}
// Center hole
cylinder(h=thickness+1, r=hole_r, center=true);
}
}
// Create a gear
gear(teeth=12, tooth_size=5, thickness=5, hole_r=3);'''
},
},
'mechanical': {
'Enclosure Box': {
'description': 'Box with lid for electronics',
'code': '''// Electronics Enclosure
$fn = 32;
box_size = [60, 40, 25];
wall = 2;
lid_height = 8;
// Bottom part
module box_bottom() {
difference() {
cube(box_size, center=true);
translate([0, 0, wall])
cube([
box_size[0] - wall*2,
box_size[1] - wall*2,
box_size[2]
], center=true);
}
}
// Lid
module box_lid() {
translate([0, 0, box_size[2]/2 + lid_height/2 + 2])
difference() {
cube([box_size[0], box_size[1], lid_height], center=true);
translate([0, 0, -wall])
cube([
box_size[0] - wall*4,
box_size[1] - wall*4,
lid_height
], center=true);
}
}
box_bottom();
box_lid();'''
},
'Bracket': {
'description': 'L-shaped mounting bracket',
'code': '''// Mounting Bracket
$fn = 32;
thickness = 3;
width = 20;
leg1 = 30;
leg2 = 25;
hole_d = 5;
hole_margin = 8;
module bracket() {
difference() {
union() {
// Vertical leg
cube([width, thickness, leg1]);
// Horizontal leg
cube([width, leg2, thickness]);
// Fillet/gusset
translate([0, thickness, thickness])
rotate([0, 90, 0])
linear_extrude(width)
polygon([[0,0], [8,0], [0,8]]);
}
// Mounting holes
translate([width/2, -1, leg1 - hole_margin])
rotate([-90, 0, 0])
cylinder(h=thickness+2, d=hole_d);
translate([width/2, leg2 - hole_margin, -1])
cylinder(h=thickness+2, d=hole_d);
}
}
bracket();'''
},
},
}
CODE_TEMPLATES = {
'python': {
'Hello World': {
'description': 'Simple Python hello world',
'language': 'python',
'code': '''def hello_world():
"""A simple example function."""
print("Hello, World!")
if __name__ == "__main__":
hello_world()'''
},
'Class Example': {
'description': 'Python class with methods',
'language': 'python',
'code': '''class Rectangle:
"""A simple rectangle class."""
def __init__(self, width: float, height: float):
self.width = width
self.height = height
@property
def area(self) -> float:
"""Calculate the area of the rectangle."""
return self.width * self.height
@property
def perimeter(self) -> float:
"""Calculate the perimeter of the rectangle."""
return 2 * (self.width + self.height)
def __repr__(self) -> str:
return f"Rectangle({self.width}, {self.height})"
# Example usage
rect = Rectangle(10, 5)
print(f"Area: {rect.area}")
print(f"Perimeter: {rect.perimeter}")'''
},
'FastAPI Endpoint': {
'description': 'FastAPI route handler example',
'language': 'python',
'code': '''from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import List, Optional
app = FastAPI()
class Item(BaseModel):
id: int
name: str
description: Optional[str] = None
price: float
items_db: List[Item] = []
@app.get("/items", response_model=List[Item])
async def get_items():
"""Get all items."""
return items_db
@app.get("/items/{item_id}", response_model=Item)
async def get_item(item_id: int):
"""Get a specific item by ID."""
for item in items_db:
if item.id == item_id:
return item
raise HTTPException(status_code=404, detail="Item not found")
@app.post("/items", response_model=Item)
async def create_item(item: Item):
"""Create a new item."""
items_db.append(item)
return item'''
},
},
'javascript': {
'Hello World': {
'description': 'Simple JavaScript hello world',
'language': 'javascript',
'code': '''// Hello World in JavaScript
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet("World"));'''
},
'Async/Await Example': {
'description': 'Async function with fetch',
'language': 'javascript',
'code': '''// Async/Await API fetch example
async function fetchUserData(userId) {
try {
const response = await fetch(`https://api.example.com/users/${userId}`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const userData = await response.json();
return userData;
} catch (error) {
console.error("Failed to fetch user data:", error);
throw error;
}
}
// Usage
async function main() {
const user = await fetchUserData(123);
console.log("User:", user);
}
main();'''
},
'React Component': {
'description': 'React functional component with hooks',
'language': 'jsx',
'code': '''import React, { useState, useEffect } from 'react';
function Counter({ initialValue = 0 }) {
const [count, setCount] = useState(initialValue);
useEffect(() => {
document.title = `Count: ${count}`;
}, [count]);
const increment = () => setCount(c => c + 1);
const decrement = () => setCount(c => c - 1);
const reset = () => setCount(initialValue);
return (
);
}
export default Counter;'''
},
},
'rust': {
'Hello World': {
'description': 'Simple Rust hello world',
'language': 'rust',
'code': '''fn main() {
println!("Hello, World!");
}'''
},
'Struct Example': {
'description': 'Rust struct with implementation',
'language': 'rust',
'code': '''use std::fmt;
#[derive(Debug)]
struct Rectangle {
width: f64,
height: f64,
}
impl Rectangle {
fn new(width: f64, height: f64) -> Self {
Rectangle { width, height }
}
fn area(&self) -> f64 {
self.width * self.height
}
fn perimeter(&self) -> f64 {
2.0 * (self.width + self.height)
}
fn is_square(&self) -> bool {
(self.width - self.height).abs() < f64::EPSILON
}
}
impl fmt::Display for Rectangle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Rectangle({}x{})", self.width, self.height)
}
}
fn main() {
let rect = Rectangle::new(10.0, 5.0);
println!("{}", rect);
println!("Area: {}", rect.area());
println!("Perimeter: {}", rect.perimeter());
println!("Is square: {}", rect.is_square());
}'''
},
},
'go': {
'Hello World': {
'description': 'Simple Go hello world',
'language': 'go',
'code': '''package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}'''
},
'HTTP Server': {
'description': 'Simple Go HTTP server',
'language': 'go',
'code': '''package main
import (
"encoding/json"
"log"
"net/http"
)
type Response struct {
Message string `json:"message"`
Status int `json:"status"`
}
func helloHandler(w http.ResponseWriter, r *http.Request) {
response := Response{
Message: "Hello, World!",
Status: 200,
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}
func main() {
http.HandleFunc("/", helloHandler)
log.Println("Server starting on :8080...")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
}'''
},
},
'sql': {
'Create Table': {
'description': 'SQL table creation with constraints',
'language': 'sql',
'code': '''-- Create users table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create orders table with foreign key
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id),
total_amount DECIMAL(10, 2) NOT NULL,
status VARCHAR(20) DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create index for faster lookups
CREATE INDEX idx_orders_user_id ON orders(user_id);
CREATE INDEX idx_orders_status ON orders(status);'''
},
'Common Queries': {
'description': 'Common SQL query patterns',
'language': 'sql',
'code': '''-- Select with join
SELECT
u.username,
u.email,
COUNT(o.id) as order_count,
COALESCE(SUM(o.total_amount), 0) as total_spent
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
GROUP BY u.id, u.username, u.email
ORDER BY total_spent DESC;
-- Subquery example
SELECT * FROM users
WHERE id IN (
SELECT DISTINCT user_id
FROM orders
WHERE total_amount > 100
);
-- Window function
SELECT
username,
total_amount,
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC) as order_rank
FROM users u
JOIN orders o ON u.id = o.user_id;'''
},
},
'bash': {
'Script Template': {
'description': 'Bash script with common patterns',
'language': 'bash',
'code': '''#!/bin/bash
# Script description
# Usage: ./script.sh [options]
set -euo pipefail # Exit on error, undefined vars, pipe failures
# Constants
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly LOG_FILE="/tmp/script.log"
# Functions
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
}
die() {
log "ERROR: $*"
exit 1
}
usage() {
cat <
My Page
Hello, World!
This is a basic HTML5 template.
'''
},
},
}
# SVG Templates for wireframes and diagrams
SVG_TEMPLATES = {
'wireframes': {
'Login Page': {
'description': 'Simple login form wireframe',
'code': '''
'''
},
'Dashboard Layout': {
'description': 'Dashboard with sidebar and cards',
'code': '''
'''
},
'Mobile App Screen': {
'description': 'Mobile app layout wireframe',
'code': '''
'''
},
},
'diagrams': {
'Simple Flowchart': {
'description': 'Basic flowchart with shapes and arrows',
'code': '''
'''
},
'System Architecture': {
'description': 'Simple system architecture diagram',
'code': '''
'''
},
},
'basic': {
'Shapes Gallery': {
'description': 'Common SVG shapes reference',
'code': '''
'''
},
},
}
# Excalidraw Templates (JSON format)
EXCALIDRAW_TEMPLATES = {
'diagrams': {
'Simple Flowchart': {
'description': 'Hand-drawn flowchart with shapes and arrows',
'code': '''{
"type": "excalidraw",
"version": 2,
"elements": [
{"type": "rectangle", "id": "start", "x": 200, "y": 20, "width": 120, "height": 50, "strokeColor": "#087f5b", "backgroundColor": "#c3fae8", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "start-txt", "x": 230, "y": 35, "width": 60, "height": 25, "text": "Start", "fontSize": 20, "strokeColor": "#087f5b"},
{"type": "arrow", "id": "a1", "x": 260, "y": 70, "width": 0, "height": 40, "points": [[0, 0], [0, 40]], "strokeColor": "#495057"},
{"type": "rectangle", "id": "proc1", "x": 180, "y": 120, "width": 160, "height": 60, "strokeColor": "#1864ab", "backgroundColor": "#d0ebff", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "proc1-txt", "x": 200, "y": 140, "width": 120, "height": 25, "text": "Process", "fontSize": 20, "strokeColor": "#1864ab"},
{"type": "arrow", "id": "a2", "x": 260, "y": 180, "width": 0, "height": 40, "points": [[0, 0], [0, 40]], "strokeColor": "#495057"},
{"type": "diamond", "id": "decision", "x": 185, "y": 230, "width": 150, "height": 100, "strokeColor": "#e67700", "backgroundColor": "#fff3bf", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "dec-txt", "x": 225, "y": 270, "width": 70, "height": 25, "text": "Valid?", "fontSize": 18, "strokeColor": "#e67700"},
{"type": "arrow", "id": "a3-yes", "x": 335, "y": 280, "width": 80, "height": 0, "points": [[0, 0], [80, 0]], "strokeColor": "#2b8a3e"},
{"type": "text", "id": "yes-lbl", "x": 355, "y": 260, "width": 40, "height": 20, "text": "Yes", "fontSize": 14, "strokeColor": "#2b8a3e"},
{"type": "rectangle", "id": "success", "x": 420, "y": 255, "width": 100, "height": 50, "strokeColor": "#2b8a3e", "backgroundColor": "#d3f9d8", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "succ-txt", "x": 445, "y": 270, "width": 50, "height": 25, "text": "Done", "fontSize": 18, "strokeColor": "#2b8a3e"},
{"type": "arrow", "id": "a3-no", "x": 185, "y": 280, "width": -80, "height": 0, "points": [[0, 0], [-80, 0]], "strokeColor": "#c92a2a"},
{"type": "text", "id": "no-lbl", "x": 130, "y": 260, "width": 40, "height": 20, "text": "No", "fontSize": 14, "strokeColor": "#c92a2a"},
{"type": "rectangle", "id": "error", "x": 0, "y": 255, "width": 100, "height": 50, "strokeColor": "#c92a2a", "backgroundColor": "#ffe3e3", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "err-txt", "x": 25, "y": 270, "width": 50, "height": 25, "text": "Error", "fontSize": 18, "strokeColor": "#c92a2a"}
],
"appState": {"viewBackgroundColor": "#ffffff"}
}'''
},
'Mind Map': {
'description': 'Simple mind map with central topic',
'code': '''{
"type": "excalidraw",
"version": 2,
"elements": [
{"type": "ellipse", "id": "center", "x": 300, "y": 200, "width": 160, "height": 80, "strokeColor": "#1864ab", "backgroundColor": "#d0ebff", "fillStyle": "solid", "roughness": 1, "strokeWidth": 2},
{"type": "text", "id": "center-txt", "x": 335, "y": 230, "width": 90, "height": 30, "text": "Main Topic", "fontSize": 20, "strokeColor": "#1864ab"},
{"type": "line", "id": "l1", "x": 380, "y": 200, "width": 100, "height": -80, "points": [[0, 0], [100, -80]], "strokeColor": "#495057"},
{"type": "rectangle", "id": "t1", "x": 480, "y": 80, "width": 120, "height": 50, "strokeColor": "#087f5b", "backgroundColor": "#c3fae8", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "t1-txt", "x": 505, "y": 95, "width": 70, "height": 25, "text": "Topic 1", "fontSize": 16, "strokeColor": "#087f5b"},
{"type": "line", "id": "l2", "x": 460, "y": 240, "width": 80, "height": 0, "points": [[0, 0], [80, 0]], "strokeColor": "#495057"},
{"type": "rectangle", "id": "t2", "x": 540, "y": 215, "width": 120, "height": 50, "strokeColor": "#e67700", "backgroundColor": "#fff3bf", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "t2-txt", "x": 565, "y": 230, "width": 70, "height": 25, "text": "Topic 2", "fontSize": 16, "strokeColor": "#e67700"},
{"type": "line", "id": "l3", "x": 380, "y": 280, "width": 100, "height": 80, "points": [[0, 0], [100, 80]], "strokeColor": "#495057"},
{"type": "rectangle", "id": "t3", "x": 480, "y": 350, "width": 120, "height": 50, "strokeColor": "#862e9c", "backgroundColor": "#f3d9fa", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "t3-txt", "x": 505, "y": 365, "width": 70, "height": 25, "text": "Topic 3", "fontSize": 16, "strokeColor": "#862e9c"},
{"type": "line", "id": "l4", "x": 300, "y": 240, "width": -80, "height": 60, "points": [[0, 0], [-80, 60]], "strokeColor": "#495057"},
{"type": "rectangle", "id": "t4", "x": 100, "y": 290, "width": 120, "height": 50, "strokeColor": "#c92a2a", "backgroundColor": "#ffe3e3", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "t4-txt", "x": 125, "y": 305, "width": 70, "height": 25, "text": "Topic 4", "fontSize": 16, "strokeColor": "#c92a2a"}
],
"appState": {"viewBackgroundColor": "#ffffff"}
}'''
},
},
'wireframes': {
'Login Sketch': {
'description': 'Hand-drawn login form sketch',
'code': '''{
"type": "excalidraw",
"version": 2,
"elements": [
{"type": "rectangle", "id": "card", "x": 100, "y": 50, "width": 280, "height": 350, "strokeColor": "#495057", "backgroundColor": "#f8f9fa", "fillStyle": "solid", "roughness": 1, "strokeWidth": 2},
{"type": "ellipse", "id": "logo", "x": 200, "y": 80, "width": 80, "height": 80, "strokeColor": "#1864ab", "backgroundColor": "#d0ebff", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "logo-txt", "x": 220, "y": 110, "width": 40, "height": 25, "text": "Logo", "fontSize": 14, "strokeColor": "#1864ab"},
{"type": "text", "id": "title", "x": 175, "y": 180, "width": 130, "height": 30, "text": "Welcome Back", "fontSize": 20, "strokeColor": "#212529"},
{"type": "rectangle", "id": "email", "x": 130, "y": 220, "width": 220, "height": 40, "strokeColor": "#adb5bd", "backgroundColor": "#ffffff", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "email-txt", "x": 145, "y": 233, "width": 50, "height": 20, "text": "Email...", "fontSize": 14, "strokeColor": "#adb5bd"},
{"type": "rectangle", "id": "pass", "x": 130, "y": 275, "width": 220, "height": 40, "strokeColor": "#adb5bd", "backgroundColor": "#ffffff", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "pass-txt", "x": 145, "y": 288, "width": 70, "height": 20, "text": "Password...", "fontSize": 14, "strokeColor": "#adb5bd"},
{"type": "rectangle", "id": "btn", "x": 130, "y": 335, "width": 220, "height": 45, "strokeColor": "#1864ab", "backgroundColor": "#339af0", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "btn-txt", "x": 200, "y": 350, "width": 80, "height": 20, "text": "Sign In", "fontSize": 16, "strokeColor": "#ffffff"}
],
"appState": {"viewBackgroundColor": "#ffffff"}
}'''
},
'Mobile Screen': {
'description': 'Hand-drawn mobile app screen',
'code': '''{
"type": "excalidraw",
"version": 2,
"elements": [
{"type": "rectangle", "id": "phone", "x": 100, "y": 20, "width": 240, "height": 480, "strokeColor": "#212529", "backgroundColor": "#f8f9fa", "fillStyle": "solid", "roughness": 1, "strokeWidth": 3},
{"type": "rectangle", "id": "statusbar", "x": 100, "y": 20, "width": 240, "height": 30, "strokeColor": "#212529", "backgroundColor": "#e9ecef", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "time", "x": 195, "y": 30, "width": 50, "height": 20, "text": "9:41", "fontSize": 14, "strokeColor": "#212529"},
{"type": "rectangle", "id": "header", "x": 100, "y": 50, "width": 240, "height": 50, "strokeColor": "#1864ab", "backgroundColor": "#339af0", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "header-txt", "x": 180, "y": 68, "width": 80, "height": 20, "text": "My App", "fontSize": 18, "strokeColor": "#ffffff"},
{"type": "rectangle", "id": "card1", "x": 115, "y": 115, "width": 210, "height": 80, "strokeColor": "#adb5bd", "backgroundColor": "#ffffff", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "card1-txt", "x": 130, "y": 140, "width": 100, "height": 20, "text": "Item 1", "fontSize": 16, "strokeColor": "#212529"},
{"type": "rectangle", "id": "card2", "x": 115, "y": 210, "width": 210, "height": 80, "strokeColor": "#adb5bd", "backgroundColor": "#ffffff", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "card2-txt", "x": 130, "y": 235, "width": 100, "height": 20, "text": "Item 2", "fontSize": 16, "strokeColor": "#212529"},
{"type": "rectangle", "id": "card3", "x": 115, "y": 305, "width": 210, "height": 80, "strokeColor": "#adb5bd", "backgroundColor": "#ffffff", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "card3-txt", "x": 130, "y": 330, "width": 100, "height": 20, "text": "Item 3", "fontSize": 16, "strokeColor": "#212529"},
{"type": "rectangle", "id": "tabbar", "x": 100, "y": 450, "width": 240, "height": 50, "strokeColor": "#212529", "backgroundColor": "#ffffff", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "tab1", "x": 130, "y": 468, "width": 40, "height": 15, "text": "Home", "fontSize": 12, "strokeColor": "#1864ab"},
{"type": "text", "id": "tab2", "x": 200, "y": 468, "width": 40, "height": 15, "text": "Search", "fontSize": 12, "strokeColor": "#868e96"},
{"type": "text", "id": "tab3", "x": 275, "y": 468, "width": 40, "height": 15, "text": "Profile", "fontSize": 12, "strokeColor": "#868e96"}
],
"appState": {"viewBackgroundColor": "#ffffff"}
}'''
},
},
'basic': {
'Shapes Demo': {
'description': 'Basic shapes in Excalidraw style',
'code': '''{
"type": "excalidraw",
"version": 2,
"elements": [
{"type": "rectangle", "id": "rect", "x": 50, "y": 50, "width": 120, "height": 80, "strokeColor": "#1864ab", "backgroundColor": "#d0ebff", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "rect-lbl", "x": 75, "y": 150, "width": 70, "height": 20, "text": "Rectangle", "fontSize": 12, "strokeColor": "#495057"},
{"type": "ellipse", "id": "ellipse", "x": 220, "y": 50, "width": 100, "height": 80, "strokeColor": "#087f5b", "backgroundColor": "#c3fae8", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "ell-lbl", "x": 245, "y": 150, "width": 50, "height": 20, "text": "Ellipse", "fontSize": 12, "strokeColor": "#495057"},
{"type": "diamond", "id": "diamond", "x": 370, "y": 40, "width": 100, "height": 100, "strokeColor": "#e67700", "backgroundColor": "#fff3bf", "fillStyle": "solid", "roughness": 1},
{"type": "text", "id": "dia-lbl", "x": 390, "y": 150, "width": 60, "height": 20, "text": "Diamond", "fontSize": 12, "strokeColor": "#495057"},
{"type": "line", "id": "line", "x": 50, "y": 200, "width": 100, "height": 60, "points": [[0, 0], [100, 60]], "strokeColor": "#862e9c", "strokeWidth": 2, "roughness": 1},
{"type": "text", "id": "line-lbl", "x": 75, "y": 280, "width": 50, "height": 20, "text": "Line", "fontSize": 12, "strokeColor": "#495057"},
{"type": "arrow", "id": "arrow", "x": 220, "y": 200, "width": 100, "height": 60, "points": [[0, 0], [100, 60]], "strokeColor": "#c92a2a", "strokeWidth": 2, "roughness": 1},
{"type": "text", "id": "arr-lbl", "x": 250, "y": 280, "width": 50, "height": 20, "text": "Arrow", "fontSize": 12, "strokeColor": "#495057"},
{"type": "text", "id": "text-demo", "x": 370, "y": 220, "width": 100, "height": 40, "text": "Text\\nElement", "fontSize": 20, "strokeColor": "#212529"},
{"type": "text", "id": "txt-lbl", "x": 395, "y": 280, "width": 50, "height": 20, "text": "Text", "fontSize": 12, "strokeColor": "#495057"}
],
"appState": {"viewBackgroundColor": "#ffffff"}
}'''
},
},
}
# Combined templates dict for backwards compatibility
TEMPLATES = PLANTUML_TEMPLATES
def get_template_categories(format_type: str = 'plantuml') -> list:
"""Get list of template categories for a format."""
templates = get_templates_for_format(format_type)
return list(templates.keys())
def get_templates_for_format(format_type: str) -> dict:
"""Get all templates for a format type."""
format_map = {
'plantuml': PLANTUML_TEMPLATES,
'mermaid': MERMAID_TEMPLATES,
'openscad': OPENSCAD_TEMPLATES,
'code': CODE_TEMPLATES,
'svg': SVG_TEMPLATES,
'excalidraw': EXCALIDRAW_TEMPLATES,
}
return format_map.get(format_type, PLANTUML_TEMPLATES)
def get_templates_for_category(category: str, format_type: str = 'plantuml') -> dict:
"""Get all templates for a diagram type category."""
templates = get_templates_for_format(format_type)
return templates.get(category, {})
def get_template(category: str, name: str, format_type: str = 'plantuml') -> dict:
"""Get a specific template by category and name."""
templates = get_templates_for_format(format_type)
return templates.get(category, {}).get(name, {})
def get_all_templates(format_type: str = 'plantuml') -> list:
"""Get all templates as a flat list with category info."""
result = []
templates = get_templates_for_format(format_type)
for category, category_templates in templates.items():
for name, template in category_templates.items():
result.append({
'category': category,
'name': name,
'description': template.get('description', ''),
'code': template.get('code', ''),
})
return result