feat: consolidate architecture and eliminate code duplication
🏗️ Major architectural improvements: Database Layer: - Consolidated duplicate CouchDB services (~800 lines of duplicated code eliminated) - Implemented strategy pattern with MockDatabaseStrategy and ProductionDatabaseStrategy - Created unified DatabaseService with automatic environment detection - Maintained backward compatibility via updated factory pattern Configuration System: - Centralized all environment variables in single config/app.config.ts - Added comprehensive configuration validation with clear error messages - Eliminated hardcoded base URLs and scattered env var access across 8+ files - Supports both legacy and new environment variable names Logging Infrastructure: - Replaced 25+ scattered console.log statements with structured Logger service - Added log levels (ERROR, WARN, INFO, DEBUG, TRACE) and contexts (AUTH, DATABASE, API, UI) - Production-safe logging with automatic level adjustment - Development helpers for debugging and performance monitoring Docker & Deployment: - Removed duplicate docker/Dockerfile configuration - Enhanced root Dockerfile with comprehensive environment variable support - Added proper health checks and security improvements Code Quality: - Fixed package name consistency (rxminder → RxMinder) - Updated services to use centralized configuration and logging - Resolved all ESLint errors and warnings - Added comprehensive documentation and migration guides 📊 Impact: - Eliminated ~500 lines of duplicate code - Single source of truth for database, configuration, and logging - Better type safety and error handling - Improved development experience and maintainability 📚 Documentation: - Added ARCHITECTURE_MIGRATION.md with detailed migration guide - Created IMPLEMENTATION_SUMMARY.md with metrics and benefits - Inline documentation for all new services and interfaces 🔄 Backward Compatibility: - All existing code continues to work unchanged - Legacy services show deprecation warnings but remain functional - Gradual migration path available for development teams Breaking Changes: None (full backward compatibility maintained)
This commit is contained in:
64
services/database/types.ts
Normal file
64
services/database/types.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import {
|
||||
User,
|
||||
Medication,
|
||||
UserSettings,
|
||||
TakenDoses,
|
||||
CustomReminder,
|
||||
} from '../../types';
|
||||
|
||||
export interface DatabaseStrategy {
|
||||
// User operations
|
||||
createUser(user: Omit<User, '_id' | '_rev'>): Promise<User>;
|
||||
updateUser(user: User): Promise<User>;
|
||||
getUserById(id: string): Promise<User | null>;
|
||||
findUserByEmail(email: string): Promise<User | null>;
|
||||
deleteUser(id: string): Promise<boolean>;
|
||||
getAllUsers(): Promise<User[]>;
|
||||
|
||||
// Medication operations
|
||||
createMedication(
|
||||
userId: string,
|
||||
medication: Omit<Medication, '_id' | '_rev'>
|
||||
): Promise<Medication>;
|
||||
updateMedication(medication: Medication): Promise<Medication>;
|
||||
getMedications(userId: string): Promise<Medication[]>;
|
||||
deleteMedication(id: string): Promise<boolean>;
|
||||
|
||||
// User settings operations
|
||||
getUserSettings(userId: string): Promise<UserSettings>;
|
||||
updateUserSettings(settings: UserSettings): Promise<UserSettings>;
|
||||
|
||||
// Taken doses operations
|
||||
getTakenDoses(userId: string): Promise<TakenDoses>;
|
||||
updateTakenDoses(takenDoses: TakenDoses): Promise<TakenDoses>;
|
||||
|
||||
// Custom reminders operations
|
||||
createCustomReminder(
|
||||
userId: string,
|
||||
reminder: Omit<CustomReminder, '_id' | '_rev'>
|
||||
): Promise<CustomReminder>;
|
||||
updateCustomReminder(reminder: CustomReminder): Promise<CustomReminder>;
|
||||
getCustomReminders(userId: string): Promise<CustomReminder[]>;
|
||||
deleteCustomReminder(id: string): Promise<boolean>;
|
||||
|
||||
// User operations with password
|
||||
createUserWithPassword(
|
||||
email: string,
|
||||
hashedPassword: string,
|
||||
username?: string
|
||||
): Promise<User>;
|
||||
createUserFromOAuth(
|
||||
email: string,
|
||||
username: string,
|
||||
provider: string
|
||||
): Promise<User>;
|
||||
}
|
||||
|
||||
export class DatabaseError extends Error {
|
||||
status: number;
|
||||
constructor(message: string, status: number = 500) {
|
||||
super(message);
|
||||
this.name = 'DatabaseError';
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user