|
| 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| SkillFind |
| 16 | + SkillFind --> RegistryList |
| 17 | + SkillFind --> IndexStore |
| 18 | + SkillFind --> IndexBuilder |
| 19 | + IndexBuilder -->|Fetch metadata| RegistrySources |
| 20 | + RegistrySources -->|skills/| IndexBuilder |
| 21 | + ``` |
| 22 | +- Key components and their responsibilities |
| 23 | + - SkillFind: CLI command `skill find` orchestrates index checks and search. |
| 24 | + - RegistryList: reads `skills/registry.json` to discover registries. |
| 25 | + - IndexBuilder: builds or updates a local index without full clones. |
| 26 | + - IndexStore: local cache file (json) with searchable entries and metadata. |
| 27 | + - RegistrySources: Git/HTTP access to registry metadata or skill folder list. |
| 28 | +- Technology stack choices and rationale |
| 29 | + - Node/TypeScript to align with existing CLI. |
| 30 | + - Git commands or HTTP fetch for low-cost metadata access. |
| 31 | + - Local cache under user cache dir to avoid repo writes. |
| 32 | + |
| 33 | +## Data Models |
| 34 | +**What data do we need to manage?** |
| 35 | + |
| 36 | +- Core entities and their relationships |
| 37 | + - Registry: `{ name, url, branch?, skillsPath }` |
| 38 | + - SkillEntry: `{ name, registry, path, description, lastIndexed }` |
| 39 | + - IndexMeta: `{ version, createdAt, updatedAt, ttlSeconds, registriesHash, registryHeads? }` |
| 40 | +- Data schemas/structures |
| 41 | + - `index.json` with `{ meta, skills: SkillEntry[] }` |
| 42 | +- Data flow between components |
| 43 | + - RegistryList -> IndexBuilder (registry config) |
| 44 | + - IndexBuilder -> IndexStore (write updated index) |
| 45 | + - SkillFind -> IndexStore (read and search) |
| 46 | + |
| 47 | +## API Design |
| 48 | +**How do components communicate?** |
| 49 | + |
| 50 | +- External APIs (if applicable) |
| 51 | + - GitHub REST tree API to list `skills/` paths without cloning. |
| 52 | + - Git `ls-remote` to detect head changes for refresh decisions. |
| 53 | +- Internal interfaces |
| 54 | + - `getRegistries(): Registry[]` |
| 55 | + - `ensureIndex(registries): Index` (checks TTL, registry list hash, optional head hash) |
| 56 | + - `searchIndex(index, keyword): SkillEntry[]` |
| 57 | +- Request/response formats |
| 58 | + - CLI: `npx ai-devkit skill find <keyword>` |
| 59 | + - Output: table or list with `skillName` and `description` |
| 60 | +- Authentication/authorization approach |
| 61 | + - Use standard Git auth (SSH/HTTPS tokens) if private registries appear. |
| 62 | + |
| 63 | +## Component Breakdown |
| 64 | +**What are the major building blocks?** |
| 65 | + |
| 66 | +- Frontend components (if applicable) |
| 67 | + - CLI output formatting only (no UI). |
| 68 | +- Backend services/modules |
| 69 | + - `skill-find` command handler. |
| 70 | + - `registry-reader` to parse registry list. |
| 71 | + - `index-builder` to assemble skill entries. |
| 72 | + - `search` utility for keyword matching. |
| 73 | +- Database/storage layer |
| 74 | + - Local cache file in user cache dir (json). |
| 75 | +- Third-party integrations |
| 76 | + - GitHub REST API for tree listing and raw file fetch. |
| 77 | + - Git CLI for optional head hash checks. |
| 78 | + |
| 79 | +## Design Decisions |
| 80 | +**Why did we choose this approach?** |
| 81 | + |
| 82 | +- Key architectural decisions and trade-offs |
| 83 | + - Use local index to avoid repeated network calls per search. |
| 84 | + - Prefer metadata fetch over full repo clone for speed and bandwidth. |
| 85 | + - TTL-based refresh plus manual `--refresh` option for freshness control. |
| 86 | + - Optionally compare remote head hashes to detect changes cheaply. |
| 87 | + - Store index at `~/.ai-devkit/skills.json`. |
| 88 | +- Alternatives considered |
| 89 | + - Git sparse checkout of `skills/` only (still needs Git and network). |
| 90 | + - Remote centralized index service (fast, but adds infra and availability). |
| 91 | + - On-demand repo scan per search (simple but slow and wasteful). |
| 92 | +- Patterns and principles applied |
| 93 | + - Cache with explicit invalidation (TTL + registry list hash). |
| 94 | + - Fail-soft behavior (use stale index if refresh fails). |
| 95 | + |
| 96 | +## Non-Functional Requirements |
| 97 | +**How should the system perform?** |
| 98 | + |
| 99 | +- Performance targets |
| 100 | + - Search completes in < 2s with a warm index. |
| 101 | + - Index refresh completes in < 30s for typical registry sizes. |
| 102 | +- Scalability considerations |
| 103 | + - Index size grows linearly with skills; support thousands of entries. |
| 104 | + - Avoid full clones to keep bandwidth stable as registries grow. |
| 105 | +- Security requirements |
| 106 | + - Avoid executing registry code; only read metadata paths. |
| 107 | + - Do not store credentials in index. |
| 108 | +- Reliability/availability needs |
| 109 | + - Use last-known index if refresh fails. |
| 110 | + - Provide clear error messaging for unreachable registries. |
| 111 | + |
0 commit comments