# onap/cps architecture

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

- Interactive diagram: https://gitdiagram.com/onap/cps
- Repository: https://github.com/onap/cps

## Overview

##### Main components
- API/Interface Layer: There are several REST-related modules (for example, “cps-rest”, “cps-ncmp-rest”, and even a “policy-executor-stub”). These modules expose HTTP endpoints (for administration, data operations, and network configuration management) used by both internal and external clients.
- Business Logic and Service Layer: Modules like “cps-application” and “cps-service” implement the core functionality. They encapsulate services such as anchor management, dataspace configuration, module service, notification service, and query services.
- Event Handling and Asynchronous Communication: Modules such as “cps-events” and “cps-ncmp-events” indicate event-driven functionality in CPS. They likely produce and consume configuration change events (for example, using Kafka or similar messaging means), coordinating asynchronous updates.
- Persistence / Repository Layer: The “cps-ri” (repository integration) module looks responsible for integrating with the database layer (as seen from SQL changelogs and repository implementations). It manages data storage for configuration models, yang resources, and transaction data.
- Utility and Support Functions: The “cps-path-parser” module (driven by ANTLR grammars) provides functionality to parse CPS-specific path expressions. Other utility modules (e.g., checkstyle, test-tools) support code quality and testing.
- Integration and Testing: There are dedicated directories for integration tests (e.g., “integration-test”, “k6-tests”, “csit”) as well as Docker Compose configurations and release YAMLs to help containerize and deploy the services.

##### Relationships and Interactions
- The REST API modules serve as the entry points, receiving HTTP/REST requests.
- They forward requests into the core business logic (from the “cps-application” or “cps-service” modules) where CPS operations are executed.
- The business logic layer, in turn, interacts with the persistence layer (cps-ri) to query, update, and persist configuration data.
- As configuration changes occur, events are generated via the events modules. These events propagate to interested external services or clients.
- Utility modules like cps-path-parser support internal processing by validating, parsing, and mapping data paths.
- Additional integrations, such as caching (e.g., Hazelcast configurations in some modules) or Kafka setups in “cps-ncmp-service”, are also present to manage performance or asynchronous processing.
- The Docker Compose setups and documentation further indicate that the system is deployed as containerized microservices with external dependencies (databases, monitoring solutions like Prometheus/Grafana, etc.).

##### Highlighted Architectural Patterns and Design Principles
- Layered/Multi-Tier Architecture: Clear separation between API endpoints, business logic, persistence, and event handling.
- Modular/Microservices Design: The division into many Maven modules allows each component (REST API, service, events, persistence) to be developed, tested, and deployed somewhat independently.
- Event-Driven Architecture: With dedicated event modules, data operation events, NMCP-events, and asynchronous messaging patterns are core parts of the design.
- Use of External Configurations and DevOps: The presence of Docker Compose configurations and integration tests supports continuous integration and containerized deployment.

- Client/External Systems (Users, external management, etc.)
- API Layer (cps-rest, cps-ncmp-rest, etc.)
- Business Logic Layer (cps-application, cps-service, policy executor)
- Persistence Layer (cps-ri module and underlying databases)
- Messaging/Event Layer (cps-events, cps-ncmp-events, Kafka, etc.)
- Utility/Support (cps-path-parser, logging aspects, etc.)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    ExternalClients["External Clients"]:::external

    %% API Layer
    subgraph "API Layer"
        REST["cps-rest"]:::api
        NCMP["cps-ncmp-rest"]:::api
        Policy["Policy Executor Stub"]:::api
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        App["Core Application Logic"]:::business
        Service["Service Implementation"]:::business
    end

    %% Persistence / Repository Layer
    subgraph "Persistence / Repository Layer"
        RI["Repository Integration"]:::persistence
    end

    %% Events / Asynchronous Processing
    subgraph "Events / Asynchronous Processing"
        CPS_Events["CPS Events"]:::event
        NMCP_Events["NMCP Events"]:::event
    end

    %% Utility / Support Functions
    subgraph "Utility / Support Functions"
        PathParser["CPS Path Parsing"]:::utility
        Checkstyle["Code Quality / Checkstyle"]:::utility
    end

    %% Integration and Testing / Deployment
    subgraph "Integration and Testing / Deployment"
        Integration["Integration Tests"]:::testing
        CSIT["CSIT"]:::testing
        LoadTests["Load/Performance Testing"]:::testing
        DockerCompose["Docker Compose Configurations"]:::testing
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Database["SQL Database"]:::persistence
        Kafka["Kafka Broker"]:::event
        Monitoring["Prometheus/Grafana"]:::external
    end

    %% Connections: External Clients to API Layer
    ExternalClients -->|"REST_Request"| REST
    ExternalClients -->|"REST_Request"| NCMP
    ExternalClients -->|"REST_Request"| Policy

    %% Connections: API Layer to Business Logic Layer
    REST -->|"Service_Call"| App
    NCMP -->|"Service_Call"| App
    Policy -->|"Service_Call"| Service

    %% Connections: Business Logic to Persistence
    App -->|"DB_Query"| RI
    Service -->|"DB_Query"| RI

    %% Connections: Business Logic to Events
    App -->|"Event_Publish"| CPS_Events
    Service -->|"Event_Publish"| NMCP_Events

    %% Connections: Business Logic to Utility Functions
    App -->|"UtilCall"| PathParser
    Service -->|"UtilCall"| PathParser

    %% Connections: Persistence Module uses External Database
    RI -->|"Uses"| Database

    %% Connections: Events Modules publish to Kafka Broker
    CPS_Events -->|"Publishes_To"| Kafka
    NMCP_Events -->|"Publishes_To"| Kafka

    %% Deployment connection from Docker Compose to Business and Persistence layers
    DockerCompose -->|"Deploys"| App
    DockerCompose -->|"Deploys"| RI

    %% Class Definitions for colour styling
    classDef external fill:#D1E8FF,stroke:#333,stroke-width:2px;
    classDef api fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef business fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef persistence fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef event fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef utility fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef testing fill:#D3D3D3,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mapping
    click REST "https://github.com/onap/cps/tree/master/cps-rest"
    click NCMP "https://github.com/onap/cps/tree/master/cps-ncmp-rest"
    click Policy "https://github.com/onap/cps/tree/master/policy-executor-stub"
    click App "https://github.com/onap/cps/tree/master/cps-application"
    click Service "https://github.com/onap/cps/tree/master/cps-service"
    click CPS_Events "https://github.com/onap/cps/tree/master/cps-events"
    click NMCP_Events "https://github.com/onap/cps/tree/master/cps-ncmp-events"
    click RI "https://github.com/onap/cps/tree/master/cps-ri"
    click PathParser "https://github.com/onap/cps/tree/master/cps-path-parser"
    click Checkstyle "https://github.com/onap/cps/tree/master/checkstyle"
    click Integration "https://github.com/onap/cps/tree/master/integration-test"
    click CSIT "https://github.com/onap/cps/tree/master/csit"
    click LoadTests "https://github.com/onap/cps/tree/master/k6-tests"
    click DockerCompose "https://github.com/onap/cps/tree/master/docker-compose"
```
