# apache/servicecomb-service-center architecture

> Architecture diagram of the GitHub repository apache/servicecomb-service-center, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/apache/servicecomb-service-center
- Repository: https://github.com/apache/servicecomb-service-center

## Overview

##### Project Type and Purpose
- Service-Center is a distributed, full-stack micro-service registry and management platform.
- It exposes REST (and WebSocket) APIs, a CLI (scctl), a cluster syncer, an event engine, and a web portal/UX.
- It supports pluggable authentication/TLS, metrics (Prometheus), tracing (Zipkin), multiple data sources (etcd, MongoDB), and multi-cluster sync.

##### Break Down the Main Components
A. User-Facing Components
1. Web Portal (ux/ and frontend/):
– Angular (ux/src) or AngularJS (frontend/app) UI
– Communicates via HTTP/REST and WebSocket to the server.
2. Command-Line Client (scctl/ and cmd/scctl):
– CLI binary
– Talks over HTTP/REST or gRPC to the server.
3. Go Client Library (client/):
– A reusable Go SDK for REST/gRPC consumption by third-party services.
B. Server (server/):
1. API Layer (server/rest/ and server/handler/):
– HTTP routers, controllers, request/response marshalling
– WebSocket subscription handlers for “subscribe” events
2. Interceptor Chain (server/interceptor/ and pkg/chain/):
– Pre/post filters for auth, CORS, tracing, logging, rate limiting
3. Core Services (server/service/, server/core/):
– Business logic for service registration, discovery, metadata, RBAC, governance, quota, heartbeat
4. Plugin Manager (server/plugin/ and pkg/plugin/):
– Dynamically loadable modules for auth, TLS, tracing, metrics, UUID, etc.
5. Event & Pub/Sub Engine (server/event/, server/pubsub/):
– Internal event bus, WebSocket broker, subscription model
6. Metrics & Tracing (pkg/metrics/, pkg/prometheus/, pkg/log/, pkg/tracing):
– Exposes Prometheus endpoints, integrates with Zipkin, logs via Zap
C. Persistence & State Layer (datasource/):
1. Pluggable Data Sources (datasource/etcd/ and datasource/mongo/):
– Adapter, engine, state management, key generation, cache, watchers
2. Common Abstractions (datasource/common.go, datasource/sdcommon/):
– Registry interfaces, cache, list-watch patterns
3. Stateful Store (etcd cluster or MongoDB cluster)
D. Cluster Synchronization (syncer/):
– A separate process that streams events across clusters via gRPC or REST,
keeping multiple Service-Center instances in sync.
E. Event Base (eventbase/):
– Lightweight event dispatcher for background tasks and tombstone cleanup.
F. Infrastructure & Examples:
– Dockerfiles, Helm charts (examples/infrastructures/k8s), docker-compose.yaml

##### Sketching the Relationships & Data Flows
- “Users & Tools” at the top: Web browsers (UI), CLI (scctl), custom clients (Go SDK).
- API Layer → Interceptor Chain → Core Service Layer → Data Source Adapter
- Core Service publishes events to the Event Bus → Pub/Sub module → WebSocket
- Metrics & Tracing modules hooked into Interceptors and Core Services.
- Plugin Manager sits beside Interceptor and Core layers, invoked dynamically.
- At the bottom or side, show external systems: Prometheus scraping metrics endpoint, Zipkin receiving spans.

##### Highlighting Architectural Patterns & Technologies
- Layered architecture: Presentation → API → Interceptors → Business Logic → Data Access
- Interceptor/Chain of Responsibility pattern (pkg/chain)
- Plugin architecture (pkg/plugin, server/plugin)
- Pub/Sub and Observer patterns (server/event, server/pubsub)
- MVC-ish division in the frontend (controllers, views, directives)
- Go-based microservices: gRPC (protobuf in api/, syncer/api), HTTP/REST (server/rest, pkg/rest), WebSocket (server/pubsub/ws)
- Caching layer in front of the datastore for performance
- Watch/List patterns for data sync from etcd/Mongo to in-memory cache.

##### Essential Elements
- Clear labels on each component (e.g., “REST Controller”, “Auth Interceptor”, “Registry Service”, “etcd cluster”)
- Plugin extension points in Server (Plugin Loader → Auth/TLS/Tracing)
- Metrics/tracing integration to Prometheus/Zipkin.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Users & Tools
    subgraph "Users & Tools"
        style UIBlur fill:#D6E9FF,stroke:#3E7BB6
        UI1("Web Portal (Angular)"):::frontend
        UI2("Web Portal (AngularJS)"):::frontend
        CLI("CLI scctl"):::frontend
        SDK("Go Client SDK"):::frontend
    end

    %% Server Layer
    subgraph "Server (Service-Center)" 
        direction TB
        API["REST Controller & Routers"]:::server
        WS["WebSocket & Pub/Sub Broker"]:::server
        INTER["Interceptor Chain"]:::server
        CORE["Core Services (Registry, Governance)"]:::server
        PLUG["Plugin Manager & Extensions"]:::server
        EVENT["Event & Pub/Sub Engine"]:::server
        METRICS["Metrics & Tracing Integration"]:::server
    end

    %% Persistence Layer
    subgraph "Persistence & State"
        direction TB
        ETCD(("etcd Cluster")):::persistence
        MONGO(("MongoDB Cluster")):::persistence
        COMMON["Common Abstractions"]:::persistence
    end

    %% Auxiliary Processes
    subgraph "Operations"
        direction TB
        SYNC("Cluster Syncer"):::ops
        EBASE("EventBase Dispatcher"):::ops
    end

    %% External Infrastructure
    subgraph "External Systems"
        PROM("Prometheus"):::infra
        ZIP("Zipkin"):::infra
    end

    %% Flows
    UI1 -->|HTTP/REST & WebSocket| API
    UI2 -->|HTTP/REST & WebSocket| API
    CLI -->|HTTP/REST/gRPC| API
    SDK -->|HTTP/REST/gRPC| API

    API -->|"pre/post filters"| INTER
    INTER -->|"invoke"| CORE
    CORE -->|"publish events"| EVENT
    EVENT --> WS
    CORE -->|"data access"| COMMON
    COMMON --> ETCD
    COMMON --> MONGO
    CORE --> METRICS
    INTER --> METRICS
    PLUG --> INTER
    PLUG --> CORE
    PLUG --> METRICS

    SYNC -->|gRPC/REST| API
    SYNC -->|sync events| SYNC
    EBASE --> COMMON

    PROM -->|scrapes /metrics| METRICS
    ZIP -->|receives spans| METRICS

    %% Click Events
    click UI1 "https://github.com/apache/servicecomb-service-center/tree/master/ux/src/app"
    click UI2 "https://github.com/apache/servicecomb-service-center/tree/master/frontend/app"
    click CLI "https://github.com/apache/servicecomb-service-center/tree/master/cmd/scctl"
    click SDK "https://github.com/apache/servicecomb-service-center/tree/master/client/"
    click API "https://github.com/apache/servicecomb-service-center/tree/master/server/rest/"
    click WS "https://github.com/apache/servicecomb-service-center/tree/master/server/pubsub/"
    click INTER "https://github.com/apache/servicecomb-service-center/tree/master/server/interceptor/"
    click INTER "https://github.com/apache/servicecomb-service-center/tree/master/pkg/chain/"
    click CORE "https://github.com/apache/servicecomb-service-center/tree/master/server/service/"
    click CORE "https://github.com/apache/servicecomb-service-center/tree/master/server/core/"
    click PLUG "https://github.com/apache/servicecomb-service-center/tree/master/server/plugin/"
    click PLUG "https://github.com/apache/servicecomb-service-center/tree/master/pkg/plugin/"
    click EVENT "https://github.com/apache/servicecomb-service-center/tree/master/server/event/"
    click EVENT "https://github.com/apache/servicecomb-service-center/tree/master/pkg/event/"
    click METRICS "https://github.com/apache/servicecomb-service-center/tree/master/pkg/metrics/"
    click METRICS "https://github.com/apache/servicecomb-service-center/tree/master/pkg/prometheus/"
    click METRICS "https://github.com/apache/servicecomb-service-center/tree/master/pkg/tracing/"
    click ETCD "https://github.com/apache/servicecomb-service-center/tree/master/datasource/etcd/"
    click MONGO "https://github.com/apache/servicecomb-service-center/tree/master/datasource/mongo/"
    click COMMON "https://github.com/apache/servicecomb-service-center/blob/master/datasource/common.go"
    click COMMON "https://github.com/apache/servicecomb-service-center/tree/master/datasource/sdcommon/"
    click SYNC "https://github.com/apache/servicecomb-service-center/tree/master/syncer/"
    click EBASE "https://github.com/apache/servicecomb-service-center/tree/master/eventbase/"
    click PROM "https://github.com/apache/servicecomb-service-center/tree/master/examples/infrastructures/"
    click PROM "https://github.com/apache/servicecomb-service-center/blob/master/docker-compose.yml"

    %% Styles
    classDef frontend fill:#D6E9FF,stroke:#3E7BB6,stroke-width:1px
    classDef server fill:#D4EDDA,stroke:#3C763D,stroke-width:1px
    classDef persistence fill:#FDEBD0,stroke:#D35400,stroke-width:1px
    classDef infra fill:#E2E3E5,stroke:#6C757D,stroke-width:1px
    classDef ops fill:#E6E0F8,stroke:#6F42C1,stroke-width:1px
```
