# muesli/gitomatic architecture

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

- Interactive diagram: https://gitdiagram.com/muesli/gitomatic
- Repository: https://github.com/muesli/gitomatic

## Overview

1. **Project shape**
   - This is a small Go command-line tool, built as a single binary from `main.go`.
   - The repository is intentionally minimal: there are no separate packages or services in-tree, so the runtime architecture is centered on one executable.

2. **Primary purpose**
   - `git-o-matic` watches a local Git repository and repeatedly reconciles it with its remote by pulling, detecting local changes, committing them, and pushing.
   - The tool is automation glue around Git, not a general-purpose server or library.

3. **Execution boundary**
   - The user invokes the binary with a repository path as the main input.
   - The process runs locally on the machine that hosts the repository, so the main system boundary is between the CLI process, the local filesystem, and the Git remote.

4. **Core control loop**
   - The app operates as a periodic polling loop, not a filesystem event daemon.
   - Each cycle checks the repository, performs a pull, inspects for added/removed files, creates commits when needed, pushes those commits, then sleeps for the configured interval.

5. **Local repository subsystem**
   - The working tree and Git metadata in the target path are the center of the system.
   - The tool reads repository state, detects file additions/deletions, and stages corresponding work-tree changes before commit creation.

6. **Synchronization flow**
   - The inbound side is `git pull`, which brings in remote changes before local processing.
   - The outbound side is `git push`, which publishes any newly created commits back to the remote.
   - This makes the tool a bidirectional sync agent for repositories where local file changes should be automatically versioned.

7. **Change-to-commit behavior**
   - When the tool sees a new file, it adds it to the work tree and creates a commit with an auto-generated message like “Add …”.
   - When it sees a deleted file, it removes it from the work tree and commits with a corresponding message like “Remove …”.
   - The README suggests the commit author name and email are configurable, so commit identity is part of the runtime configuration.

8. **Remote authentication boundary**
   - The remote connection supports SSH private-key auth and username/password auth.
   - That means the repo can target both SSH-based and HTTPS/basic-auth Git remotes, depending on how credentials are supplied.

9. **Operational configuration**
   - The key runtime knobs are repository path, pull/push enablement, polling interval, auth credentials, and author identity.
   - This makes the binary suitable for unattended use in cron-like or daemon-like deployment scenarios, even though it is itself a foreground process.

10. **Build and release tooling**
   - The project is built with Go and distributed via released binaries for Linux, macOS, and Windows.
   - `.goreleaser.yml` indicates release automation, while the Go module files define dependencies and build reproducibility.

11. **Architecture diagram takeaway**
   - A good diagram would show: user/CLI input → `gitomatic` polling loop → local Git repository inspection and staging → commit creation → remote Git push/pull, with configuration and credentials feeding the loop.
   - The dominant dependencies are the local filesystem, Git tooling/library behavior, and the remote Git server.

Main entry points: [`main.go`](https://github.com/muesli/gitomatic/blob/master/main.go) (git-o-matic), [`README.md`](https://github.com/muesli/gitomatic/blob/master/README.md) (Credentials), [`.goreleaser.yml`](https://github.com/muesli/gitomatic/blob/master/.goreleaser.yml) (Release), [`go.mod`](https://github.com/muesli/gitomatic/blob/master/go.mod) (Go module)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_cli["git-o-matic<br/>command<br/>[main.go]"]
  node_config["Config<br/>[README.md]"]
  node_loop(("Poll loop<br/>scheduler<br/>[main.go]"))
  node_pull["Pull<br/>sync in<br/>[main.go]"]
  node_scan["Scan changes<br/>diff detection<br/>[main.go]"]
  node_stageadd["Add file<br/>staging action<br/>[main.go]"]
  node_stageremove["Remove file<br/>staging action<br/>[main.go]"]
  node_commit["Commit<br/>[main.go]"]
  node_push["Push<br/>sync out<br/>[main.go]"]
  node_auth["Credentials<br/>auth<br/>[README.md]"]
  node_identity["Author<br/>commit identity<br/>[README.md]"]
end

subgraph group_external["External"]
  node_user(("User<br/>operator"))
  node_repo[("Local repo<br/>git working tree")]
  node_remote[("Git remote<br/>remote server")]
end

subgraph group_tooling["Tooling"]
  node_goreleaser["Release<br/>[.goreleaser.yml]"]
  node_gomod["Go module<br/>module metadata<br/>[go.mod]"]
  node_gosum["Checksums<br/>module lock<br/>[go.sum]"]
end

node_user -->|"run"| node_cli
node_config -->|"settings"| node_cli
node_cli -->|"start"| node_loop
node_loop -->|"step"| node_pull
node_pull -->|"fetch"| node_remote
node_auth -->|"auth"| node_pull
node_loop -->|"inspect"| node_repo
node_repo -->|"state"| node_scan
node_pull -->|"after pull"| node_scan
node_scan -->|"new files"| node_stageadd
node_scan -->|"deleted files"| node_stageremove
node_stageadd -->|"prepare"| node_commit
node_stageremove -->|"prepare"| node_commit
node_identity -->|"author"| node_commit
node_commit -->|"publish"| node_push
node_push -->|"send"| node_remote
node_auth -->|"auth"| node_push
node_gomod -->|"build"| node_cli
node_gosum -->|"lock"| node_cli
node_goreleaser -->|"package"| node_cli

click node_cli "https://github.com/muesli/gitomatic/blob/master/main.go"
click node_config "https://github.com/muesli/gitomatic/blob/master/README.md"
click node_loop "https://github.com/muesli/gitomatic/blob/master/main.go"
click node_pull "https://github.com/muesli/gitomatic/blob/master/main.go"
click node_scan "https://github.com/muesli/gitomatic/blob/master/main.go"
click node_stageadd "https://github.com/muesli/gitomatic/blob/master/main.go"
click node_stageremove "https://github.com/muesli/gitomatic/blob/master/main.go"
click node_commit "https://github.com/muesli/gitomatic/blob/master/main.go"
click node_push "https://github.com/muesli/gitomatic/blob/master/main.go"
click node_auth "https://github.com/muesli/gitomatic/blob/master/README.md"
click node_identity "https://github.com/muesli/gitomatic/blob/master/README.md"
click node_goreleaser "https://github.com/muesli/gitomatic/blob/master/.goreleaser.yml"
click node_gomod "https://github.com/muesli/gitomatic/blob/master/go.mod"
click node_gosum "https://github.com/muesli/gitomatic/blob/master/go.sum"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_config,node_loop,node_pull,node_scan,node_stageadd,node_stageremove,node_commit,node_push,node_auth,node_identity toneBlue
class node_user,node_repo,node_remote toneAmber
class node_goreleaser,node_gomod,node_gosum toneMint
```

## Components

### Runtime

Single-binary Git sync loop

- [git-o-matic](https://github.com/muesli/gitomatic/blob/master/main.go): command · Single Go executable · `main.go`
- [Config](https://github.com/muesli/gitomatic/blob/master/README.md): runtime config · Repo path, interval, auth, author, and sync toggles · `README.md`
- [Poll loop](https://github.com/muesli/gitomatic/blob/master/main.go): scheduler · Repeated reconcile cycle with sleep between runs · `main.go`
- [Pull](https://github.com/muesli/gitomatic/blob/master/main.go): sync in · Brings remote changes into the local repo · `main.go`
- [Scan changes](https://github.com/muesli/gitomatic/blob/master/main.go): diff detection · Detects added and deleted files · `main.go`
- [Add file](https://github.com/muesli/gitomatic/blob/master/main.go): staging action · Stages new files for commit · `main.go`
- [Remove file](https://github.com/muesli/gitomatic/blob/master/main.go): staging action · Stages deletions for commit · `main.go`
- [Commit](https://github.com/muesli/gitomatic/blob/master/main.go): git commit · Creates auto-generated add/remove commits · `main.go`
- [Push](https://github.com/muesli/gitomatic/blob/master/main.go): sync out · Publishes new commits to the remote · `main.go`
- [Credentials](https://github.com/muesli/gitomatic/blob/master/README.md): auth · SSH key or username/password credentials · `README.md`
- [Author](https://github.com/muesli/gitomatic/blob/master/README.md): commit identity · Commit author name and email · `README.md`

### External

Local repo and remote Git boundary

- **User**: operator · Invokes the binary with a repo path
- **Local repo**: git working tree · Target repository path and Git metadata
- **Git remote**: remote server · SSH or HTTPS authenticated Git endpoint

### Tooling

Build and release inputs

- [Release](https://github.com/muesli/gitomatic/blob/master/.goreleaser.yml): release config · Builds distributed binaries for major platforms · `.goreleaser.yml`
- [Go module](https://github.com/muesli/gitomatic/blob/master/go.mod): module metadata · Dependency and build metadata · `go.mod`
- [Checksums](https://github.com/muesli/gitomatic/blob/master/go.sum): module lock · Dependency checksum lockfile · `go.sum`

## Connections

- User → git-o-matic: run · Launches the binary with a repository path
- Config → git-o-matic: settings · Supplies runtime knobs and credentials
- git-o-matic → Poll loop: start · Enters the periodic reconcile cycle
- Poll loop → Pull: step · Begins each cycle by pulling remote changes
- Pull → Git remote: fetch · Reads updates from the configured remote
- Credentials → Pull: auth · Credentials enable remote access
- Poll loop → Local repo: inspect · Works against the local repository path
- Local repo → Scan changes: state · Provides working tree and Git metadata
- Pull → Scan changes: after pull · Scans for local changes after inbound sync
- Scan changes → Add file: new files · Routes added files to staging
- Scan changes → Remove file: deleted files · Routes deleted files to staging
- Add file → Commit: prepare · Adds new files before commit creation
- Remove file → Commit: prepare · Removes deleted files before commit creation
- Author → Commit: author · Provides commit author identity
- Commit → Push: publish · Sends newly created commits to the remote
- Push → Git remote: send · Pushes commits to the Git server
- Credentials → Push: auth · Credentials also authorize outbound push
- Go module → git-o-matic: build · Module metadata for the Go binary
- Checksums → git-o-matic: lock · Checksum lockfile for reproducible builds
- Release → git-o-matic: package · Release automation packages binaries from the Go build
