{
    "name": "n8n Workflow Analyzer and Vector Storage System",
    "nodes": [
        {
            "parameters": {
                "conditions": {
                    "options": {
                        "caseSensitive": true,
                        "leftValue": "",
                        "typeValidation": "strict",
                        "version": 1
                    },
                    "conditions": [
                        {
                            "leftValue": "={{$json.stored_version}}",
                            "rightValue": "={{$json.version}}",
                            "operator": {
                                "type": "string",
                                "operation": "notEquals"
                            },
                            "id": "81e60ef5-0b4c-4914-a116-f22c875597f3"
                        },
                        {
                            "leftValue": "={{ $json.file_id }}",
                            "rightValue": "",
                            "operator": {
                                "type": "string",
                                "operation": "isEmpty"
                            },
                            "id": "2c7a184e-0de9-4a07-af5d-1ff73c3d0e25"
                        },
                        {
                            "id": "010623f1-f2f0-470c-bb80-8846645b13b5",
                            "leftValue": "={{$json.stored_version}}",
                            "rightValue": "",
                            "operator": {
                                "type": "string",
                                "operation": "empty",
                                "singleValue": true
                            }
                        }
                    ],
                    "combinator": "or"
                },
                "options": []
            },
            "type": "n8n-nodes-base.if",
            "typeVersion": 2,
            "position": [
                576,
                80
            ],
            "id": "c3d4e5f6-a7b8-9012-cdef-345678901234",
            "name": "Is New or Updated?"
        },
        {
            "parameters": {
                "operation": "download",
                "fileId": {
                    "__rl": true,
                    "value": "={{ $json.file_id }}",
                    "mode": "id"
                },
                "options": []
            },
            "type": "n8n-nodes-base.googleDrive",
            "typeVersion": 3,
            "position": [
                800,
                80
            ],
            "id": "d4e5f6a7-b8c9-0123-defa-456789012345",
            "name": "Download Workflow File",
            "credentials": {
                "googleDriveOAuth2Api": {
                    "id": "3GeY38MVrO78i1ns",
                    "name": "Google Drive account"
                }
            }
        },
        {
            "parameters": {
                "jsCode": "\/\/ قراءة مباشرة إذا الملف JSON\nconst workflowContent = $json;\n\n\/\/ إنشاء الميتاداتا\nconst metadata = {\n  fileId: $json.id || '',\n  fileName: $json.name || '',\n  modifiedTime: $json.modifiedTime || '',\n  workflowName: workflowContent.name || 'Unnamed Workflow',\n  nodeCount: workflowContent.nodes?.length || 0,\n  nodes: workflowContent.nodes || [],\n  connections: workflowContent.connections || {},\n  categories: [],\n  applications: new Set(),\n  workflowType: ''\n};\n\nreturn [{ json: { metadata, workflowContent } }];\n"
            },
            "type": "n8n-nodes-base.code",
            "typeVersion": 2,
            "position": [
                1024,
                80
            ],
            "id": "e5f6a7b8-c9d0-1234-efab-567890123456",
            "name": "Analyze Workflow Structure"
        },
        {
            "parameters": {
                "jsCode": "\/\/ جلب البيانات من العقدة السابقة\nconst inputData = $input.first()?.json || {};\n\nif (!inputData.metadata) {\n  throw new Error(\"لا توجد بيانات metadata من العقدة السابقة.\");\n}\n\nconst metadata = inputData.metadata;\nconst fullWorkflow = inputData.workflowContent || {};\n\n\/\/ إنشاء نص وصفي للـ embedding\nconst descriptionText = `\nWorkflow Name: ${metadata.workflowName}\nType: ${metadata.workflowType}\nCategories: ${(metadata.categories || []).join(', ')}\nApplications: ${(metadata.applications || []).join(', ')}\nNodes: ${(metadata.nodes || []).map(n => `${n.name} (${n.type})`).join(', ')}\nNode Count: ${metadata.nodeCount}\n`;\n\n\/\/ إعداد البيانات للتخزين\nconst vectorData = {\n  id: metadata.fileId,\n  text: descriptionText,\n  metadata: {\n    fileId: metadata.fileId,\n    fileName: metadata.fileName,\n    workflowName: metadata.workflowName,\n    workflowType: metadata.workflowType,\n    categories: metadata.categories,\n    applications: metadata.applications,\n    nodeCount: metadata.nodeCount,\n    modifiedTime: metadata.modifiedTime,\n    nodeTypes: (metadata.nodes || []).map(n => n.type),\n    workflowJson: JSON.stringify(fullWorkflow)\n  }\n};\n\nreturn vectorData;\n"
            },
            "type": "n8n-nodes-base.code",
            "typeVersion": 2,
            "position": [
                1456,
                80
            ],
            "id": "a7b8c9d0-e1f2-3456-abcd-789012345678",
            "name": "Prepare Vector Data"
        },
        {
            "parameters": {
                "pineconeIndex": {
                    "__rl": true,
                    "value": "n8n-workflow-analyzer",
                    "mode": "list",
                    "cachedResultName": "n8n-workflow-analyzer"
                },
                "options": {
                    "pineconeNamespace": "n8n-workflow-josn-file"
                }
            },
            "type": "@n8n\/n8n-nodes-langchain.vectorStorePinecone",
            "typeVersion": 1,
            "position": [
                1680,
                192
            ],
            "id": "b8c9d0e1-f2a3-4567-bcde-890123456789",
            "name": "Store in Pinecone",
            "credentials": {
                "pineconeApi": {
                    "id": "eliwNj7WZ1PTR4Zl",
                    "name": "PineconeApi account"
                }
            }
        },
        {
            "parameters": {
                "operation": "executeQuery",
                "query": "INSERT INTO processed_workflows (file_id, file_name, workflow_name, workflow_type, categories, last_processed_time, node_count)\nVALUES (\n  '{{ $json.metadata.fileId }}',\n  '{{ $json.metadata.fileName }}',\n  '{{ $json.metadata.workflowName }}',\n  '{{ $json.metadata.workflowType }}',\n  '{{ $json.metadata.categories.join(\",\") }}',\n  '{{ $json.metadata.modifiedTime }}',\n  {{ $json.metadata.nodeCount }}\n)\nON CONFLICT (file_id) DO UPDATE SET\n  file_name = EXCLUDED.file_name,\n  workflow_name = EXCLUDED.workflow_name,\n  workflow_type = EXCLUDED.workflow_type,\n  categories = EXCLUDED.categories,\n  last_processed_time = EXCLUDED.last_processed_time,\n  node_count = EXCLUDED.node_count;",
                "options": []
            },
            "type": "n8n-nodes-base.postgres",
            "typeVersion": 2.5,
            "position": [
                2048,
                176
            ],
            "id": "c9d0e1f2-a3b4-5678-cdef-901234567890",
            "name": "Update Processing Record",
            "credentials": {
                "postgres": {
                    "id": "VrRSp705gu0IHQy1",
                    "name": "Postgres account"
                }
            }
        },
        {
            "parameters": {
                "chatId": "7340018958",
                "text": "{{ $json.name }} تمت معالجته بنجاح.",
                "additionalFields": []
            },
            "type": "n8n-nodes-base.telegram",
            "typeVersion": 1.2,
            "position": [
                2272,
                176
            ],
            "id": "d0e1f2a3-b4c5-6789-defa-012345678901",
            "name": "Send Success Notification",
            "webhookId": "22aad1d2-4c07-4bbe-b102-a456a90f7fbb",
            "credentials": {
                "telegramApi": {
                    "id": "S13dG3LjlpvCmdMl",
                    "name": "Telegram account"
                }
            }
        },
        {
            "parameters": {
                "assignments": {
                    "assignments": [
                        {
                            "id": "be9d7dbd-14ef-486d-bbde-b2a0b13d6fb6",
                            "name": "file_id",
                            "value": "={{ $json.id }}",
                            "type": "string"
                        },
                        {
                            "id": "bd6f6c18-7d86-43ff-a857-9e8886d9c61e",
                            "name": "version",
                            "value": "={{ $json.version }}",
                            "type": "string"
                        }
                    ]
                },
                "includeOtherFields": "=",
                "options": []
            },
            "type": "n8n-nodes-base.set",
            "typeVersion": 3.4,
            "position": [
                352,
                80
            ],
            "id": "f18f5c41-505a-4a4f-9c29-a55185f9d70b",
            "name": "Edit Fields"
        },
        {
            "parameters": {
                "model": "text-embedding-3-large",
                "options": []
            },
            "type": "@n8n\/n8n-nodes-langchain.embeddingsOpenAi",
            "typeVersion": 1.2,
            "position": [
                1712,
                400
            ],
            "id": "e6cb25df-5218-4427-86ac-aa941327b4ac",
            "name": "Embeddings OpenAI",
            "credentials": {
                "openAiApi": {
                    "id": "XMEsLBYvPf9TQsy0",
                    "name": "OpenAi account"
                }
            }
        },
        {
            "parameters": {
                "mode": "combine",
                "advanced": true,
                "mergeByFields": {
                    "values": [
                        {
                            "field1": "file_id",
                            "field2": "file_id"
                        }
                    ]
                },
                "joinMode": "keepNonMatches",
                "options": []
            },
            "type": "n8n-nodes-base.merge",
            "typeVersion": 3.2,
            "position": [
                128,
                480
            ],
            "id": "62b8261d-311e-4799-bdcf-a8fa72d708e1",
            "name": "Merge"
        },
        {
            "parameters": {
                "resource": "fileFolder",
                "returnAll": true,
                "filter": {
                    "folderId": {
                        "__rl": true,
                        "value": "1VElyeAJkNuQgp4D7nHJRPSsuGT2YxnKy",
                        "mode": "list",
                        "cachedResultName": "n8n workflow",
                        "cachedResultUrl": "https:\/\/drive.google.com\/drive\/folders\/1VElyeAJkNuQgp4D7nHJRPSsuGT2YxnKy"
                    }
                },
                "options": {
                    "fields": [
                        "version",
                        "id"
                    ]
                }
            },
            "type": "n8n-nodes-base.googleDrive",
            "typeVersion": 3,
            "position": [
                128,
                80
            ],
            "id": "a2d51ed6-f54e-4612-8c75-6916fad23a56",
            "name": "Search files and folders",
            "alwaysOutputData": false,
            "credentials": {
                "googleDriveOAuth2Api": {
                    "id": "3GeY38MVrO78i1ns",
                    "name": "Google Drive account"
                }
            }
        },
        {
            "parameters": {
                "rule": {
                    "interval": [
                        []
                    ]
                }
            },
            "type": "n8n-nodes-base.scheduleTrigger",
            "typeVersion": 1.2,
            "position": [
                -96,
                80
            ],
            "id": "9085a156-3d15-4219-a96c-a3b5c7807dd5",
            "name": "Schedule Trigger"
        },
        {
            "parameters": {
                "operation": "executeQuery",
                "query": "SELECT DISTINCT file_id\nFROM public.\"processed_workflows\";",
                "options": []
            },
            "type": "n8n-nodes-base.postgres",
            "typeVersion": 2.6,
            "position": [
                -96,
                480
            ],
            "id": "f9deb600-c07e-44f6-97e7-00451ab43b15",
            "name": "Execute a SQL query",
            "credentials": {
                "postgres": {
                    "id": "VrRSp705gu0IHQy1",
                    "name": "Postgres account"
                }
            }
        }
    ],
    "pinData": {
        "Schedule Trigger": [
            {
                "json": {
                    "timestamp": "2025-08-15T00:00:25.024+03:00",
                    "Readable date": "August 15th 2025, 12:00:25 am",
                    "Readable time": "12:00:25 am",
                    "Day of week": "Friday",
                    "Year": "2025",
                    "Month": "August",
                    "Day of month": "15",
                    "Hour": "00",
                    "Minute": "00",
                    "Second": "25",
                    "Timezone": "Asia\/Riyadh (UTC+03:00)"
                }
            }
        ]
    },
    "connections": {
        "Is New or Updated?": {
            "main": [
                [
                    {
                        "node": "Download Workflow File",
                        "type": "main",
                        "index": 0
                    }
                ],
                []
            ]
        },
        "Download Workflow File": {
            "main": [
                [
                    {
                        "node": "Analyze Workflow Structure",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Analyze Workflow Structure": {
            "main": [
                [
                    {
                        "node": "Prepare Vector Data",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Prepare Vector Data": {
            "main": [
                [
                    {
                        "node": "Store in Pinecone",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Store in Pinecone": {
            "main": [
                [
                    {
                        "node": "Update Processing Record",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Update Processing Record": {
            "main": [
                [
                    {
                        "node": "Send Success Notification",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Edit Fields": {
            "main": [
                [
                    {
                        "node": "Is New or Updated?",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Embeddings OpenAI": {
            "ai_embedding": [
                [
                    {
                        "node": "Store in Pinecone",
                        "type": "ai_embedding",
                        "index": 0
                    }
                ]
            ]
        },
        "Merge": {
            "main": [
                []
            ]
        },
        "Search files and folders": {
            "main": [
                [
                    {
                        "node": "Edit Fields",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Schedule Trigger": {
            "main": [
                [
                    {
                        "node": "Search files and folders",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Execute a SQL query": {
            "main": [
                [
                    {
                        "node": "Merge",
                        "type": "main",
                        "index": 1
                    }
                ]
            ]
        }
    },
    "active": true,
    "settings": {
        "executionOrder": "v1",
        "saveManualExecutions": true,
        "saveDataSuccessExecution": "all",
        "saveExecutionProgress": true,
        "saveDataErrorExecution": "all",
        "errorWorkflow": "",
        "timezone": "Asia\/Riyadh"
    },
    "versionId": "cbb33a6f-0d3f-40f9-b191-06bba87b2113",
    "meta": {
        "templateCredsSetupCompleted": true,
        "instanceId": "a85fc6519b374e86e01063acbb733de8f006266ec78aa34c0f3dbebd8434a16e"
    },
    "id": "5Zc25JTudhZVKqIc",
    "tags": []
}