|
| 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 | +```mermaid |
| 13 | +graph TD |
| 14 | + User --> CLI[ai-devkit lint command] |
| 15 | + CLI --> ArgParser[Feature and output argument parser] |
| 16 | + ArgParser --> LintService[Lint validation service] |
| 17 | + LintService --> BaseCheck[Base docs checker] |
| 18 | + LintService --> FeatureCheck[Feature docs checker] |
| 19 | + LintService --> GitCheck[Worktree and branch checker] |
| 20 | + BaseCheck --> FS[(File System)] |
| 21 | + FeatureCheck --> FS |
| 22 | + GitCheck --> Git[(Git metadata)] |
| 23 | + CLI --> Reporter[Terminal and JSON reporter] |
| 24 | +``` |
| 25 | + |
| 26 | +- Key components and responsibilities |
| 27 | + - `lint` command handler: parse options and orchestrate checks. |
| 28 | + - Name normalizer: convert `--feature` input into canonical `<name>` and `feature-<name>` (accept `foo` and `feature-foo`). |
| 29 | + - Base docs checker: validate required phase template files (`docs/ai/*/README.md`). |
| 30 | + - Feature docs checker: validate `docs/ai/{phase}/feature-<name>.md` across lifecycle phases. |
| 31 | + - Git/worktree checker: evaluate feature branch/worktree convention used by `dev-lifecycle` Phase 1 prerequisite. |
| 32 | + - Reporter (command-owned): consistent output rows (`[OK]`, `[MISS]`, `[WARN]`) and final summary with exit code. |
| 33 | +- Technology stack choices and rationale |
| 34 | + - TypeScript within existing CLI package for shared UX and testability. |
| 35 | + - Extract shell script checks into reusable TS utilities to avoid behavior drift. |
| 36 | + - Git checks via lightweight git commands (`git worktree list`, branch existence checks) to preserve compatibility. |
| 37 | + |
| 38 | +## Data Models |
| 39 | +**What data do we need to manage?** |
| 40 | + |
| 41 | +- Core entities and their relationships |
| 42 | + - `LintOptions`: parsed CLI options. |
| 43 | + - `LintTarget`: normalized feature identity (`name`, `branchName`, `docSlug`). |
| 44 | + - `LintCheckResult`: result of individual check. |
| 45 | + - `LintSummary`: aggregate counts and final status. |
| 46 | +- Data schemas/structures |
| 47 | + - `LintOptions` |
| 48 | + - `{ feature?: string, json?: boolean }` |
| 49 | + - `LintTarget` |
| 50 | + - `{ rawFeature: string, normalizedName: string, branchName: string, docFilePrefix: string }` |
| 51 | + - `LintCheckResult` |
| 52 | + - `{ id: string, level: 'ok' | 'miss' | 'warn', category: 'base-docs' | 'feature-docs' | 'git-worktree', required: boolean, message: string, fix?: string }` |
| 53 | + - `LintSummary` |
| 54 | + - `{ checks: LintCheckResult[], hasRequiredFailures: boolean, warningCount: number }` |
| 55 | +- Data flow between components |
| 56 | + - Parse args -> normalize feature -> run applicable checks -> collect results -> render terminal or JSON output -> return exit code. |
| 57 | + |
| 58 | +## API Design |
| 59 | +**How do components communicate?** |
| 60 | + |
| 61 | +- External APIs (if applicable) |
| 62 | + - CLI invocations: |
| 63 | + - `ai-devkit lint` |
| 64 | + - `ai-devkit lint --feature <name>` |
| 65 | + - `ai-devkit lint --feature <name> --json` |
| 66 | +- Internal interfaces |
| 67 | + - `runLintChecks(options, dependencies?): LintReport` |
| 68 | + - `renderLintReport(report, options): void` (in `commands/lint`) |
| 69 | + - `normalizeFeatureName(input): string` |
| 70 | + - `isInsideGitWorkTreeSync(cwd): boolean` |
| 71 | + - `localBranchExistsSync(cwd, branchName): boolean` |
| 72 | + - `getWorktreePathsForBranchSync(cwd, branchName): string[]` |
| 73 | +- Request/response formats |
| 74 | + - Input: CLI flags and current working directory. |
| 75 | + - Output: |
| 76 | + - Default: human-readable checklist and summary. |
| 77 | + - `--json`: structured JSON object for CI parsing (checks, counts, normalized feature, pass/fail state). |
| 78 | + - Exit code policy: |
| 79 | + - `0`: no required failures. |
| 80 | + - `1`: one or more required failures. |
| 81 | + - Warnings (including missing dedicated worktree) do not change exit code when required checks pass. |
| 82 | +- Authentication/authorization approach |
| 83 | + - Read-only operations only (filesystem + git metadata queries). |
| 84 | + |
| 85 | +## Component Breakdown |
| 86 | +**What are the major building blocks?** |
| 87 | + |
| 88 | +- Frontend components (if applicable) |
| 89 | + - Terminal output formatter using existing CLI conventions. |
| 90 | + - JSON formatter for machine-readable mode. |
| 91 | +- Backend services/modules |
| 92 | + - `commands/lint` command entry. |
| 93 | + - `services/lint/lint.service.ts` for orchestration and business rules only. |
| 94 | + - `services/lint/rules/*` for modular validation rules (base docs, feature docs, feature-name, git worktree). |
| 95 | + - `util/git` sync helpers for git/worktree checks. |
| 96 | + - `util/terminal-ui` for consistent terminal output formatting. |
| 97 | +- Database/storage layer |
| 98 | + - None. |
| 99 | +- Third-party integrations |
| 100 | + - Local git executable. |
| 101 | + |
| 102 | +## Design Decisions |
| 103 | +**Why did we choose this approach?** |
| 104 | + |
| 105 | +- Key architectural decisions and trade-offs |
| 106 | + - Re-implement shell checks in TypeScript while keeping output semantics: |
| 107 | + - Pros: testable, reusable, cross-command integration. |
| 108 | + - Cons: initial duplication until script is retired/repointed. |
| 109 | + - Classify checks as required vs warning: |
| 110 | + - Pros: keeps lifecycle gating strict for missing docs while allowing advisory worktree guidance. |
| 111 | + - Cons: users may ignore warnings if not enforced in team policy. |
| 112 | + - Normalize feature names automatically: |
| 113 | + - Pros: better UX (`foo` and `feature-foo` both accepted). |
| 114 | + - Cons: requires clear messaging of normalized value. |
| 115 | + - Include `--json` output in v1: |
| 116 | + - Pros: CI-friendly parsing and automated reporting. |
| 117 | + - Cons: requires stable output schema maintenance. |
| 118 | +- Alternatives considered |
| 119 | + - Keep shell script only and wrap it from CLI: |
| 120 | + - Rejected due to weaker cross-platform consistency and lower unit-test coverage. |
| 121 | + - Hard-fail when dedicated worktree is missing: |
| 122 | + - Rejected; requirement is warning-only behavior for this condition. |
| 123 | +- Patterns and principles applied |
| 124 | + - Single-responsibility check modules. |
| 125 | + - Deterministic output for CI and humans. |
| 126 | + - Collect-all-results reporting to surface all issues in one run. |
| 127 | + - Avoid shell interpolation for git operations by using argument-based command execution. |
| 128 | + |
| 129 | +## Non-Functional Requirements |
| 130 | +**How should the system perform?** |
| 131 | + |
| 132 | +- Performance targets |
| 133 | + - Complete typical checks in under 1 second on standard repositories. |
| 134 | +- Scalability considerations |
| 135 | + - Check implementation should be extensible for additional lifecycle validations later. |
| 136 | +- Security requirements |
| 137 | + - No file writes or mutations. |
| 138 | + - No network access required. |
| 139 | +- Reliability/availability needs |
| 140 | + - Command should gracefully handle missing git repo context and provide actionable fixes. |
0 commit comments