Skip to content

Implemented /compile Endpoint#28

Closed
ElectricAvenu671 wants to merge 2 commits into
mainfrom
dev-kaydo
Closed

Implemented /compile Endpoint#28
ElectricAvenu671 wants to merge 2 commits into
mainfrom
dev-kaydo

Conversation

@ElectricAvenu671

@ElectricAvenu671 ElectricAvenu671 commented Apr 9, 2026

Copy link
Copy Markdown

What

  • Added /compile endpoint to generate Terraform from an input intent graph.

Resolves

Summary by CodeRabbit

  • New Features

    • Added infrastructure resource types (compute, database, load balancer, security group, storage bucket) for designing cloud architectures visually.
    • Introduced network security and performance analysis capabilities for infrastructure graphs.
    • Added Terraform code generation from infrastructure designs via new API endpoints.
  • Improvements

    • Enhanced UI styling and theming system with dark theme support and design tokens.
    • Expanded component library for improved interface consistency.

@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR integrates shadcn UI components into the React frontend, introduces custom React Flow node/edge components for infrastructure diagramming, establishes backend graph abstractions (DirectedGraph and IntentGraph) with CRUD operations, implements analysis and compilation HTTP handlers, and adds corresponding test data and configuration files for the napkin infrastructure visualization tool.

Changes

Cohort / File(s) Summary
Shadcn UI Setup
components.json, package.json
Adds shadcn configuration with Tailwind integration, CSS variables, and UI library dependencies (class-variance-authority, clsx, lucide-react, radix-ui, tailwind-merge).
Frontend Styling & Theme
src/App.css
Introduces Tailwind theme variables for light/dark modes, CSS custom variant for .dark class, base layer styling for borders/outlines, and semantic color tokens for UI components.
Frontend UI Component Library
src/components/ui/button.tsx, src/components/ui/badge.tsx, src/components/ui/card.tsx
Adds reusable shadcn-style button, badge, and card components with CVA-based variant systems and semantic styling via Tailwind.
Frontend Base Components
src/components/base-node.tsx, src/components/base-handle.tsx, src/components/button-edge.tsx, src/components/labeled-handle.tsx
Establishes React Flow wrapper components (BaseNode, BaseHandle, ButtonEdge, LabeledHandle) with consistent styling and layout composition.
Frontend Infrastructure Nodes/Edges
src/components/ResourceNode.tsx, src/components/ResourceEdge.tsx
Adds React Flow node and edge components for infrastructure resources with input/output port definitions, delete buttons, and visual styling.
Frontend App Logic & Config
src/App.tsx, src/ToolBox.tsx, vite.config.ts, tsconfig.json, tsconfig.app.json
Updates app to use resource node/edge types with compute/database/loadBalancer/securityGroup/storageBucket kinds; refactors ToolBox with typed NodeItem array; configures TypeScript path aliases (@/*./src/*) and Vite resolver; removes erasableSyntaxOnly option.
Frontend Utilities & Workspace
src/lib/utils.ts, src/components/ui/napkin.code-workspace
Adds cn utility for merging Tailwind classes; includes workspace configuration file.
Backend Graph Abstractions
napkin-backend/graph/directed_graph.go, napkin-backend/graph/intent_graph.go, napkin-backend/graph/type.go
Implements DirectedGraph (adjacency-list representation) and IntentGraph (node/edge maps) with CRUD operations, JSON serialization, and graph traversal helpers; extends Edge struct with SourcePort, TargetPort, Type fields.
Backend Analysis Framework
napkin-backend/analysis/NetworkSecurityAnalyzer.go, napkin-backend/analysis/PerformanceAnalyzer.go
Introduces analyzer types with Analyze methods returning errors and annotations; currently return empty results as stubs.
Backend Compilation & IR
napkin-backend/compiler/tf_target.go, napkin-backend/compiler/tf_writer.go, napkin-backend/lib/handlers/compile.go, napkin-backend/lib/handlers/compile_helpers.go
Extracts Terraform generation into TFFile.String() method; adds HTTP POST handler for compile requests supporting terraform target; implements IntentGraphToIR helper to convert infrastructure spec to compiler IR with node class/attributes/edges.
Backend Analysis Handler
napkin-backend/lib/handlers/analyze.go
Adds HTTP POST handler for analyze requests; runs NetworkSecurityAnalyzer and PerformanceAnalyzer against DirectedGraph; returns errors and annotations from both analyzers.
Backend Main & Routing
napkin-backend/main.go, napkin-backend/output.tf
Registers new /api/compile and /api/analyze POST endpoints; logs generated Terraform string before writing to file; reorders Terraform block attributes.
Configuration & Test Data
napkin-backend/src/nodes.json, napkin-backend/test_data/graph.json, napkin-app/src/test_data/graph.json
Adds node definitions for ec2, db, loadBalancer, securityGroup, storageBucket with input/output port schemas; includes Spring '26 test schema with Server and Database node types and edge definitions.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Frontend as React Frontend
    participant API as Backend API
    participant Graph as Graph Engine
    participant Compiler as Terraform Compiler
    participant Disk as File System

    User->>Frontend: Add nodes & edges to diagram
    User->>Frontend: Click "Compile to Terraform"
    Frontend->>API: POST /api/compile { intentGraph, target: "terraform" }
    
    API->>Graph: Parse IntentGraph from JSON
    Graph->>Graph: Build node/edge structure
    API->>Graph: Convert to DirectedGraph
    Graph-->>API: DirectedGraph instance
    
    API->>Compiler: Compile(DirectedGraph, "terraform")
    Compiler->>Compiler: Generate Terraform blocks
    Compiler-->>API: Terraform code as string
    
    API->>Disk: Write output.tf
    API-->>Frontend: { success: true, target: "terraform", code: "..." }
    Frontend->>User: Display Terraform output
Loading
sequenceDiagram
    actor User
    participant Frontend as React Frontend
    participant API as Backend API
    participant Graph as Graph Engine
    participant Analyzer1 as NetworkSecurityAnalyzer
    participant Analyzer2 as PerformanceAnalyzer

    User->>Frontend: Submit diagram for analysis
    Frontend->>API: POST /api/analyze { intentGraph }
    
    API->>Graph: Parse IntentGraph from JSON
    Graph-->>API: IntentGraph instance
    API->>Graph: Convert to DirectedGraph
    Graph-->>API: DirectedGraph instance
    
    API->>Analyzer1: Analyze(DirectedGraph)
    Analyzer1-->>API: { errors: [...], annotations: [...] }
    
    API->>Analyzer2: Analyze(DirectedGraph)
    Analyzer2-->>API: { errors: [...], annotations: [...] }
    
    API->>API: Aggregate results
    API-->>Frontend: { success: true, networkSecurityErrors, networkSecurityAnnotations, performanceErrors, performanceAnnotations }
    Frontend->>User: Display analysis results
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • PR #9 — Continues React Flow integration and custom node/edge setup started in this PR, expanding the same component architecture for infrastructure visualization.
  • PR #20 — Implements concrete NetworkSecurityAnalyzer and PerformanceAnalyzer logic that uses the analyzer interface and types introduced here.
  • PR #12 — Extends the compiler package (TFFile.String() and TerraformTarget) that this PR establishes as the compilation backend.

Suggested reviewers

  • joshuasilva414

🐰 A framework takes shape, nodes connect with care,
Graph structures bloom in the backend air,
UI components dance in shades of light,
Analyzers whisper insights through the night,
Infrastructure dreams compile just right!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Implemented /compile Endpoint' directly and specifically describes the primary feature added in this PR: a new HTTP endpoint for compiling intent graphs to Terraform.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev-kaydo

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant