# cloudforet-io/repository architecture

> Architecture diagram of the GitHub repository cloudforet-io/repository, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cloudforet-io/repository
- Repository: https://github.com/cloudforet-io/repository

## Overview

##### Project Type and Purpose
- This is a backend microservice (part of a larger SpaceONE platform) responsible for managing container-image repositories and plugin definitions.
- It exposes both gRPC and REST APIs, schedules background jobs, runs worker processes, and interfaces with external container registries (Docker Hub, AWS ECR, GCP Artifact Registry).
- It persists metadata (plugins, dashboard templates, capabilities) in a database and uses a layered (hexagonal/clean) architecture.

##### Main Components
A. API Layer
- gRPC Server (“application-grpc”)
- REST Server (“application-rest”, fronted by nginx)
B. Scheduler
- Periodic job dispatcher (“application-scheduler”)
C. Worker
- Background job executor (“application-worker”)
D. Service Layer
- spaceone.repository.service
– plugin_service
– repository_service
– dashboard_template_service
E. Manager & Repository Layer
- Managers (local, managed, remote)
- Connectors (registry_connector, AWSPrivateECRConnector, GCPPrivateGCRConnector)
- Data models & Info objects
F. External Systems
- Container registries (Docker Hub, AWS ECR, GCP Artifact Registry)
G. Persistent Storage
- Relational or document database (configured via database-conf.yaml)
H. Deployment & Delivery
- Helm charts (deploy/helm)
- Docker (Dockerfile)
- CI/CD pipelines (GitHub Actions, Skaffold)

##### Relationships & Data Flows
1. Client → API Layer
- External clients call REST (HTTP/JSON) or gRPC endpoints.
2. API Layer → Service Layer
- API controllers invoke service methods.
3. Service Layer → Manager Layer
- Services delegate to managers for business logic, data transformations.
4. Manager Layer → Repository Layer (Ports & Adapters)
- Connectors pull/push images to external registries.
- Repository implementations read/write from the internal database.
5. Scheduler → Worker
- Scheduler enqueues tasks.
- Worker picks up tasks and uses connectors to sync repository/plugin metadata.
6. Database
- All services and managers persist or query metadata from the database.

##### Architectural Patterns & Principles
- Layered architecture (API → Service → Manager → Repository)
- Hexagonal/Ports & Adapters: repository interfaces in `src/spaceone/repository/interface`, adapters in `connector/*` and `managed_resource/*`.
- Separation of concerns:
- API adapters (REST, gRPC)
- Domain logic (service + manager)
- Persistence & external calls (repository + connectors)
- Infrastructure as code: Helm templates for Kubernetes deployment.

##### Putting It All Together
- To the side, show the database.
- Scheduler and Worker drawn as separate pods invoking the same service code.
- External registry nodes on the far right.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Kubernetes Namespace: spaceone-repo-service"
        subgraph "API Layer"
            REST["REST API\n(application-rest)"]:::api
            GRPC["gRPC API\n(application-grpc)"]:::api
        end

        subgraph "Scheduler"
            SCHED["Scheduler\n(application-scheduler)"]:::app
        end

        subgraph "Worker"
            WORK["Worker\n(application-worker)"]:::app
        end

        subgraph "Service & Manager"
            subgraph "Service Layer"
                REP_SVC["repository_service"]:::service
                PLG_SVC["plugin_service"]:::service
                DASH_SVC["dashboard_template_service"]:::service
            end
            subgraph "Manager Layer"
                MGR["Manager Layer\n(src/spaceone/repository/manager)"]:::manager
            end
        end
    end

    DB["Database\n(PostgreSQL/Mongo)"]:::db

    subgraph "External Registries"
        DOCKERHUB["Docker Hub"]:::external
        AWS_ECR["AWS ECR"]:::external
        GCP_AR["GCP Artifact Registry"]:::external
    end

    subgraph "CI/CD & Deployment"
        CI["GitHub Actions"]:::infra
        DOCKER["Dockerfile"]:::infra
        HELM["Helm Charts\n(deploy/helm/)"]:::infra
    end

    REST -->|HTTP/JSON| REP_SVC
    GRPC -->|gRPC| REP_SVC

    REP_SVC -->|calls| MGR
    PLG_SVC -->|calls| MGR
    DASH_SVC -->|calls| MGR

    MGR -->|uses| REGCON["Registry Connector"]:::connector
    REGCON -->|Pull/Push| DOCKERHUB
    REGCON -->|Pull/Push| AWS_ECR
    REGCON -->|Pull/Push| GCP_AR

    MGR -->|DB query| DB
    REP_SVC -->|DB query| DB

    SCHED -->|enqueue tasks| WORK
    WORK -->|exec tasks| MGR
    WORK -->|persist metadata| DB

    CI --> DOCKER
    CI --> HELM
    DOCKER -->|"Deploy images"| HELM
    HELM -->|"Deploy to"| REST
    HELM -->|"Deploy to"| GRPC
    HELM -->|"Deploy to"| SCHED
    HELM -->|"Deploy to"| WORK

    click REST "https://github.com/cloudforet-io/repository/blob/master/deploy/helm/templates/rest-nginx-proxy-conf.yaml"
    click GRPC "https://github.com/cloudforet-io/repository/tree/master/src/spaceone/repository/interface/grpc"
    click SCHED "https://github.com/cloudforet-io/repository/blob/master/deploy/helm/templates/application-scheduler-conf.yaml"
    click WORK "https://github.com/cloudforet-io/repository/blob/master/deploy/helm/templates/application-worker-conf.yaml"
    click REP_SVC "https://github.com/cloudforet-io/repository/blob/master/src/spaceone/repository/service/repository_service.py"
    click PLG_SVC "https://github.com/cloudforet-io/repository/blob/master/src/spaceone/repository/service/plugin_service.py"
    click DASH_SVC "https://github.com/cloudforet-io/repository/blob/master/src/spaceone/repository/service/dashboard_template_service.py"
    click MGR "https://github.com/cloudforet-io/repository/tree/master/src/spaceone/repository/manager"
    click REGCON "https://github.com/cloudforet-io/repository/blob/master/src/spaceone/repository/connector/registry_connector.py"
    click DB "https://github.com/cloudforet-io/repository/blob/master/deploy/helm/templates/database-conf.yaml"
    click HELM "https://github.com/cloudforet-io/repository/tree/master/deploy/helm/"
    click DOCKER "https://github.com/cloudforet-io/repository/tree/master/Dockerfile"
    click CI "https://github.com/cloudforet-io/repository/tree/master/.github/workflows/"

    classDef api fill:#cce5ff,stroke:#005cbf,stroke-width:1px
    classDef app fill:#e2e3e5,stroke:#6c757d,stroke-width:1px
    classDef service fill:#d4edda,stroke:#155724,stroke-width:1px
    classDef manager fill:#fff3cd,stroke:#856404,stroke-width:1px
    classDef connector fill:#ffe5b4,stroke:#ff8c00,stroke-width:1px
    classDef db fill:#f1f1f1,stroke:#333333,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:1px
    classDef infra fill:#d1ecf1,stroke:#0c5460,stroke-width:1px,stroke-dasharray: 2 2
```
