diff --git a/docs/architecture/PROJECT_STRUCTURE.md b/docs/architecture/PROJECT_STRUCTURE.md index c92c328..215c858 100644 --- a/docs/architecture/PROJECT_STRUCTURE.md +++ b/docs/architecture/PROJECT_STRUCTURE.md @@ -1,50 +1,21 @@ # π Project Structure -## Final Organized Structure +## Current Development Structure ``` rxminder/ -βββ π README.md # Main documentation -βββ package.json # Dependencies and scripts +βββ π README.md # Main project documentation +βββ π¦ package.json # Dependencies and scripts βββ βοΈ vite.config.ts # Build configuration βββ π tsconfig.json # TypeScript configuration -βββ π¨ index.html # Entry point +βββ π¨ index.html # Generated entry point +βββ π¨ index.html.template # Template for HTML generation βββ π .env.example # Environment template βββ π metadata.json # Project metadata βββ πΌοΈ banner.jpeg # Project banner image -β -βββ οΏ½ docker/ # Container configuration -β βββ π³ Dockerfile # Multi-stage Docker build -β βββ οΏ½ docker-compose.yaml # Service orchestration -β βββ π nginx.conf # Production web server config -β βββ π« .dockerignore # Docker ignore patterns -β -βββ π scripts/ # All deployment and utility scripts -β βββ π deploy.sh # Production deployment -β βββ β‘ deploy-k8s.sh # Kubernetes deployment -β βββ π§ setup.sh # Development setup -β βββ π± seed-production.js # Database seeding -β βββ β validate-env.sh # Environment validation -β βββ π§ͺ validate-deployment.sh # Deployment testing -β -βββ π tests/ # Testing infrastructure -β βββ π README.md # Testing documentation -β βββ βοΈ setup.ts # Jest configuration -β βββ π integration/ # Integration tests -β β βββ π§ͺ production.test.js # Production validation -β βββ π manual/ # Manual testing scripts -β β βββ π§ admin-login-debug.js # Admin debugging -β β βββ π§ auth-db-debug.js # Auth debugging -β β βββ π§ debug-email-validation.js # Email debugging -β βββ π e2e/ # End-to-end tests with Playwright -β βββ π README.md # E2E testing documentation -β βββ π§ͺ fixtures.ts # Custom test fixtures -β βββ π§ͺ helpers.ts # Test utilities and data -β βββ π§ͺ auth.spec.ts # Authentication flow tests -β βββ π§ͺ medication.spec.ts # Medication management tests -β βββ π§ͺ admin.spec.ts # Admin interface tests -β βββ π§ͺ ui-navigation.spec.ts # UI and navigation tests -β βββ π§ͺ reminders.spec.ts # Reminder system tests +βββ π index.tsx # React application entry point +βββ π― App.tsx # Main React component +βββ π types.ts # Global type definitions β βββ π components/ # React components (organized by feature) β βββ π README.md # Component architecture docs @@ -81,102 +52,293 @@ rxminder/ β βββ π services/ # Business logic & APIs β βββ ποΈ database/ # Unified database service -β β βββ DatabaseService.ts # Main service with strategy pattern -β β βββ MockDatabaseStrategy.ts # In-memory implementation -β β βββ ProductionDatabaseStrategy.ts # CouchDB implementation -β β βββ types.ts # Database interfaces +β β βββ π DatabaseService.ts # Main service with strategy pattern +β β βββ π§ͺ MockDatabaseStrategy.ts # In-memory implementation +β β βββ π ProductionDatabaseStrategy.ts # CouchDB implementation +β β βββ π types.ts # Database interfaces +β β βββ π¦ index.ts # Public exports +β β βββ π README.md # Database service documentation +β βββ π§ logging/ # Centralized logging system +β β βββ π Logger.ts # Main logger implementation +β β βββ π¦ index.ts # Public exports β βββ π§ email.ts # Email utilities -β βββ π§ mailgun.service.ts # Email delivery -β βββ π§ mailgun.config.ts # Email configuration -β βββ π± database.seeder.ts # Data seeding -β βββ π oauth.ts # OAuth integration -β βββ π auth/ # Authentication services -β βββ π auth.service.ts # Core auth logic -β βββ π auth.types.ts # Auth type definitions -β βββ π auth.constants.ts # Auth constants -β βββ π auth.error.ts # Error handling -β βββ π auth.middleware.ts # Middleware +β βββ π§ mailgun.service.ts # Email delivery +β βββ π§ mailgun.config.ts # Email configuration +β βββ π± database.seeder.ts # Data seeding +β βββ π oauth.ts # OAuth integration +β βββ π auth/ # Authentication services +β βββ π auth.service.ts # Core auth logic +β βββ π auth.types.ts # Auth type definitions +β βββ π auth.constants.ts # Auth constants +β βββ β οΈ auth.error.ts # Error handling +β βββ π‘οΈ auth.middleware.ts # Middleware β βββ βοΈ emailVerification.service.ts -β βββ π templates/ # Email templates +β βββ π templates/ # Email templates β β βββ βοΈ verification.email.ts -β βββ π __tests__/ # Unit tests +β βββ π __tests__/ # Unit tests β βββ π§ͺ auth.integration.test.ts β βββ π§ͺ emailVerification.test.ts β +βββ π config/ # Configuration management +β βββ βοΈ unified.config.ts # Centralized configuration with validation +β βββ π contexts/ # React context providers -β βββ π€ UserContext.tsx # User state management +β βββ π€ UserContext.tsx # User state management β βββ π hooks/ # Custom React hooks -β βββ πΎ useLocalStorage.ts # Persistent storage -β βββ βοΈ useSettings.ts # User preferences -β βββ π¨ useTheme.ts # Theme management -β βββ π€ useUserData.ts # User data management +β βββ πΎ useLocalStorage.ts # Persistent storage +β βββ βοΈ useSettings.ts # User preferences +β βββ π¨ useTheme.ts # Theme management +β βββ π€ useUserData.ts # User data management β βββ π utils/ # Utility functions -β βββ β° schedule.ts # Reminder scheduling +β βββ β° schedule.ts # Reminder scheduling +β +βββ π types/ # TypeScript type definitions +β βββ π index.ts # Global type exports +β +βββ π scripts/ # Development and build scripts +β βββ π§ setup.sh # Development setup +β βββ π¨ process-html.sh # HTML template processing +β βββ π§Ή setup-pre-commit.sh # Git hooks setup +β βββ π± seed-production.js # Database seeding +β +βββ π tests/ # Testing infrastructure +β βββ π README.md # Testing documentation +β βββ βοΈ setup.ts # Jest configuration +β βββ π integration/ # Integration tests +β β βββ π§ͺ production.test.js # Production validation +β βββ π manual/ # Manual testing scripts +β β βββ π§ admin-login-debug.js # Admin debugging +β β βββ π§ auth-db-debug.js # Auth debugging +β β βββ π§ debug-email-validation.js # Email debugging +β βββ π e2e/ # End-to-end tests with Playwright +β βββ π README.md # E2E testing documentation +β βββ π§ͺ fixtures.ts # Custom test fixtures +β βββ π§ͺ helpers.ts # Test utilities and data +β βββ π§ͺ auth.spec.ts # Authentication flow tests +β βββ π§ͺ medication.spec.ts # Medication management tests +β βββ π§ͺ admin.spec.ts # Admin interface tests +β βββ π§ͺ ui-navigation.spec.ts # UI and navigation tests +β βββ π§ͺ reminders.spec.ts # Reminder system tests β βββ π docs/ # Project documentation -β βββ π SECURITY.md # Security guidelines -β βββ π DEPLOYMENT.md # Deployment instructions -β βββ π API.md # API documentation +β βββ π README.md # Documentation index +β βββ π architecture/ # Design & Architecture +β β βββ ποΈ PROJECT_STRUCTURE.md # This file +β β βββ π― TEMPLATE_APPROACH.md # Configuration approach +β βββ π setup/ # Setup & Configuration +β β βββ βοΈ COMPLETE_TEMPLATE_CONFIGURATION.md +β β βββ β SETUP_COMPLETE.md +β β βββ π ENVIRONMENT_VARIABLES.md +β β βββ π·οΈ APP_NAME_CONFIGURATION.md +β βββ π development/ # Development Guides +β β βββ π API.md # API documentation +β β βββ ποΈ DATABASE.md # Database service docs +β β βββ β¨ CODE_QUALITY.md # Quality standards +β β βββ π APPLICATION_SECURITY.md # Security practices +β β βββ π SECURITY_CHANGES.md # Security updates +β β βββ πͺ PRE_COMMIT_HOOKS.md # Git hook configuration +β βββ π implementation/ # Current Status +β βββ π IMPLEMENTATION_SUMMARY.md β -βββ π k8s/ # Kubernetes manifests -β βββ π README.md # K8s deployment guide -β βββ πΊοΈ configmap.yaml # Configuration -β βββ π *-secret.yaml # Secrets -β βββ π *-deployment.yaml # Deployments -β βββ π *-service.yaml # Services -β βββ π hpa.yaml # Auto-scaling -β βββ π ingress.yaml # Load balancing -β βββ π network-policy.yaml # Network security +βββ π coverage/ # Test coverage reports +βββ π dist/ # Production build output +βββ π node_modules/ # Dependencies β -βββ π .github/ # GitHub configuration - βββ π pull_request_template.md - βββ π ISSUE_TEMPLATE/ - βββ π bug_report.md - βββ β¨ feature_request.md +βββ π Configuration Files # Development configuration + βββ π§ .gitignore # Git ignore patterns + βββ π¨ .prettierrc # Code formatting rules + βββ β‘ eslint.config.cjs # Linting configuration + βββ π§ͺ jest.config.json # Test configuration + βββ π playwright.config.ts # E2E test configuration + βββ π .markdownlint.json # Markdown linting + βββ π .secretlintrc.json # Secret detection + βββ βοΈ .editorconfig # Editor consistency + βββ πͺ .husky/ # Git hooks + βββ π Various other config files ``` ## Key Organizational Principles -### β **Feature-Based Organization** +### β **Feature-Based Component Organization** + +Components are organized by functionality rather than by type: + +``` +components/ +βββ medication/ # All medication-related UI +βββ auth/ # Authentication components +βββ admin/ # Admin interface +βββ modals/ # Modal dialogs +βββ ui/ # Reusable UI components +``` + +**Benefits:** + +- Related functionality stays together +- Easy to find and modify features +- Clear boundaries between different parts of the app +- Scalable as features grow + +### β **Service Layer Architecture** + +Services provide business logic separate from UI components: + +``` +services/ +βββ database/ # Data persistence with strategy pattern +βββ logging/ # Centralized logging system +βββ auth/ # Authentication and user management +``` + +**Benefits:** -- Components grouped by functionality (medication, auth, admin, etc.) - Clear separation of concerns -- Easy to locate related files - -### β **Script Centralization** - -- All deployment and utility scripts in `/scripts/` -- Consistent naming conventions -- Easy access via npm/bun scripts - -### β **Testing Structure** - -- Unit tests alongside source code (`services/auth/__tests__/`) -- Integration tests in `/tests/integration/` -- E2E tests with Playwright in `/tests/e2e/` -- Manual debugging tools in `/tests/manual/` -- Comprehensive test documentation -- TypeScript support with temporary type declarations - -### β **Documentation Organization** - -- Feature-specific READMEs in relevant folders -- Centralized docs in `/docs/` folder -- Clear architectural documentation +- Reusable business logic +- Easy to test and mock +- Strategy pattern allows flexible implementations ### β **Configuration Management** -- Environment files at root level -- Build configurations easily accessible -- Docker and K8s configs clearly separated +Centralized configuration with environment-based templates: -## Benefits +``` +config/ +βββ unified.config.ts # Single source of truth -π― **Maintainability** - Clear structure makes code easy to maintain -π **Discoverability** - Logical organization helps find files quickly -π§ͺ **Testability** - Well-organized test structure -π¦ **Deployability** - Scripts and configs clearly separated +# Template approach +index.html.template β index.html # Processed with environment variables +.env.example β .env # User customization +``` + +**Benefits:** + +- No hardcoded configuration +- Environment-specific settings +- Type-safe configuration access +- Clear separation of config and code + +### β **Testing Strategy** + +Comprehensive testing at multiple levels: + +``` +tests/ +βββ integration/ # Service integration tests +βββ manual/ # Debug scripts and manual testing +βββ e2e/ # Full application testing + +# Unit tests alongside code +services/auth/__tests__/ # Co-located with services +components/__tests__/ # Component-specific tests +``` + +**Benefits:** + +- Tests close to the code they test +- Multiple testing strategies +- Easy to run specific test suites +- Clear separation of test types + +### β **Documentation Structure** + +Documentation organized by purpose and audience: + +``` +docs/ +βββ architecture/ # System design and patterns +βββ setup/ # Configuration and installation +βββ development/ # Developer guides and APIs +βββ implementation/ # Current status and features +``` + +**Benefits:** + +- Easy navigation by role (developer, ops, etc.) +- Clear separation of different doc types +- Comprehensive coverage of all aspects +- Living documentation that stays current + +## π― Development Workflow + +### Local Development Setup + +1. **Environment Configuration** + + ```bash + cp .env.example .env # Copy template + nano .env # Customize settings + ``` + +2. **Template Processing** + + ```bash + bun run predev # Process HTML templates + bun run dev # Start development server + ``` + +3. **Code Quality** + ```bash + bun run lint # Check code quality + bun run format # Format code + bun run type-check # TypeScript validation + ``` + +### Database Strategy Selection + +The application automatically selects the appropriate database strategy: + +- **Development**: Mock database (instant responses, no setup) +- **Testing**: Mock database (isolated test data) +- **Production**: CouchDB (persistent storage) + +### Component Development + +1. **Create feature-based components** in appropriate folders +2. **Export from index.ts** for clean imports +3. **Co-locate tests** with components when appropriate +4. **Use TypeScript** for type safety + +### Service Development + +1. **Implement business logic** in service layer +2. **Use dependency injection** for testability +3. **Follow strategy pattern** for flexibility +4. **Add comprehensive tests** for reliability + +## π Metrics and Standards + +### Code Organization + +- **Feature cohesion**: Related code stays together +- **Clear boundaries**: Services, components, utilities clearly separated +- **Consistent patterns**: Similar organization across features +- **Scalable structure**: Easy to add new features without reorganization + +### Development Experience + +- **Fast setup**: One command to get started +- **Quick iteration**: Hot reloading and instant feedback +- **Easy testing**: Multiple test strategies available +- **Clear debugging**: Structured logging and debug tools + +### Maintainability + +- **Self-documenting**: Clear folder structure and naming +- **Consistent patterns**: Similar approaches across the codebase +- **Easy refactoring**: Loose coupling between components +- **Future-proof**: Architecture supports growth and changes + +## π Benefits + +π― **Discoverability** - Logical structure makes files easy to find +π§ **Maintainability** - Clear patterns make code easy to modify +π§ͺ **Testability** - Well-organized test structure and strategy +π **Scalability** - Architecture supports feature growth π₯ **Team Collaboration** - Consistent patterns across the project -π **Scalability** - Structure supports growth and new features +π‘οΈ **Reliability** - Strategy pattern provides flexibility and fallbacks +β‘ **Performance** - Optimized development and build processes +π **Documentation** - Comprehensive guides for all aspects + +This structure provides a solid foundation for continued development and future enhancements while maintaining code quality and developer productivity. diff --git a/docs/architecture/TEMPLATE_APPROACH.md b/docs/architecture/TEMPLATE_APPROACH.md index bd45c86..7f239aa 100644 --- a/docs/architecture/TEMPLATE_APPROACH.md +++ b/docs/architecture/TEMPLATE_APPROACH.md @@ -1,159 +1,278 @@ -# π― Template-Based Kubernetes Configuration +# π― Template-Based Configuration Approach ## Overview -We've implemented a **template-based approach** using environment variables instead of manual base64 encoding for Kubernetes secrets. This is much more user-friendly and secure. +RxMinder uses a **template-based configuration approach** with environment variables to provide flexible, secure, and maintainable configuration management across different environments. -## π Before vs After Comparison +## π Configuration Philosophy -### β Before (Manual Base64 Encoding) +### β Before (Hardcoded Values) -**Old approach required manual base64 encoding:** +**Old approach with hardcoded configuration:** -```yaml -# k8s/couchdb-secret.yaml -apiVersion: v1 -kind: Secret -data: - # User had to manually encode: - # echo -n "admin" | base64 -> YWRtaW4= - # echo -n "password" | base64 -> cGFzc3dvcmQ= - username: YWRtaW4= - password: cGFzc3dvcmQ= +```typescript +// Hardcoded configuration +const config = { + appName: 'RxMinder', + baseUrl: 'http://localhost:5173', + dbUrl: 'http://localhost:5984', + adminPassword: 'admin123', // β Security risk +}; ``` **Problems:** -- π£ Manual base64 encoding required -- π§ Error-prone (encoding mistakes) -- π Hard to read/verify credentials -- π Credentials visible in YAML files +- π£ No environment flexibility +- π§ Configuration changes require code changes +- π Hard to customize for different deployments +- π Security risks with hardcoded credentials ### β After (Template-Based) -**New approach uses templates with automatic substitution:** +**New approach uses environment variables with templates:** -```yaml -# k8s/couchdb-secret.yaml.template -apiVersion: v1 -kind: Secret -metadata: - name: couchdb-secret - labels: - app: ${APP_NAME} -type: Opaque -stringData: - # Kubernetes automatically base64 encodes stringData - username: ${COUCHDB_USER} - password: ${COUCHDB_PASSWORD} +```typescript +// Environment-based configuration +const config = { + appName: process.env.VITE_APP_NAME || 'RxMinder', + baseUrl: process.env.VITE_BASE_URL || 'http://localhost:5173', + dbUrl: process.env.VITE_COUCHDB_URL || 'http://localhost:5984', + adminPassword: process.env.VITE_COUCHDB_PASSWORD, // β Secure +}; ``` **Benefits:** -- β No manual base64 encoding needed -- β Environment variables from `.env` file -- β Human-readable configuration -- β Automatic deployment script -- β Customizable app names +- β Environment-specific configuration +- β No hardcoded secrets in code +- β Easy customization via `.env` files +- β Template processing for HTML and other assets +- β Type-safe configuration with validation ## π How It Works -### 1. Configuration in `.env` +### 1. Environment Configuration ```bash -# .env (user-friendly configuration) -APP_NAME=my-rxminder -COUCHDB_USER=admin -COUCHDB_PASSWORD=super-secure-password-123 -INGRESS_HOST=rxminder.mydomain.com +# .env.example (template for all environments) +VITE_APP_NAME=RxMinder +VITE_BASE_URL=http://localhost:5173 +VITE_COUCHDB_URL=http://localhost:5984 +VITE_COUCHDB_USER=admin +VITE_COUCHDB_PASSWORD=secure-password-123 + +# Email configuration (optional) +VITE_MAILGUN_API_KEY=your-mailgun-api-key +VITE_MAILGUN_DOMAIN=your-domain.com + +# OAuth configuration (optional) +VITE_GOOGLE_CLIENT_ID=your-google-client-id +VITE_GITHUB_CLIENT_ID=your-github-client-id + +# Feature flags +ENABLE_EMAIL_VERIFICATION=true +ENABLE_OAUTH=true +DEBUG_MODE=false ``` -### 2. Template Substitution +### 2. Template Processing + +#### HTML Template Processing + +```html + + + +
+