5.2 KiB
5.2 KiB
ACS Node.js Migration Plan
Goal
Convert ACS from the current Spring Boot backend deployment model to an AI DEV compliant Node.js application.
The target deployment must:
- Run as a Node.js app.
- Run on port
3000. - Use
process.env.DATABASE_URLsupplied by.project-env/ AI DEV. - Avoid self-managed PostgreSQL containers in the deployment path.
- Build through the root
Dockerfile. - Preserve the existing React frontend where possible.
- Preserve the current
/apicontract and response envelope:
{ "code": 200, "message": "OK", "data": {} }
Target Architecture
Node.js app
├─ /api/* Express API
├─ /assets, /index.html Static React build from frontend/dist
├─ PostgreSQL process.env.DATABASE_URL
└─ migrations SQL files adapted from existing Flyway migrations
Recommended stack:
- Runtime: Node.js + TypeScript
- HTTP: Express
- Database:
pg - Session:
express-sessionwith PostgreSQL-backed store - Password hashing:
bcrypt - QR generation:
qrcode - Excel import/export:
multer+exceljs - Frontend: existing React/Vite app
Migration Principles
- Keep the frontend API surface stable.
- Reuse the current PostgreSQL schema as much as possible.
- Convert by feature slice, not by framework layer.
- Keep Spring Boot code available as the behavior reference until parity is verified.
- Make AI DEV deployment simple:
npm install,npm run build,npm start.
Feature Migration Order
Phase 1. Node Foundation
- Add root Node package and TypeScript config.
- Add
server/source tree. - Add env loader for local
.project-envcompatibility. - Add PostgreSQL connection pool using
DATABASE_URL. - Add migration runner using SQL files in
migrations/. - Add health check endpoint:
GET /api/health. - Add AI DEV health check endpoint:
GET /healthz. - Add AI DEV DB check endpoint:
GET /db. - Add S3 status endpoint:
GET /s3with an explicit skip response because ACS does not use S3/MinIO. - Serve
frontend/distfor non-API routes.
Phase 2. Auth and Common Infrastructure
- Implement API response helper.
- Implement error handler.
- Implement session middleware.
- Implement role guard middleware.
- Implement:
POST /api/auth/loginPOST /api/auth/logoutGET /api/auth/mePOST /api/auth/change-password
Phase 3. Read-First Business APIs
GET /api/zonesGET /api/visit-requestsGET /api/visit-requests/pendingGET /api/visit-requests/:idGET /api/stats/summary
Phase 4. Visit Request and Approval Workflow
POST /api/visit-requestsPOST /api/visit-requests/:id/cancelPOST /api/approvals/:id/approvePOST /api/approvals/:id/reject- Generate
qr_tokenon approval. - Insert approval and audit log records.
- Preserve "notification failure must not rollback approval" behavior.
Phase 5. Pass, QR, and Access Control
GET /api/passes/:idGET /api/passes/:id/qr.pngGET /api/public/passes/:tokenGET /api/public/passes/:token/qr.pngPOST /api/access/check-inPOST /api/access/check-outGET /api/access/insideGET /api/access/today- Public kiosk check-in/out endpoints.
Phase 6. Admin Features
- Blacklist CRUD.
- Audit log list.
- Delivery outbox list and retry.
- Excel upload for visit requests.
- XLSX visit report download.
Phase 7. Deployment Cleanup
- Update README and AI DEV run instructions.
- Mark Spring Boot backend and Docker Compose deployment as legacy.
- Keep or remove legacy files after user confirmation.
- Verify deployment in AI DEV with real
.project-env.
API Compatibility Rules
- Keep
/apiprefix. - Keep frontend DTO field names in camelCase.
- Keep HTTP status behavior close to the Spring implementation:
- 400 validation error
- 401 unauthenticated
- 403 forbidden
- 404 missing resource
- 409 business conflict
- State-changing APIs must require an authenticated session unless they are public token endpoints.
- Public pass endpoints must not require login.
Database Migration Strategy
Existing files:
V1__init.sqlV2__audit_log.sqlV3__pass_delivery.sqlV4__visit_request_contact_fields.sql
Node target:
- Copy SQL into
migrations/001_init.sqletc. - Create a
schema_migrationstable. - Apply migrations in filename order.
- Do not create or manage a PostgreSQL container.
- Use only
DATABASE_URL.
Verification Checklist
npm run typechecknpm run buildnpm run db:checkin AI DEV/Coder with.project-envloadednpm run minio:checkreturns a documented skip because ACS does not use S3npm startGET /healthzGET /dbGET /api/health- Login with seeded admin user.
- Create visit request.
- Approve request and confirm QR token.
- Open public pass page.
- Check in and check out.
- Confirm inside/today access views.
- Confirm blacklist blocks check-in.
- Download report XLSX.
Open Decisions
- Exact AI DEV Node version.
- Whether AI DEV automatically runs
npm run buildor onlynpm start. - Whether
.project-envexists in the repository root or must be sourced by the shell before startup. - Whether the production app should seed initial users automatically or require an explicit seed command.