<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Terraph documentation Generator</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,300;0,400;0,600;1,400&family=Lato:wght@300;400&display=swap" rel="stylesheet">
<!-- GSAP Animation -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<!-- Three.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
<!-- Icons (Phosphor - soft style) -->
<script src="https://unpkg.com/@phosphor-icons/web"></script>
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
serif: ['"Crimson Pro"', 'serif'],
sans: ['"Lato"', 'sans-serif'],
},
colors: {
earth: {
50: '#F9F7F2',
100: '#F0ECE6',
200: '#E2DCD3',
300: '#CFC5B4',
400: '#B8A68B',
500: '#A18C6A',
600: '#8E7354',
700: '#6F5B46',
800: '#524936',
900: '#3B3127',
},
sage: {
50: '#F2F7F2',
100: '#DDE5D8',
200: '#BBC7B0',
300: '#9AA985',
400: '#7E8B6A',
500: '#667151',
600: '#546045',
},
clay: {
50: '#FDF6EF',
100: '#FAEBD8',
200: '#F5DCC2',
300: '#EEC5AB',
400: '#E6A892',
500: '#DC8B79',
600: '#D06C5D',
}
},
animation: {
'float': 'float 6s ease-in-out infinite',
},
keyframes: {
float: {
'0%, 100%': { transform: 'translateY(0)' },
'50%': { transform: 'translateY(-10px)' },
}
}
}
}
}
</script>
<style>
/* Core Biophilic Settings */
:root {
--color-bg: #F9F7F2;
--color-stone: #E2DCD3;
--color-ink: #3B3127;
--color-sage: #9AA985;
--color-clay: #F5DCC2;
--color-highlight: #DC6C5D; /* Soft Sienna */
}
body {
background-color: var(--color-bg);
color: var(--color-ink);
font-family: 'Crimson Pro', serif;
overflow: hidden;
cursor: default;
}
/* Paper Grain Texture Overlay */
.grain-overlay {
position: fixed;
top: 0; left: 0; width: 100%; height: 100%;
pointer-events: none;
z-index: 50;
opacity: 0.08;
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.4'/%3E%3C/svg%3E");
}
/* UI Glass Style - Frosted Paper */
.glass-panel {
background: rgba(249, 247, 242, 0.65);
backdrop-filter: blur(12px) saturate(120%);
-webkit-backdrop-filter: blur(12px) saturate(120%);
border: 1px solid rgba(255, 255, 255, 0.8);
box-shadow:
0 4px 6px -1px rgba(60, 50, 40, 0.05),
0 2px 4px -1px rgba(60, 50, 40, 0.03),
inset 0 0 0 1px rgba(255,255,255,0.5);
}
/* Organic Radius */
.blob {
border-radius: 47% 53% 61% 39% / 61% 39% 61% 39%;
transition: border-radius 0.8s ease-out;
}
.blob:hover {
border-radius: 50% 50% 40% 60% / 50% 60% 40% 50%;
}
/* Custom Scrollbar for YAML */
.custom-scroll::-webkit-scrollbar {
width: 8px;
}
.custom-scroll::-webkit-scrollbar-track {
background: transparent;
}
.custom-scroll::-webkit-scrollbar-thumb {
background: var(--color-clay);
border-radius: 4px;
}
.custom-scroll::-webkit-scrollbar-thumb:hover {
background: var(--color-sage);
}
/* Typewriter cursor */
.cursor-blink::after {
content: '|';
animation: blink 1s step-start infinite;
}
@keyframes blink { 50% { opacity: 0; } }
/* Graph Canvas Container */
#graph-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
/* UI Container */
#ui-layer {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10;
pointer-events: none; /* Let clicks pass through to canvas where needed */
}
.pointer-events-auto {
pointer-events: auto;
}
/* Button Styles */
.wooden-btn {
background: linear-gradient(180deg, var(--color-clay) 0%, #E0B896 100%);
border: 1px solid rgba(255,255,255,0.6);
box-shadow: 0 4px 6px rgba(60, 50, 40, 0.1), inset 0 1px 0 rgba(255,255,255,0.4);
transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
font-family: 'Lato', sans-serif;
letter-spacing: 0.05em;
text-transform: uppercase;
font-size: 0.75rem;
padding: 0.75rem 1.5rem;
border-radius: 9999px; /* Pill shape, but organic */
}
.wooden-btn:hover {
transform: translateY(-2px) scale(1.02);
box-shadow: 0 8px 12px rgba(60, 50, 40, 0.15), inset 0 1px 0 rgba(255,255,255,0.4);
filter: brightness(1.05);
}
.wooden-btn:active {
transform: translateY(1px) scale(0.98);
}
/* Status Badge */
.status-dot {
box-shadow: 0 0 0 2px white, 0 0 0 4px var(--color-sage);
}
</style>
</head>
<body>
<!-- Noise Texture -->
<div class="grain-overlay"></div>
<!-- Three.js Background (Depth) -->
<div id="three-container" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 0;"></div>
<!-- Graph Canvas -->
<div id="graph-container">
<canvas id="main-canvas"></canvas>
</div>
<!-- UI Overlay -->
<div id="ui-layer" class="flex flex-col justify-between p-6 md:p-10">
<!-- Header -->
<header class="relative flex justify-between items-start pointer-events-auto">
<div class="glass-panel px-6 py-4 rounded-2xl max-w-md animate-float">
<div class="flex items-center gap-3 mb-2">
<i class="ph-fill ph-tree-nature text-3xl" style="color: var(--color-sage);"></i>
<div>
<h1 class="text-2xl font-bold tracking-tight bg-clip-text text-transparent bg-gradient-to-r from-[var(--color-ink)] to-[var(--color-sage)]">
Terraph Genera
</h1>
<p class="text-sm italic opacity-70">Dynamic Infrastructure Blueprint</p>
</div>
</div>
<p class="text-sm leading-relaxed text-[var(--color-ink)] opacity-80">
Parsing IaC configurations into a living dependency graph.
Real-time state diffing visualized as organic growth and transformation.
</p>
</div>
<div class="hidden md:flex flex-col items-end gap-2">
<div class="glass-panel px-4 py-2 rounded-xl flex items-center gap-2 text-sm font-sans">
<span class="w-2 h-2 rounded-full bg-sage-300 animate-pulse"></span>
System State: Stable
</div>
<div class="glass-panel px-4 py-2 rounded-xl text-sm font-sans opacity-70">
Last Parsed: <span id="timestamp" class="font-bold">Just now</span>
</div>
</div>
</header>
<!-- Dynamic Content Area (Center) -->
<main class="flex-grow flex items-center justify-center relative pointer-events-none">
<!-- Empty state / Prompt -->
<div id="prompt" class="text-center opacity-0 translate-y-4 transition-all duration-1000">
<p class="text-xl italic text-[var(--color-ink)] opacity-60">Click and drag to explore the ecosystem</p>
</div>
</main>
<!-- Footer / Controls -->
<footer class="flex flex-col md:flex-row justify-between items-end md:items-center gap-4 pointer-events-auto">
<!-- Legend -->
<div class="glass-panel px-5 py-3 rounded-xl flex gap-6 text-sm font-sans shadow-sm">
<div class="flex items-center gap-2">
<div class="w-3 h-3 rounded-full bg-sage-300"></div>
<span>Compute</span>
</div>
<div class="flex items-center gap-2">
<div class="w-3 h-3 rounded-full bg-clay-300"></div>
<span>Storage</span>
</div>
<div class="flex items-center gap-2">
<div class="w-3 h-3 rounded-full bg-earth-300"></div>
<span>Network</span>
</div>
<div class="flex items-center gap-2">
<div class="w-3 h-3 rounded-full border-2 border-[var(--color-ink)]"></div>
<span>Security</span>
</div>
</div>
<!-- Action Buttons -->
<div class="flex gap-3">
<button onclick="app.simulateDiff()" class="wooden-btn flex items-center gap-2 text-[var(--color-ink)]">
<i class="ph ph-arrows-left-right"></i> Simulate State
</button>
<button onclick="app.generateDocs()" class="wooden-btn flex items-center gap-2 bg-[var(--color-sage)] text-white">
<i class="ph ph-file-text"></i> Generate Docs
</button>
<button onclick="app.resetView()" class="wooden-btn flex items-center gap-2 opacity-60 hover:opacity-100">
<i class="ph ph-arrows-out"></i> Reset
</button>
</div>
</footer>
</div>
<!-- Manifestation Modal (Documentation) -->
<div id="docs-modal" class="fixed inset-0 bg-[var(--color-bg)] z-50 opacity-0 pointer-events-none flex items-center justify-center p-4">
<div class="glass-panel w-full max-w-4xl h-[80vh] rounded-2xl flex flex-col pointer-events-auto border-2 border-[var(--color-sage)]/20 shadow-2xl">
<div class="p-6 border-b border-[var(--color-stone)] flex justify-between items-center">
<h2 class="text-2xl font-serif font-bold text-[var(--color-ink)]">Infrastructure Blueprint</h2>
<button onclick="app.closeDocs()" class="group p-2 rounded-full hover:bg-[var(--color-clay)] transition-colors">
<i class="ph ph-x text-xl text-[var(--color-ink)] group-hover:rotate-90 transition-transform duration-500"></i>
</button>
</div>
<div class="p-0 overflow-hidden flex-grow relative">
<div id="docs-content" class="absolute inset-0 p-8 overflow-y-auto custom-scroll font-sans text-sm leading-6 text-[var(--color-ink)]">
<!-- Content Generated via JS -->
</div>
</div>
<div class="p-4 border-t border-[var(--color-stone)] text-xs text-center opacity-60 italic">
Generated dynamically by Terraph • Respect the rhythm of nature
</div>
</div>
</div>
<script>
/**
* Configuration & Constants
*/
const THEME = {
bg: '#F9F7F2',
ink: '#3B3127',
types: {
vpc: { color: '#667151', label: 'Network', icon: 'ph-globe' }, // Sage
subnet: { color: '#8E7354', label: 'Subnet', icon: 'ph-network' }, // Earth
ec2: { color: '#9AA985', label: 'Compute', icon: 'ph-cpu' }, // Sage
rds: { color: '#EEC5AB', label: 'Database', icon: 'ph-hard-drives' }, // Clay
sg: { color: '#E2DCD3', label: 'Security', icon: 'ph-shield-check' },
iam: { color: '#DC8B79', label: 'Identity', icon: 'ph-key' }
}
};
/**
* Three.js Background: Floating Matter / Pollen
*/
class Atmosphere {
constructor(containerId) {
this.container = document.getElementById(containerId);
this.scene = new THREE.Scene();
this.scene.fog = new THREE.FogExp2(THEME.bg, 0.002);
this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1000);
this.camera.position.z = 100;
this.renderer = new THREE.WebGLRenderer({ alpha: true });
this.renderer.setSize(window.innerWidth, window.innerHeight);
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
this.container.appendChild(this.renderer.domElement);
this.particles = [];
this.mouse = new THREE.Vector2(0,0);
this.init();
this.addListeners();
this.animate();
}
init() {
const geometry = new THREE.BufferGeometry();
const vertices = [];
const sizes = [];
// Create floating "dust motes"
for (let i = 0; i < 150; i++) {
const x = (Math.random() - 0.5) * 400;
const y = (Math.random() - 0.5) * 200;
const z = (Math.random() - 0.5) * 200;
vertices.push(x, y, z);
sizes.push(Math.random() * 2 + 0.5);
}
geometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
geometry.setAttribute('size', new THREE.Float32BufferAttribute(sizes, 1));
const material = new THREE.PointsMaterial({
color: 0x9AA985, // Sage
size: 1.5,
transparent: true,
opacity: 0.4,
sizeAttenuation: true
});
this.pointCloud = new THREE.Points(geometry, material);
this.scene.add(this.pointCloud);
}
addListeners() {
window.addEventListener('resize', () => {
this.camera.aspect = window.innerWidth / window.innerHeight;
this.camera.updateProjectionMatrix();
this.renderer.setSize(window.innerWidth, window.innerHeight);
});
window.addEventListener('mousemove', (e) => {
this.mouse.x = (e.clientX / window.innerWidth) * 2 - 1;
this.mouse.y = -(e.clientY / window.innerHeight) * 2 + 1;
});
}
animate() {
requestAnimationFrame(this.animate.bind(this));
const positions = this.pointCloud.geometry.attributes.position.array;
const time = Date.now() * 0.0005;
for (let i = 0; i < positions.length; i += 3) {
// Gentle floating
positions[i] += Math.sin(time + positions[i+1]) * 0.05;
positions[i+1] += Math.cos(time + positions[i]) * 0.05;
positions[i+2] += Math.sin(time) * 0.05;
}
this.pointCloud.geometry.attributes.position.needsUpdate = true;
// Camera follows mouse slightly
this.camera.position.x += (this.mouse.x * 20 - this.camera.position.x) * 0.02;
this.camera.position.y += (this.mouse.y * 10 - this.camera.position.y) * 0.02;
this.camera.lookAt(this.scene.position);
this.renderer.render(this.scene, this.camera);
}
}
/**
* Graph System: Canvas, Nodes, Links (Organic Look)
*/
class Node {
constructor(id, type, x, y) {
this.id = id;
this.type = type;
this.x = x;
this.y = y;
this.vx = 0;
this.vy = 0;
this.radius = 25 + Math.random() * 5;
this.blobOffset = Math.random() * 100;
this.state = 'stable'; // stable, added, modified, deleting
this.pulse = 0;
this.color = THEME.types[type].color;
}
getBlobRadius(t) {
// Organic pulsation
const base = this.radius + Math.sin(t * 2 + this.blobOffset) * 2;
return Math.max(10, base);
}
}
class Graph {
constructor(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext('2d');
this.nodes = [];
this.links = []; // { source: Node, target: Node }
this.width = window.innerWidth;
this.height = window.innerHeight;
this.draggingNode = null;
this.hoverNode = null;
this.selectedNode = null;
this.resize();
window.addEventListener('resize', () => this.resize());
// Mouse Events
this.canvas.addEventListener('mousedown', this.onMouseDown.bind(this));
this.canvas.addEventListener('mousemove', this.onMouseMove.bind(this));
window.addEventListener('mouseup', this.onMouseUp.bind(this));
}
resize() {
this.width = window.innerWidth;
this.height = window.innerHeight;
this.canvas.width = this.width;
this.canvas.height = this.height;
}
// Load data structure simulating parsed IaC
loadData(data) {
this.nodes = data.nodes.map(n => new Node(n.id, n.type, n.x, n.y));
this.links = data.links.map(l => ({
source: this.nodes.find(n => n.id === l.source),
target: this.nodes.find(n => n.id === l.target)
})).filter(l => l.source && l.target);
}
// Simulate the generation process with staggered animation
async generate() {
this.ctx.clearRect(0,0,this.width,this.height);
this.nodes.forEach(n => {
n.x = this.width/2;
n.y = this.height/2;
n.radius = 0; // Start tiny
});
// Animate nodes expanding out from center
gsap.to(this.nodes, {
duration: 1.5,
radius: (i) => 25 + Math.random() * 5,
ease: "back.out(1.7)",
stagger: 0.1
});
// Spread to positions
await new Promise(resolve => {
gsap.to(this.nodes, {
x: (n, i) => this.nodesPos[i].x,
y: (n, i) => this.nodesPos[i].y,
duration: 2.5,
ease: "power3.out",
stagger: 0.05,
onComplete: resolve
});
});
this.animate();
}
animate() {
this.update();
this.draw();
requestAnimationFrame(this.animate.bind(this));
}
update() {
// Simple force-directed repulsion/attraction to keep organically spaced
const damping = 0.9;
const repulsion = 2000;
const stiffness = 0.05;
const centerPull = 0.005;
// Repulsion
for(let i=0; i<this.nodes.length; i++) {
let a = this.nodes[i];
for(let j=i+1; j<this.nodes.length; j++) {
let b = this.nodes[j];
let dx = a.x - b.x;
let dy = a.y - b.y;
let dist = Math.sqrt(dx*dx + dy*dy) || 1;
if (dist < 200) {
let f = repulsion / (dist*dist);
let fx = (dx/dist) * f;
let fy = (dy/dist) * f;
if (!a.isDragging) { a.vx += fx; a.vy += fy; }
if (!b.isDragging) { b.vx -= fx; b.vy -= fy; }
}
}
}
// Link attraction (spring)
this.links.forEach(link => {
let dx = link.target.x - link.source.x;
let dy = link.target.y - link.source.y;
let dist = Math.sqrt(dx*dx + dy*dy) || 1;
let targetDist = 150; // Rest length
let f = (dist - targetDist) * stiffness;
let fx = (dx/dist) * f;
let fy = (dy/dist) * f;
if (!link.source.isDragging) { link.source.vx += fx; link.source.vy += fy; }
if (!link.target.isDragging) { link.target.vx -= fx; link.target.vy -= fy; }
});
// Center gravity
this.nodes.forEach(n => {
if (!n.isDragging) {
n.vx -= (n.x - this.width/2) * centerPull;
n.vy -= (n.y - this.height/2) * centerPull;
n.vx *= damping;
n.vy *= damping;
n.x += n.vx;
n.y += n.vy;
}
});
}
draw() {
this.ctx.clearRect(0,0,this.width,this.height);
const time = Date.now() * 0.002;
// Draw Links (Organic Roots)
this.links.forEach(link => {
this.ctx.beginPath();
// Cubic bezier for smooth curves
const sx = link.source.x;
const sy = link.source.y;
const tx = link.target.x;
const ty = link.target.y;
// Control points create a subtle "bowing"
const cx1 = sx + (tx - sx) * 0.5 + (Math.random() - 0.5) * 10;
const cy1 = sy + (ty - sy) * 0.5 + (Math.random() - 0.5) * 10;
this.ctx.moveTo(sx, sy);
this.ctx.quadraticCurveTo(cx1, cy1, tx, ty);
this.ctx.strokeStyle = THEME.earth[300];
this.ctx.lineWidth = link.source.state === 'modified' ? 3 : 1.5;
this.ctx.lineCap = 'round';
this.ctx.stroke();
// Animated flow dots on link if modified
if (link.source.state === 'modified') {
const progress = (Math.sin(time * 2) + 1) / 2;
const px = sx + (tx - sx) * progress;
const py = sy + (ty - sy) * progress;
this.ctx.fillStyle = THEME.clay[500];
this.ctx.beginPath();
this.ctx.arc(px, py, 2, 0, Math.PI*2);
this.ctx.fill();
}
});
// Draw Nodes
this.nodes.forEach(node => {
const r = node.getBlobRadius(time);
this.ctx.save();
this.ctx.translate(node.x, node.y);
// Glow/Shadow for depth
this.ctx.shadowColor = "rgba(60, 49, 39, 0.15)";
this.ctx.shadowBlur = 15;
this.ctx.shadowOffsetY = 5;
// Node Body (Organic Blob)
this.ctx.fillStyle = node === this.hoverNode || node === this.selectedNode ? lightenColor(node.color, 20) : node.color;
// Draw blob manually using sin waves for outline? Just circle for canvas simplicity but with noise texture?
// We'll use a simple circle for geometry but add a texture brush or noise fill in code.
this.ctx.beginPath();
this.ctx.arc(0, 0, r, 0, Math.PI * 2);
this.ctx.fill();
// Reset shadow for inner details
this.ctx.shadowColor = "transparent";
// Texture: Draw noise on top of circle to look like paper/stone
this.drawNoise(0, 0, r);
// Type Icon (Simplified geometric shapes or letters)
this.ctx.fillStyle = node.color === THEME.bg ? THEME.ink : 'rgba(255,255,255,0.9)';
this.ctx.font = `${r}px "Crimson Pro"`;
this.ctx.textAlign = 'center';
this.ctx.textBaseline = 'middle';
const label = getInitial(node.type);
this.ctx.fillText(label, 0, 0);
// Status Indicator Ring (Added/Modified)
if (node.state === 'added') {
this.ctx.strokeStyle = THEME.sage[400];
this.ctx.lineWidth = 3;
this.ctx.beginPath();
this.ctx.arc(0, 0, r + 6 + Math.sin(time*5)*2, 0, Math.PI*2);
this.ctx.stroke();
} else if (node.state === 'modified') {
this.ctx.strokeStyle = THEME.clay[400];
this.ctx.lineWidth = 3;
this.ctx.beginPath();
this.ctx.arc(0, 0, r + 4, 0, Math.PI*2);
this.ctx.stroke();
} else if (node.connecting) {
// Connection indicator
this.ctx.strokeStyle = THEME.highlight;
this.ctx.lineWidth = 4;
this.ctx.beginPath();
this.ctx.arc(0, 0, r + 8, 0, Math.PI*2);
this.ctx.stroke();
}
this.ctx.restore();
});
}
drawNoise(x, y, radius) {
// Simulate grain by drawing random small dots inside the node
// Performance: Only do if needed, or sample a small bitmap. For demo, just a few dots.
this.ctx.save();
this.ctx.beginPath();
this.ctx.arc(x,y,radius,0,Math.PI*2);
this.ctx.clip();
this.ctx.fillStyle = "rgba(255,255,255,0.1)";
for(let i=0; i<10; i++) {
const dx = (Math.random() - 0.5) * radius * 2;
const dy = (Math.random() - 0.5) * radius * 2;
this.ctx.beginPath();
this.ctx.arc(dx, dy, 1, 0, Math.PI*2);
this.ctx.fill();
}
this.ctx.restore();
}
// Mouse Handling
getMousePos(e) {
const rect = this.canvas.getBoundingClientRect();
return {
x: e.clientX - rect.left,
y: e.clientY - rect.top
};
}
onMouseDown(e) {
const pos = this.getMousePos(e);
const node = this.findNode(pos.x, pos.y);
if (node) {
this.draggingNode = node;
node.isDragging = true;
node.vx = 0; node.vy = 0;
this.selectedNode = node;
this.showNodeDetails(node);
}
}
onMouseMove(e) {
const pos = this.getMousePos(e);
if (this.draggingNode) {
this.draggingNode.x = pos.x;
this.draggingNode.y = pos.y;
} else {
const node = this.findNode(pos.x, pos.y);
this.hoverNode = node;
this.canvas.style.cursor = node ? 'pointer' : 'default';
}
}
onMouseUp() {
if (this.draggingNode) {
this.draggingNode.isDragging = false;
this.draggingNode = null;
}
}
findNode(x, y) {
// Reverse iterate to catch top ones first
for (let i = this.nodes.length - 1; i >= 0; i--) {
const n = this.nodes[i];
const dx = x - n.x;
const dy = y - n.y;
if (dx*dx + dy*dy < n.radius * n.radius * 1.5) return n; // slightly forgiving hit
}
return null;
}
// UI Logic
showNodeDetails(node) {
const detailsPanel = document.getElementById('details-panel');
if (!detailsPanel) {
this.createDetailsPanel(node);
} else {
this.updateDetailsPanel(node);
}
}
createDetailsPanel(node) {
const panel = document.createElement('div');
panel.id = 'details-panel';
panel.className = 'fixed right-6 top-24 w-80 glass-panel p-6 rounded-2xl pointer-events-auto shadow-xl transform translate-x-[120%] duration-700 ease-[cubic-bezier(0.25,0.8,0.25,1)] z-40';
const typeConfig = THEME.types[node.type];
panel.innerHTML = `
<div class="flex justify-between items-center mb-4 border-b border-stone-200 pb-2">
<span class="text-xs uppercase font-bold tracking-wider text-earth-600" style="color: ${typeConfig.color}">${typeConfig.label}</span>
<div id="node-status-dot" class="w-2 h-2 rounded-full bg-sage-400"></div>
</div>
<h3 class="text-xl font-bold mb-2 text-earth-800">${node.id}</h3>
<div class="space-y-3 text-sm Gothic" style="font-family: 'Lato', sans-serif;">
<div class="flex justify-between">
<span class="opacity-60">Type</span>
<span class="font-bold">${node.type}</span>
</div>
<div class="flex justify-between">
<span class="opacity-60">ID</span>
<span class="font-mono opacity-80 text-xs">i-${Math.random().toString(16).substr(2,8)}</span>
</div>
<div class="flex justify-between">
<span class="opacity-60">State</span>
<span id="node-state-text" class="font-bold">Active</span>
</div>
<div class="mt-4 p-3 rounded bg-earth-100/50 border border-earth-200/50 font-mono text-xs leading-tight break-all">
<span class="block opacity-50 mb-1">Latest Diff:</span>
<span id="node-diff-text" class="text-earth-800 italic">No changes detected.</span>
</div>
</div>
`;
document.body.appendChild(panel);
// Animate In
setTimeout(() => {
panel.classList.remove('translate-x-[120%]');
}, 10);
this.updateDetailsPanel(node);
}
updateDetailsPanel(node) {
if (!this.detailsPanel) this.detailsPanel = document.getElementById('details-panel');
if (this.detailsPanel) {
// Update content via data attributes or inner HTML would be flashy, let's just update specific spans
const stateText = document.getElementById('node-state-text');
const statusDot = document.getElementById('node-status-dot');
const diffText = document.getElementById('node-diff-text');
if (stateText && statusDot && diffText) {
gsap.to(this.detailsPanel, { scale: 0.98, duration: 0.1, yoyo: true, repeat: 1 });
if (node.state === 'modified') {
stateText.textContent = 'Updated';
stateText.style.color = THEME.clay[600];
statusDot.className = 'w-2 h-2 rounded-full animate-pulse';
statusDot.style.backgroundColor = THEME.clay[500];
statusDot.style.boxShadow = `0 0 0 4px white, 0 0 0 6px ${THEME.clay[300]}`;
diffText.textContent = `Configuration drifted: image_id -> ami-0ff8a9...`;
diffText.style.color = THEME.clay[600];
} else if (node.state === 'added') {
stateText.textContent = 'Provisioned';
stateText.style.color = THEME.sage[600];
statusDot.className = 'w-2 h-2 rounded-full bg-sage-500';
diffText.textContent = `New resource interpolated from HCL.`;
diffText.style.color = THEME.sage[700];
} else {
stateText.textContent = 'Stable';
stateText.style.color = THEME.ink;
statusDot.className = 'w-2 h-2 rounded-full bg-sage-400';
statusDot.style.boxShadow = 'none';
diffText.textContent = "No changes detected.";
diffText.style.color = THEME.earth[600];
}
}
}
}
}
/**
* Main Application
*/
class App {
constructor() {
this.atmosphere = new Atmosphere('three-container');
this.canvas = document.getElementById('main-canvas');
this.graph = new Graph(this.canvas);
// Generate Mock Data (Terraform-like topology)
this.data = this.generateMockData();
// Initial Load
setTimeout(() => {
this.graph.loadData(this.data);
this.graph.generate();
document.getElementById('prompt').style.opacity = '1';
document.getElementById('prompt').style.transform = 'translateY(0)';
document.getElementById('timestamp').innerText = new Date().toLocaleTimeString();
}, 500);
// Resize fix
window.addEventListener('resize', () => {
this.graph.resize();
});
}
generateMockData() {
// Create a radial-ish layout math manually so we have target positions for graph
const nodes = [];
const links = [];
const idCounter = 1;
// Definitions
const types = ['vpc', 'subnet', 'ec2', 'rds', 'sg', 'iam'];
// VPC Center
nodes.push({ id: 'VPC-Main', type: 'vpc', x: 0, y: 0 });
// 2 Subnets (Public, Private) surrounding VPC
nodes.push({ id: 'Subnet-Public-A', type: 'subnet', x: 0, y: -180 });
nodes.push({ id: 'Subnet-Private-A', type: 'subnet', x: 0, y: 180 });
// EC2 instances in subnets
nodes.push({ id: 'EC2-Web-1', type: 'ec2', x: -120, y: -240 });
nodes.push({ id: 'EC2-Web-2', type: 'ec2', x: 120, y: -240 });
nodes.push({ id: 'EC2-App-1', type: 'ec2', x: -120, y: 240 });
nodes.push({ id: 'EC2-App-2', type: 'ec2', x: 120, y: 240 });
// RDS
nodes.push({ id: 'RDS-Primary', type: 'rds', x: 0, y: 0 }); // Overlap VPC conceptually, but placed differently? Let's put it hidden or inside.
// Security Groups
nodes.push({ id: 'SG-Web', type: 'sg', x: -200, y: -280 });
nodes.push({ id: 'SG-App', type: 'sg', x: 200, y: -280 });
// IAM Role
nodes.push({ id: 'IAM-InstanceProfile', type: 'iam', x: 0, y: -300 });
// Build Links (Dependencies)
links.push(...this.linkNodes('VPC-Main', 'Subnet-Public-A', 'Subnet-Private-A'));
links.push(...this.linkNodes('Subnet-Public-A', 'EC2-Web-1', 'EC2-Web-2'));
links.push(...this.linkNodes('Subnet-Private-A', 'EC2-App-1', 'EC2-App-2'));
links.push(...this.linkNodes('VPC-Main', 'SG-Web', 'SG-App'));
links.push(...this.linkNodes('SG-Web', 'EC2-Web-1', 'EC2-Web-2'));
links.push(...this.linkNodes('SG-App', 'EC2-App-1', 'EC2-App-2'));
links.push(...this.linkNodes('Subnet-Private-A', 'RDS-Primary'));
links.push(...this.linkNodes('IAM-InstanceProfile', 'EC2-App-1', 'EC2-Web-1'));
// Convert to relative screen coords
const cx = window.innerWidth / 2;
const cy = window.innerHeight / 2;
nodes.forEach(n => {
n.x += cx;
n.y += cy;
});
return { nodes, links };
}
linkNodes(parent, ...children) {
return children.map(child => ({
source: parent,
target: child
}));
}
// Simulate a state drift / change
simulateDiff() {
const randomNode = this.graph.nodes[Math.floor(Math.random() * this.graph.nodes.length)];
// 33% chance to be deletion (temporary), 66% modification
const action = Math.random() > 0.8 ? 'modify' : (Math.random() > 0.5 ? 'add' : 'modify');
if (action === 'add') {
randomNode.state = 'added';
} else if (action === 'modify') {
randomNode.state = 'modified';
}
// Pulse animation on the node itself
// Highlight links to it
this.graph.links.forEach(l => {
if (l.target === randomNode || l.source === randomNode) {
l.source.state = randomNode.state; // propagate visual state to source
}
});
// Flash details panel if open
if (this.graph.selectedNode === randomNode) {
this.graph.updateDetailsPanel(randomNode);
}
// Log effect (optional toast)
this.showNotice(`${randomNode.id} state changed: ${action}`);
}
showNotice(msg) {
// Create a transient floating note
const note = document.createElement('div');
note.className = 'fixed bottom-24 left-1/2 transform -translate-x-1/2 bg-stone-800 text-white px-4 py-2 rounded-full text-sm shadow-lg opacity-0 transition-opacity duration-1000 pointer-events-none';
note.textContent = msg;
document.body.appendChild(note);
gsap.to(note, { opacity: 1, duration: 0.5 });
setTimeout(() => {
gsap.to(note, { opacity: 0, duration: 0.5, onComplete: () => note.remove() });
}, 2000);
}
async generateDocs() {
const modal = document.getElementById('docs-modal');
const content = document.getElementById('docs-content');
// Show Modal
modal.classList.remove('opacity-0', 'pointer-events-none');
modal.classList.add('opacity-100', 'pointer-events-auto');
// Simulate parsing / typing
content.innerHTML = `<span class="cursor-blink"></span>`;
const yaml = this.buildYaml();
await this.typewriter(content, yaml);
}
buildYaml() {
let output = [
"# Infrastructure Blueprint - Terraph Generated",
"# Timestamp: " + new Date().toISOString(),
'',
'config:',
` system_name: "phaethon-${Math.floor(Math.random()*100)}"`
];
// Group by type
const groups = {};
this.graph.nodes.forEach(n => {
if (!groups[n.type]) groups[n.type] = [];
groups[n.type].push(n.id);
});
Object.entries(groups).forEach(([type, nodes]) => {
output.push(` ${type}s:`);
nodes.forEach(id => {
output.push(` - ${id}:`);
output.push(` state: ${this.getNodeState(id)}`);
output.push(` region: us-east-1`);
output.push(` type: ${type.toUpperCase()}-${Math.floor(Math.random()*100)}`);
});
});
output.push('', 'dependencies:');
this.graph.links.forEach(l => {
output.push(` - source: ${l.source.id}`);
output.push(` target: ${l.target.id}`);
output.push(` relation: depends_on`);
});
return output.join('\n');
}
getNodeState(id) {
const n = this.graph.nodes.find(x => x.id === id);
if (!n) return 'absent';
if (n.state === 'added') return 'creating';
if (n.state === 'modified') return 'updating';
return 'active';
}
typewriter(element, text, i = 0) {
return new Promise(resolve => {
if (i < text.length) {
// Inserting text. For better performance with large text, we chunk.
element.innerHTML = text.substring(0, i+1).replace(/\n/g, '<br>') + '<span class="cursor-blink"></span>';
const charsPerFrame = Math.ceil(text.length / 100); // fast
setTimeout(() => this.typewriter(element, text, i + charsPerFrame).then(resolve), 10);
} else {
resolve();
}
});
}
closeDocs() {
const modal = document.getElementById('docs-modal');
modal.classList.remove('opacity-100', 'pointer-events-auto');
modal.classList.add('opacity-0', 'pointer-events-none');
}
resetView() {
this.graph.nodes.forEach(n => {
n.state = 'stable';
});
this.graph.generate();
}
}
// Utility: Get first letter for icon
function getInitial(type) {
const map = { 'vpc': 'V', 'subnet': 'S', 'ec2': 'C', 'rds': 'D', 'sg': 'G', 'iam': 'I' };
return map[type] || '?';
}
// Utility: Lighten hex color
function lightenColor(color, percent) {
const num = parseInt(color.replace("#",""),16),
amt = Math.round(2.55 * percent),
R = (num >> 16) + amt,
B = (num >> 8 & 0x00FF) + amt,
G = (num & 0x0000FF) + amt;
return "#" + (0x1000000 + (R<255?R<1?0:R:255)*0x10000 + (B<255?B<1?0:B:255)*0x100 + (G<255?G<1?0:G:255)).toString(16).slice(1);
}
// Initialize App once DOM is ready
window.addEventListener('DOMContentLoaded', () => {
window.app = new App();
});
</script>
</body>
</html>