|
| 1 | +--- |
| 2 | +phase: design |
| 3 | +title: System Design & Architecture |
| 4 | +description: Define the technical architecture, components, and data models |
| 5 | +feature: install-command |
| 6 | +--- |
| 7 | + |
| 8 | +# System Design & Architecture - Install Command |
| 9 | + |
| 10 | +## Architecture Overview |
| 11 | + |
| 12 | +**What is the high-level system structure?** |
| 13 | + |
| 14 | +```mermaid |
| 15 | +graph TD |
| 16 | + User[User: ai-devkit install] --> InstallCommand |
| 17 | + InstallCommand --> ConfigLoader[Config Service: load .ai-devkit.json] |
| 18 | + ConfigLoader --> Validator[Config Util Validator] |
| 19 | + Validator --> Reconciler[Install Reconciler] |
| 20 | + Reconciler --> Confirmer[Overwrite Confirmation Prompt] |
| 21 | + Reconciler --> EnvSetup[TemplateManager.setupMultipleEnvironments] |
| 22 | + Reconciler --> PhaseSetup[TemplateManager.copyPhaseTemplate] |
| 23 | + Reconciler --> SkillSetup[SkillManager.addSkill] |
| 24 | + SkillSetup --> SkillConfigSync[ConfigManager.update skills metadata] |
| 25 | + Reconciler --> Reporter[Install Summary Reporter] |
| 26 | +``` |
| 27 | + |
| 28 | +**Key components and responsibilities:** |
| 29 | + |
| 30 | +- `install` command handler: orchestrates install lifecycle. |
| 31 | +- `InstallConfig Validator`: validates environments, phases, and optional skills. |
| 32 | +- `Install Reconciler`: computes desired state vs existing files. |
| 33 | +- `TemplateManager` integration: applies environment and phase templates. |
| 34 | +- `SkillManager` integration: installs skills from config entries. |
| 35 | +- `Overwrite Confirmation Prompt`: when destination artifacts already exist, ask user to confirm replacement. |
| 36 | +- `SkillConfigSync`: ensures `ai-devkit skill add` writes skill metadata back to `.ai-devkit.json`. |
| 37 | +- `Reporter`: emits per-section summary and final exit status. |
| 38 | + |
| 39 | +## Data Models |
| 40 | + |
| 41 | +**What data do we need to manage?** |
| 42 | + |
| 43 | +```typescript |
| 44 | +interface DevKitInstallConfig { |
| 45 | + version: string; |
| 46 | + environments: EnvironmentCode[]; |
| 47 | + phases: Phase[]; |
| 48 | + skills?: Array<{ |
| 49 | + registry: string; |
| 50 | + name: string; |
| 51 | + }>; |
| 52 | + createdAt: string; |
| 53 | + updatedAt: string; |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +- Existing fields continue unchanged. |
| 58 | +- New `skills` field is optional for backward compatibility. |
| 59 | +- Duplicate skill entries deduplicated by `registry + name`. |
| 60 | + |
| 61 | +## API Design |
| 62 | + |
| 63 | +**How do components communicate?** |
| 64 | + |
| 65 | +**CLI surface:** |
| 66 | + |
| 67 | +- `ai-devkit install` |
| 68 | +- Optional follow-up flags (proposed): |
| 69 | + - `--config <path>` (default `.ai-devkit.json`) |
| 70 | + - `--overwrite` (overwrite all existing artifacts without additional prompts) |
| 71 | + |
| 72 | +**Internal interfaces (proposed):** |
| 73 | + |
| 74 | +```typescript |
| 75 | +async function installCommand(options: InstallOptions): Promise<void>; |
| 76 | +async function validateInstallConfig(config: unknown): Promise<ValidatedInstallConfig>; |
| 77 | +async function reconcileAndInstall(config: ValidatedInstallConfig, options: InstallOptions): Promise<InstallReport>; |
| 78 | +``` |
| 79 | + |
| 80 | +**Output contract:** |
| 81 | + |
| 82 | +- Section summaries for environments, phases, and skills. |
| 83 | +- Final totals: installed/skipped/failed. |
| 84 | +- Exit codes: |
| 85 | + - Invalid/missing config: `1` |
| 86 | + - Valid config with success: `0` |
| 87 | + - Partial skill-install failures: `0` with warning output and failed item details. |
| 88 | + |
| 89 | +## Component Breakdown |
| 90 | + |
| 91 | +**What are the major building blocks?** |
| 92 | + |
| 93 | +1. `packages/cli/src/commands/install.ts` (new): top-level command execution. |
| 94 | +2. `packages/cli/src/services/config/config.service.ts` (new): load config file from disk. |
| 95 | +3. `packages/cli/src/util/config.ts` (new): schema validation and normalization. |
| 96 | +4. `packages/cli/src/services/install/install.service.ts` (new): reconcile and apply installation. |
| 97 | +5. `packages/cli/src/lib/Config.ts` (update): persist/read `skills` metadata. |
| 98 | +6. `packages/cli/src/lib/SkillManager.ts` (update): on successful `addSkill`, sync skill entry into `.ai-devkit.json`. |
| 99 | +7. `packages/cli/src/cli.ts` (update): register `install` command and options. |
| 100 | + |
| 101 | +## Design Decisions |
| 102 | + |
| 103 | +**Why did we choose this approach?** |
| 104 | + |
| 105 | +- Reuse existing managers (`TemplateManager`, `SkillManager`) for consistency and lower risk. |
| 106 | +- Add `install` as separate command instead of overloading `init` to keep intent clear: |
| 107 | + - `init`: configure project interactively/template-first. |
| 108 | + - `install`: apply existing project config deterministically. |
| 109 | +- Keep new config field optional to avoid breaking older projects. |
| 110 | +- Existing artifacts require explicit user confirmation before overwrite (safe interactive default). |
| 111 | +- Partial skill failures do not fail the whole install run; command exits `0` and reports warnings for failed items. |
| 112 | + |
| 113 | +## Non-Functional Requirements |
| 114 | + |
| 115 | +**How should the system perform?** |
| 116 | + |
| 117 | +- Performance: install should scale linearly with configured phases and skills. |
| 118 | +- Reliability: each section continues independently and reports failures. |
| 119 | +- Security: validate config values before filesystem/network actions. |
| 120 | +- Usability: actionable errors that point to field names and file path. |
0 commit comments