|
| 1 | +# Raid - Distributed Development Orchestration |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Raid is a Go-based CLI tool that orchestrates development tasks, environments, and dependencies across distributed repositories. It uses YAML/JSON profile configurations to define multi-repo environments and automates setup/execution workflows. |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +### Core Components |
| 10 | +- **CLI Layer**: `src/cmd/` - Cobra-based command structure with subcommands for profiles, installation, and environments |
| 11 | +- **Business Logic**: `src/raid/` - High-level API layer that delegates to internal libraries |
| 12 | +- **Internal Implementation**: `src/internal/lib/` - Core functionality for profiles, repositories, environments, and task execution |
| 13 | +- **System Utilities**: `src/internal/sys/` and `src/utils/` - System-level operations and shared utilities |
| 14 | + |
| 15 | +### Key Design Patterns |
| 16 | + |
| 17 | +#### Configuration Management |
| 18 | +- Uses **Viper** for configuration with global state in `src/internal/lib/config.go` |
| 19 | +- **Context singleton** pattern: `lib.Context` struct caches active profile and environment |
| 20 | +- **Lazy loading**: `Load()` uses cached context, `ForceLoad()` rebuilds from scratch |
| 21 | +- Configuration path customizable via `--config/-c` flag |
| 22 | + |
| 23 | +#### Profile System |
| 24 | +- Profiles define collections of repositories and environments |
| 25 | +- **Multi-document YAML** support using `---` separators for multiple profiles per file |
| 26 | +- **JSON Schema validation** against `schemas/raid-profile.schema.json` |
| 27 | +- Profile state managed in Viper config under `"profiles"` key |
| 28 | + |
| 29 | +#### Repository Management |
| 30 | +- Concurrent cloning with optional thread limits (`--threads/-t` flag) |
| 31 | +- Uses Go routines with semaphore pattern for concurrency control |
| 32 | +- Repository validation and error aggregation across parallel operations |
| 33 | + |
| 34 | +#### Environment Execution |
| 35 | +- Environments contain tasks (Shell commands or Script files) and environment variables |
| 36 | +- Task execution supports concurrent execution flag per task |
| 37 | +- Environment variables set globally during environment execution |
| 38 | + |
| 39 | +### Key Files & Patterns |
| 40 | + |
| 41 | +#### Entry Points |
| 42 | +- `main.go` - Simple delegator to `cmd.Execute()` |
| 43 | +- `src/cmd/raid.go` - Root Cobra command with initialization lifecycle |
| 44 | + |
| 45 | +#### Command Structure |
| 46 | +``` |
| 47 | +src/cmd/ |
| 48 | +├── raid.go # Root command, global flags, initialization |
| 49 | +├── profile/ # Profile management (add, list, use, remove) |
| 50 | +├── install/ # Repository installation |
| 51 | +└── env/ # Environment execution |
| 52 | +``` |
| 53 | + |
| 54 | +#### Core Business Logic Flow |
| 55 | +1. **Initialize**: `raid.Initialize()` → `lib.InitConfig()` → `lib.Load()` |
| 56 | +2. **Profile Management**: Viper-backed persistence with JSON schema validation |
| 57 | +3. **Repository Installation**: Concurrent git cloning with error aggregation |
| 58 | +4. **Environment Execution**: Task orchestration with variable setting |
| 59 | + |
| 60 | +### Development Workflows |
| 61 | + |
| 62 | +#### Building & Testing |
| 63 | +```bash |
| 64 | +go build -o raid # Build binary |
| 65 | +go test ./... # Run tests |
| 66 | +go test -coverprofile=coverage.out ./... # Generate coverage |
| 67 | +``` |
| 68 | + |
| 69 | +#### JSON Schema Integration |
| 70 | +- Schemas in `schemas/` directory define validation rules |
| 71 | +- Use `github.com/santhosh-tekuri/jsonschema/v6` for validation |
| 72 | +- YAML language server integration with `# yaml-language-server: $schema=...` comments |
| 73 | + |
| 74 | +#### Configuration Files |
| 75 | +- **Profile configs**: YAML/JSON files following `schemas/raid-profile.schema.json` |
| 76 | +- **Multi-profile files**: Use YAML `---` document separators |
| 77 | +- **Examples**: See `docs/examples/` for reference configurations |
| 78 | + |
| 79 | +### Common Patterns |
| 80 | + |
| 81 | +#### Error Handling |
| 82 | +- Use `fmt.Errorf()` for wrapped errors with context |
| 83 | +- Aggregate errors from concurrent operations into slices |
| 84 | +- CLI commands print errors to stderr via `cmd.PrintErrln()` |
| 85 | + |
| 86 | +#### Concurrent Operations |
| 87 | +```go |
| 88 | +// Semaphore pattern for limiting concurrency |
| 89 | +semaphore := make(chan struct{}, maxThreads) |
| 90 | +var wg sync.WaitGroup |
| 91 | +errorChan := make(chan error, len(items)) |
| 92 | + |
| 93 | +// In goroutine: |
| 94 | +semaphore <- struct{}{} |
| 95 | +defer func() { <-semaphore }() |
| 96 | +``` |
| 97 | + |
| 98 | +#### Viper Configuration |
| 99 | +- Global config management via `viper.GetString()`, `viper.Set()` |
| 100 | +- Nested keys accessed with dot notation: `viper.GetStringMapString("profiles")` |
| 101 | +- Automatic config file discovery and loading |
| 102 | + |
| 103 | +### Testing & Quality |
| 104 | +- Uses standard Go testing with coverage reporting |
| 105 | +- GitHub Actions CI/CD pipeline defined (`.github/workflows/build.yml`) |
| 106 | +- Codecov integration for coverage tracking |
0 commit comments