# ilsuono/git-remote-g2g architecture

> Architecture diagram of the GitHub repository ilsuono/git-remote-g2g, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ilsuono/git-remote-g2g
- Repository: https://github.com/ilsuono/git-remote-g2g

## Overview

##### Main Components
- Server Command Utility (“git g2g”): Found in cmd/git-g2g, this is the entry point for starting a git server (that outputs a host ID used by clients).
- Client Command Utility (“git-remote-g2g”): Located in cmd/git-remote-g2g, this component integrates with git (triggered via “git clone g2g://…”), connecting to the server with the provided host ID.
- Internal Library Components:
- pkg/pack: Implements functionality around reading and scanning ‘packs’ (likely the transport or packaging of git data).
- pkg/specs: Defines constants and data structures (IDs and protocol specifications) that are used across the application.
- Build and Deployment Artifacts: Indicated by Dockerfile, Makefile, GitHub workflows, and goreleaser configuration. These are important for understanding how the system is built, tested, and deployed, though they are secondary to runtime architecture.

##### Relationships and Interactions
- API/Data Flow: Show how git operations on the client trigger underlying functions that make use of the “pkg/pack” and “pkg/specs” libraries. Similarly, the server side uses these libraries for processing incoming requests.
- P2P Network: Illustrate that both client and server are connected via a libp2p-based communication channel. This may be depicted as a central “libp2p Network” component that facilitates peer discovery and data message exchange.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The cmd/ directories serve as clear entry points while the pkg/ directories encapsulate core functionality (business logic, pack handling, protocol specifications).
- Client-Server Communication over a P2P Network: This is an unusual design compared to centralized servers, so it’s important to emphasize the decoupled and distributed nature of the system.
- Modularity and Extensibility: The use of separate libraries (e.g., for pack handling and specs) suggests that new protocols or extensions could be added without major refactoring to the command utilities.

##### Relevant Technologies & Details
- Language: Go (as indicated by the .go files and go.mod).
- Networking Library: libp2p (as referenced in the README).
- Git Integration: Hooks or custom protocols that integrate with standard git commands (e.g., “git clone g2g://…”).
- Build Tools: Makefile, Dockerfile, GitHub Actions workflows, and goreleaser for building and deploying the application across platforms.

- “git g2g” (Server) and “git-remote-g2g” (Client).
- “pkg/pack” and “pkg/specs” as shared internal libraries.
- A separate cloud or network symbol labeled “libp2p Network” to represent the peer-to-peer communication medium.
- For example: “git-remote-g2g” → “libp2p Network” → “git g2g”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        C["git-remote-g2g"]:::client
    end

    %% P2P Communication Layer
    subgraph "P2P Layer"
        P["libp2p Network"]:::network
    end

    %% Server Side
    subgraph "Server Side"
        S["git g2g"]:::server
    end

    %% Internal Libraries
    subgraph "Internal Libraries"
        L1["pkg/pack"]:::library
        L2["pkg/specs"]:::library
    end

    %% Build and Deployment Artifacts
    subgraph "Build/Deployment"
        B1["Dockerfile"]:::build
        B2["Makefile"]:::build
        B3["goreleaser config"]:::build
        B4["GitHub Actions Workflow"]:::build
    end

    %% Main flow: Client to P2P to Server
    C -->|"git_clone/pull"| P
    P -->|"P2P_message"| S

    %% Dependencies on Internal Libraries
    C -->|"uses"| L1
    C -->|"uses"| L2
    S -->|"uses"| L1
    S -->|"uses"| L2

    %% Build and Deployment ties (dashed arrows)
    B1 ---|"builds"| C
    B1 ---|"builds"| S
    B2 ---|"builds"| C
    B2 ---|"builds"| S
    B3 ---|"releases"| C
    B3 ---|"releases"| S
    B4 ---|"tests/deploys"| C
    B4 ---|"tests/deploys"| S

    %% Click Events
    click C "https://github.com/ilsuono/git-remote-g2g/tree/main/cmd/git-remote-g2g"
    click S "https://github.com/ilsuono/git-remote-g2g/tree/main/cmd/git-g2g"
    click L1 "https://github.com/ilsuono/git-remote-g2g/tree/main/pkg/pack"
    click L2 "https://github.com/ilsuono/git-remote-g2g/tree/main/pkg/specs"
    click B1 "https://github.com/ilsuono/git-remote-g2g/tree/main/Dockerfile"
    click B2 "https://github.com/ilsuono/git-remote-g2g/tree/main/Makefile"
    click B3 "https://github.com/ilsuono/git-remote-g2g/blob/main/.goreleaser.yaml"
    click B4 "https://github.com/ilsuono/git-remote-g2g/blob/main/.github/workflows/go.yml"

    %% Styles
    classDef client fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef server fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef library fill:#f9844a,stroke:#333,stroke-width:2px;
    classDef network fill:#577590,stroke:#fff,stroke-width:2px,fill-opacity:0.5;
    classDef build fill:#8ecae6,stroke:#333,stroke-width:2px;
```
