How akashrajpurohit/git-sync works
Project type and purpose
• This is a Go‑based CLI tool (“git‑sync”) whose sole purpose is to back up and periodically sync Git repositories from multiple hosting providers (GitHub, GitLab, Bitbucket, Gitea/Forgejo) into a local directory.
File structure
• cmd/ & main.go: CLI entrypoint & commands (root, version)
• pkg/config: configuration loader, defaults, validation
• pkg/token: token management for authentication
• pkg/client: generic HTTP client wrapper
• pkg/{github,gitlab,bitbucket,forgejo}: provider‑specific API adapters
• pkg/raw: raw Git operations (clone, fetch)
• pkg/sync: core sync engine (concurrency, retry, stats)
• pkg/notification: send post‑sync alerts (Gotify, ntfy)
• pkg/logger: structured logging
• systemd + Dockerfile: deployment options
Key README insights
• Supports CLI flags + YAML config for settings
• Concurrent sync, shallow/bare/mirror clones
• External notification hooks
• Multi‑platform provider support
Main components and interactions
a. Components
• CLI Layer (cmd/, entrypoint.sh)
• Configuration Manager (pkg/config)
• Authentication Manager (pkg/token)
• API Adapters (pkg/github, pkg/gitlab, pkg/bitbucket, pkg/forgejo)
• Core Sync Engine (pkg/sync)
• Git Executor (pkg/raw)
• Notification Service (pkg/notification)
• Logging Service (pkg/logger)
• File System (local backup directory)
• External Services (Git providers, Gotify/ntfy endpoints)
b. Relationships & Data Flow
1. User invokes CLI → CLI Layer
2. CLI reads/parses CLI flags & loads YAML via Configuration Manager
3. Configuration Manager validates settings
4. Authentication Manager retrieves or refreshes tokens for each provider
5. For each provider: API Adapter calls provider’s REST API to list repositories
6. Core Sync Engine schedules jobs (concurrency manager, retry logic)
7. For each repository job: Git Executor (bare/shallow/mirror) reads/writes to File System
8. Sync Engine updates stats
9. Upon completion or error: Notification Service posts to configured channels
10. Logging Service records structured logs throughout
c. Architectural patterns & principles
• Modular provider abstraction (one pkg per host)
• Dependency injection via interfaces (client, logger, notification)
• Worker pool / concurrency pattern for parallel sync
• Retry decorator in sync module
• Single responsibility per package
d. Key technologies/frameworks
• Go modules (go.mod)
• Cobra (CLI parsing in cmd/)
• net/http via pkg/client
• Git CLI invoked in pkg/raw
• systemd unit & Dockerfile for deployment
• YAML config
Essential details to capture
• All major pkg/ subdirectories as modules
• Config & token retrieval before any sync
• Parallel sync jobs with retry & stats tracking
• Raw Git operations writing to the file system
• Notification & logging as first‑class citizens
• Deployment options (systemd, container)