# port-experimental/deep-copy-entities architecture

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

- Interactive diagram: https://gitdiagram.com/port-experimental/deep-copy-entities
- Repository: https://github.com/port-experimental/deep-copy-entities

## Overview

Key Components to Include:

##### Source Environment
- A component for Port.io API Authentication using SOURCE credentials
- Entity storage/database representation

##### Destination Environment
- Similar structure to source, but with DEST credentials

##### Deep Copy Script Components
- Main Script Controller (main.ts)
- Port Client Handler (port_client.ts)
- Entity Traversal Engine

##### Component Relationships
- Authentication flow from credentials to respective environments
- Entity reading from source
- Deep traversal of related entities
- Writing to destination
- Recursive relationship handling

##### Specific Elements

**→ Data Flow**
**⟲ Recursive Operation**
**🔑 Authentication Point**
**📦 Entity Container**

a. Input Processing:
- Command line arguments (--root-blueprint, --entity-ids)
- Environment variables handling

b. Core Processing:
- Entity traversal logic
- Relationship mapping
- Deep copy mechanics

c. Authentication:
- Dual authentication handling
- Client credential flows

d. Data Flow:
- Entity reading
- Relationship discovery
- Entity replication
- Verification steps

##### Replicates to destination

A small notes section explaining any important considerations like:
- Handling of circular references
- Error handling flow
- Validation steps
- Rate limiting considerations

This will give other engineers a clear understanding of both the architecture and the operational flow of the entity copying process.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Data Flow]
        L2[Recursive Operation]
        L3[Authentication Point]
        L4[Entity Container]
        style L1 fill:#f5f5f5,stroke:#333
        style L2 fill:#f5f5f5,stroke:#333
        style L3 fill:#f5f5f5,stroke:#333
        style L4 fill:#f5f5f5,stroke:#333
    end

    subgraph "Source Environment"
        SA[("Port.io Source API")]:::source
        SC[("Source Credentials")]:::auth
        SE[("Entity Storage")]:::source
    end

    subgraph "Core Processing"
        MC["Main Controller"]:::process
        click MC "https://github.com/port-experimental/deep-copy-entities/blob/main/main.ts"
        PCH["Port Client Handler"]:::process
        click PCH "https://github.com/port-experimental/deep-copy-entities/blob/main/src/port_client.ts"
        PC["Project Config"]:::config
        click PC "https://github.com/port-experimental/deep-copy-entities/blob/main/package.json"
        DC["Dev Environment"]:::config
        click DC "https://github.com/port-experimental/deep-copy-entities/blob/main/devenv.nix"
        DOC["Documentation"]:::docs
        click DOC "https://github.com/port-experimental/deep-copy-entities/blob/main/README.md"
        TE["Traversal Engine"]:::process
        VAL["Validation Layer"]:::process
    end

    subgraph "Destination Environment"
        DA[("Port.io Dest API")]:::dest
        DC2[("Dest Credentials")]:::auth
        DE[("Entity Storage")]:::dest
    end

    %% Connections
    SC -->|Authenticate| SA
    DC2 -->|Authenticate| DA
    SA -->|Read Entities| TE
    SE -->|Source Data| TE
    TE -->|Traverse Relations| TE
    TE -->|Write Entities| DA
    MC -->|Initialize| PCH
    PCH -->|Handle API Calls| SA
    PCH -->|Handle API Calls| DA
    TE -->|Validate| VAL
    VAL -->|Verify| DE

    %% Notes
    subgraph "Processing Notes"
        N1["Circular Reference Handling"]
        N2["Rate Limiting"]
        N3["Error Management"]
    end

    %% Styles
    classDef source fill:#a8d1f0,stroke:#333
    classDef dest fill:#f5b042,stroke:#333
    classDef process fill:#90EE90,stroke:#333
    classDef auth fill:#d3d3d3,stroke:#333
    classDef config fill:#FFB6C1,stroke:#333
    classDef docs fill:#DDA0DD,stroke:#333
```
