# georgknabl/git-ssh-deploy architecture

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

- Interactive diagram: https://gitdiagram.com/georgknabl/git-ssh-deploy
- Repository: https://github.com/georgknabl/git-ssh-deploy

## Overview

##### Main Components
- Local Git Environment: Include the Git repository where files are tracked, the configuration stored in .git/config (containing environment settings like host, user, remote directory, commands, etc.), and the local execution of the deployment script.
- Deployment Script (git-ssh-deploy.sh): This is the core component that coordinates operations. Represent it as the controller that reads configuration, detects changes via “git diff”, fires off commands, and bundles files into a tarball.
- SSH Channel: A communication component that represents the secure SSH connection. Show the use of tools like scp (to copy the tarball) and SSH command execution (to extract files and run pre/post commands on the remote server).
- Remote Server: Illustrate this component as the destination system, including:
o The file extraction process (receiving the tarball and unpacking it into the specified remote directory).
o The state management on the server (logging the commit ID in .git-ssh-deploy-state-commit-id.log).
o Execution of pre-deployment and post-deployment commands.
o Optionally, a health check (HTTP request triggered after deployment).

##### Relationships and Interactions
- Start at the local Git repository, where changes are detected using Git diff.
- The Deployment Script takes these changes, bundles them (tarball), and then uses scp to copy to the remote server.
- On the remote side, the server extracts the tarball and executes any configured commands; state is then logged for future reference.

##### Architectural Patterns and Design Principles
- Configuration Driven — Emphasize that the behavior of the deployment (like command executions and exclusions) is governed by settings in .git/config.
- Lightweight, synchronous execution — As a Bash script, the tool is not built with asynchronous pipelines or separate services, so there isn’t a “service-oriented” component, but rather a linear, well-delineated workflow.

##### Technologies and Key Tools Highlighted
- Git and Git Config: Used for version control, diff calculation, and environment-specific configuration.
- SSH and SCP: For secure connection and file transfer.
- Bash scripting and tar: For file bundling, remote command execution, and offline state logging.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Local Environment"
        A["Local Git Repository & Config"]:::local
        B["Deployment Script (git-ssh-deploy.sh)"]:::local
    end

    C["SSH Channel (scp/ssh)"]:::transport

    subgraph "Remote Environment"
        D["Remote Server"]:::remote
        E["State Log File (.git-ssh-deploy-state-commit-id.log)"]:::remote
    end

    A -->|"git_diff_and_config_read"| B
    B -->|"tarball_creation_and_scp_transfer"| C
    C -->|"ssh_remote_extraction_and_commands"| D
    D -->|"log_commitID"| E
    D -->|"healthcheck_response"| A

    click A "https://github.com/georgknabl/git-ssh-deploy/tree/main/.git/config"
    click B "https://github.com/georgknabl/git-ssh-deploy/blob/main/git-ssh-deploy.sh"

    classDef local fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef transport fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef remote fill:#90EE90,stroke:#000,stroke-width:1px;
```
