|
| 1 | +--- |
| 2 | +phase: design |
| 3 | +title: System Design & Architecture |
| 4 | +description: Define the technical architecture, components, and data models |
| 5 | +--- |
| 6 | + |
| 7 | +# System Design & Architecture |
| 8 | + |
| 9 | +## Architecture Overview |
| 10 | +**What is the high-level system structure?** |
| 11 | + |
| 12 | +- Include a mermaid diagram that captures the main components and their relationships. Example: |
| 13 | + ```mermaid |
| 14 | + graph TD |
| 15 | + User -->|CLI| SetupWizard |
| 16 | + SetupWizard --> Detector[Environment Detector] |
| 17 | + SetupWizard --> ProfileEngine[Profile Recommender] |
| 18 | + SetupWizard --> Planner[Plan Builder] |
| 19 | + Planner --> Adapters[Tool Adapters] |
| 20 | + Adapters --> FileOps[Safe File Ops] |
| 21 | + FileOps --> ToolDirs[Global Tool Directories] |
| 22 | + Planner --> StateStore[Setup State + Manifest] |
| 23 | + SetupWizard --> Reporter[Result Reporter] |
| 24 | + ``` |
| 25 | +- Key components and their responsibilities |
| 26 | + - SetupWizard: orchestrates interactive and non-interactive flows. |
| 27 | + - Environment Detector: discovers installed/supported tools and existing global configs. |
| 28 | + - Profile Recommender: proposes setup defaults by user persona (quickstart, team baseline, custom). |
| 29 | + - Plan Builder: computes deterministic operations (`create`, `update`, `skip`, `backup`). |
| 30 | + - Tool Adapters: map tool capabilities and paths (commands/skills/instruction files). |
| 31 | + - Safe File Ops: apply with backup, dry-run preview, conflict handling, and rollback boundaries. |
| 32 | + - State Store: keeps setup metadata for idempotency and drift detection. |
| 33 | + - Reporter: prints result summary and next-step recommendations. |
| 34 | +- Technology stack choices and rationale |
| 35 | + - Node/TypeScript to align with current CLI architecture. |
| 36 | + - Reuse existing prompt UI (`inquirer` and terminal-ui abstractions) for consistent UX. |
| 37 | + - Adapter-based design to avoid hardcoded branching and simplify future tool expansion. |
| 38 | + |
| 39 | +## Data Models |
| 40 | +**What data do we need to manage?** |
| 41 | + |
| 42 | +- Core entities and their relationships |
| 43 | + - ToolAdapter: describes capabilities and paths for one environment. |
| 44 | + - SetupProfile: predefined recommendation set (assets + policies). |
| 45 | + - SetupPlan: resolved operations generated from user choices + current state. |
| 46 | + - SetupState: persisted metadata from prior setup runs. |
| 47 | + - SetupReport: structured outcome summary of applied/skipped/failed operations. |
| 48 | +- Data schemas/structures |
| 49 | + - `ToolAdapter` |
| 50 | + - `{ code, name, capabilities: { globalCommands, globalSkills, globalInstructionFile }, paths, formats }` |
| 51 | + - `SetupPlan` |
| 52 | + - `{ id, createdAt, toolSelections, operations[], backupPolicy, overwritePolicy, dryRun }` |
| 53 | + - `Operation` |
| 54 | + - `{ type, source, target, assetType, toolCode, strategy, status, reason? }` |
| 55 | + - `SetupState` |
| 56 | + - `{ version, lastRunAt, fingerprintsByTarget, selectedProfile, selectedTools }` |
| 57 | +- Data flow between components |
| 58 | + - Detector -> Profile Recommender -> Plan Builder -> Safe File Ops -> State Store -> Reporter. |
| 59 | + |
| 60 | +## API Design |
| 61 | +**How do components communicate?** |
| 62 | + |
| 63 | +- External APIs (if applicable) |
| 64 | + - No mandatory external API calls in v1 core flow. |
| 65 | + - Optional future metadata refresh may use registry endpoints if online. |
| 66 | +- Internal interfaces |
| 67 | + - `detectEnvironments(): DetectedEnvironment[]` |
| 68 | + - `recommendProfiles(context): SetupProfile[]` |
| 69 | + - `buildPlan(input): SetupPlan` |
| 70 | + - `applyPlan(plan): SetupReport` |
| 71 | + - `renderReport(report): void` |
| 72 | +- Request/response formats |
| 73 | + - CLI entry points |
| 74 | + - `npx ai-devkit setup` (interactive wizard default) |
| 75 | + - `npx ai-devkit setup --non-interactive --profile <name> --tools codex,claude --assets commands,skills` |
| 76 | + - `npx ai-devkit setup --dry-run` |
| 77 | + - `npx ai-devkit setup --doctor` (recommended extension for diagnostics) |
| 78 | + - Output |
| 79 | + - Human-readable summary by default. |
| 80 | + - Optional machine-readable JSON report (`--json`) for CI/auditing. |
| 81 | +- Authentication/authorization approach |
| 82 | + - Setup writes only to user-accepted paths. |
| 83 | + - No secret material stored in setup state. |
| 84 | + - Existing auth for each tool remains managed by that tool. |
| 85 | + |
| 86 | +## Component Breakdown |
| 87 | +**What are the major building blocks?** |
| 88 | + |
| 89 | +- Frontend components (if applicable) |
| 90 | + - Terminal wizard screens: welcome, profile selection, tool selection, asset selection, preview, apply, summary. |
| 91 | +- Backend services/modules |
| 92 | + - `SetupWizardService` |
| 93 | + - `EnvironmentDetector` |
| 94 | + - `ProfileRecommendationService` |
| 95 | + - `SetupPlanner` |
| 96 | + - `SetupExecutor` |
| 97 | + - `SetupStateRepository` |
| 98 | + - `SetupReporter` |
| 99 | +- Database/storage layer |
| 100 | + - Local state file under user config/cache path (for example `~/.ai-devkit/setup-state.json`). |
| 101 | + - Backup snapshots with timestamps when overwrite policy requires backup. |
| 102 | +- Third-party integrations |
| 103 | + - Tool path conventions from Codex/Claude/Antigravity adapter definitions. |
| 104 | + - Optional shells for environment checks where required. |
| 105 | + |
| 106 | +## Design Decisions |
| 107 | +**Why did we choose this approach?** |
| 108 | + |
| 109 | +- Key architectural decisions and trade-offs |
| 110 | + - Make wizard the default instead of requiring `--global`: |
| 111 | + - Pros: better discoverability, lower onboarding friction. |
| 112 | + - Cons: users who prefer scripts need explicit non-interactive flags. |
| 113 | + - Use capability-driven adapters instead of tool-specific branching: |
| 114 | + - Pros: scalable for new tools and clearer testability. |
| 115 | + - Cons: initial refactor overhead. |
| 116 | + - Use plan/apply workflow with dry-run: |
| 117 | + - Pros: safer writes, auditable operations, easier debugging. |
| 118 | + - Cons: slightly more implementation complexity. |
| 119 | + - Keep idempotent state + fingerprints: |
| 120 | + - Pros: fast reruns, accurate drift detection. |
| 121 | + - Cons: need robust state migration/versioning. |
| 122 | + - Keep setup local-first (no required network): |
| 123 | + - Pros: reliable and fast. |
| 124 | + - Cons: recommendations may be less dynamic without optional online metadata. |
| 125 | +- Alternatives considered |
| 126 | + - Keep `setup --global` and add more flags: |
| 127 | + - Rejected: scales poorly as feature matrix grows. |
| 128 | + - One-off shell scripts per tool: |
| 129 | + - Rejected: difficult to maintain and non-portable. |
| 130 | + - Full policy engine in v1: |
| 131 | + - Deferred: high complexity for limited initial user value. |
| 132 | +- Patterns and principles applied |
| 133 | + - Progressive disclosure (quick path vs advanced mode). |
| 134 | + - Idempotent infrastructure-like planning/apply model. |
| 135 | + - Fail-soft execution: partial success with explicit report. |
| 136 | + |
| 137 | +## Non-Functional Requirements |
| 138 | +**How should the system perform?** |
| 139 | + |
| 140 | +- Performance targets |
| 141 | + - Startup detection and wizard initialization under 2s for typical local setups. |
| 142 | + - Dry-run planning under 1s with warm state. |
| 143 | +- Scalability considerations |
| 144 | + - Adapter registry should support 10+ environments without major UX degradation. |
| 145 | + - File operation engine should handle large command/skill templates predictably. |
| 146 | +- Security requirements |
| 147 | + - Never write outside approved user paths. |
| 148 | + - Never overwrite without policy confirmation. |
| 149 | + - Never persist secrets in state, logs, or reports. |
| 150 | +- Reliability/availability needs |
| 151 | + - Each operation isolated; one tool failure should not corrupt others. |
| 152 | + - Backup and recoverable operations for overwrite scenarios. |
| 153 | + - Clear actionable failure messages with remediation steps. |
| 154 | + |
0 commit comments