graph TB
    %% 개발환경 네트워크 다이어그램
    %% KT AI 기반 소상공인 이벤트 자동 생성 서비스 - 개발환경

    %% 외부 영역
    subgraph Internet["🌐 인터넷"]
        Developer["👨‍💻 개발자"]
        QATester["🧪 QA팀"]
        ExternalAPIs["🔌 외부 API"]

        subgraph ExternalServices["외부 서비스"]
            OpenAI["🤖 OpenAI API<br/>(GPT-4)"]
            KakaoAPI["💬 카카오 API"]
            NaverAPI["📧 네이버 API"]
            InstagramAPI["📸 Instagram API"]
        end
    end

    %% Azure 클라우드 영역
    subgraph AzureCloud["☁️ Azure Cloud"]

        %% Virtual Network
        subgraph VNet["🏢 Virtual Network (VNet)<br/>주소 공간: 10.0.0.0/16"]

            %% AKS 서브넷
            subgraph AKSSubnet["🎯 AKS Subnet<br/>10.0.1.0/24"]

                %% Kubernetes 클러스터
                subgraph AKSCluster["⚙️ AKS Cluster"]

                    %% Ingress Controller
                    subgraph IngressController["🚪 NGINX Ingress Controller"]
                        LoadBalancer["⚖️ LoadBalancer Service<br/>(External IP)"]
                        IngressPod["📦 Ingress Controller Pod"]
                    end

                    %% Application Tier
                    subgraph AppTier["🚀 Application Tier"]
                        EventService["🎉 Event Service<br/>Pod"]
                        TemplateService["📋 Template Service<br/>Pod"]
                        ParticipationService["👥 Participation Service<br/>Pod"]
                        AnalyticsService["📊 Analytics Service<br/>Pod"]
                        AIService["🤖 AI Service<br/>Pod"]
                        AdminService["⚙️ Admin Service<br/>Pod"]
                    end

                    %% Frontend Tier
                    subgraph FrontendTier["🎨 Frontend Tier"]
                        UserPortal["🌐 User Portal<br/>Pod (React)"]
                        AdminPortal["🔧 Admin Portal<br/>Pod (React)"]
                    end

                    %% Database Tier
                    subgraph DBTier["🗄️ Database Tier"]
                        PostgreSQL["🐘 PostgreSQL<br/>Pod"]
                        PostgreSQLStorage["💾 hostPath Volume<br/>(/data/postgresql)"]
                    end

                    %% Cache Tier
                    subgraph CacheTier["⚡ Cache Tier"]
                        Redis["🔴 Redis<br/>Pod"]
                    end

                    %% Cluster Internal Services
                    subgraph ClusterServices["🔗 ClusterIP Services"]
                        EventServiceDNS["event-service:8080"]
                        TemplateServiceDNS["template-service:8080"]
                        ParticipationServiceDNS["participation-service:8080"]
                        AnalyticsServiceDNS["analytics-service:8080"]
                        AIServiceDNS["ai-service:8080"]
                        AdminServiceDNS["admin-service:8080"]
                        UserPortalDNS["user-portal:80"]
                        AdminPortalDNS["admin-portal:80"]
                        PostgreSQLDNS["postgresql:5432"]
                        RedisDNS["redis:6379"]
                    end
                end
            end

            %% Service Bus 서브넷
            subgraph ServiceBusSubnet["📨 Service Bus Subnet<br/>10.0.2.0/24"]
                ServiceBus["📮 Azure Service Bus<br/>(Basic Tier)"]

                subgraph Queues["📬 Message Queues"]
                    EventQueue["🎉 event-creation"]
                    ScheduleQueue["📅 schedule-generation"]
                    NotificationQueue["🔔 notification"]
                    AnalyticsQueue["📊 analytics-processing"]
                end
            end
        end
    end

    %% 네트워크 연결 관계

    %% 외부에서 클러스터로의 접근
    Developer -->|"HTTPS:443<br/>(개발용 도메인)"| LoadBalancer
    QATester -->|"API 호출/테스트"| LoadBalancer

    %% Ingress Controller 내부 흐름
    LoadBalancer -->|"트래픽 라우팅"| IngressPod

    %% Ingress에서 Frontend로
    IngressPod -->|"/"| UserPortalDNS
    IngressPod -->|"/admin/**"| AdminPortalDNS

    %% Ingress에서 Application Services로
    IngressPod -->|"/api/events/**"| EventServiceDNS
    IngressPod -->|"/api/templates/**"| TemplateServiceDNS
    IngressPod -->|"/api/participation/**"| ParticipationServiceDNS
    IngressPod -->|"/api/analytics/**"| AnalyticsServiceDNS
    IngressPod -->|"/api/ai/**"| AIServiceDNS
    IngressPod -->|"/api/admin/**"| AdminServiceDNS

    %% ClusterIP Services에서 실제 Pod로 (Frontend)
    UserPortalDNS -->|"내부 로드밸런싱"| UserPortal
    AdminPortalDNS -->|"내부 로드밸런싱"| AdminPortal

    %% ClusterIP Services에서 실제 Pod로 (Backend)
    EventServiceDNS -->|"내부 로드밸런싱"| EventService
    TemplateServiceDNS -->|"내부 로드밸런싱"| TemplateService
    ParticipationServiceDNS -->|"내부 로드밸런싱"| ParticipationService
    AnalyticsServiceDNS -->|"내부 로드밸런싱"| AnalyticsService
    AIServiceDNS -->|"내부 로드밸런싱"| AIService
    AdminServiceDNS -->|"내부 로드밸런싱"| AdminService

    %% Frontend에서 Backend API로
    UserPortal -->|"API 호출"| EventServiceDNS
    UserPortal -->|"API 호출"| TemplateServiceDNS
    UserPortal -->|"API 호출"| ParticipationServiceDNS
    AdminPortal -->|"API 호출"| AdminServiceDNS
    AdminPortal -->|"API 호출"| AnalyticsServiceDNS

    %% Application Services에서 Database로
    EventService -->|"DB 연결<br/>TCP:5432"| PostgreSQLDNS
    TemplateService -->|"DB 연결<br/>TCP:5432"| PostgreSQLDNS
    ParticipationService -->|"DB 연결<br/>TCP:5432"| PostgreSQLDNS
    AnalyticsService -->|"DB 연결<br/>TCP:5432"| PostgreSQLDNS
    AIService -->|"DB 연결<br/>TCP:5432"| PostgreSQLDNS
    AdminService -->|"DB 연결<br/>TCP:5432"| PostgreSQLDNS

    %% Application Services에서 Cache로
    EventService -->|"캐시 연결<br/>TCP:6379"| RedisDNS
    TemplateService -->|"캐시 연결<br/>TCP:6379"| RedisDNS
    ParticipationService -->|"캐시 연결<br/>TCP:6379"| RedisDNS
    AnalyticsService -->|"캐시 연결<br/>TCP:6379"| RedisDNS
    AIService -->|"캐시 연결<br/>TCP:6379"| RedisDNS

    %% ClusterIP Services에서 실제 Pod로 (Database/Cache)
    PostgreSQLDNS -->|"DB 요청 처리"| PostgreSQL
    RedisDNS -->|"캐시 요청 처리"| Redis

    %% Storage 연결
    PostgreSQL -->|"데이터 영속화"| PostgreSQLStorage

    %% Service Bus 연결
    EventService -->|"비동기 메시징<br/>HTTPS/AMQP"| ServiceBus
    AIService -->|"비동기 메시징<br/>HTTPS/AMQP"| ServiceBus
    AnalyticsService -->|"비동기 메시징<br/>HTTPS/AMQP"| ServiceBus
    AdminService -->|"비동기 메시징<br/>HTTPS/AMQP"| ServiceBus

    ServiceBus --> EventQueue
    ServiceBus --> ScheduleQueue
    ServiceBus --> NotificationQueue
    ServiceBus --> AnalyticsQueue

    %% 외부 API 연결
    AIService -->|"HTTPS:443<br/>(GPT-4 호출)"| OpenAI
    EventService -->|"HTTPS:443<br/>(SNS 공유)"| KakaoAPI
    EventService -->|"HTTPS:443<br/>(SNS 공유)"| NaverAPI
    EventService -->|"HTTPS:443<br/>(SNS 공유)"| InstagramAPI

    %% 서비스 간 내부 통신
    EventService -.->|"이벤트 조회"| TemplateServiceDNS
    ParticipationService -.->|"이벤트 정보"| EventServiceDNS
    AnalyticsService -.->|"데이터 수집"| EventServiceDNS
    AnalyticsService -.->|"데이터 수집"| ParticipationServiceDNS

    %% 스타일 정의
    classDef azureStyle fill:#0078D4,stroke:#fff,stroke-width:2px,color:#fff
    classDef k8sStyle fill:#326CE5,stroke:#fff,stroke-width:2px,color:#fff
    classDef appStyle fill:#28A745,stroke:#fff,stroke-width:2px,color:#fff
    classDef frontStyle fill:#17A2B8,stroke:#fff,stroke-width:2px,color:#fff
    classDef dbStyle fill:#DC3545,stroke:#fff,stroke-width:2px,color:#fff
    classDef cacheStyle fill:#FF6B35,stroke:#fff,stroke-width:2px,color:#fff
    classDef serviceStyle fill:#6610F2,stroke:#fff,stroke-width:2px,color:#fff
    classDef queueStyle fill:#FD7E14,stroke:#fff,stroke-width:2px,color:#fff
    classDef externalStyle fill:#FFC107,stroke:#fff,stroke-width:2px,color:#000

    %% 스타일 적용
    class AzureCloud,VNet azureStyle
    class AKSCluster,AKSSubnet,IngressController k8sStyle
    class AppTier,EventService,TemplateService,ParticipationService,AnalyticsService,AIService,AdminService appStyle
    class FrontendTier,UserPortal,AdminPortal frontStyle
    class DBTier,PostgreSQL,PostgreSQLStorage dbStyle
    class CacheTier,Redis cacheStyle
    class ClusterServices,EventServiceDNS,TemplateServiceDNS,ParticipationServiceDNS,AnalyticsServiceDNS,AIServiceDNS,AdminServiceDNS,UserPortalDNS,AdminPortalDNS,PostgreSQLDNS,RedisDNS serviceStyle
    class ServiceBus,ServiceBusSubnet,Queues,EventQueue,ScheduleQueue,NotificationQueue,AnalyticsQueue queueStyle
    class ExternalAPIs,ExternalServices,OpenAI,KakaoAPI,NaverAPI,InstagramAPI externalStyle
