Files
proxmox/reports/status/DBIS_SOURCE_CODE_FIXES_FINAL.md
defiQUG cb47cce074 Complete markdown files cleanup and organization
- Organized 252 files across project
- Root directory: 187 → 2 files (98.9% reduction)
- Moved configuration guides to docs/04-configuration/
- Moved troubleshooting guides to docs/09-troubleshooting/
- Moved quick start guides to docs/01-getting-started/
- Moved reports to reports/ directory
- Archived temporary files
- Generated comprehensive reports and documentation
- Created maintenance scripts and guides

All files organized according to established standards.
2026-01-06 01:46:25 -08:00

3.6 KiB

DBIS Source Code Fixes - Final Solution

Date: 2026-01-03
Status: CUSTOM PATH RESOLVER IMPLEMENTED


Problem

The API service failed with MODULE_NOT_FOUND errors for TypeScript path aliases (@shared/, @/core/, etc.).

Root Cause:

  • tsconfig-paths resolves paths based on tsconfig.json, which maps aliases to src/*
  • At runtime, files are in dist/*, not src/*
  • tsconfig-paths was looking for files in src/shared/config/env but they're actually in dist/shared/config/env

Solution Implemented

Custom Path Resolver - Created a runtime module resolver that maps TypeScript path aliases directly to the dist directory structure.

Implementation

Created /opt/dbis-core/dist/index-runtime.js that:

  1. Intercepts Node.js module resolution (Module._resolveFilename)
  2. Maps path aliases (@/, @/shared/, @/core/, etc.) to dist/* directories
  3. Tries multiple file extensions (.js, .json, and directory index.js)
  4. Falls back to original Node.js resolution if alias doesn't match

Files Created/Modified

/opt/dbis-core/dist/index-runtime.js

This file intercepts require() calls and resolves path aliases to the correct locations in the dist directory.

Key Features:

  • Maps @/dist/
  • Maps @/shared/dist/shared/
  • Maps @/core/dist/core/
  • Maps @/integration/dist/integration/
  • Maps @/sovereign/dist/sovereign/
  • Maps @/infrastructure/dist/infrastructure/

/etc/systemd/system/dbis-api.service

Updated ExecStart to use dist/index-runtime.js instead of dist/index.js.


Verification

After applying the fix:

  1. Check service status:

    ssh root@192.168.11.10 "pct exec 10150 -- systemctl status dbis-api"
    
  2. Check logs:

    ssh root@192.168.11.10 "pct exec 10150 -- journalctl -u dbis-api -n 50"
    
  3. Test health endpoint:

    curl http://192.168.11.155:3000/health
    
  4. Verify port listening:

    ssh root@192.168.11.10 "pct exec 10150 -- ss -tln | grep 3000"
    

Applied To

  • VMID 10150 (API Primary)
  • VMID 10151 (API Secondary)

Why This Solution Works

  1. Direct Mapping: Maps aliases directly to dist/* without needing tsconfig.json interpretation
  2. Runtime Resolution: Works at runtime without build-time changes
  3. No Dependencies: Doesn't require tsconfig-paths package (though it's installed)
  4. Flexible: Handles multiple file extensions and directory indexes
  5. Fallback: Falls back to original Node.js resolution for non-alias imports

Alternative Solutions Considered

  1. tsconfig-paths: Failed because it resolves to src/* instead of dist/*
  2. tsc-alias: Would require rebuild and redeployment (build-time solution)
  3. Custom resolver: Chosen - Works immediately at runtime

Next Steps

If the service starts successfully:

  1. Test API endpoints - Verify the API is responding correctly
  2. Run database migrations - If needed:
    ssh root@192.168.11.10 "pct exec 10150 -- cd /opt/dbis-core && npx prisma migrate deploy"
    
  3. Test Frontend connectivity - Verify frontend can connect to API
  4. Monitor logs - Check for any runtime errors

Summary

Custom path resolver implemented
Maps TypeScript aliases to dist directory
Applied to both API containers
Service configured to use runtime entry point

Status: Solution implemented and ready for testing.


Last Updated: 2026-01-03