digraph HZHubArchitecture {
    graph [fontname="Arial", fontsize=24, bgcolor=white, margin=0, rankdir=TB, splines=ortho, nodesep=0.6, ranksep=1.2];
    node [fontname="Arial", shape=box, style="rounded,filled", fontsize=11, margin="0.3,0.2"];
    edge [fontname="Arial", fontsize=10, color="#666666"];

    // Title
    labelloc="t";
    label="HZHub Architecture Diagram\nEnterprise Business Middle-Platform";

    // Frontend Layer
    subgraph cluster_frontend {
        label="Frontend Layer";
        style=filled;
        color="#E3F2FD";
        fontcolor="#1565C0";
        fontsize=14;
        labelloc=b;
        labeljust=left;

        admin [label="hzhub-admin\nManagement Portal\n• Model Management\n• Knowledge Base Config\n• Agent Orchestration", fillcolor="#BBDEFB", color="#1976D2"];
        company [label="hzhub-portal-company\nCompany Portal\n• WeChat Work H5\n• Approval Workflow\n• Sales CRM\n• BI Reports", fillcolor="#BBDEFB", color="#1976D2"];
        dealer [label="hzhub-portal-dealer\nDealer Portal\n• WeChat Work H5\n• Self-service Order\n• Inventory Mgmt\n• AI Material Gen", fillcolor="#BBDEFB", color="#1976D2"];
    }

    // Gateway Layer
    subgraph cluster_gateway {
        label="Gateway Layer";
        style=filled;
        color="#FFF3E0";
        fontcolor="#E65100";
        fontsize=14;
        labelloc=b;
        labeljust=left;

        gateway [label="HZHub-Gateway\nAPI Gateway\n• Unified Authentication\n• Routing & Load Balancing\n• Rate Limiting & Circuit Breaker", fillcolor="#FFE0B2", color="#F57C00", width=4.5];
    }

    // Service Layer
    subgraph cluster_service {
        label="Service Layer";
        style=filled;
        color="#E8F5E9";
        fontcolor="#2E7D32";
        fontsize=14;
        labelloc=b;
        labeljust=left;

        ai [label="hzhub-ai\nAI Service\n• Spring Boot 4.0\n• Spring AI 2.0\n• LangChain4j\n• RAG / Knowledge Base\n• Multi-Agent System", fillcolor="#C8E6C9", color="#388E3C"];
        erp [label="hzhub-erp\nERP Service\n• Spring Boot 4.0\n• JDBC / SQL Server\n• Data Adapter Layer\n• Dual DataSource (Reserved)", fillcolor="#C8E6C9", color="#388E3C"];
        n8n [label="n8n\nWorkflow Engine\n• Workflow Orchestration\n• Approval Automation\n• Scheduled Tasks\n• Webhook Integration", fillcolor="#F8BBD9", color="#C2185B"];
    }

    // Data Layer
    subgraph cluster_data {
        label="Data Layer";
        style=filled;
        color="#F3E5F5";
        fontcolor="#7B1FA2";
        fontsize=14;
        labelloc=b;
        labeljust=left;

        mysql [label="MySQL\nBusiness Data\n• User & Permission\n• System Config", fillcolor="#E1BEE7", color="#7B1FA2"];
        milvus [label="Milvus\nVector Database\n• Document Embeddings\n• Semantic Search", fillcolor="#E1BEE7", color="#7B1FA2"];
        sqlserver [label="SQL Server 2008 R2\nERP Database\n• Stored Procedures\n• Direct Connection", fillcolor="#E1BEE7", color="#7B1FA2"];
    }

    // Connections
    admin -> gateway;
    company -> gateway;
    dealer -> gateway;

    gateway -> ai;
    gateway -> erp;
    gateway -> n8n;

    ai -> mysql;
    ai -> milvus;
    erp -> sqlserver;

    // Workflow trigger (dashed)
    ai -> n8n [style=dashed, color="#9E9E9E", label="Workflow Trigger"];

    // Rankings for layout
    {rank=same; admin; company; dealer}
    {rank=same; ai; erp; n8n}
    {rank=same; mysql; milvus; sqlserver}
}
