Terraform Infrastructure Builder
Run ID: 69cc03d504066a6c4a16892e2026-03-31Infrastructure
PantheraHive BOS
BOS Dashboard

Generate production-ready Terraform configurations for cloud infrastructure including VPC, compute, storage, databases, and networking.

As part of the "Terraform Infrastructure Builder" workflow, this step focuses on research_design_requirements. The goal is to generate comprehensive, detailed, and production-ready design specifications for cloud infrastructure that will subsequently be translated into Terraform configurations.


1. Introduction & Context Setting

This document outlines the detailed design specifications for a robust, scalable, secure, and cost-optimized cloud infrastructure, intended for production environments. The primary objective is to define the architectural components, their interconnections, and operational considerations that will guide the generation of Terraform configurations.

It's important to clarify the interpretation of certain terms in the context of Infrastructure-as-Code (IaC):

  • Design Specifications: Refer to the detailed architectural blueprints of the cloud infrastructure components (VPC, compute, storage, databases, security, etc.).
  • "Wireframe" Descriptions: Are re-interpreted as conceptual architectural diagrams and Terraform module structure visualizations, illustrating the logical layout and relationships of infrastructure components.
  • "Color Palettes": Are considered in the context of enhancing readability for architectural diagrams and code syntax highlighting, rather than user interface aesthetics.
  • "UX Recommendations": Are re-interpreted as Developer Experience (DX) Recommendations, focusing on the usability, maintainability, and clarity of the generated Terraform code for developers and operations teams.

For this deliverable, we will assume AWS as the target cloud provider due to its widespread adoption and comprehensive service offerings, but the principles are largely cloud-agnostic.


2. Cloud Provider & Scope

  • Cloud Provider: Amazon Web Services (AWS)
  • Target Environment: Production
  • Scope of Infrastructure:

* Virtual Private Cloud (VPC) and Networking

* Compute Resources (EC2, Auto Scaling, Load Balancing)

* Database Services (Relational, NoSQL)

* Storage Solutions (Object, Block, File)

* Security, Identity, and Access Management (IAM)

* Monitoring, Logging, and Alerting

* Deployment Pipeline Considerations


3. Detailed Infrastructure Design Specifications

3.1. Core Networking (VPC)

  • VPC Structure:

* Dedicated VPC: A single, isolated VPC per environment (e.g., prod-vpc).

* CIDR Block: Appropriately sized CIDR block (e.g., /16 or /18) to allow for future expansion.

* Multi-AZ Deployment: At least three Availability Zones (AZs) for high availability.

* Subnetting Strategy:

* Public Subnets: For resources requiring direct internet access (e.g., Load Balancers, NAT Gateways). One per AZ.

* Private Application Subnets: For application servers, backend services. One per AZ.

* Private Database Subnets: For database instances. One per AZ.

* Private Management Subnets (Optional): For jump boxes, monitoring agents.

* Internet Gateway (IGW): Attached to the VPC for outbound internet access from public subnets.

* NAT Gateway (NAT GW): Deployed in public subnets (one per AZ for redundancy) to allow private instances outbound internet access.

* Route Tables:

* Public Route Table: Routes to IGW for public subnets.

* Private Route Table: Routes to NAT GW for private subnets.

* Database Route Table: Routes to NAT GW for private database subnets.

* DNS Resolution: Enable DNS Hostnames and DNS Resolution within the VPC.

3.2. Compute Layer

  • EC2 Instances:

* Instance Types: Selected based on application workload requirements (CPU, memory, network performance). Utilize burstable (T-series) for low-traffic, cost-sensitive, or development workloads; general-purpose (M-series) or compute-optimized (C-series) for production.

* AMIs: Use hardened, up-to-date AMIs (e.g., Amazon Linux 2, Ubuntu LTS) or custom golden AMIs.

* Auto Scaling Groups (ASG):

* Deployed across multiple private application subnets for high availability and scalability.

* Min/Max/Desired capacities configured based on expected load.

* Scaling Policies: Target Tracking (e.g., CPU utilization, ALB request count per target) and Scheduled Scaling.

* Launch Templates: Used for defining instance configurations (AMI, instance type, EBS, user data, security groups, IAM role).

* Load Balancers:

* Application Load Balancer (ALB): For HTTP/HTTPS traffic, deployed in public subnets. Configured with listener rules, target groups, and health checks. Integrated with AWS WAF for web application firewall capabilities.

* Network Load Balancer (NLB) (Optional): For high-performance TCP/UDP traffic or specific needs.

  • Containerization (Optional - if specified):

* ECS/EKS Cluster: If containerized applications are in scope, an ECS/EKS cluster will be provisioned within the private application subnets.

* Fargate/EC2: Choice between Fargate (serverless) or EC2 (managed instances) for compute, based on control and cost requirements.

3.3. Database Layer

  • Relational Databases (RDS):

* Engine: PostgreSQL or MySQL (or Aurora for higher performance/scalability) preferred.

* Deployment: Multi-AZ deployment for high availability with automatic failover.

* Instance Type: Chosen based on performance requirements (IOPS, memory).

* Storage: Provisioned IOPS (PIOPS) or General Purpose SSD (gp2/gp3) based on workload. Encryption at rest enabled.

* Backup & Recovery: Automated backups, retention period configured. Point-in-time recovery enabled.

* Read Replicas (Optional): For read-heavy workloads or cross-region disaster recovery.

* Connectivity: Accessible only from private application subnets via security groups.

  • NoSQL Databases (DynamoDB):

* Tables: Provisioned with appropriate Read/Write Capacity Units (RCUs/WCUs) or On-Demand mode.

* Global Tables (Optional): For multi-region replication.

* Backup: Point-in-time recovery enabled, or on-demand backups.

* Encryption: Encryption at rest enabled.

3.4. Storage Layer

  • Object Storage (S3):

* Buckets: Created for static assets, backups, logs, data lakes.

* Versioning: Enabled for critical data.

* Lifecycle Policies: Configured for cost optimization (e.g., transition to Glacier, expiration).

* Encryption: Server-side encryption (SSE-S3, SSE-KMS) enabled by default.

* Access Control: Least privilege IAM policies and bucket policies.

  • Block Storage (EBS):

* Volumes: Provisioned for EC2 instances. General Purpose SSD (gp2/gp3) or Provisioned IOPS SSD (io1/io2) based on performance needs.

* Encryption: Encryption at rest enabled.

* Snapshots: Automated snapshots for backup.

  • File Storage (EFS/FSx - Optional):

* EFS: For shared file systems across multiple EC2 instances or containers. Encryption at rest and in transit.

* FSx for Lustre/Windows File Server: For specific high-performance computing or Windows-based workloads.

3.5. Security & Identity

  • Identity and Access Management (IAM):

* Least Privilege Principle: All IAM roles and policies will grant only the minimum necessary permissions.

* IAM Roles for EC2: Instances will use IAM roles instead of access keys for AWS service interaction.

* MFA: Enforced for all root and administrative IAM users.

* Access Keys: Regularly rotated, ideally avoided for programmatic access unless absolutely necessary.

  • Security Groups (SGs):

* Granular Rules: Defined for each component (e.g., ALB SG, App SG, DB SG) allowing only necessary inbound/outbound traffic.

* Stateful: Traffic permitted in one direction is automatically allowed back.

  • Network Access Control Lists (NACLs):

* Stateless: Used as an additional layer of security at the subnet level, primarily for stricter inbound/outbound control if needed (less common than SGs for primary control).

  • Key Management Service (KMS):

* CMKs: Used for encrypting EBS volumes, S3 buckets, RDS databases, and other services.

* Centralized Key Management: All encryption keys managed centrally.

  • AWS WAF (Web Application Firewall):

* Associated with ALBs for protection against common web exploits (OWASP Top 10).

  • AWS Secrets Manager/Parameter Store:

* For secure storage and retrieval of database credentials, API keys, and other sensitive configuration data.

3.6. Monitoring & Logging

  • AWS CloudWatch:

* Metrics: Collect standard and custom metrics for EC2, RDS, ALB, etc.

* Alarms: Configure alarms for critical thresholds (e.g., high CPU, low disk space, error rates) to trigger notifications (SNS).

* Dashboards: Create centralized dashboards for operational visibility.

  • AWS CloudWatch Logs:

* Log Groups: Centralized collection of application logs, VPC Flow Logs, Load Balancer Access Logs.

* Log Retention: Configured based on compliance and operational needs.

  • AWS CloudTrail:

* Audit Logging: Enabled for all management events and data events (optional for S3, Lambda) to track API calls and user activity.

* S3 Storage: Logs stored in an S3 bucket with appropriate lifecycle policies.

  • AWS Config:

* Compliance: Enabled for continuous monitoring of resource configurations and compliance with desired state.

3.7. CI/CD & Deployment Considerations

While this step focuses on infrastructure generation, the generated Terraform will be designed to integrate seamlessly into a CI/CD pipeline:

  • Terraform State Management: Backend configured for S3 with DynamoDB locking for concurrent operations.
  • Modularity: Generated code will leverage Terraform modules for reusability and maintainability.
  • Parameterization: Input variables will allow for easy customization across environments (e.g., dev, staging, prod).

3.8. Modularity & Naming Conventions

  • Terraform Module Structure: The generated configurations will be structured into logical modules (e.g., vpc, ec2, rds, s3) for reusability and clarity.
  • Naming Convention: Consistent, descriptive naming will be enforced across all AWS resources and Terraform variables
gemini Output

As a professional AI assistant within PantheraHive, I am generating detailed design specifications for the "Terraform Infrastructure Builder" workflow. This output is comprehensive, actionable, and designed to provide a clear vision for the user interface and experience.


Terraform Infrastructure Builder: Detailed Design Specifications

This document outlines the design specifications, wireframe descriptions, color palettes, and user experience (UX) recommendations for the Terraform Infrastructure Builder. The goal is to create an intuitive, powerful, and professional tool for generating production-ready Terraform configurations.


1. Detailed Design Specifications

This section covers the core functionality, workflow, input mechanisms, output, and advanced features of the Terraform Infrastructure Builder.

1.1 Core Functionality

  • Cloud Provider Selection: Users can select one or more
gemini Output

This document details the finalized design assets for your cloud infrastructure, leveraging Terraform for robust, scalable, and maintainable deployment. While "design assets" typically refer to user interface elements, in the context of Infrastructure as Code (IaC) and Terraform, we interpret these as comprehensive architectural specifications, visual representations of the infrastructure, and best practices for managing and interacting with the deployed environment.


Finalized Infrastructure Design Assets: Terraform Infrastructure Builder

1. Introduction and Scope

This deliverable encompasses the detailed specifications, architectural representations, and operational recommendations for your production-ready cloud infrastructure, built entirely with Terraform. The goal is to provide a holistic view of the infrastructure design, ensuring clarity, maintainability, and alignment with modern cloud best practices.

Key Deliverables in this Section:

  • Detailed Infrastructure Design Specifications
  • Architectural Diagram Descriptions (Wireframes)
  • Consistent Visual Language for Diagrams (Color Palettes)
  • User Experience (UX) Recommendations for Terraform Management and Operations

2. Detailed Infrastructure Design Specifications

These specifications form the backbone of your Terraform configurations, outlining every component with precision.

2.1. Virtual Private Cloud (VPC) & Networking

  • VPC CIDR Block: 10.0.0.0/16 (Example: Customizable per environment/region)
  • Public Subnets (per AZ):

* CIDR Blocks: 10.0.1.0/24 (AZ-1), 10.0.2.0/24 (AZ-2), 10.0.3.0/24 (AZ-3)

* Purpose: Load balancers, NAT Gateways, public-facing services (if applicable).

* Associated with: Internet Gateway, Public Route Table.

  • Private Application Subnets (per AZ):

* CIDR Blocks: 10.0.11.0/24 (AZ-1), 10.0.12.0/24 (AZ-2), 10.0.13.0/24 (AZ-3)

* Purpose: Application servers, container orchestrators.

* Associated with: NAT Gateway (for outbound internet access), Private Route Table.

  • Private Database Subnets (per AZ):

* CIDR Blocks: 10.0.21.0/24 (AZ-1), 10.0.22.0/24 (AZ-2), 10.0.23.0/24 (AZ-3)

* Purpose: Database instances (RDS, DocumentDB, etc.).

* Associated with: Private Route Table (no direct internet access).

  • Internet Gateway (IGW): Single IGW attached to the VPC for public subnet internet access.
  • NAT Gateways (per Public Subnet): Highly available NAT Gateways for private subnet outbound internet access.
  • Route Tables:

* Public Route Table: Default route to IGW.

* Private Route Table (App): Default route to NAT Gateway.

* Private Route Table (DB): No default route to internet, only internal VPC routes.

  • Network ACLs (NACLs): Default permissive, security managed primarily by Security Groups. (Recommendation: Apply NACLs for stricter subnet-level control if specific compliance requires it).

2.2. Compute Resources (Example: EC2)

  • Application Servers:

* Instance Type: t3.medium (scalable, e.g., m5.large for production)

* AMI: Latest Amazon Linux 2 or Ubuntu LTS.

* Auto Scaling Group:

* Min/Max/Desired: 2/6/2 (example, based on load)

* Scaling Policies: CPU utilization-based (e.g., scale out > 70%, scale in < 30%).

* Launch Template: Defines instance configuration, user data for bootstrapping.

* Placement: Across multiple private application subnets for high availability.

  • Load Balancers (Application Load Balancer - ALB):

* Type: application

* Scheme: internet-facing (for public apps) or internal (for internal apps).

* Listener Ports: HTTP:80 (redirect to HTTPS), HTTPS:443.

* Target Groups: Registered with Auto Scaling Groups for dynamic scaling.

* Security Group: Allows inbound traffic on 80/443 from 0.0.0.0/0 (for public ALB) or specific VPC CIDRs (for internal ALB).

2.3. Storage Resources (Example: S3 & EBS)

  • S3 Buckets:

* Purpose: Static content hosting, logging, backups, data lake.

* Configuration:

* Versioning: Enabled for critical data.

* Encryption: SSE-S3 by default, SSE-KMS for sensitive data.

* Public Access Block: Enabled by default (no public access).

* Lifecycle Policies: Define transitions to Glacier, deletion rules.

* Bucket Policy: Restrict access to specific IAM roles/users.

  • EBS Volumes:

* Attached to EC2: Root volumes for OS, additional volumes for data (if not ephemeral).

* Type: gp3 (cost-effective general purpose, scalable IOPS/throughput).

* Encryption: Enabled by default using AWS KMS.

* Snapshots: Automated backups configured via AWS Backup or custom scripts.

2.4. Database Resources (Example: RDS PostgreSQL)

  • Engine: PostgreSQL
  • Version: Latest stable minor version (e.g., 14.x)
  • Instance Class: db.t3.small (scalable, e.g., db.m5.large for production).
  • Multi-AZ Deployment: Enabled for high availability and failover.
  • Storage: gp3 (scalable, e.g., 100GB initial, auto-scaling enabled).
  • Backup Retention: 7 days (scalable up to 35 days).
  • Encryption: Enabled using AWS KMS.
  • Parameter Group: Custom group for application-specific tuning (e.g., connection limits, timeouts).
  • Option Group: (If applicable)
  • Placement: Across private database subnets.
  • Security Group: Allows inbound traffic on 5432 from application security groups only.

2.5. Security Groups (Firewall Rules)

  • ALB Security Group:

* Inbound: HTTP:80, HTTPS:443 from 0.0.0.0/0 (public ALB) or specific CIDRs/SGs (internal ALB).

* Outbound: All traffic.

  • Application Security Group:

* Inbound: HTTP:80, HTTPS:443 from ALB Security Group.

* Inbound: SSH:22 from specific bastion host/VPN IP (for management).

* Outbound: 5432 to Database Security Group.

* Outbound: 443 to S3/External APIs (via NAT Gateway).

  • Database Security Group:

* Inbound: PostgreSQL:5432 from Application Security Group.

* Outbound: None (or specific ports for replication/monitoring if required).

  • Bastion Host Security Group:

* Inbound: SSH:22 from specific trusted IP ranges.

* Outbound: SSH:22 to Application Security Group (for management).

2.6. Identity and Access Management (IAM)

  • IAM Roles for EC2:

* Principle of Least Privilege: Roles attached to EC2 instances granting only necessary permissions (e.g., S3 read/write, CloudWatch metrics, SSM access).

  • IAM Users/Groups: Defined for administrative access, with MFA enforced.
  • IAM Policies: Granular permissions defined and attached to roles/users.

2.7. Monitoring & Logging

  • CloudWatch Logs: Centralized logging for EC2 instances, Load Balancers, VPC Flow Logs.
  • CloudWatch Metrics & Alarms: CPU, memory, network I/O, database connections, latency, error rates.
  • VPC Flow Logs: Enabled for all network interfaces to S3 for auditing and troubleshooting.

3. Architectural Diagram Descriptions (Wireframes)

These "wireframes" describe the visual architecture diagrams that will accompany your Terraform deployment, providing a clear map of the infrastructure. We recommend using standard cloud provider iconography (e.g., AWS Architecture Icons) for clarity.

3.1. High-Level Architecture Diagram

  • Purpose: Provides an overview of the entire infrastructure, showing major components and their relationships.
  • Key Elements:

* Cloud Provider Region boundary.

* VPC boundary.

* Public vs. Private Subnets.

* Internet Gateway, NAT Gateways.

* Load Balancer (ALB).

* Auto Scaling Group (representing application servers).

* Database (RDS Multi-AZ).

* S3 (for storage/static assets).

* Arrows indicating primary data flow (e.g., User -> ALB -> App -> DB).

3.2. Network Topology Diagram

  • Purpose: Detailed view of network segmentation, routing, and security group interactions.
  • Key Elements:

* VPC with all subnets clearly labeled (Public, Private App, Private DB) and their CIDR ranges.

* Internet Gateway, NAT Gateways, Route Tables.

* Security Groups as conceptual boundaries around components (ALB, App, DB).

* Inbound/outbound traffic flows between components and to/from the internet.

* Availability Zones clearly demarcated.

3.3. Application Tier Detail Diagram

  • Purpose: Focuses on the application layer, showing how compute instances are deployed and managed.
  • Key Elements:

* ALB with listeners and target groups.

* Auto Scaling Group with multiple EC2 instances spread across AZs.

* Connection from application instances to the database.

* Connection to S3 for static assets or logging.

* Monitoring (CloudWatch) and Logging (CloudWatch Logs) integrations.

3.4. Database Tier Detail Diagram

  • Purpose: Illustrates the database deployment, including high availability and security.
  • Key Elements:

* RDS Multi-AZ deployment with primary and standby instances.

* Replication between primary and standby.

* Database subnets and their isolation.

* Security Group protecting the database.

* Connections from application servers to the database.


4. Consistent Visual Language for Diagrams (Color Palettes)

To ensure clarity and consistency across all architectural diagrams, we recommend the following visual guidelines:

4.1. Cloud Provider Iconography

  • Standard Icons: Utilize the official iconography provided by your chosen cloud provider (e.g., AWS Architecture Icons, Azure Icon Set). This ensures immediate recognition and understanding.

4.2. Environment-Specific Color Coding

  • Production (Prod): Red or Dark Blue (signifies critical, live environment)
  • Staging (Stage): Orange or Medium Blue (pre-production, testing)
  • Development (Dev): Green or Light Blue (sandbox, feature development)
  • Shared/Common: Grey or Purple (components shared across environments, e.g., VPN, central logging)

4.3. Component Type Color Coding (within diagrams)

  • Network: Light Blue/Cyan (VPC, Subnets, Gateways, Route Tables)
  • Compute: Green (EC2, Auto Scaling Groups, Containers)
  • Storage: Yellow/Orange (S3, EBS, EFS)
  • Database: Dark Blue/Purple (RDS, DynamoDB, ElastiCache)
  • Security: Red/Dark Grey (Security Groups, IAM, KMS)
  • Load Balancing/Routing: Light Grey/White (ALB, Route 53)
  • Monitoring/Logging: Brown/Orange (CloudWatch, CloudTrail)

4.4. Line Styles and Arrows

  • Solid Lines: Active connections, primary data flow.
  • Dashed Lines: Management access, backup connections, conceptual boundaries.
  • Arrows: Indicate direction of data flow.
  • Labels: Clear text labels for all components, connections, and security groups.

5. User Experience (UX) Recommendations for Terraform Management and Operations

These recommendations focus on improving the "user experience" for engineers and operations teams interacting with the Terraform codebase and the deployed infrastructure.

5.1. Terraform Code Structure & Modularity

  • Module-Based Design:

* Break down infrastructure into reusable, logical modules (e.g., vpc, ec2-app-tier, rds-postgres, s3-bucket).

* Each module should have a clear purpose, inputs, outputs, and README.md.

* This promotes reusability, reduces redundancy, and simplifies maintenance.

  • Environment-Specific Configurations:

* Separate root modules for each environment (e./environments/dev, ./environments/stage, ./environments/prod).

Use terraform.tfvars or -dev.tfvars, *-prod.tfvars for environment-specific variable overrides.

  • Naming Conventions:

* Implement consistent, descriptive naming conventions for all resources (e.g., `project-env-resource-purpose

terraform_infrastructure_build.md
Download as Markdown
Copy all content
Full output as text
Download ZIP
IDE-ready project ZIP
Copy share link
Permanent URL for this run
Get Embed Code
Embed this result on any website
Print / Save PDF
Use browser print dialog
\n\n\n"); var hasSrcMain=Object.keys(extracted).some(function(k){return k.indexOf("src/main")>=0;}); if(!hasSrcMain) zip.file(folder+"src/main."+ext,"import React from 'react'\nimport ReactDOM from 'react-dom/client'\nimport App from './App'\nimport './index.css'\n\nReactDOM.createRoot(document.getElementById('root')!).render(\n \n \n \n)\n"); var hasSrcApp=Object.keys(extracted).some(function(k){return k==="src/App."+ext||k==="App."+ext;}); if(!hasSrcApp) zip.file(folder+"src/App."+ext,"import React from 'react'\nimport './App.css'\n\nfunction App(){\n return(\n
\n
\n

"+slugTitle(pn)+"

\n

Built with PantheraHive BOS

\n
\n
\n )\n}\nexport default App\n"); zip.file(folder+"src/index.css","*{margin:0;padding:0;box-sizing:border-box}\nbody{font-family:system-ui,-apple-system,sans-serif;background:#f0f2f5;color:#1a1a2e}\n.app{min-height:100vh;display:flex;flex-direction:column}\n.app-header{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;padding:40px}\nh1{font-size:2.5rem;font-weight:700}\n"); zip.file(folder+"src/App.css",""); zip.file(folder+"src/components/.gitkeep",""); zip.file(folder+"src/pages/.gitkeep",""); zip.file(folder+"src/hooks/.gitkeep",""); Object.keys(extracted).forEach(function(p){ var fp=p.startsWith("src/")?p:"src/"+p; zip.file(folder+fp,extracted[p]); }); zip.file(folder+"README.md","# "+slugTitle(pn)+"\n\nGenerated by PantheraHive BOS.\n\n## Setup\n\`\`\`bash\nnpm install\nnpm run dev\n\`\`\`\n\n## Build\n\`\`\`bash\nnpm run build\n\`\`\`\n\n## Open in IDE\nOpen the project folder in VS Code or WebStorm.\n"); zip.file(folder+".gitignore","node_modules/\ndist/\n.env\n.DS_Store\n*.local\n"); } /* --- Vue (Vite + Composition API + TypeScript) --- */ function buildVue(zip,folder,app,code,panelTxt){ var pn=pkgName(app); var C=cc(pn); var extracted=extractCode(panelTxt); zip.file(folder+"package.json",'{\n "name": "'+pn+'",\n "version": "0.0.0",\n "type": "module",\n "scripts": {\n "dev": "vite",\n "build": "vue-tsc -b && vite build",\n "preview": "vite preview"\n },\n "dependencies": {\n "vue": "^3.5.13",\n "vue-router": "^4.4.5",\n "pinia": "^2.3.0",\n "axios": "^1.7.9"\n },\n "devDependencies": {\n "@vitejs/plugin-vue": "^5.2.1",\n "typescript": "~5.7.3",\n "vite": "^6.0.5",\n "vue-tsc": "^2.2.0"\n }\n}\n'); zip.file(folder+"vite.config.ts","import { defineConfig } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport { resolve } from 'path'\n\nexport default defineConfig({\n plugins: [vue()],\n resolve: { alias: { '@': resolve(__dirname,'src') } }\n})\n"); zip.file(folder+"tsconfig.json",'{"files":[],"references":[{"path":"./tsconfig.app.json"},{"path":"./tsconfig.node.json"}]}\n'); zip.file(folder+"tsconfig.app.json",'{\n "compilerOptions":{\n "target":"ES2020","useDefineForClassFields":true,"module":"ESNext","lib":["ES2020","DOM","DOM.Iterable"],\n "skipLibCheck":true,"moduleResolution":"bundler","allowImportingTsExtensions":true,\n "isolatedModules":true,"moduleDetection":"force","noEmit":true,"jsxImportSource":"vue",\n "strict":true,"paths":{"@/*":["./src/*"]}\n },\n "include":["src/**/*.ts","src/**/*.d.ts","src/**/*.tsx","src/**/*.vue"]\n}\n'); zip.file(folder+"env.d.ts","/// \n"); zip.file(folder+"index.html","\n\n\n \n \n "+slugTitle(pn)+"\n\n\n
\n \n\n\n"); var hasMain=Object.keys(extracted).some(function(k){return k==="src/main.ts"||k==="main.ts";}); if(!hasMain) zip.file(folder+"src/main.ts","import { createApp } from 'vue'\nimport { createPinia } from 'pinia'\nimport App from './App.vue'\nimport './assets/main.css'\n\nconst app = createApp(App)\napp.use(createPinia())\napp.mount('#app')\n"); var hasApp=Object.keys(extracted).some(function(k){return k.indexOf("App.vue")>=0;}); if(!hasApp) zip.file(folder+"src/App.vue","\n\n\n\n\n"); zip.file(folder+"src/assets/main.css","*{margin:0;padding:0;box-sizing:border-box}body{font-family:system-ui,sans-serif;background:#fff;color:#213547}\n"); zip.file(folder+"src/components/.gitkeep",""); zip.file(folder+"src/views/.gitkeep",""); zip.file(folder+"src/stores/.gitkeep",""); Object.keys(extracted).forEach(function(p){ var fp=p.startsWith("src/")?p:"src/"+p; zip.file(folder+fp,extracted[p]); }); zip.file(folder+"README.md","# "+slugTitle(pn)+"\n\nGenerated by PantheraHive BOS.\n\n## Setup\n\`\`\`bash\nnpm install\nnpm run dev\n\`\`\`\n\n## Build\n\`\`\`bash\nnpm run build\n\`\`\`\n\nOpen in VS Code or WebStorm.\n"); zip.file(folder+".gitignore","node_modules/\ndist/\n.env\n.DS_Store\n*.local\n"); } /* --- Angular (v19 standalone) --- */ function buildAngular(zip,folder,app,code,panelTxt){ var pn=pkgName(app); var C=cc(pn); var sel=pn.replace(/_/g,"-"); var extracted=extractCode(panelTxt); zip.file(folder+"package.json",'{\n "name": "'+pn+'",\n "version": "0.0.0",\n "scripts": {\n "ng": "ng",\n "start": "ng serve",\n "build": "ng build",\n "test": "ng test"\n },\n "dependencies": {\n "@angular/animations": "^19.0.0",\n "@angular/common": "^19.0.0",\n "@angular/compiler": "^19.0.0",\n "@angular/core": "^19.0.0",\n "@angular/forms": "^19.0.0",\n "@angular/platform-browser": "^19.0.0",\n "@angular/platform-browser-dynamic": "^19.0.0",\n "@angular/router": "^19.0.0",\n "rxjs": "~7.8.0",\n "tslib": "^2.3.0",\n "zone.js": "~0.15.0"\n },\n "devDependencies": {\n "@angular-devkit/build-angular": "^19.0.0",\n "@angular/cli": "^19.0.0",\n "@angular/compiler-cli": "^19.0.0",\n "typescript": "~5.6.0"\n }\n}\n'); zip.file(folder+"angular.json",'{\n "$schema": "./node_modules/@angular/cli/lib/config/schema.json",\n "version": 1,\n "newProjectRoot": "projects",\n "projects": {\n "'+pn+'": {\n "projectType": "application",\n "root": "",\n "sourceRoot": "src",\n "prefix": "app",\n "architect": {\n "build": {\n "builder": "@angular-devkit/build-angular:application",\n "options": {\n "outputPath": "dist/'+pn+'",\n "index": "src/index.html",\n "browser": "src/main.ts",\n "tsConfig": "tsconfig.app.json",\n "styles": ["src/styles.css"],\n "scripts": []\n }\n },\n "serve": {"builder":"@angular-devkit/build-angular:dev-server","configurations":{"production":{"buildTarget":"'+pn+':build:production"},"development":{"buildTarget":"'+pn+':build:development"}},"defaultConfiguration":"development"}\n }\n }\n }\n}\n'); zip.file(folder+"tsconfig.json",'{\n "compileOnSave": false,\n "compilerOptions": {"baseUrl":"./","outDir":"./dist/out-tsc","forceConsistentCasingInFileNames":true,"strict":true,"noImplicitOverride":true,"noPropertyAccessFromIndexSignature":true,"noImplicitReturns":true,"noFallthroughCasesInSwitch":true,"paths":{"@/*":["src/*"]},"skipLibCheck":true,"esModuleInterop":true,"sourceMap":true,"declaration":false,"experimentalDecorators":true,"moduleResolution":"bundler","importHelpers":true,"target":"ES2022","module":"ES2022","useDefineForClassFields":false,"lib":["ES2022","dom"]},\n "references":[{"path":"./tsconfig.app.json"}]\n}\n'); zip.file(folder+"tsconfig.app.json",'{\n "extends":"./tsconfig.json",\n "compilerOptions":{"outDir":"./dist/out-tsc","types":[]},\n "files":["src/main.ts"],\n "include":["src/**/*.d.ts"]\n}\n'); zip.file(folder+"src/index.html","\n\n\n \n "+slugTitle(pn)+"\n \n \n \n\n\n \n\n\n"); zip.file(folder+"src/main.ts","import { bootstrapApplication } from '@angular/platform-browser';\nimport { appConfig } from './app/app.config';\nimport { AppComponent } from './app/app.component';\n\nbootstrapApplication(AppComponent, appConfig)\n .catch(err => console.error(err));\n"); zip.file(folder+"src/styles.css","* { margin: 0; padding: 0; box-sizing: border-box; }\nbody { font-family: system-ui, -apple-system, sans-serif; background: #f9fafb; color: #111827; }\n"); var hasComp=Object.keys(extracted).some(function(k){return k.indexOf("app.component")>=0;}); if(!hasComp){ zip.file(folder+"src/app/app.component.ts","import { Component } from '@angular/core';\nimport { RouterOutlet } from '@angular/router';\n\n@Component({\n selector: 'app-root',\n standalone: true,\n imports: [RouterOutlet],\n templateUrl: './app.component.html',\n styleUrl: './app.component.css'\n})\nexport class AppComponent {\n title = '"+pn+"';\n}\n"); zip.file(folder+"src/app/app.component.html","
\n
\n

"+slugTitle(pn)+"

\n

Built with PantheraHive BOS

\n
\n \n
\n"); zip.file(folder+"src/app/app.component.css",".app-header{display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:60vh;gap:16px}h1{font-size:2.5rem;font-weight:700;color:#6366f1}\n"); } zip.file(folder+"src/app/app.config.ts","import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';\nimport { provideRouter } from '@angular/router';\nimport { routes } from './app.routes';\n\nexport const appConfig: ApplicationConfig = {\n providers: [\n provideZoneChangeDetection({ eventCoalescing: true }),\n provideRouter(routes)\n ]\n};\n"); zip.file(folder+"src/app/app.routes.ts","import { Routes } from '@angular/router';\n\nexport const routes: Routes = [];\n"); Object.keys(extracted).forEach(function(p){ var fp=p.startsWith("src/")?p:"src/"+p; zip.file(folder+fp,extracted[p]); }); zip.file(folder+"README.md","# "+slugTitle(pn)+"\n\nGenerated by PantheraHive BOS.\n\n## Setup\n\`\`\`bash\nnpm install\nng serve\n# or: npm start\n\`\`\`\n\n## Build\n\`\`\`bash\nng build\n\`\`\`\n\nOpen in VS Code with Angular Language Service extension.\n"); zip.file(folder+".gitignore","node_modules/\ndist/\n.env\n.DS_Store\n*.local\n.angular/\n"); } /* --- Python --- */ function buildPython(zip,folder,app,code){ var title=slugTitle(app); var pn=pkgName(app); var src=code.replace(/^\`\`\`[\w]*\n?/m,"").replace(/\n?\`\`\`$/m,"").trim(); var reqMap={"numpy":"numpy","pandas":"pandas","sklearn":"scikit-learn","tensorflow":"tensorflow","torch":"torch","flask":"flask","fastapi":"fastapi","uvicorn":"uvicorn","requests":"requests","sqlalchemy":"sqlalchemy","pydantic":"pydantic","dotenv":"python-dotenv","PIL":"Pillow","cv2":"opencv-python","matplotlib":"matplotlib","seaborn":"seaborn","scipy":"scipy"}; var reqs=[]; Object.keys(reqMap).forEach(function(k){if(src.indexOf("import "+k)>=0||src.indexOf("from "+k)>=0)reqs.push(reqMap[k]);}); var reqsTxt=reqs.length?reqs.join("\n"):"# add dependencies here\n"; zip.file(folder+"main.py",src||"# "+title+"\n# Generated by PantheraHive BOS\n\nprint(title+\" loaded\")\n"); zip.file(folder+"requirements.txt",reqsTxt); zip.file(folder+".env.example","# Environment variables\n"); zip.file(folder+"README.md","# "+title+"\n\nGenerated by PantheraHive BOS.\n\n## Setup\n\`\`\`bash\npython3 -m venv .venv\nsource .venv/bin/activate\npip install -r requirements.txt\n\`\`\`\n\n## Run\n\`\`\`bash\npython main.py\n\`\`\`\n"); zip.file(folder+".gitignore",".venv/\n__pycache__/\n*.pyc\n.env\n.DS_Store\n"); } /* --- Node.js --- */ function buildNode(zip,folder,app,code){ var title=slugTitle(app); var pn=pkgName(app); var src=code.replace(/^\`\`\`[\w]*\n?/m,"").replace(/\n?\`\`\`$/m,"").trim(); var depMap={"mongoose":"^8.0.0","dotenv":"^16.4.5","axios":"^1.7.9","cors":"^2.8.5","bcryptjs":"^2.4.3","jsonwebtoken":"^9.0.2","socket.io":"^4.7.4","uuid":"^9.0.1","zod":"^3.22.4","express":"^4.18.2"}; var deps={}; Object.keys(depMap).forEach(function(k){if(src.indexOf(k)>=0)deps[k]=depMap[k];}); if(!deps["express"])deps["express"]="^4.18.2"; var pkgJson=JSON.stringify({"name":pn,"version":"1.0.0","main":"src/index.js","scripts":{"start":"node src/index.js","dev":"nodemon src/index.js"},"dependencies":deps,"devDependencies":{"nodemon":"^3.0.3"}},null,2)+"\n"; zip.file(folder+"package.json",pkgJson); var fallback="const express=require(\"express\");\nconst app=express();\napp.use(express.json());\n\napp.get(\"/\",(req,res)=>{\n res.json({message:\""+title+" API\"});\n});\n\nconst PORT=process.env.PORT||3000;\napp.listen(PORT,()=>console.log(\"Server on port \"+PORT));\n"; zip.file(folder+"src/index.js",src||fallback); zip.file(folder+".env.example","PORT=3000\n"); zip.file(folder+".gitignore","node_modules/\n.env\n.DS_Store\n"); zip.file(folder+"README.md","# "+title+"\n\nGenerated by PantheraHive BOS.\n\n## Setup\n\`\`\`bash\nnpm install\n\`\`\`\n\n## Run\n\`\`\`bash\nnpm run dev\n\`\`\`\n"); } /* --- Vanilla HTML --- */ function buildVanillaHtml(zip,folder,app,code){ var title=slugTitle(app); var isFullDoc=code.trim().toLowerCase().indexOf("=0||code.trim().toLowerCase().indexOf("=0; var indexHtml=isFullDoc?code:"\n\n\n\n\n"+title+"\n\n\n\n"+code+"\n\n\n\n"; zip.file(folder+"index.html",indexHtml); zip.file(folder+"style.css","/* "+title+" — styles */\n*{margin:0;padding:0;box-sizing:border-box}\nbody{font-family:system-ui,-apple-system,sans-serif;background:#fff;color:#1a1a2e}\n"); zip.file(folder+"script.js","/* "+title+" — scripts */\n"); zip.file(folder+"assets/.gitkeep",""); zip.file(folder+"README.md","# "+title+"\n\nGenerated by PantheraHive BOS.\n\n## Open\nDouble-click \`index.html\` in your browser.\n\nOr serve locally:\n\`\`\`bash\nnpx serve .\n# or\npython3 -m http.server 3000\n\`\`\`\n"); zip.file(folder+".gitignore",".DS_Store\nnode_modules/\n.env\n"); } /* ===== MAIN ===== */ var sc=document.createElement("script"); sc.src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"; sc.onerror=function(){ if(lbl)lbl.textContent="Download ZIP"; alert("JSZip load failed — check connection."); }; sc.onload=function(){ var zip=new JSZip(); var base=(_phFname||"output").replace(/\.[^.]+$/,""); var app=base.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"my_app"; var folder=app+"/"; var vc=document.getElementById("panel-content"); var panelTxt=vc?(vc.innerText||vc.textContent||""):""; var lang=detectLang(_phCode,panelTxt); if(_phIsHtml){ buildVanillaHtml(zip,folder,app,_phCode); } else if(lang==="flutter"){ buildFlutter(zip,folder,app,_phCode,panelTxt); } else if(lang==="react-native"){ buildReactNative(zip,folder,app,_phCode,panelTxt); } else if(lang==="swift"){ buildSwift(zip,folder,app,_phCode,panelTxt); } else if(lang==="kotlin"){ buildKotlin(zip,folder,app,_phCode,panelTxt); } else if(lang==="react"){ buildReact(zip,folder,app,_phCode,panelTxt); } else if(lang==="vue"){ buildVue(zip,folder,app,_phCode,panelTxt); } else if(lang==="angular"){ buildAngular(zip,folder,app,_phCode,panelTxt); } else if(lang==="python"){ buildPython(zip,folder,app,_phCode); } else if(lang==="node"){ buildNode(zip,folder,app,_phCode); } else { /* Document/content workflow */ var title=app.replace(/_/g," "); var md=_phAll||_phCode||panelTxt||"No content"; zip.file(folder+app+".md",md); var h=""+title+""; h+="

"+title+"

"; var hc=md.replace(/&/g,"&").replace(//g,">"); hc=hc.replace(/^### (.+)$/gm,"

$1

"); hc=hc.replace(/^## (.+)$/gm,"

$1

"); hc=hc.replace(/^# (.+)$/gm,"

$1

"); hc=hc.replace(/\*\*(.+?)\*\*/g,"$1"); hc=hc.replace(/\n{2,}/g,"

"); h+="

"+hc+"

Generated by PantheraHive BOS
"; zip.file(folder+app+".html",h); zip.file(folder+"README.md","# "+title+"\n\nGenerated by PantheraHive BOS.\n\nFiles:\n- "+app+".md (Markdown)\n- "+app+".html (styled HTML)\n"); } zip.generateAsync({type:"blob"}).then(function(blob){ var a=document.createElement("a"); a.href=URL.createObjectURL(blob); a.download=app+".zip"; a.click(); URL.revokeObjectURL(a.href); if(lbl)lbl.textContent="Download ZIP"; }); }; document.head.appendChild(sc); } function phShare(){navigator.clipboard.writeText(window.location.href).then(function(){var el=document.getElementById("ph-share-lbl");if(el){el.textContent="Link copied!";setTimeout(function(){el.textContent="Copy share link";},2500);}});}function phEmbed(){var runId=window.location.pathname.split("/").pop().replace(".html","");var embedUrl="https://pantherahive.com/embed/"+runId;var code='';navigator.clipboard.writeText(code).then(function(){var el=document.getElementById("ph-embed-lbl");if(el){el.textContent="Embed code copied!";setTimeout(function(){el.textContent="Get Embed Code";},2500);}});}