# maticnetwork/pos-portal architecture

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

- Interactive diagram: https://gitdiagram.com/maticnetwork/pos-portal
- Repository: https://github.com/maticnetwork/pos-portal

## Overview

##### Main Components

a. Root Chain (Ethereum) Components:
- RootChainManager
- StateSender
- TokenPredicates (Various token types: ERC20, ERC721, ERC1155, Ether)
- RootToken Contracts
- Proxy Contracts

b. Child Chain (Polygon) Components:
- ChildChainManager
- ChildToken Contracts (Various implementations)
- State Receiver Contract

**Top Layer: Root Chain (Ethereum)**
**Middle Layer: Bridge Components**
**Bottom Layer: Child Chain (Polygon)**

##### Key Elements to Highlight

a. Contract Interactions:
- Checkpoint verification paths
- Token mapping relationships

- Blue: Root chain components
- Green: Child chain components
- Orange: Bridge/tunnel components
- Purple: Proxy contracts
- Gray: External interfaces

##### Specific Component Relationships

a. Root Chain Manager Interactions:
- Connection to StateSender
- Integration with TokenPredicates
- Communication with Checkpoint contract

b. Child Chain Manager Interactions:
- Connection to StateReceiver
- Integration with ChildToken contracts
- Token mapping registry

##### Technical Details

a. Smart Contract Architecture:
- Proxy upgrade patterns
- Initialization flows
- Predicate contract hierarchy

b. Bridge Mechanics:
- State sync mechanism
- Exit process flow
- Token mapping system

##### Implementation Notes

Create distinct sections showing:
- Token Standards Support (ERC20, ERC721, ERC1155)
- Security Roles and Access Control
- Upgrade Mechanisms
- State Management

##### Additional Elements

- Contract types and their purposes
- Security boundaries

##### Deployment Flow

Deployment sequence:
##### Child Chain Initialization

This system design should reflect the project's core purpose as a bridge mechanism while accurately representing the smart contract architecture and interaction patterns present in the codebase.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Root_Chain[Root Chain - Ethereum]
        direction TB
        RCM[RootChainManager]
        SS[StateSender]
        TP[TokenPredicates]
        RTC[RootToken Contracts]
        PC[Proxy Contracts]
        
        RCM --> SS
        RCM --> TP
        TP --> RTC
        PC --> RCM
    end

    subgraph Bridge_Components[Bridge Layer]
        direction TB
        CP[Checkpoint]
        SM[State Management]
        TM[Token Mapping]
        
        CP --> SM
        SM --> TM
    end

    subgraph Child_Chain[Child Chain - Polygon]
        direction TB
        CCM[ChildChainManager]
        SRC[State Receiver Contract]
        CTC[ChildToken Contracts]
        
        CCM --> SRC
        CCM --> CTC
    end

    Root_Chain --> Bridge_Components
    Bridge_Components --> Child_Chain

    %% Component Mappings
    click RCM "https://github.com/maticnetwork/pos-portal/tree/master/contracts/root/RootChainManager"
    click SS "https://github.com/maticnetwork/pos-portal/tree/master/contracts/root/StateSender"
    click TP "https://github.com/maticnetwork/pos-portal/tree/master/contracts/root/TokenPredicates"
    click RTC "https://github.com/maticnetwork/pos-portal/tree/master/contracts/root/RootToken"
    click PC "https://github.com/maticnetwork/pos-portal/tree/master/contracts/common/Proxy"
    click CCM "https://github.com/maticnetwork/pos-portal/tree/master/contracts/child/ChildChainManager"
    click CTC "https://github.com/maticnetwork/pos-portal/tree/master/contracts/child/ChildToken"

    %% Styling
    classDef ethereum fill:#4a90e2,stroke:#2c3e50,color:white
    classDef polygon fill:#8bc34a,stroke:#2c3e50,color:white
    classDef bridge fill:#ff9800,stroke:#2c3e50,color:white
    classDef proxy fill:#9c27b0,stroke:#2c3e50,color:white

    class RCM,SS,TP,RTC ethereum
    class CCM,SRC,CTC polygon
    class CP,SM,TM bridge
    class PC proxy

    %% Legend
    subgraph Legend
        direction TB
        E[Ethereum Components]:::ethereum
        P[Polygon Components]:::polygon
        B[Bridge Components]:::bridge
        PR[Proxy Contracts]:::proxy
    end
```
