5.3 KiB
5.3 KiB
Client API Reorganization Plan
The client/src/api directory is currently a flat list of adapters, core logic, and helpers, mixing different abstraction layers. This document outlines a plan to reorganize them into logical layers to improve maintainability and separation of concerns.
Analysis
1. Adapters (Implementations)
Target Directory: client/src/api/adapters/
| File | Exports | Call Sites | Dependencies | Tests |
|---|---|---|---|---|
cached-adapter.ts |
cachedAPI |
index.ts, index.test.ts |
interface, types, cached/* |
cached-adapter.test.ts |
cached/* |
(Various API sections) | cached-adapter.ts |
interface, types |
N/A |
mock-adapter.ts |
mockAPI |
index.ts, index.test.ts |
interface, types, mock-data, mock-stream |
mock-adapter.test.ts |
mock-data.ts |
generateId, generateMeeting, ... |
mock-adapter.ts |
types |
mock-data.test.ts |
mock-transcription-stream.ts |
MockTranscriptionStream |
mock-adapter.ts |
interface, types |
mock-transcription-stream.test.ts |
tauri-adapter/ |
(Directory) | index.ts |
interface, types, @tauri-apps/* |
tauri-adapter/**/*.test.ts |
tauri-constants.ts |
TauriCommands, TauriEvents |
tauri-adapter, constants.ts |
N/A | tauri-constants.test.ts |
offline-defaults.ts |
offlineServerInfo, ... |
cached-adapter, cached/base.ts |
types |
N/A |
2. Core Logic & State
Target Directory: client/src/api/core/
| File | Exports | Call Sites | Dependencies | Tests |
|---|---|---|---|---|
connection-state.ts |
getConnectionState, setConnectionMode |
index.ts, reconnection.ts, hooks |
N/A | connection-state.test.ts |
reconnection.ts |
startReconnection, onReconnected |
index.ts, hooks |
interface, connection-state |
reconnection.test.ts |
error-utils.ts |
extractErrorMessage, classifyError |
adapters/*, helpers.ts |
types |
N/A (Tested in helpers.test.ts) |
helpers.ts |
delay, paginate, stateToGrpcEnum |
adapters/* |
types, error-utils |
helpers.test.ts |
constants.ts |
Timing, IdentityDefaults |
adapters/* |
tauri-constants |
N/A |
transcription-stream.ts |
TranscriptionStream (interface) |
interface.ts, adapters/* |
types |
N/A |
3. Contracts (Root)
Target Directory: client/src/api/ (Keep in root)
| File | Exports | Call Sites | Dependencies | Tests |
|---|---|---|---|---|
index.ts |
initializeAPI, getAPI |
Application Entry | adapters/*, core/*, interface |
index.test.ts |
interface.ts |
NoteFlowAPI |
Everywhere | types, core/streams |
N/A |
types/ |
(Type definitions) | Everywhere | N/A | types/**/*.test.ts |
Execution Plan
- Create Directories:
client/src/api/adapters/{cached,mock,tauri},client/src/api/core. - Move Core Files:
connection-state.ts->core/connection.tsreconnection.ts->core/reconnection.tsconstants.ts->core/constants.tshelpers.ts->core/helpers.tserror-utils.ts->core/errors.tstranscription-stream.ts->core/streams.ts(Rename to avoid confusion with implementation)
- Move Adapters:
cached-adapter.ts->adapters/cached/index.tsclient/src/api/cached/->adapters/cached/implementations/(or flatten intoadapters/cached/)offline-defaults.ts->adapters/cached/defaults.tsmock-adapter.ts->adapters/mock/index.tsmock-data.ts->adapters/mock/data.tsmock-transcription-stream.ts->adapters/mock/stream.tstauri-adapter/content ->adapters/tauri/tauri-constants.ts->adapters/tauri/constants.ts(Update rootconstants.tsto re-export if needed, or update imports)
- Move Tests: Move all associated tests (
.test.ts) alongside their source files.- Note:
tauri-transcription-stream.test.tsis currently in root, move toadapters/tauri/stream.test.ts.
- Note:
- Update Imports:
- Update relative imports within the moved files.
- Update usages in
index.tsandinterface.ts. - Update usages across the codebase (using search & replace).
- Cleanup:
- Ensure
client/src/api/constants.tsproperly re-exports Tauri constants if they are still needed globally, or update call sites to import fromadapters/tauri/constants.
- Ensure
Impacted Tests
api/index.test.tsapi/cached-adapter.test.tsapi/mock-adapter.test.tsapi/connection-state.test.tsapi/reconnection.test.tsapi/tauri-transcription-stream.test.tsapi/helpers.test.tshooks/use-*.test.ts(Indirectly via imports)
Recommendations
- Flatten Cached Adapter: The
cached/subdirectory currently contains one file per feature. This is good structure, keep it withinadapters/cached/. - Unified Stream Interface: Ensure
TranscriptionStreamis clearly defined incoreand implemented consistently inadapters. - Error Handling: Centralize error types in
core/errors.tsand ensure all adapters use them. - Constants:
client/src/api/constants.tsre-exports fromtauri-constants.ts. This dependency direction should be verified. If generic constants depend on adapter-specific constants, it might be better to decouple them.