graph TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        WebApp[Web App (React)]
        MobileApp[Mobile App (React Native)]
        AdminPanel[Admin Panel (React)]
    end

    %% API Gateway Layer
    subgraph "API Gateway Layer"
        Gateway[API Gateway (Kong/Traefik)]
        AuthGateway[Auth Gateway]
        RateLimit[Rate Limiter]
        CORS[CORS Handler]
    end

    %% Microservices Layer
    subgraph "Microservices Layer"
        subgraph "User Domain"
            UserService[User Service]
            AuthService[Auth Service]
            ProfileService[Profile Service]
        end
        
        subgraph "Audio Domain"
            TrackService[Track Service]
            StreamService[Stream Service]
            TranscodeService[Transcode Service]
        end
        
        subgraph "Social Domain"
            ChatService[Chat Service]
            MessageService[Message Service]
            NotificationService[Notification Service]
        end
        
        subgraph "Commerce Domain"
            MarketplaceService[Marketplace Service]
            PaymentService[Payment Service]
            OrderService[Order Service]
        end
        
        subgraph "Analytics Domain"
            AnalyticsService[Analytics Service]
            RecommendationService[Recommendation Service]
            SearchService[Search Service]
        end
    end

    %% Event-Driven Architecture
    subgraph "Event Layer"
        EventBus[Event Bus (Kafka/RabbitMQ)]
        EventStore[Event Store]
        SagaOrchestrator[Saga Orchestrator]
    end

    %% Data Layer
    subgraph "Data Layer"
        subgraph "Primary Databases"
            UserDB[(User DB)]
            AudioDB[(Audio DB)]
            SocialDB[(Social DB)]
            CommerceDB[(Commerce DB)]
        end
        
        subgraph "Read Models"
            SearchIndex[Search Index (Elasticsearch)]
            CacheLayer[Cache Layer (Redis Cluster)]
            AnalyticsDB[(Analytics DB)]
        end
        
        subgraph "File Storage"
            ObjectStorage[Object Storage (S3)]
            CDN[CDN (CloudFront)]
        end
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        subgraph "Monitoring"
            Prometheus[Prometheus]
            Grafana[Grafana]
            Jaeger[Jaeger (Tracing)]
            AlertManager[Alert Manager]
        end
        
        subgraph "Security"
            WAF[WAF]
            Vault[Vault (Secrets)]
            CertManager[Cert Manager]
        end
        
        subgraph "Deployment"
            Kubernetes[Kubernetes]
            Istio[Istio (Service Mesh)]
            Helm[Helm Charts]
        end
    end

    %% External Services
    subgraph "External Services"
        Stripe[Stripe]
        PayPal[PayPal]
        EmailService[Email Service]
        SMS[SMS Service]
        PushNotifications[Push Notifications]
    end

    %% Connections - Frontend to Gateway
    WebApp --> Gateway
    MobileApp --> Gateway
    AdminPanel --> Gateway

    %% Gateway to Services
    Gateway --> AuthGateway
    Gateway --> RateLimit
    Gateway --> CORS
    
    AuthGateway --> UserService
    AuthGateway --> AuthService

    %% Service to Service Communication
    UserService --> ProfileService
    TrackService --> StreamService
    TrackService --> TranscodeService
    ChatService --> MessageService
    MessageService --> NotificationService
    MarketplaceService --> PaymentService
    PaymentService --> OrderService
    AnalyticsService --> RecommendationService
    RecommendationService --> SearchService

    %% Event-Driven Communication
    UserService --> EventBus
    TrackService --> EventBus
    ChatService --> EventBus
    MarketplaceService --> EventBus
    AnalyticsService --> EventBus
    
    EventBus --> EventStore
    EventBus --> SagaOrchestrator

    %% Data Access
    UserService --> UserDB
    AuthService --> UserDB
    ProfileService --> UserDB
    
    TrackService --> AudioDB
    StreamService --> AudioDB
    TranscodeService --> AudioDB
    
    ChatService --> SocialDB
    MessageService --> SocialDB
    NotificationService --> SocialDB
    
    MarketplaceService --> CommerceDB
    PaymentService --> CommerceDB
    OrderService --> CommerceDB
    
    AnalyticsService --> AnalyticsDB
    RecommendationService --> AnalyticsDB
    SearchService --> SearchIndex

    %% Cache and Storage
    UserService --> CacheLayer
    TrackService --> CacheLayer
    ChatService --> CacheLayer
    MarketplaceService --> CacheLayer
    
    TrackService --> ObjectStorage
    StreamService --> ObjectStorage
    ObjectStorage --> CDN

    %% Monitoring
    UserService --> Prometheus
    TrackService --> Prometheus
    ChatService --> Prometheus
    MarketplaceService --> Prometheus
    
    Prometheus --> Grafana
    Prometheus --> AlertManager

    %% Tracing
    UserService --> Jaeger
    TrackService --> Jaeger
    ChatService --> Jaeger
    MarketplaceService --> Jaeger

    %% Security
    Gateway --> WAF
    UserService --> Vault
    AuthService --> Vault
    PaymentService --> Vault

    %% Deployment
    Gateway --> Kubernetes
    UserService --> Kubernetes
    TrackService --> Kubernetes
    ChatService --> Kubernetes
    MarketplaceService --> Kubernetes
    
    Kubernetes --> Istio

    %% External Integrations
    PaymentService --> Stripe
    PaymentService --> PayPal
    NotificationService --> EmailService
    NotificationService --> SMS
    NotificationService --> PushNotifications

    %% Styling
    classDef frontend fill:#61DAFB,stroke:#333,stroke-width:2px,color:#fff
    classDef gateway fill:#FF6B6B,stroke:#333,stroke-width:2px,color:#fff
    classDef service fill:#4ECDC4,stroke:#333,stroke-width:2px,color:#fff
    classDef event fill:#45B7D1,stroke:#333,stroke-width:2px,color:#fff
    classDef data fill:#96CEB4,stroke:#333,stroke-width:2px,color:#fff
    classDef infra fill:#FFEAA7,stroke:#333,stroke-width:2px,color:#333
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:2px,color:#fff

    class WebApp,MobileApp,AdminPanel frontend
    class Gateway,AuthGateway,RateLimit,CORS gateway
    class UserService,AuthService,ProfileService,TrackService,StreamService,TranscodeService,ChatService,MessageService,NotificationService,MarketplaceService,PaymentService,OrderService,AnalyticsService,RecommendationService,SearchService service
    class EventBus,EventStore,SagaOrchestrator event
    class UserDB,AudioDB,SocialDB,CommerceDB,SearchIndex,CacheLayer,AnalyticsDB,ObjectStorage,CDN data
    class Prometheus,Grafana,Jaeger,AlertManager,WAF,Vault,CertManager,Kubernetes,Istio,Helm infra
    class Stripe,PayPal,EmailService,SMS,PushNotifications external 