{
  "id": "ds-wf-analyzer-11",
  "meta": {
    "instanceId": "vorlux-hub"
  },
  "name": "Vorlux AI | Dataset Workflow Analyzer (Weekly Pattern Extraction)",
  "active": true,
  "nodes": [
    {
      "id": "e1f2a3b4-0011-4eee-8011-000000000001",
      "name": "Weekly Wednesday",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [220, 300],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 168
            }
          ]
        }
      }
    },
    {
      "id": "e1f2a3b4-0011-4eee-8011-000000000002",
      "name": "List All n8n Workflows",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 300],
      "parameters": {
        "method": "GET",
        "url": "={{$env.N8N_BASE_URL || 'http://localhost:5678'}}/api/v1/workflows?limit=2000",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "timeout": 30000
        }
      },
      "notes": "Fetches all workflows from n8n API (1680+ expected)"
    },
    {
      "id": "e1f2a3b4-0011-4eee-8011-000000000003",
      "name": "Extract Patterns",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [700, 300],
      "notes": "Analyzes ALL workflows and extracts: node types, connection patterns, trigger types, API endpoints, common chains",
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const workflows = $input.first().json.data || [];\n\nconst nodeTypeCounts = {};\nconst triggerTypes = {};\nconst apiEndpoints = new Set();\nconst connectionPatterns = {};\nconst chains = {};\nlet totalNodes = 0;\nlet totalConnections = 0;\n\nfor (const wf of workflows) {\n  const nodes = wf.nodes || [];\n  const connections = wf.connections || {};\n  totalNodes += nodes.length;\n  \n  // Count node types\n  for (const node of nodes) {\n    const type = node.type || 'unknown';\n    nodeTypeCounts[type] = (nodeTypeCounts[type] || 0) + 1;\n    \n    // Detect triggers\n    if (type.includes('Trigger') || type.includes('trigger')) {\n      triggerTypes[type] = (triggerTypes[type] || 0) + 1;\n    }\n    \n    // Extract API endpoints from httpRequest nodes\n    if (type.includes('httpRequest') && node.parameters?.url) {\n      const url = node.parameters.url.replace(/={{.*?}}/g, '{env}');\n      const path = url.replace(/https?:\\/\\/[^/]+/, '').replace(/\\?.*/,'');\n      if (path.startsWith('/api/')) apiEndpoints.add(path);\n    }\n  }\n  \n  // Analyze connection patterns\n  for (const [fromNode, conns] of Object.entries(connections)) {\n    const fromType = nodes.find(n => n.name === fromNode)?.type || 'unknown';\n    totalConnections++;\n    for (const branch of (conns.main || [])) {\n      for (const conn of (branch || [])) {\n        const toType = nodes.find(n => n.name === conn.node)?.type || 'unknown';\n        const pattern = `${fromType.split('.').pop()} -> ${toType.split('.').pop()}`;\n        connectionPatterns[pattern] = (connectionPatterns[pattern] || 0) + 1;\n      }\n    }\n  }\n  \n  // Detect common chains (3-node sequences)\n  for (const [startNode, conns] of Object.entries(connections)) {\n    const startType = nodes.find(n => n.name === startNode)?.type?.split('.').pop() || '?';\n    for (const branch of (conns.main || [])) {\n      for (const conn of (branch || [])) {\n        const midType = nodes.find(n => n.name === conn.node)?.type?.split('.').pop() || '?';\n        const midConns = connections[conn.node];\n        if (midConns?.main) {\n          for (const b2 of midConns.main) {\n            for (const c2 of (b2 || [])) {\n              const endType = nodes.find(n => n.name === c2.node)?.type?.split('.').pop() || '?';\n              const chain = `${startType} -> ${midType} -> ${endType}`;\n              chains[chain] = (chains[chain] || 0) + 1;\n            }\n          }\n        }\n      }\n    }\n  }\n}\n\n// Sort and take top entries\nconst sortObj = (obj, limit) => Object.fromEntries(Object.entries(obj).sort((a,b) => b[1] - a[1]).slice(0, limit));\n\nconst catalog = {\n  totalWorkflows: workflows.length,\n  totalNodes,\n  totalConnections,\n  nodeTypes: sortObj(nodeTypeCounts, 100),\n  uniqueNodeTypes: Object.keys(nodeTypeCounts).length,\n  triggerTypes: sortObj(triggerTypes, 20),\n  apiEndpoints: [...apiEndpoints].sort().slice(0, 50),\n  connectionPatterns: sortObj(connectionPatterns, 30),\n  commonChains: sortObj(chains, 20),\n  vorluxWorkflows: workflows.filter(w => (w.name || '').startsWith('Vorlux AI')).length,\n  communityWorkflows: workflows.filter(w => !(w.name || '').startsWith('Vorlux AI')).length\n};\n\nreturn [{ json: catalog }];"
      }
    },
    {
      "id": "e1f2a3b4-0011-4eee-8011-000000000004",
      "name": "Store Pattern Catalog",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [960, 200],
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/admin/knowledge/store",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ type: 'workflow_pattern_catalog', data: $json, timestamp: new Date().toISOString() }) }}",
        "options": {
          "timeout": 30000
        }
      }
    },
    {
      "id": "e1f2a3b4-0011-4eee-8011-000000000005",
      "name": "Discord Report",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [960, 400],
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"embeds\":[{\"title\":\"Workflow Pattern Analysis\",\"description\":\"**Total workflows:** {{ $json.totalWorkflows }} (Vorlux AI: {{ $json.vorluxWorkflows }}, Community: {{ $json.communityWorkflows }})\\n**Total nodes:** {{ $json.totalNodes }}\\n**Unique node types:** {{ $json.uniqueNodeTypes }}\\n\\n**Top 10 Node Types:**\\n{{ Object.entries($json.nodeTypes || {}).slice(0,10).map(([k,v]) => k.split('.').pop() + ': ' + v).join('\\\\n') }}\\n\\n**Top 5 Chains:**\\n{{ Object.entries($json.commonChains || {}).slice(0,5).map(([k,v]) => k + ' (' + v + 'x)').join('\\\\n') }}\",\"color\":3447003,\"footer\":{\"text\":\"Weekly Workflow Analyzer\"}}]}",
        "options": {
          "timeout": 10000
        }
      }
    }
  ],
  "connections": {
    "Weekly Wednesday": {
      "main": [
        [
          {
            "node": "List All n8n Workflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List All n8n Workflows": {
      "main": [
        [
          {
            "node": "Extract Patterns",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Patterns": {
      "main": [
        [
          {
            "node": "Store Pattern Catalog",
            "type": "main",
            "index": 0
          },
          {
            "node": "Discord Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  },
  "tags": [
    { "name": "ai" },
    { "name": "dataset" },
    { "name": "analysis" }
  ],
  "versionId": "2"
}