# openp2p-cn/openp2p architecture

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

- Interactive diagram: https://gitdiagram.com/openp2p-cn/openp2p
- Repository: https://github.com/openp2p-cn/openp2p

## Overview

##### Main Components
- Core P2P Engine:
– Located in the “core” folder (with modules for NAT traversal, hole punching, UDP/TCP/QUIC handling, tunnelling, and encryption).
– Also “cmd” and “lib” provide executable entry points and shared functions.
- Android Client Application:
– Found under the “app” directory; it has the typical Android project structure (gradle files, manifest, Java/Kotlin source for login pages, service components like BootReceiver, and UI layers).
- P2PApp Manager Module:
– As highlighted in the README, there is a “P2PApp” abstraction that maps remote services (like MSTSC, SSH, etc.) to local ports.
- Deployment & Configuration:
– Docker files, configuration JSON, and build scripts (Makefile, gradle, etc.) indicate a readiness for containerized deployment and cross-platform building.
- External Interfaces & Integration Points:
– The project integrates with external servers (for TLS key exchange, TOTP verification, and scheduling relay nodes) as per the README’s discussion of security and node management.

##### Relationships & Interactions
- The Android client interacts with the core network library via local services. It provides the user interface for login and for managing P2PApp instances.
- The core engine, implemented in Go, is responsible for establishing secure P2P connections between nodes. It handles NAT traversal (KCP, QUIC, etc.), authentication, and data relaying.
- The P2PApp management module is in charge of mapping remote/relay services to the local listening ports; this module bridges the core functions with user-level APIs.
- Communication flows include:
– Data flow from the client to the core engine when establishing a connection.
– Secure data transfer between nodes (using TLS and AES encryption, with keys exchanged through a central server mechanism).
- Configuration and build pipelines (using Gradle for Android and Makefile/Go modules for the core) ensure that the various components are compiled and packaged for diverse platforms.

##### Architectural Patterns & Design Principles
- Modular Design: Separate components for client UI (Android app) and backend P2P networking (Golang core and libraries).
- Security & Encryption: Emphasis on TLS1.3 and AES double encryption, along with a TOTP mechanism for authenticating relay nodes.
- Cross-Platform Considerations: The main engine is written in Go (offering multi-OS support) and the Android client provides mobile gateway capabilities.

##### Technologies & Frameworks Involved
- Golang (v1.20) for the core network functionality.
- Gradle-based Android application (Java/Kotlin) for the client.
- Containerization hints via Docker deployment files.
- Standard tools (Makefile, gradle, etc.) for building and configuration.

##### Final Recommendations for the Principal Software Engineer
- Component with well-defined labels and specify the protocols and frameworks being used (e.g., TLS1.3 in the security module, Quic protocol in underlay communication).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Client Layer"
        A1["Android Client (UI,Service,Receiver)"]:::client
    end

    subgraph "Core Network Layer"
        C1["Core Modules (NAT,traversal,HolePunch,UDP/TCP/QUIC,Encryption)"]:::core
        C2["Entry Point (cmd/openp2p.go)"]:::core
        C3["Shared Functions (lib/openp2p.go)"]:::core
    end

    subgraph "Management & Integration Layer"
        M1["P2PApp Manager (core/p2papp.go)"]:::manager
        M2["P2PApp Keys (core/p2pappkeys.go)"]:::manager
    end

    subgraph "Deployment & Configuration"
        D1["Docker Files"]:::deployment
        D2["Makefile"]:::deployment
        D3["Config JSON"]:::deployment
    end

    subgraph "External Services"
        E1["Relay & Authentication Server"]:::external
    end

    %% Connections
    A1 -->|"initiates"| C1
    A1 -->|"manages"| M1
    C2 -->|"launches"| C1
    C3 -->|"supports"| C1
    M1 -->|"bridges"| C1
    C1 -->|"secure-connection"| E1
    M1 -->|"key-exchange"| E1
    M1 -->|"provides-keys"| M2
    D1 -->|"containerizes"| C1
    D2 -->|"builds"| C1
    D3 -->|"configures"| M1

    %% Click Events
    click A1 "https://github.com/openp2p-cn/openp2p/tree/master/app/"
    click C1 "https://github.com/openp2p-cn/openp2p/tree/master/core/"
    click C2 "https://github.com/openp2p-cn/openp2p/blob/master/cmd/openp2p.go"
    click C3 "https://github.com/openp2p-cn/openp2p/blob/master/lib/openp2p.go"
    click M1 "https://github.com/openp2p-cn/openp2p/blob/master/core/p2papp.go"
    click M2 "https://github.com/openp2p-cn/openp2p/blob/master/core/p2pappkeys.go"
    click D1 "https://github.com/openp2p-cn/openp2p/tree/master/docker/"
    click D2 "https://github.com/openp2p-cn/openp2p/tree/master/Makefile"
    click D3 "https://github.com/openp2p-cn/openp2p/blob/master/config.json"

%% Class Definitions
classDef client fill:#aqua,stroke:#000,stroke-width:2px
classDef core fill:#ffcccc,stroke:#cc0000,stroke-width:2px
classDef manager fill:#ccffcc,stroke:#008000,stroke-width:2px
classDef deployment fill:#e0ccff,stroke:#800080,stroke-width:2px
classDef external fill:#ffe6cc,stroke:#ff8000,stroke-width:2px
```
