|
| 1 | +--- |
| 2 | +phase: design |
| 3 | +title: System Design & Architecture |
| 4 | +description: Resolve memory database path from project config with default fallback |
| 5 | +--- |
| 6 | + |
| 7 | +# System Design & Architecture |
| 8 | + |
| 9 | +## Architecture Overview |
| 10 | +```mermaid |
| 11 | +graph TD |
| 12 | + ProjectConfig[./.ai-devkit.json] --> ConfigManager |
| 13 | + ConfigManager --> Resolver[CLI memory path resolver] |
| 14 | + CLI[ai-devkit memory *] --> Resolver |
| 15 | + Resolver --> MemoryAPI[@ai-devkit/memory API] |
| 16 | + DefaultPath[~/.ai-devkit/memory.db] --> MemoryAPI |
| 17 | + MemoryAPI --> DatabasePath[Effective DB path] |
| 18 | + DatabasePath --> SQLite[(SQLite memory.db)] |
| 19 | +``` |
| 20 | + |
| 21 | +- Keep `DEFAULT_DB_PATH` as the baseline fallback in the memory package. |
| 22 | +- Add a CLI-owned resolver that can return a project override from `.ai-devkit.json`. |
| 23 | +- Pass the resolved path from the CLI into `@ai-devkit/memory` before opening SQLite. |
| 24 | +- Leave the standalone `@ai-devkit/memory` MCP server unchanged so it continues using `DEFAULT_DB_PATH`. |
| 25 | + |
| 26 | +## Data Models |
| 27 | +- Extend `DevKitConfig` with an optional memory section: |
| 28 | + ```ts |
| 29 | + interface DevKitConfig { |
| 30 | + memory?: { |
| 31 | + path?: string; |
| 32 | + }; |
| 33 | + } |
| 34 | + ``` |
| 35 | +- Extend CLI-to-memory command options with optional `dbPath?: string`. |
| 36 | +- Resolver output is either: |
| 37 | + - an absolute filesystem path derived from `memory.path` |
| 38 | + - `undefined`, which means the memory package falls back to `DEFAULT_DB_PATH` |
| 39 | + |
| 40 | +## API Design |
| 41 | +- Add `ConfigManager.getMemoryDbPath(): Promise<string | undefined>` to read project config safely. |
| 42 | +- Resolve `memory.path` inside the CLI command layer, not inside `packages/memory`. |
| 43 | +- Add optional `dbPath` support to the memory package command APIs used by the CLI: |
| 44 | + - `memoryStoreCommand(options)` |
| 45 | + - `memorySearchCommand(options)` |
| 46 | + - `memoryUpdateCommand(options)` |
| 47 | +- Keep `packages/memory/src/server.ts` and the `ai-devkit-memory` binary unchanged in this feature. |
| 48 | + |
| 49 | +## Component Breakdown |
| 50 | +- `packages/cli/src/types.ts` |
| 51 | + - Add optional `memory.path` typing to project config. |
| 52 | +- `packages/cli/src/lib/Config.ts` |
| 53 | + - Parse and validate `memory.path` from project config. |
| 54 | + - Resolve relative paths against the config file directory. |
| 55 | +- `packages/cli/src/commands/memory.ts` |
| 56 | + - Load the project config once per command invocation. |
| 57 | + - Pass resolved `dbPath` into the imported memory command API. |
| 58 | +- `packages/memory/src/database/connection.ts` |
| 59 | + - Continue exposing `DEFAULT_DB_PATH`. |
| 60 | + - Accept explicit `dbPath` from callers without changing fallback semantics. |
| 61 | +- `packages/memory/src/api.ts` |
| 62 | + - Accept optional `dbPath` on CLI-facing command option types. |
| 63 | + - Call `getDatabase({ dbPath })` so the explicit path only affects CLI-triggered operations that pass it. |
| 64 | +- Tests |
| 65 | + - Config parsing tests in CLI package. |
| 66 | + - Memory command resolution tests in CLI and memory package. |
| 67 | + - No standalone MCP server behavior change tests are needed beyond regression confidence. |
| 68 | + |
| 69 | +## Design Decisions |
| 70 | +- Keep fallback logic in the memory package and config parsing in the CLI package to preserve clear responsibilities. |
| 71 | +- Resolve relative paths from the project root so checked-in config behaves consistently across shells and CI. |
| 72 | +- Treat missing, blank, or non-string `memory.path` as unset and fall back silently to `DEFAULT_DB_PATH` to preserve backward compatibility. |
| 73 | +- Keep the package boundary intact by passing `dbPath` explicitly from the CLI rather than making `packages/memory` depend on `ConfigManager`. |
| 74 | +- Apply the configured path to `store`, `search`, and `update` so CLI memory subcommands stay consistent. |
| 75 | + |
| 76 | +## Non-Functional Requirements |
| 77 | +- No change to default behavior for projects without `memory.path`. |
| 78 | +- No additional network or external service dependency. |
| 79 | +- Path resolution must be deterministic across macOS and Linux path semantics already supported by Node's `path` module. |
| 80 | +- Database initialization and schema migration behavior remain unchanged once the final path is selected. |
| 81 | +- Standalone `@ai-devkit/memory` server startup and runtime behavior remain unchanged in this feature. |
0 commit comments