@prefix agw: <https://ggen.ai/ontology/api-gateway#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dcterms: <http://purl.org/dc/terms/> .

# Ontology Definition
agw: a owl:Ontology ;
    dcterms:title "API Gateway & Service Mesh Ontology" ;
    dcterms:description "Comprehensive ontology for API gateway routing, service mesh, mTLS, circuit breakers, and distributed tracing" ;
    dcterms:created "2025-01-08"^^xsd:date ;
    owl:versionInfo "1.0.0" .

# ============================================================================
# CORE CLASSES - API Gateway
# ============================================================================

agw:ApiGateway a owl:Class ;
    rdfs:label "API Gateway" ;
    rdfs:comment "Central entry point for API requests with routing, authentication, and load balancing" .

agw:Route a owl:Class ;
    rdfs:label "Route" ;
    rdfs:comment "API route definition with path, method, and backend service" .

agw:LoadBalancer a owl:Class ;
    rdfs:label "Load Balancer" ;
    rdfs:comment "Load balancing strategy for distributing requests" .

agw:RateLimiter a owl:Class ;
    rdfs:label "Rate Limiter" ;
    rdfs:comment "Request rate limiting and throttling policy" .

agw:ThrottlingPolicy a owl:Class ;
    rdfs:label "Throttling Policy" ;
    rdfs:comment "Policy for controlling request throughput" .

agw:CircuitBreaker a owl:Class ;
    rdfs:label "Circuit Breaker" ;
    rdfs:comment "Circuit breaker pattern for fault tolerance" .

agw:RetryPolicy a owl:Class ;
    rdfs:label "Retry Policy" ;
    rdfs:comment "Retry configuration for failed requests" .

agw:Timeout a owl:Class ;
    rdfs:label "Timeout" ;
    rdfs:comment "Request timeout configuration" .

# ============================================================================
# SERVICE MESH CLASSES
# ============================================================================

agw:ServiceMesh a owl:Class ;
    rdfs:label "Service Mesh" ;
    rdfs:comment "Service mesh infrastructure (Istio, Linkerd, Consul Connect)" .

agw:Sidecar a owl:Class ;
    rdfs:label "Sidecar Proxy" ;
    rdfs:comment "Sidecar proxy (Envoy) for service mesh" .

agw:ControlPlane a owl:Class ;
    rdfs:label "Control Plane" ;
    rdfs:comment "Service mesh control plane (Istiod, Linkerd controller)" .

agw:DataPlane a owl:Class ;
    rdfs:label "Data Plane" ;
    rdfs:comment "Service mesh data plane proxies" .

agw:VirtualService a owl:Class ;
    rdfs:label "Virtual Service" ;
    rdfs:comment "Istio virtual service for traffic routing" .

agw:DestinationRule a owl:Class ;
    rdfs:label "Destination Rule" ;
    rdfs:comment "Istio destination rule for load balancing and subsets" .

agw:ServiceEntry a owl:Class ;
    rdfs:label "Service Entry" ;
    rdfs:comment "Service entry for external service integration" .

agw:Gateway a owl:Class ;
    rdfs:label "Gateway" ;
    rdfs:comment "Istio gateway for ingress/egress traffic" .

# ============================================================================
# SECURITY CLASSES
# ============================================================================

agw:MutualTLS a owl:Class ;
    rdfs:label "Mutual TLS" ;
    rdfs:comment "mTLS configuration for service-to-service encryption" .

agw:Certificate a owl:Class ;
    rdfs:label "Certificate" ;
    rdfs:comment "X.509 certificate for TLS" .

agw:CertificateAuthority a owl:Class ;
    rdfs:label "Certificate Authority" ;
    rdfs:comment "CA for issuing and rotating certificates" .

agw:PeerAuthentication a owl:Class ;
    rdfs:label "Peer Authentication" ;
    rdfs:comment "Istio peer authentication policy" .

agw:AuthorizationPolicy a owl:Class ;
    rdfs:label "Authorization Policy" ;
    rdfs:comment "Service mesh authorization rules" .

agw:JWTAuthentication a owl:Class ;
    rdfs:label "JWT Authentication" ;
    rdfs:comment "JWT-based authentication for APIs" .

agw:ApiKey a owl:Class ;
    rdfs:label "API Key" ;
    rdfs:comment "API key authentication mechanism" .

agw:OAuth2 a owl:Class ;
    rdfs:label "OAuth2" ;
    rdfs:comment "OAuth2 authentication and authorization" .

# ============================================================================
# SERVICE DISCOVERY & HEALTH
# ============================================================================

agw:ServiceDiscovery a owl:Class ;
    rdfs:label "Service Discovery" ;
    rdfs:comment "Service discovery mechanism (Consul, Eureka, etcd)" .

agw:ServiceRegistry a owl:Class ;
    rdfs:label "Service Registry" ;
    rdfs:comment "Registry of available services and instances" .

agw:HealthCheck a owl:Class ;
    rdfs:label "Health Check" ;
    rdfs:comment "Service health check configuration" .

agw:HealthEndpoint a owl:Class ;
    rdfs:label "Health Endpoint" ;
    rdfs:comment "HTTP endpoint for health checks" .

agw:LivenessProbe a owl:Class ;
    rdfs:label "Liveness Probe" ;
    rdfs:comment "Kubernetes liveness probe" .

agw:ReadinessProbe a owl:Class ;
    rdfs:label "Readiness Probe" ;
    rdfs:comment "Kubernetes readiness probe" .

agw:StartupProbe a owl:Class ;
    rdfs:label "Startup Probe" ;
    rdfs:comment "Kubernetes startup probe" .

# ============================================================================
# OBSERVABILITY & TRACING
# ============================================================================

agw:DistributedTracing a owl:Class ;
    rdfs:label "Distributed Tracing" ;
    rdfs:comment "Distributed tracing integration (Jaeger, Zipkin)" .

agw:TracingContext a owl:Class ;
    rdfs:label "Tracing Context" ;
    rdfs:comment "Trace context propagation (W3C Trace Context)" .

agw:Span a owl:Class ;
    rdfs:label "Span" ;
    rdfs:comment "Distributed trace span" .

agw:Metrics a owl:Class ;
    rdfs:label "Metrics" ;
    rdfs:comment "API gateway and service mesh metrics" .

agw:AccessLog a owl:Class ;
    rdfs:label "Access Log" ;
    rdfs:comment "HTTP access log configuration" .

agw:AuditLog a owl:Class ;
    rdfs:label "Audit Log" ;
    rdfs:comment "Security audit log for compliance" .

# ============================================================================
# TRAFFIC MANAGEMENT
# ============================================================================

agw:TrafficSplit a owl:Class ;
    rdfs:label "Traffic Split" ;
    rdfs:comment "Weighted traffic splitting for canary deployments" .

agw:CanaryDeployment a owl:Class ;
    rdfs:label "Canary Deployment" ;
    rdfs:comment "Canary deployment configuration" .

agw:BlueGreenDeployment a owl:Class ;
    rdfs:label "Blue-Green Deployment" ;
    rdfs:comment "Blue-green deployment strategy" .

agw:TrafficMirroring a owl:Class ;
    rdfs:label "Traffic Mirroring" ;
    rdfs:comment "Mirror traffic to shadow backend" .

agw:RequestTransformation a owl:Class ;
    rdfs:label "Request Transformation" ;
    rdfs:comment "Transform HTTP request headers/body" .

agw:ResponseTransformation a owl:Class ;
    rdfs:label "Response Transformation" ;
    rdfs:comment "Transform HTTP response headers/body" .

# ============================================================================
# API VERSIONING & LIFECYCLE
# ============================================================================

agw:ApiVersion a owl:Class ;
    rdfs:label "API Version" ;
    rdfs:comment "API version (v1, v2, etc.)" .

agw:VersioningStrategy a owl:Class ;
    rdfs:label "Versioning Strategy" ;
    rdfs:comment "URL path, header, or query param versioning" .

agw:DeprecationPolicy a owl:Class ;
    rdfs:label "Deprecation Policy" ;
    rdfs:comment "API deprecation timeline and warnings" .

agw:BackwardCompatibility a owl:Class ;
    rdfs:label "Backward Compatibility" ;
    rdfs:comment "Backward compatibility rules" .

# ============================================================================
# BACKEND SERVICES
# ============================================================================

agw:BackendService a owl:Class ;
    rdfs:label "Backend Service" ;
    rdfs:comment "Upstream backend service" .

agw:ServiceInstance a owl:Class ;
    rdfs:label "Service Instance" ;
    rdfs:comment "Individual service instance (pod, container)" .

agw:UpstreamCluster a owl:Class ;
    rdfs:label "Upstream Cluster" ;
    rdfs:comment "Envoy upstream cluster configuration" .

agw:ConnectionPool a owl:Class ;
    rdfs:label "Connection Pool" ;
    rdfs:comment "HTTP/TCP connection pool settings" .

# ============================================================================
# PROPERTIES - API Gateway
# ============================================================================

agw:routePath a owl:DatatypeProperty ;
    rdfs:domain agw:Route ;
    rdfs:range xsd:string ;
    rdfs:label "route path" ;
    rdfs:comment "URL path pattern for route matching" .

agw:httpMethod a owl:DatatypeProperty ;
    rdfs:domain agw:Route ;
    rdfs:range xsd:string ;
    rdfs:label "HTTP method" ;
    rdfs:comment "HTTP method (GET, POST, PUT, DELETE, etc.)" .

agw:requestsPerSecond a owl:DatatypeProperty ;
    rdfs:domain agw:RateLimiter ;
    rdfs:range xsd:integer ;
    rdfs:label "requests per second" ;
    rdfs:comment "Maximum requests per second" .

agw:burstSize a owl:DatatypeProperty ;
    rdfs:domain agw:RateLimiter ;
    rdfs:range xsd:integer ;
    rdfs:label "burst size" ;
    rdfs:comment "Maximum burst request size" .

agw:failureThreshold a owl:DatatypeProperty ;
    rdfs:domain agw:CircuitBreaker ;
    rdfs:range xsd:integer ;
    rdfs:label "failure threshold" ;
    rdfs:comment "Number of failures before opening circuit" .

agw:timeoutSeconds a owl:DatatypeProperty ;
    rdfs:domain agw:Timeout ;
    rdfs:range xsd:integer ;
    rdfs:label "timeout seconds" ;
    rdfs:comment "Request timeout in seconds" .

agw:retryAttempts a owl:DatatypeProperty ;
    rdfs:domain agw:RetryPolicy ;
    rdfs:range xsd:integer ;
    rdfs:label "retry attempts" ;
    rdfs:comment "Maximum number of retry attempts" .

agw:backoffMultiplier a owl:DatatypeProperty ;
    rdfs:domain agw:RetryPolicy ;
    rdfs:range xsd:decimal ;
    rdfs:label "backoff multiplier" ;
    rdfs:comment "Exponential backoff multiplier" .

# ============================================================================
# PROPERTIES - Service Mesh
# ============================================================================

agw:meshType a owl:DatatypeProperty ;
    rdfs:domain agw:ServiceMesh ;
    rdfs:range xsd:string ;
    rdfs:label "mesh type" ;
    rdfs:comment "Service mesh implementation (istio, linkerd, consul)" .

agw:mtlsMode a owl:DatatypeProperty ;
    rdfs:domain agw:MutualTLS ;
    rdfs:range xsd:string ;
    rdfs:label "mTLS mode" ;
    rdfs:comment "STRICT, PERMISSIVE, or DISABLE" .

agw:certificateExpiry a owl:DatatypeProperty ;
    rdfs:domain agw:Certificate ;
    rdfs:range xsd:dateTime ;
    rdfs:label "certificate expiry" ;
    rdfs:comment "Certificate expiration timestamp" .

agw:rotationPeriod a owl:DatatypeProperty ;
    rdfs:domain agw:Certificate ;
    rdfs:range xsd:duration ;
    rdfs:label "rotation period" ;
    rdfs:comment "Certificate rotation period" .

agw:weight a owl:DatatypeProperty ;
    rdfs:domain agw:TrafficSplit ;
    rdfs:range xsd:integer ;
    rdfs:label "weight" ;
    rdfs:comment "Traffic weight percentage (0-100)" .

# ============================================================================
# PROPERTIES - Health & Discovery
# ============================================================================

agw:healthCheckInterval a owl:DatatypeProperty ;
    rdfs:domain agw:HealthCheck ;
    rdfs:range xsd:duration ;
    rdfs:label "health check interval" ;
    rdfs:comment "Time between health checks" .

agw:healthCheckPath a owl:DatatypeProperty ;
    rdfs:domain agw:HealthEndpoint ;
    rdfs:range xsd:string ;
    rdfs:label "health check path" ;
    rdfs:comment "HTTP path for health endpoint" .

agw:successThreshold a owl:DatatypeProperty ;
    rdfs:domain agw:HealthCheck ;
    rdfs:range xsd:integer ;
    rdfs:label "success threshold" ;
    rdfs:comment "Number of successes to mark healthy" .

agw:failureThresholdHealth a owl:DatatypeProperty ;
    rdfs:domain agw:HealthCheck ;
    rdfs:range xsd:integer ;
    rdfs:label "failure threshold" ;
    rdfs:comment "Number of failures to mark unhealthy" .

# ============================================================================
# PROPERTIES - Observability
# ============================================================================

agw:traceId a owl:DatatypeProperty ;
    rdfs:domain agw:Span ;
    rdfs:range xsd:string ;
    rdfs:label "trace ID" ;
    rdfs:comment "Distributed trace ID" .

agw:spanId a owl:DatatypeProperty ;
    rdfs:domain agw:Span ;
    rdfs:range xsd:string ;
    rdfs:label "span ID" ;
    rdfs:comment "Span identifier" .

agw:parentSpanId a owl:DatatypeProperty ;
    rdfs:domain agw:Span ;
    rdfs:range xsd:string ;
    rdfs:label "parent span ID" ;
    rdfs:comment "Parent span identifier" .

agw:samplingRate a owl:DatatypeProperty ;
    rdfs:domain agw:DistributedTracing ;
    rdfs:range xsd:decimal ;
    rdfs:label "sampling rate" ;
    rdfs:comment "Trace sampling rate (0.0-1.0)" .

# ============================================================================
# OBJECT PROPERTIES - Relationships
# ============================================================================

agw:hasRoute a owl:ObjectProperty ;
    rdfs:domain agw:ApiGateway ;
    rdfs:range agw:Route ;
    rdfs:label "has route" ;
    rdfs:comment "Gateway has route configuration" .

agw:hasLoadBalancer a owl:ObjectProperty ;
    rdfs:domain agw:Route ;
    rdfs:range agw:LoadBalancer ;
    rdfs:label "has load balancer" ;
    rdfs:comment "Route uses load balancer" .

agw:hasRateLimiter a owl:ObjectProperty ;
    rdfs:domain agw:Route ;
    rdfs:range agw:RateLimiter ;
    rdfs:label "has rate limiter" ;
    rdfs:comment "Route protected by rate limiter" .

agw:hasCircuitBreaker a owl:ObjectProperty ;
    rdfs:domain agw:Route ;
    rdfs:range agw:CircuitBreaker ;
    rdfs:label "has circuit breaker" ;
    rdfs:comment "Route protected by circuit breaker" .

agw:hasRetryPolicy a owl:ObjectProperty ;
    rdfs:domain agw:Route ;
    rdfs:range agw:RetryPolicy ;
    rdfs:label "has retry policy" ;
    rdfs:comment "Route has retry policy" .

agw:hasBackendService a owl:ObjectProperty ;
    rdfs:domain agw:Route ;
    rdfs:range agw:BackendService ;
    rdfs:label "has backend service" ;
    rdfs:comment "Route targets backend service" .

agw:hasSidecar a owl:ObjectProperty ;
    rdfs:domain agw:BackendService ;
    rdfs:range agw:Sidecar ;
    rdfs:label "has sidecar" ;
    rdfs:comment "Service has sidecar proxy" .

agw:hasHealthCheck a owl:ObjectProperty ;
    rdfs:domain agw:BackendService ;
    rdfs:range agw:HealthCheck ;
    rdfs:label "has health check" ;
    rdfs:comment "Service has health check configuration" .

agw:hasMutualTLS a owl:ObjectProperty ;
    rdfs:domain agw:BackendService ;
    rdfs:range agw:MutualTLS ;
    rdfs:label "has mutual TLS" ;
    rdfs:comment "Service requires mTLS" .

agw:hasCertificate a owl:ObjectProperty ;
    rdfs:domain agw:MutualTLS ;
    rdfs:range agw:Certificate ;
    rdfs:label "has certificate" ;
    rdfs:comment "mTLS uses certificate" .

agw:hasTrafficSplit a owl:ObjectProperty ;
    rdfs:domain agw:Route ;
    rdfs:range agw:TrafficSplit ;
    rdfs:label "has traffic split" ;
    rdfs:comment "Route has canary traffic split" .

agw:hasServiceMesh a owl:ObjectProperty ;
    rdfs:domain agw:BackendService ;
    rdfs:range agw:ServiceMesh ;
    rdfs:label "has service mesh" ;
    rdfs:comment "Service participates in service mesh" .
