model {
  developer = actor 'Developer' {
    description 'The regular user of the platform'
  }

  edp = system 'EDP' {

    container ui 'Backstage' {
      description 'Developer Portal'

      component backstage 'Backstage' {
        style {
          icon tech:react
          shape browser
        }
      }

      component database 'Database' {
        technology 'Postgresql'
        icon tech:postgresql
        style {
          shape storage
        }
      }

      backstage -> database 'reads/writes'
    }

    container forgejo 'Forgejo' {
      description '
        Fully managed DevOps Platfrom
        offering capabilities like
        code version controling
        collaboration and ticketing
        and security scanning
      '
      component forgejo 'Forgejo' {
        technology 'Golang'
        icon tech:go
      }

      component forgejoRunner 'CI Runner'{
        technology 'Golang'
        icon tech:go
        style {
          multiple true
        }
      }

      forgejoRunner -> forgejo 'executes pipelines'
    }

    container argoCD 'ArgoCD' {
      description 'GitOps Service'

      component argocdServer 'ArgoCD Server'
      component argocdAppController 'ApplicationController'
      component argocdAppSetController 'ApplicationSeetController'
      component argocdRedis 'Redis'
      component argocdRepoServer 'Repo Server'
    }

    container keycloak 'Keycloak' {
      description '
        Single Sign On for all EDP products
      '
      component keycloak 'Keycloak' {
        technology 'Java'
        icon tech:java
      }

      component keycloakDB 'Database' {
        technology 'Postgresql'
        icon tech:postgresql
        style {
          shape storage
        }
      }
      keycloak -> keycloakDB 'reads/writes'
    }

    container crossplane 'Crossplane' {
      #internal
      description 'Declarative management of ressources'

      component crossplane 'Crossplane'
      component crossplaneFunction 'Function Patch and Transform'
      component crossplaneRbacManager 'RBAC Manager'
      component providerArgoCD 'ArgoCD Provider'
      component providerKind 'Kind Provider'
      component providerShell 'Shell Provider'
    }

    container externalSecrets 'external-secrets' {
      #internal
      description 'Provider to access externally stored Kubernetes secrets'
      
      component externalSecrets 'external-secrets controller'
      component certController 'cert-controller'
      component webhook 'webhook'
    }

    container minio 'Minio' {
      description 'S3 compatible blob storage'

      component minio 'S3 Blob Storage' {
        technology 'Minio'
        style {
          shape storage
        }
      }
    }

    container velero 'Velero' {
      #internal
      description 'Backup Kubernetes resources'

      component velero 'Velero'

      velero -> minio.minio 'store backups'
    }

    container openbao 'OpenBao' {
      description 'Secure secret storage'

      component openbao 'Openbao' {
        technology 'Openbao'
        style {
          shape storage
        }
      }

      component agentInjector 'Agent Injector'
    }

    container monitoring 'Monitoring' {
      description 'Observability system to monitor deployed components'

      component alloy 'Alloy' {
        description 'Open Telemetry Collector'

        style {
          icon tech:grafana
          multiple true
        }
      }

      container loki 'Loki' {
        description 'Log aggregation system'
        icon tech:grafana

        component queryFrontend 'Query Frontend'
        component distributor 'Distributor'
        component gateway 'Gateway'
        component ingestor 'Ingestor'
        component querier 'Querier'
      }

      alloy -> loki 'pushes logs'
    }

    container ingressNginx 'Ingress' {
      #internal
      description 'Ingress Controller for incoming http(s) traffic'

      component ingressNginx 'ingress-nginx'{
        technology 'Nginx'
        icon tech:nginx
      }

      ingressNginx -> forgejo.forgejo 'https'
      ingressNginx -> keycloak.keycloak 'https'
      ingressNginx -> openbao.openbao 'https'
      ingressNginx -> argoCD.argocdServer 'https'
      ingressNginx -> ui.backstage 'https'
      ingressNginx -> minio.minio 'https'
      ingressNginx -> monitoring.alloy 'https'
      ingressNginx -> testApp.fibonacci 'https'
      ingressNginx -> mailhog.mailhog 'https'
    }

    container testApp 'Fibonacci' {
      description 'Testapp to validate deployments'

      component fibonacci 'Fibonacci' {
        technology 'Golang'
        icon tech:go
      }
    }

    container mailhog 'Mailhog' {
      #internal
      description 'Web and API based SMTP testing'

      component mailhog 'Mailhog' {
        technology 'Golang'
        icon tech:go
      }
    }

    // UI requests data from the Backend
    // ui -> backend 'fetches via HTTPS'
  }

  developer -> ui 'manages project'
  developer -> forgejo 'manages code'
  developer -> keycloak 'authenticates'
}

views {

  view overview {
    title 'Landscape view'

    include *
  }

  view edp of edp {
    title 'Context view'
    include *
    exclude ingressNginx ->
    exclude element.tag = #internal

    style * {
      opacity 25%
    }
  }

  view keycloak of keycloak {
    include 
      *,
      ingressNginx ->
  }

  view forgejo of forgejo {
    include 
      *,
      ingressNginx ->
  }

  view crossplane of crossplane {
    include 
      *,
      ingressNginx ->
  }

  view externalSecrets of externalSecrets {
    include 
      *,
      ingressNginx ->
  }

  view velero of velero {
    include 
      *,
      ingressNginx ->
  }

  view minio of minio {
    include 
      *,
      ingressNginx ->
  }

  view monitoring of monitoring {
    include 
      *,
      ingressNginx ->,
      loki.*
  }

  view ingressNginx of ingressNginx {
    include *
  }

  view testapp of testApp {
      include 
      *,
      ingressNginx ->
  }

  view mailhog of mailhog {
    include 
      *,
      ingressNginx ->
  }

}


