{
  "openapi": "3.0.3",
  "info": {
    "title": "Dangling Dice Studios™ Central & Stateless Compute API",
    "version": "1.2.0",
    "description": "Official unified developer API for Dangling Dice Studios™. Includes Media Converter, Discovery & SEO, Catalog & Releases, plus 15+ ultra-low-latency (<15ms) Stateless Compute APIs for FinTech Amortization, Software Project Scoping, JSON/Zod/SQL Schema Inference, GIS Parcel & WireGuard Config Generation, and HIPAA/PCI-DSS PII Scrubbing.",
    "contact": {
      "name": "Dangling Dice Studios™ Engineering",
      "url": "https://dangling-dice-studios.com/",
      "email": "jacob.yancey@danglingdicestudios.com"
    },
    "license": {
      "name": "MIT",
      "url": "https://opensource.org/licenses/MIT"
    }
  },
  "servers": [
    {
      "url": "https://dangling-dice-studios.com",
      "description": "Production Direct Gateway"
    },
    {
      "url": "https://dangling-dice-studios.com/api",
      "description": "Production Sub-Path Gateway (/api prefix)"
    },
    {
      "url": "http://localhost:4100",
      "description": "Local Stateless Compute Gateway"
    }
  ],
  "tags": [
    { "name": "Media Converter", "description": "YouTube to MP3 (320kbps) & MP4 media stream extraction" },
    { "name": "Discovery & SEO", "description": "oEmbed 1.0 rich preview generation & crawler endpoints" },
    { "name": "Catalog & Releases", "description": "Dangling Beats instrumentals, coding tutorials, and apps" },
    { "name": "Schema Engine", "description": "JSON to Zod/TypeScript/SQL DDL inference, SQL-to-TS compiler, and Database URI validator" },
    { "name": "Finance Engine", "description": "Penny-accurate loan amortization, extra payment simulator, cash flow metrics, and software project scoping" },
    { "name": "Geo & Network Engine", "description": "GIS polygon acreage/perimeter, Haversine distance/bearing, WireGuard tunnel generator, and DocScanner sessions" },
    { "name": "Privacy Engine", "description": "Luhn credit card & PII text redaction, recursive JSON secret masking, and HIPAA PHI telemetry firewall" },
    { "name": "Connected Ecosystem", "description": "DaaS stealth web scraper job dispatcher and Marketing Leviathan local AI generator" },
    { "name": "System & Telemetry", "description": "Real-time health diagnostics, database state, and request counters" }
  ],
  "paths": {
    "/media/convert": {
      "post": {
        "operationId": "convertMediaStream",
        "tags": ["Media Converter"],
        "summary": "Extract Audio/Video Stream from URL",
        "description": "Validates a public YouTube or audio URL and returns resolved high-speed download streams for MP3 (192kbps/320kbps) or MP4.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url"],
                "properties": {
                  "url": { "type": "string", "example": "https://www.youtube.com/watch?v=Db7ZrUtuCxU" },
                  "format": { "type": "string", "enum": ["mp3-320", "mp3-192", "mp4"], "default": "mp3-320" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Stream metadata and direct download link resolved" },
          "400": { "description": "Invalid URL or SSRF attempt blocked" }
        }
      }
    },
    "/oembed": {
      "get": {
        "operationId": "getOembedRichPreview",
        "tags": ["Discovery & SEO"],
        "summary": "oEmbed 1.0 Rich Preview Provider",
        "description": "Returns compliant oEmbed 1.0 JSON representation used by Discord, Twitter/X, Reddit, and Slack for rich embeds.",
        "parameters": [
          {
            "name": "url",
            "in": "query",
            "required": true,
            "description": "The target URL to generate rich embed metadata for.",
            "schema": { "type": "string", "example": "https://dangling-dice-studios.com/" }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "The requested serialization format (defaults to json).",
            "schema": { "type": "string", "enum": ["json"], "default": "json" }
          }
        ],
        "responses": {
          "200": { "description": "Standard oEmbed 1.0 JSON payload" }
        }
      }
    },
    "/affiliates": {
      "get": {
        "operationId": "listPartnerDeals",
        "tags": ["Discovery & SEO"],
        "summary": "Verified Cloud Credits & Partner Deals",
        "description": "Returns verified developer cloud credits (DigitalOcean $200, MongoDB Atlas) and music production perks.",
        "responses": {
          "200": { "description": "Directory of verified developer partner deals" }
        }
      }
    },
    "/items": {
      "get": {
        "operationId": "listCatalogItems",
        "tags": ["Catalog & Releases"],
        "summary": "List Studio Resources & Beats",
        "description": "Fetches verified studio releases, including Dangling Beats music instrumentals, coding courses, and phone apps.",
        "parameters": [
          {
            "name": "category",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["All", "Coding Tutorials", "Beats & Audio", "Mobile Apps", "Developer Tools"]
            }
          }
        ],
        "responses": {
          "200": { "description": "List of catalog items" }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "getSystemHealth",
        "tags": ["System & Telemetry"],
        "summary": "System Health & Live Analytics",
        "description": "Returns operational status, database connectivity, server uptime, and active compute engine modules.",
        "responses": {
          "200": { "description": "Service is healthy and operational" }
        }
      }
    },
    "/v1/schema/infer": {
      "post": {
        "operationId": "inferSchemaFromJson",
        "tags": ["Schema Engine"],
        "summary": "Infer Zod, TypeScript, JSON Schema, and Postgres DDL from JSON",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["jsonInput"],
                "properties": {
                  "jsonInput": {
                    "type": "string",
                    "description": "Raw JSON string or serialized JSON object",
                    "example": "{\"userId\": 1024, \"email\": \"founder@dangling-dice-studios.com\", \"active\": true}"
                  },
                  "rootName": { "type": "string", "default": "RootRecord" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Generated TypeScript, Zod, JSON Schema, and SQL DDL" }
        }
      }
    },
    "/v1/schema/sql-to-ts": {
      "post": {
        "operationId": "convertSqlToTypeScript",
        "tags": ["Schema Engine"],
        "summary": "Convert SQL CREATE TABLE DDL into TypeScript interfaces and Zod schemas",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["sqlDdl"],
                "properties": {
                  "sqlDdl": {
                    "type": "string",
                    "example": "CREATE TABLE users (id UUID PRIMARY KEY, email VARCHAR(255) NOT NULL, created_at TIMESTAMPTZ);"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Generated TypeScript & Zod definitions" }
        }
      }
    },
    "/v1/schema/inspect-uri": {
      "post": {
        "operationId": "inspectDatabaseConnectionUri",
        "tags": ["Schema Engine"],
        "summary": "Validate MongoDB, PostgreSQL, or Redis connection strings and RFC-3986 encode credentials",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["uri"],
                "properties": {
                  "uri": {
                    "type": "string",
                    "example": "mongodb+srv://admin:p@ss:word#1@cluster0.example.mongodb.net/prod_db"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Encoded safe URI, .env snippet, and diagnostic warnings" }
        }
      }
    },
    "/v1/finance/amortization": {
      "post": {
        "operationId": "calculateLoanAmortization",
        "tags": ["Finance Engine"],
        "summary": "Generate penny-accurate monthly loan amortization schedule",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["principal", "annualRatePercent", "termMonths"],
                "properties": {
                  "principal": { "type": "number", "example": 350000 },
                  "annualRatePercent": { "type": "number", "example": 6.5 },
                  "termMonths": { "type": "integer", "example": 360 }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Monthly payment, total interest, and full schedule" }
        }
      }
    },
    "/v1/finance/extra-payments": {
      "post": {
        "operationId": "simulateExtraLoanPayments",
        "tags": ["Finance Engine"],
        "summary": "Compare baseline loan against accelerated payoff with extra payments",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["principal", "annualRatePercent", "termMonths"],
                "properties": {
                  "principal": { "type": "number", "example": 350000 },
                  "annualRatePercent": { "type": "number", "example": 6.5 },
                  "termMonths": { "type": "integer", "example": 360 },
                  "extraMonthlyPayment": { "type": "number", "default": 300 },
                  "oneTimeExtraPayment": { "type": "number", "default": 5000 }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Interest saved, months shaved, and accelerated schedule" }
        }
      }
    },
    "/v1/finance/cash-flow": {
      "post": {
        "operationId": "calculateCashFlowMetrics",
        "tags": ["Finance Engine"],
        "summary": "Compute Net Present Value (NPV), Internal Rate of Return (IRR), ROI, and Payback Period",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["discountRatePercent", "initialInvestment", "cashFlows"],
                "properties": {
                  "discountRatePercent": { "type": "number", "example": 8.0 },
                  "initialInvestment": { "type": "number", "example": 100000 },
                  "cashFlows": {
                    "type": "array",
                    "items": { "type": "number" },
                    "example": [28000, 34000, 42000, 48000]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "NPV, IRR percentage, payback period, and ROI" }
        }
      }
    },
    "/v1/finance/project-scope": {
      "post": {
        "operationId": "calculateSoftwareProjectScope",
        "tags": ["Finance Engine"],
        "summary": "Calculate software engineering hours, cost brackets, and 50% deposit (Code_Craft Engine)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["category", "hasBrandAssets", "hasWrittenContent", "hasDomainAndDns", "designPreference"],
                "properties": {
                  "category": {
                    "type": "string",
                    "enum": ["WEBSITE_CREATION", "FULLSTACK", "MOBILE_APPS", "ECOMMERCE", "CUSTOM_INTEGRATION"],
                    "example": "FULLSTACK"
                  },
                  "hasBrandAssets": { "type": "boolean", "example": true },
                  "hasWrittenContent": { "type": "boolean", "example": false },
                  "hasDomainAndDns": { "type": "boolean", "example": true },
                  "designPreference": {
                    "type": "string",
                    "enum": ["component_library", "bespoke_scratch"],
                    "example": "bespoke_scratch"
                  },
                  "hourlyRateUsd": { "type": "number", "default": 80 }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Deterministic hour range, cost bracket, and 50% deposit" }
        }
      }
    },
    "/v1/geo/parcel-metrics": {
      "post": {
        "operationId": "calculateParcelMetrics",
        "tags": ["Geo & Network Engine"],
        "summary": "Calculate polygon acreage, square feet, hectares, perimeter, and centroid",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["coordinates"],
                "properties": {
                  "coordinates": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": { "type": "number" }
                    },
                    "example": [
                      [-97.7431, 30.2672],
                      [-97.7421, 30.2672],
                      [-97.7421, 30.2682],
                      [-97.7431, 30.2682]
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Computed parcel area and boundary metrics" }
        }
      }
    },
    "/v1/geo/distance": {
      "post": {
        "operationId": "calculateDistanceAndBearing",
        "tags": ["Geo & Network Engine"],
        "summary": "Compute Haversine distance, compass bearing, and midpoint between two coordinates",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["from", "to"],
                "properties": {
                  "from": {
                    "type": "object",
                    "required": ["lat", "lng"],
                    "properties": {
                      "lat": { "type": "number", "example": 30.2672 },
                      "lng": { "type": "number", "example": -97.7431 }
                    }
                  },
                  "to": {
                    "type": "object",
                    "required": ["lat", "lng"],
                    "properties": {
                      "lat": { "type": "number", "example": 32.7767 },
                      "lng": { "type": "number", "example": -96.797 }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Distance in meters, km, miles, feet + bearing and midpoint" }
        }
      }
    },
    "/v1/geo/wireguard-config": {
      "post": {
        "operationId": "generateWireGuardTunnelConfig",
        "tags": ["Geo & Network Engine"],
        "summary": "Generate deterministic WireGuard client .conf and server peer snippets (Dangling Dice VPN)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["clientName", "serverEndpoint"],
                "properties": {
                  "clientName": { "type": "string", "example": "workstation-alpha" },
                  "serverEndpoint": { "type": "string", "example": "vpn.dangling-dice-studios.com:51820" },
                  "peerIndex": { "type": "integer", "default": 2 }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Generated WireGuard client and server configuration blocks" }
        }
      }
    },
    "/v1/geo/docscan-session": {
      "post": {
        "operationId": "buildDocScannerSession",
        "tags": ["Geo & Network Engine"],
        "summary": "Generate Android DocScanner deep links and QR webhook upload payloads",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["sessionId", "callbackUrl"],
                "properties": {
                  "sessionId": { "type": "string", "example": "scan_99481a" },
                  "callbackUrl": { "type": "string", "example": "https://dangling-dice-studios.com/webhooks/docscan" },
                  "documentTitle": { "type": "string", "example": "Signed_MSA_Contract.pdf" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Deep link URI, QR payload, and PDF geometry metadata" }
        }
      }
    },
    "/v1/privacy/redact": {
      "post": {
        "operationId": "redactPiiText",
        "tags": ["Privacy Engine"],
        "summary": "Sanitize PII (Emails, SSNs, Luhn-checked Credit Cards, Phones, IPs, API Keys)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["text"],
                "properties": {
                  "text": {
                    "type": "string",
                    "example": "Customer jane@acme.io paid with card 4532015112830366 and SSN 123-45-6789."
                  },
                  "mode": { "type": "string", "enum": ["placeholder", "mask", "hash"], "default": "placeholder" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Sanitized text and category breakdown" }
        }
      }
    },
    "/v1/privacy/mask-json": {
      "post": {
        "operationId": "maskSensitiveJsonPayload",
        "tags": ["Privacy Engine"],
        "summary": "Recursively mask passwords, tokens, SSNs, and secrets in nested JSON objects",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["payload"],
                "properties": {
                  "payload": {
                    "type": "object",
                    "example": { "user": "jacob", "password": "super_secret_password", "stripeToken": "sk_live_999" }
                  },
                  "sensitiveKeys": { "type": "array", "items": { "type": "string" } }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Masked JSON object and list of redacted key paths" }
        }
      }
    },
    "/v1/privacy/hipaa-scrub": {
      "post": {
        "operationId": "scrubHipaaAnalyticsTelemetry",
        "tags": ["Privacy Engine"],
        "summary": "Strip HIPAA PHI fields and ad-tech tracking IDs from analytics telemetry (Titrate-Health Engine)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["payload"],
                "properties": {
                  "payload": {
                    "type": "object",
                    "example": { "event": "dosage_logged", "patientName": "John Doe", "dosageMg": 25, "fbclid": "IwAR123" }
                  },
                  "queryUrl": {
                    "type": "string",
                    "example": "https://app.titrate.health/log?utm_source=meta&fbclid=IwAR999&gclid=Cj0KCQ"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Sanitized payload and list of stripped PHI & tracker fields" }
        }
      }
    },
    "/v1/extract/scrape-job": {
      "post": {
        "operationId": "dispatchDaasScrapeJob",
        "tags": ["Connected Ecosystem"],
        "summary": "Dispatch stealth browser extraction job to DaaS Scraper BullMQ cluster",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["targetUrl"],
                "properties": {
                  "targetUrl": { "type": "string", "example": "https://example.com/pricing" },
                  "proxyMode": { "type": "string", "enum": ["tor_socks5", "residential_fallback"] }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Queued job ID and cluster node status" }
        }
      }
    },
    "/v1/ai/leviathan-generate": {
      "post": {
        "operationId": "dispatchLeviathanAiPrompt",
        "tags": ["Connected Ecosystem"],
        "summary": "Dispatch prompt to Marketing Leviathan & local LLM engine",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["prompt"],
                "properties": {
                  "prompt": { "type": "string", "example": "Generate a launch campaign for our new JSON-to-Zod API." },
                  "modelType": { "type": "string", "enum": ["coding", "general", "marketing_leviathan"] }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Dispatched model response metadata" }
        }
      }
    }
  }
}
