Skip to content

Refactor/architecture hardening#35

Merged
NeuroKoder3 merged 13 commits intomainfrom
refactor/architecture-hardening
Mar 22, 2026
Merged

Refactor/architecture hardening#35
NeuroKoder3 merged 13 commits intomainfrom
refactor/architecture-hardening

Conversation

@NeuroKoder3
Copy link
Owner

@NeuroKoder3 NeuroKoder3 commented Mar 22, 2026

Description

Brief description of the changes.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe)

Testing

How has this been tested?

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex code
  • Documentation updated if needed
  • No new warnings introduced
  • Tests pass locally

Compliance Considerations

  • No PHI in code or comments
  • Audit logging maintained
  • Access controls respected

Screenshots

If applicable, add screenshots.

… improve architecture

- Split 2000-line electron/ipc/handlers.cjs into 9 domain-specific modules
  (auth, entities, admin, license, barriers, ahhq, labs, clinical, operations)
  with shared session state and utilities in shared.cjs
- Add 33 comprehensive business logic tests covering priority scoring,
  donor matching, FHIR validation/import, notification rules, password
  validation, and entity helper functions
- Fix FHIR parameter mismatch (fhir_bundle -> fhir_data) in FHIRImporter
- Add React ErrorBoundary component wrapping the entire app
- Add .env.example documenting all environment variables
- Add docs/ARCHITECTURE.md with system diagrams and module map
- Harden LICENSE_FAIL_OPEN to also check app.isPackaged (prevents leak to production)
- Harden default credential seeding (suppress console output in production)
- Remove unused moment dependency, standardize on date-fns
- Convert utils/index.ts to .js for codebase consistency
- Upgrade apiClient.js with safeApiCall error handling utility
- Add test execution step to CI workflow
- Fix pre-existing lint error in LabsPanel.jsx

Made-with: Cursor
…ilities

CRITICAL fixes:
- Add input validation for MELD/LAS/PRA/cPRA medical scores with range checking
- Add HLA typing format validation, parsing, and proper match scoring
- Implement HIPAA-compliant audit trail (WHO/WHAT/WHEN/WHERE/WHY) with SHA-256
  record hashing for immutability verification
- Sanitize patient names in all notifications to prevent XSS/injection
- Mitigate race conditions in donor matching via patient freshness re-check
- Cache parsed HLA antigens to avoid redundant regex splitting per patient

HIGH fixes:
- Replace generic catch-all error handlers across all Deno functions with
  structured logging and safe error responses (no internal details leaked)
- Fix license bypass vulnerability in App.jsx (fail-closed on error)
- Harden license check in electron/main.cjs with clock-skew protection
- Add CSP, X-Frame-Options, X-Content-Type-Options headers in Electron

MEDIUM fixes:
- Refactor App.jsx license state to useReducer with discriminated auth errors
- Extract magic numbers into named constants (functions/lib/constants.ts)
- Sanitize diagnosis text in FHIR export against injection
- Add comprehensive tests for priority score boundaries and HLA matching
- Add HIPAA compliance matrix documentation

New shared modules: functions/lib/{constants,validators,logger,audit}.ts

Made-with: Cursor
CRITICAL (1-8):
1. DevTools disabled in production builds with event listener block
2. HIPAA BAA requirements documented (docs/HIPAA_BAA_REQUIREMENTS.md)
3. Encryption key management procedures documented
4. Audit log immutability enforced via SQLite triggers (no UPDATE/DELETE)
5. Structured error logging with file rotation (electron/ipc/errorLogger.cjs)
6. Medical score validators for electron IPC layer (MELD/LAS/PRA/HLA)
7. Backup integrity verification with SHA-256 checksums
8. SECURITY.md expanded with full threat model and defense-in-depth architecture

HIGH (9-14):
9. Security workflow hardened with fail-on-moderate, lockfile check
10. Data residency controls for export destination validation
11. Disaster recovery plan with RTO/RPO objectives
12. Compliance audit trail report generator for HIPAA reviews
13. Production deployment checklist
14. Secrets management template (.env.PRODUCTION.example)

MEDIUM (15-17):
15. Code signing config added to electron-builder.enterprise.json
16. IPC rate limiting per handler with configurable limits
17. package-lock.json committed for reproducible builds

New IPC handlers registered: backup, dataResidency, auditReport
New docs: BAA, encryption, disaster recovery, deployment, threat model,
          API security, operations manual

Made-with: Cursor
… validation, migrations, key rotation, and comprehensive testing

Critical:
- Enhanced backup verification with actual DB restore test (disasterRecovery.cjs)
- Added FHIR R4 structural validation for Patient, Condition, Observation, Bundle
- Added database migration strategy with versioned, transactional migrations
- Added encryption key rotation service with audit trail and cooldown
- Added request context tracing for end-to-end operation linking

Testing:
- Added compliance validation tests (31 checks: HIPAA, FDA, org isolation, security)
- Added performance load tests (5000 patients, 50k audit logs, <1s queries)
- Added Playwright E2E test framework with app launch and API verification
- Enhanced CI security workflow with Snyk scanning and load test jobs

Documentation:
- Created incident response runbook (HIPAA breach notification procedures)
- Created comprehensive production deployment guide (step-by-step)
- Created full API reference for all IPC channels and parameters

Made-with: Cursor
…eAuditLogTriggers()

Moved HIPAA 164.312(b) audit log immutability triggers from inline
init.cjs code to a dedicated exported function in schema.cjs with
standardized trigger names (audit_logs_immutable_update,
audit_logs_immutable_delete). Updated compliance tests to verify
triggers exist in schema.cjs.

Made-with: Cursor
…cy audit, native module rebuild

- Fix shared.cjs: remove duplicate logAudit function and INSERT from bad merge
- Fix package.json: remove duplicate test/test:security/test:business scripts from merge
- Fix CodeQL: use iterative tag stripping in sanitizePlainText to prevent bypass
- Fix dependency audit: update jspdf to 4.2.1 (fixes 9 CVEs), run npm audit fix (0 vulns)
- Fix security workflow: add system deps + npm rebuild for native sqlite module
- Fix audit flag: use --omit=dev instead of deprecated --production

Made-with: Cursor
@NeuroKoder3
Copy link
Owner Author

commit

@NeuroKoder3 NeuroKoder3 merged commit deaec6d into main Mar 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant