# zopdev/zop-api architecture

> Architecture diagram of the GitHub repository zopdev/zop-api, 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/zopdev/zop-api
- Repository: https://github.com/zopdev/zop-api

## Overview

##### Project Identification
- The README explains that ZopDev comprises three parts: the backend API (zop-api), a UI (zop-ui), and a CLI (zop-cli). This repository, with its main.go, migrations, and Go modules, represents the backend service (zop-api).
- Its purpose is to orchestrate cloud infrastructure management by providing API endpoints (notably with a swagger endpoint at “/.well-known/swagger”), and the file structure supports a layered architecture for different domain areas.

##### Analyzing the File Structure
- The repository is organized into multiple domain-specific directories: “applications”, “cloudaccounts”, “deploymentspace”, and “environments”. Each of these contains subdirectories for “handler”, “service”, and “store”.
– Handlers: Likely act as the API controllers, interfacing with the HTTP layer.
– Services: Implement business logic.
– Stores: Manage data access (possibly interacting with databases using migrations defined in the “migrations” folder).
- Additionally, the “provider” package integrates with external cloud providers (there is a dedicated “gcp” folder) to handle aspects like deployments, pods, and services.
- Files like “configs/.env”, “Dockerfile”, GitHub workflows, and CI configurations indicate that containerization, continuous integration, and deployment are supported.

a. Main Components:
– Zop API (backend) as the central service.
– Domain modules/components:
- Applications
- CloudAccounts
- DeploymentSpace
- Environments
– Each domain should be subdivided into:
- Handlers (presentation/API endpoints)
- Services (business logic)
- Stores (data access/repository layer)
– External Provider Integrations (with modules under “provider”, notably for GCP, which manage cloud-specific operations)
– Infrastructure Tools:
- Database (implied by migrations and store implementations)
- Docker-based deployment (via Dockerfile and CI/CD workflows)
– Frontend and CLI components (zop-ui and zop-cli) as consumers of the API:

b. Relationships and Data Flow:
– Service components should, in turn, interact with the “Store” layer which handles database interactions.
– Include connections from the “provider” module to relevant domain services that require external cloud integrations (for example, deployment operations via GCP).
– Illustrate that the API endpoints (e.g., swagger at “/.well-known/swagger”) are exposed and consumed by the UI and CLI components.
– Optionally, indicate that the “migrations” directory is tied to the “Store” layer for database schema management.

c. Architectural Patterns and Design Principles:
– The project uses a layered (or n-tier) architecture: presentation (handler), application (service), and data (store) layers.
– This separation enforces separation of concerns, testability (note the presence of test files like *_test.go in each package), and modularity.
– The use of interfaces and mock implementations (e.g., mock_interface.go files in several directories) suggests a dependency injection strategy for easier testing and potential extensibility.
– Docker and CI/CD configurations suggest an emphasis on deployment automation and containerized microservice practices.

– Since this is a full-stack application with distinct frontend (zop-ui) and CLI (zop-cli) components, visually segregate the backend API from the consumer-facing applications.
– Emphasize the API boundaries and how the UI/CLI consume these endpoints.
– For the API, clearly demarcate each domain module along with its internal layers.
– Highlight external integrations (providers) and datastores.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Consumers
    zopUI["zop-ui"]:::external
    zopCLI["zop-cli"]:::external

    %% Backend API and Swagger Endpoint
    zopAPI["Zop API"]:::backend
    SwaggerEP["Swagger Endpoint (/.well-known/swagger)"]:::api
    zopAPI --> SwaggerEP
    zopUI -->|"consumes"| SwaggerEP
    zopCLI -->|"consumes"| SwaggerEP

    %% Applications Module
    A_Handler["Applications Handler"]:::handler
    A_Service["Applications Service"]:::service
    A_Store["Applications Store"]:::store
    zopAPI --> A_Handler
    A_Handler --> A_Service
    A_Service --> A_Store

    %% CloudAccounts Module
    CA_Handler["CloudAccounts Handler"]:::handler
    CA_Service["CloudAccounts Service"]:::service
    CA_Store["CloudAccounts Store"]:::store
    zopAPI --> CA_Handler
    CA_Handler --> CA_Service
    CA_Service --> CA_Store

    %% DeploymentSpace Module
    DS_Handler["DeploymentSpace Handler"]:::handler
    DS_Service["DeploymentSpace Service"]:::service
    DS_Store["DeploymentSpace Store"]:::store
    zopAPI --> DS_Handler
    DS_Handler --> DS_Service
    DS_Service --> DS_Store

    %% DeploymentSpace Cluster-specific Operations
    DS_Cluster_Service["DeploymentSpace Cluster Service"]:::service
    DS_Cluster_Store["DeploymentSpace Cluster Store"]:::store
    DS_Service --> DS_Cluster_Service
    DS_Cluster_Service --> DS_Cluster_Store

    %% Environments Module
    E_Handler["Environments Handler"]:::handler
    E_Service["Environments Service"]:::service
    E_Store["Environments Store"]:::store
    zopAPI --> E_Handler
    E_Handler --> E_Service
    E_Service --> E_Store

    %% Database (Migrations)
    DB["Database (Migrations)"]:::store
    A_Store -->|"stores"| DB
    CA_Store -->|"stores"| DB
    DS_Store -->|"stores"| DB
    DS_Cluster_Store -->|"stores"| DB
    E_Store -->|"stores"| DB

    %% Provider Integration (GCP)
    Provider["GCP Provider"]:::external
    DS_Service -->|"integrates"| Provider

    %% Configuration and Deployment
    ConfigEnv["Environment Config (.env)"]:::config
    Docker["Dockerfile"]:::config
    CICD["CI/CD Workflows"]:::config
    ConfigEnv -->|"configures"| zopAPI
    Docker -->|"builds"| zopAPI
    CICD -->|"deploys"| zopAPI

    %% Click Events
    click zopAPI "https://github.com/zopdev/zop-api/blob/main/main.go"
    click A_Handler "https://github.com/zopdev/zop-api/blob/main/applications/handler/handler.go"
    click A_Service "https://github.com/zopdev/zop-api/blob/main/applications/service/service.go"
    click A_Store "https://github.com/zopdev/zop-api/blob/main/applications/store/store.go"
    click CA_Handler "https://github.com/zopdev/zop-api/blob/main/cloudaccounts/handler/handler.go"
    click CA_Service "https://github.com/zopdev/zop-api/blob/main/cloudaccounts/service/service.go"
    click CA_Store "https://github.com/zopdev/zop-api/blob/main/cloudaccounts/store/store.go"
    click DS_Handler "https://github.com/zopdev/zop-api/blob/main/deploymentspace/handler/handler.go"
    click DS_Service "https://github.com/zopdev/zop-api/blob/main/deploymentspace/service/service.go"
    click DS_Store "https://github.com/zopdev/zop-api/blob/main/deploymentspace/store/store.go"
    click DS_Cluster_Service "https://github.com/zopdev/zop-api/blob/main/deploymentspace/cluster/service/service.go"
    click DS_Cluster_Store "https://github.com/zopdev/zop-api/blob/main/deploymentspace/cluster/store/store.go"
    click E_Handler "https://github.com/zopdev/zop-api/blob/main/environments/handler/handler.go"
    click E_Service "https://github.com/zopdev/zop-api/blob/main/environments/service/service.go"
    click E_Store "https://github.com/zopdev/zop-api/blob/main/environments/store/store.go"
    click Provider "https://github.com/zopdev/zop-api/tree/main/provider/gcp"
    click DB "https://github.com/zopdev/zop-api/tree/main/migrations/"
    click ConfigEnv "https://github.com/zopdev/zop-api/blob/main/configs/.env"
    click Docker "https://github.com/zopdev/zop-api/tree/main/Dockerfile"
    click CICD "https://github.com/zopdev/zop-api/tree/main/.github/workflows"

    %% Styles
    classDef backend fill:#B3E5FC,stroke:#0288D1,stroke-width:2px;
    classDef handler fill:#81D4FA,stroke:#01579B;
    classDef service fill:#C5E1A5,stroke:#558B2F;
    classDef store fill:#FFCC80,stroke:#F57C00,stroke-width:2px;
    classDef external fill:#FFF176,stroke:#F9A825;
    classDef api fill:#F8BBD0,stroke:#AD1457;
    classDef config fill:#D1C4E9,stroke:#512DA8;
```
