|
| 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. |
| 13 | + ```mermaid |
| 14 | + graph TD |
| 15 | + User -->|init --template| InitCommand |
| 16 | + InitCommand --> TemplateLoader |
| 17 | + TemplateLoader --> TemplateValidator |
| 18 | + TemplateValidator --> InitConfigurator |
| 19 | + InitConfigurator --> EnvConfigurator[Environment Configurator] |
| 20 | + InitConfigurator --> PhaseConfigurator[Phase Configurator] |
| 21 | + InitConfigurator --> SkillInstaller[Skill Installer Bridge] |
| 22 | + SkillInstaller --> SkillAdd[Existing skill add flow] |
| 23 | + InitConfigurator --> Reporter |
| 24 | + ``` |
| 25 | +- Key components and their responsibilities |
| 26 | + - `InitCommand`: reads CLI args and routes interactive vs template-driven flow. |
| 27 | + - `TemplateLoader`: reads template file from path and parses YAML/JSON. |
| 28 | + - `TemplateValidator`: validates schema for `environments`, `skills`, and `phases`. |
| 29 | + - `InitConfigurator`: orchestrates applying resolved values. |
| 30 | + - `SkillInstaller Bridge`: adapts template skill entries into `skill add` invocations. |
| 31 | + - `Reporter`: prints summary of applied config + skill install results. |
| 32 | +- Technology stack choices and rationale |
| 33 | + - Continue with existing Node/TypeScript CLI stack. |
| 34 | + - Reuse current argument parsing and prompt layers. |
| 35 | + - Reuse existing `skill add` domain logic to avoid duplicated install behavior. |
| 36 | + |
| 37 | +## Data Models |
| 38 | +**What data do we need to manage?** |
| 39 | + |
| 40 | +- Core entities and their relationships |
| 41 | + - `InitTemplate` |
| 42 | + - `TemplateSkill` |
| 43 | + - `TemplateValidationResult` |
| 44 | + - `SkillInstallResult` |
| 45 | +- Data schemas/structures |
| 46 | + - `InitTemplate` |
| 47 | + - `{ version?, environments?, phases?, skills? }` |
| 48 | + - `TemplateSkill` |
| 49 | + - `{ registry: string, skill: string, options?: Record<string, string> }` |
| 50 | + - Skill entry processing key |
| 51 | + - Unique key is `registry + skill`; same registry with different skills is valid and processed as separate installs. |
| 52 | + - `SkillInstallResult` |
| 53 | + - `{ registry, skill, status: 'installed' | 'skipped' | 'failed', reason? }` |
| 54 | +- Data flow between components |
| 55 | + - CLI args -> template file parse -> validation -> init apply -> per-skill install -> summary output. |
| 56 | + |
| 57 | +## API Design |
| 58 | +**How do components communicate?** |
| 59 | + |
| 60 | +- External APIs (if applicable) |
| 61 | + - None required; optional network access occurs only through existing skill installation behavior. |
| 62 | +- Internal interfaces |
| 63 | + - `loadTemplate(path: string): Promise<unknown>` (supports relative and absolute paths) |
| 64 | + - `validateTemplate(raw: unknown): TemplateValidationResult` |
| 65 | + - `applyTemplate(config: InitTemplate): Promise<InitApplyResult>` |
| 66 | + - `installSkills(skills: TemplateSkill[]): Promise<SkillInstallResult[]>` |
| 67 | +- Request/response formats |
| 68 | + - CLI command |
| 69 | + - `npx ai-devkit init --template <path>` |
| 70 | + - Path resolution: absolute path as-is; relative path resolved from current working directory. |
| 71 | + - Sample YAML template |
| 72 | + ```yaml |
| 73 | + version: 1 |
| 74 | + environments: |
| 75 | + - codex |
| 76 | + - claude |
| 77 | + phases: |
| 78 | + - requirements |
| 79 | + - design |
| 80 | + - planning |
| 81 | + - implementation |
| 82 | + - testing |
| 83 | + skills: |
| 84 | + - registry: codeaholicguy/ai-devkit |
| 85 | + skill: debug |
| 86 | + - registry: codeaholicguy/ai-devkit |
| 87 | + skill: memory |
| 88 | + ``` |
| 89 | + - Output |
| 90 | + - Validation errors include template path + invalid field(s). |
| 91 | + - Success summary includes configured environments/phases and skill outcomes. |
| 92 | + - Skill installation failures are warnings; command exits with code `0` and includes failed items in report. |
| 93 | +- Authentication/authorization approach |
| 94 | + - No new auth model. Skill installation uses current auth/network behavior in existing `skill add` flow. |
| 95 | + |
| 96 | +## Component Breakdown |
| 97 | +**What are the major building blocks?** |
| 98 | + |
| 99 | +- Frontend components (if applicable) |
| 100 | + - CLI prompt layer remains as fallback when template is partial. |
| 101 | +- Backend services/modules |
| 102 | + - `init.command` argument handling (`--template`). |
| 103 | + - `template-parser` module. |
| 104 | + - `template-validator` module. |
| 105 | + - `init-apply` orchestration module. |
| 106 | + - `skill-install-adapter` module (bridge to existing install logic). |
| 107 | +- Database/storage layer |
| 108 | + - No new persistent store required for v1. |
| 109 | +- Third-party integrations |
| 110 | + - YAML parser library (existing or new lightweight dependency). |
| 111 | + |
| 112 | +## Design Decisions |
| 113 | +**Why did we choose this approach?** |
| 114 | + |
| 115 | +- Key architectural decisions and trade-offs |
| 116 | + - Reuse `skill add` implementation: |
| 117 | + - Pros: consistent behavior and less duplication. |
| 118 | + - Cons: init flow depends on skill module API stability. |
| 119 | + - Add template as optional mode, not replacement: |
| 120 | + - Pros: backward compatibility and low migration risk. |
| 121 | + - Cons: dual paths increase test surface. |
| 122 | + - Continue-on-error for skill install with exit code `0`: |
| 123 | + - Pros: init can apply as much as possible and provide complete failure report in one run. |
| 124 | + - Cons: downstream automation must inspect warning/report output instead of relying only on exit code. |
| 125 | + - Validate template before applying side effects: |
| 126 | + - Pros: deterministic behavior and better errors. |
| 127 | + - Cons: requires explicit schema maintenance. |
| 128 | +- Alternatives considered |
| 129 | + - Implement separate installer inside `init`. |
| 130 | + - Rejected due to divergence from `skill add` behavior. |
| 131 | + - Force non-interactive mode whenever template provided. |
| 132 | + - Rejected; fallback prompts for missing values are more user-friendly. |
| 133 | +- Patterns and principles applied |
| 134 | + - Schema-first validation. |
| 135 | + - Orchestrator + adapters for integration points. |
| 136 | + - Backward-compatible CLI extension. |
| 137 | + |
| 138 | +## Non-Functional Requirements |
| 139 | +**How should the system perform?** |
| 140 | + |
| 141 | +- Performance targets |
| 142 | + - Template loading + validation under 300ms for small files. |
| 143 | + - No regression in plain interactive init startup. |
| 144 | +- Scalability considerations |
| 145 | + - Support multiple skill entries without blocking summary reporting. |
| 146 | +- Security requirements |
| 147 | + - Treat template input as untrusted; validate and sanitize fields before use. |
| 148 | + - Avoid arbitrary command execution from template values. |
| 149 | +- Reliability/availability needs |
| 150 | + - Partial failure handling for multi-skill installs with explicit status. |
| 151 | + - Duplicate `registry + skill` entries are deduplicated during execution and reported as skipped/warning. |
| 152 | + - Deterministic error codes for invalid template input. |
0 commit comments