mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-31 21:40:28 +00:00
refactor: Update README.md to document shared/common.sh architecture
Added "Architecture" section explaining: - Library structure (shared/common.sh + cloud-specific extensions) - How shared utilities reduce duplication across providers - Benefits: DRY, consistency, maintainability, extensibility Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
5954455030
commit
69cc92a52e
1 changed files with 45 additions and 0 deletions
45
README.md
45
README.md
|
|
@ -351,6 +351,51 @@ OPENROUTER_API_KEY=sk-or-v1-xxxxx \
|
|||
|
||||
---
|
||||
|
||||
## Architecture
|
||||
|
||||
Spawn uses a **shared library pattern** to reduce code duplication across cloud providers:
|
||||
|
||||
### Library Structure
|
||||
|
||||
```
|
||||
spawn/
|
||||
shared/
|
||||
common.sh # Provider-agnostic utilities (logging, OAuth, SSH helpers)
|
||||
{cloud}/
|
||||
lib/common.sh # Cloud-specific functions (sources shared/common.sh)
|
||||
{agent}.sh # Agent deployment scripts
|
||||
```
|
||||
|
||||
### How It Works
|
||||
|
||||
1. **`shared/common.sh`** - Core utilities used by all clouds:
|
||||
- Color logging (`log_info`, `log_warn`, `log_error`)
|
||||
- Safe input handling (`safe_read`)
|
||||
- OAuth flow for OpenRouter authentication
|
||||
- Network utilities (`nc_listen`, `open_browser`)
|
||||
- SSH key management and connectivity helpers
|
||||
- Security validation (`validate_model_id`, `json_escape`)
|
||||
|
||||
2. **`{cloud}/lib/common.sh`** - Cloud-specific extensions:
|
||||
- Sources `shared/common.sh` first
|
||||
- Adds provider-specific functions (API wrappers, provisioning logic)
|
||||
- Examples: `sprite/lib/common.sh` adds Sprite CLI functions, `hetzner/lib/common.sh` adds Hetzner API functions
|
||||
|
||||
3. **Agent scripts** - Combine shared utilities with cloud-specific provisioning:
|
||||
- Source their cloud's `lib/common.sh`
|
||||
- Use shared functions for authentication and setup
|
||||
- Use cloud functions for server provisioning
|
||||
- Deploy and configure the specific agent
|
||||
|
||||
### Benefits
|
||||
|
||||
- **DRY (Don't Repeat Yourself)** - OAuth, logging, and SSH logic are written once
|
||||
- **Consistency** - All scripts use the same patterns for authentication and error handling
|
||||
- **Maintainability** - Bug fixes in `shared/common.sh` benefit all cloud providers
|
||||
- **Extensibility** - Adding a new cloud only requires writing provider-specific logic
|
||||
|
||||
---
|
||||
|
||||
## Security
|
||||
|
||||
### API Token Storage
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue