This document summarizes the changes made to enable strongly-typed server-side settings configuration.
Created a new workspace package for types shared between client and server:
Files Created:
settings-types.ts- Shared TypeScript interfaces and typespackage.json- Package definitiontsconfig.json- TypeScript configuration
Key Types:
Settings- Complete settings structure (client + server)ServerConfig- Server-specific subset of settingsModelConfiguration- AI model configurationCategory- Note category definitionsDEFAULT_SETTINGS- Default values- Helper functions:
extractServerConfig(),validateServerConfig()
src/settings-manager.ts- Singleton settings managersrc/adapters/FileSystemSettingsAdapter.ts- File system persistenceREADME.md- Documentation for server-side usage
src/index.ts- Added settings loading and API endpointspackage.json- Added dependencies (@open-notes/shared, @types/node)
API Endpoints Added:
GET /api/settings- Get current server configurationPOST /api/settings/reload- Reload settings from file system
Settings File Location:
Default: ~/.open-notes/settings.json (customizable)
Files Created:
src/adapters/HybridSettingsAdapter.ts- Local + server sync adapter
Files Modified:
package.json- Added @open-notes/shared dependency
Files Modified:
package.json- Added packages/shared to workspaces
┌─────────────────────────────────────────────────────────────┐
│ @open-notes/shared │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ settings-types.ts │ │
│ │ - Settings (full client+server) │ │
│ │ - ServerConfig (server subset) │ │
│ │ - ModelConfiguration, Category, etc. │ │
│ │ - DEFAULT_SETTINGS, validation helpers │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
▲ ▲
│ │
┌────────────┴────────┐ ┌────────┴──────────┐
│ │ │ │
┌───────▼────────────────┐ │ │ ┌─────────────────▼────────┐
│ @open-notes/client │ │ │ │ @open-notes/server │
│ │ │ │ │ │
│ LocalStorageSettings │ │ │ │ FileSystemSettings │
│ Adapter │ │ │ │ Adapter │
│ ▼ │ │ │ │ ▼ │
│ HybridSettings │───┘ └──│ SettingsManager │
│ Adapter (sync) │ │ (singleton) │
│ │ │ │ │
│ localStorage + │ │ File: ~/.open-notes/ │
│ server sync │ │ settings.json │
└────────────────────────┘ └──────────────────────────┘
import { getSettingsManager } from './settings-manager.js';
// Initialize server
const settingsManager = getSettingsManager();
await settingsManager.load();
// Access typed configuration
const config = await settingsManager.getConfig();
console.log('Language Model:', config.languageModel?.modelName);
console.log('Categories:', config.categories.length);
// Type-safe access
if (config.languageModel) {
const { provider, modelName, apiKey } = config.languageModel;
// Full IntelliSense support
}import { HybridSettingsAdapter } from './adapters/HybridSettingsAdapter';
// Use hybrid adapter for local + server sync
const adapter = new HybridSettingsAdapter('http://localhost:3001');
const settings = await adapter.load();- Compile-Time Validation: TypeScript catches type errors during development
- IntelliSense Support: Full autocompletion in IDEs
- Refactoring Safety: Renaming/changing types updates all usages
- Documentation: Types serve as inline documentation
- Validation Helpers: Runtime validation with
validateServerConfig()
{
languageModel?: ModelConfiguration;
embeddingModel?: ModelConfiguration;
categories: Category[];
genericEnrichmentPrompt: string;
categoryRecognitionPrompt: string;
}{
// Server fields (above) +
theme: 'light' | 'dark' | 'system';
fontSize: 'sm' | 'md' | 'lg' | 'xl';
editorSettings: {
autoSave: boolean;
autoSaveInterval: number;
};
lastSavedAt?: number;
}To use the new server-side settings:
-
Install dependencies:
npm install
-
Create settings file:
mkdir -p ~/.open-notes echo '{}' > ~/.open-notes/settings.json
-
Start server:
npm run dev -w packages/server
-
Test API endpoints:
# Get settings curl http://localhost:3001/api/settings # Reload settings curl -X POST http://localhost:3001/api/settings/reload
- Existing client code continues to work with
LocalStorageSettingsAdapter - Optional: Switch to
HybridSettingsAdapterfor server sync - No breaking changes to existing settings store
- Add to
Settingsinterface inpackages/shared/settings-types.ts - Update
DEFAULT_SETTINGSwith default value - If server needs it, add to
ServerConfiginterface - Update
extractServerConfig()if needed - TypeScript will enforce updates throughout codebase
✅ Type Safety: Strongly-typed configuration across client and server ✅ Code Sharing: Single source of truth for settings types ✅ Validation: Built-in runtime validation helpers ✅ Flexibility: File system adapter allows custom storage locations ✅ Singleton Pattern: Consistent configuration access on server ✅ API Endpoints: HTTP access to server configuration ✅ Documentation: Comprehensive README and inline comments ✅ Future-Proof: Easy to extend with new settings
New Directories:
packages/shared/(new package)packages/server/src/adapters/(new directory)
New Files: (9 files)
packages/shared/settings-types.tspackages/shared/package.jsonpackages/shared/tsconfig.jsonpackages/server/src/settings-manager.tspackages/server/src/adapters/FileSystemSettingsAdapter.tspackages/server/README.mdpackages/client/src/adapters/HybridSettingsAdapter.ts- This summary document
Modified Files: (4 files)
packages/server/src/index.tspackages/server/package.jsonpackages/client/package.jsonpackage.json(root)