Bob X-Ray · Legacy Knowledge Rescue
Auto-generated Onboarding Kit for oms-api (legacy order management)
repo: oms-api port: 4790 🔒 analysis: 4 subtasks
14
Files scanned
1
Outdated doc (8 lies)
0
Tests found
7
Landmines
6
Quick wins
1
Bus factor ⚠️
bob xray ./oms-api — 4/4 subtasks completed
$ bob xray ./oms-api --deep → parsing 14 files · require graph · complexity ......... done → entry: server.js · stack: Node / Express / PostgreSQL (FAKE_MODE fallback) → ⚠ docs/API_DOCS_v2019.md conflicts with code — 8 lies flagged (Basic Auth · TTL 24h vs 72h · no coupons · no refund · hard delete · /v1/ · no R status · no /health) → ⚠ pricing engine orderController 300+ lines — tiers 10/25/50 · LAUNCH50 · GHOST20 expired-but-active · floorCents penny rule (2019 audit) → risk 8/10 → ⚠ hardcoded secrets in config.js (staging DB URL · TOKEN_SALT) ✓ ONBOARDING.md · ARCHITECTURE.md (5 diagrams) · RISK-REPORT.md · STARTER-TASKS.md — kit ready → impact: onboarding 3 weeks → day 1 · senior mentoring load -40%

🔍 What is this project?

OMS API — an internal Order Management API. Create / track / cancel / refund orders. Customers never touch it; finance jobs, support tooling and the mobile app talk to it.

Node.jsExpress PostgreSQL + FAKE_MODEToken auth (72h TTL) 0 tests
  • Entry point: server.js — port 4790 (finance dependency — changing it = 💥)
  • Business logic: lives in controllers/ — routes are just wiring
  • Runs even without a DB — FAKE_MODE in-memory stubs

🗂️ Folder guide

server.jsExpress app + /health (200-always contract)
config.jsenv fallbacks + ⚠️ hardcoded secrets
routes/3 files — URL → controller wiring
controllers/auth · users · orders (pricing engine ⭐)
db/connection.jspool + FAKE_MODE in-memory stubs
utils/helpers (dead code) + logger (frozen format)
legacy/v1 schema — do not drop ⚠️
docs/2019 doc — 8 lies, replaced by this kit

⚡ Before vs After

😐 Before Bob X-Ray
  • Undocumented repo with lying 2019 docs
  • New dev: 3-4 weeks of confusion
  • Seniors spend 30-40% of time explaining
  • Tribal knowledge locked in comments
  • No map of pricing quirks or landmines
🚀 After (1 command)
  • Day 1: setup + first API call working
  • Day 2: architecture clear (5 diagrams)
  • Week 1: 3 real PRs (starter tasks)
  • Landmines documented (GHOST20, penny rule...)
  • Bus factor risk visible + actionable
💡 Judge one-liner: Bob cross-checked the outdated 2019 doc against the code and flagged 8 lies — then generated the full knowledge kit with 4 parallel subtasks.

📊 Architecture 5 diagrams · mermaid-safe

1 · System map
flowchart LR
    C[Clients] -->|HTTP 4790| S[server.js]
    S --> M[Middleware]
    M --> AR[authRoutes]
    M --> UR[userRoutes]
    M --> OR[orderRoutes]
    AR --> AC[authController]
    UR --> UC[userController]
    OR --> OC[orderController]
    AC --> DB[(db connection)]
    UC --> DB
    OC --> DB
    DB --> PG[(PostgreSQL)]
    AC --> L[app.log]
    OC --> L
    UC --> L
2 · Module dependency graph (color = risk)
flowchart TD
    SRV[server.js]:::med
    CFG[config.js]:::med
    DB[(db connection)]:::high
    AR[authRoutes]:::low
    UR[userRoutes]:::low
    OR[orderRoutes]:::low
    AC[authController]:::high
    UC[userController]:::med
    OC[orderController]:::crit
    H[helpers.js]:::med
    LG[logger.js]:::low
    SRV --> AR
    SRV --> UR
    SRV --> OR
    SRV --> CFG
    SRV --> LG
    SRV --> DB
    SRV --> AC
    AR --> AC
    UR --> UC
    OR --> OC
    AC --> DB
    AC --> CFG
    AC --> LG
    UC --> DB
    UC --> CFG
    UC --> LG
    UC --> AC
    UC --> H
    OC --> DB
    OC --> CFG
    OC --> LG
    OC --> H
    DB --> CFG
    LG --> CFG
    classDef crit fill:#da1e28,color:#fff
    classDef high fill:#ff832b,color:#000
    classDef med fill:#f1c21b,color:#000
    classDef low fill:#42be65,color:#000
3 · Order-create sequence — POST /orders
sequenceDiagram
    autonumber
    participant Cl as Client
    participant Ex as Express server
    participant Au as requireAuth
    participant OC as orderController
    participant PR as calculatePricing
    participant DB as db-connection
    participant PG as PostgreSQL
    Cl->>Ex: POST /orders with token header
    Ex->>Au: requireAuth middleware
    Au->>Au: validate token and expiry
    alt token invalid or expired
        Au-->>Cl: 401 invalid or expired token
    else token valid
        Au->>Ex: attach user and role to request
    end
    Ex->>OC: createOrder
    OC->>OC: validate items fields
    alt validation fails
        OC-->>Cl: 400 items missing
    else items ok
        OC->>PR: calculatePricing items coupon
        PR->>PR: qty tiers coupons tax shipping floor
        PR-->>OC: pricing breakdown object
        alt FAKE MODE active
            OC->>DB: fake insert in memory
            DB-->>OC: fake order object
            OC-->>Cl: 201 order fakeMode true
        else real DB path
            OC->>DB: pool connect and insert
            DB->>PG: SQL insert orders
            PG-->>DB: row inserted
            DB-->>OC: order row
            OC-->>Cl: 201 order created
        end
    end
4 · Entity-relationship diagram
erDiagram
    USERS ||--o{ ORDERS : places
    USERS {
        int id PK
        varchar login
        varchar pwd_hash
        varchar full_name
        varchar dept
        boolean is_active
        int points
    }
    ORDERS {
        int id PK
        int user_id FK
        jsonb items_json
        int total_cents
        varchar status
        timestamp created_on
    }
5 · Order status machine
stateDiagram-v2
    [*] --> P: order created
    P --> C: confirmed
    P --> X: cancelled
    C --> X: cancelled
    C --> R: refunded
    X --> [*]
    R --> [*]
🔁 Highlights: pricing tiers 10/25/50 → 5/10/15% · coupons LAUNCH50 + GHOST20 · 18% tax · $5.99 shipping (free over $100) · floorCents round-DOWN · FAKE_MODE fallback.

⚠️ Knowledge Risk Report BUS FACTOR = 1

🚌 Bus Factor 1: the pricing engine, auth scheme, FAKE_MODE behavior, status codes and the port-4790 dependency are all "documented" only in code comments. The migration history has Bus Factor 0 (the files don't even exist in the repo).

File-by-file risk scorecard (from Bob scan)

FileRiskScoreCore issue
controllers/orderController.jsCRITICAL
8/10
300+ line pricing engine — tiers, coupons, tax, shipping, penny rule — documented only in comments.
docs/API_DOCS_v2019.mdHIGH
7/10
"The lie table" — 8 confirmed conflicts with code. The biggest onboarding trap.
controllers/userController.jsMEDIUM
6/10
Soft-delete semantics + auth coupling. Hard delete breaks finance joins.
utils/helpers.jsMEDIUM
4/10
Dead code (formatPhoneE164 deprecated) + duplicate date formatters.
server.jsLOW
3/10
/health 200-always contract — monitoring depends on it.
utils/logger.jsLOW
2/10
Format frozen — ops grep scripts depend on it.

See RISK-REPORT.md for config.js and db/connection.js scores.

🚨 Top landmines

  • Remove GHOST20 → sales escalation (expired but active)
  • Use Math.round → $0.01 discrepancy (2019 audit) — keep floorCents
  • Change port 4790 → finance reconciliation silently breaks
  • Hard-delete a user → dashboards break (soft-delete only)
  • Drop old_schema → legacy reporting job fails
  • Change logger format → ops scripts break
  • Ignore FAKE_MODE → watch logs to detect fake orders in prod

✅ Quick wins (6)

  • Config → env vars (keep 4790 fallback at 4790)
  • Role guard on PATCH /orders/:id/status
  • Delete dead code (grep-verified)
  • Archive API_DOCS_v2019.md (this kit replaces it ✅)
  • Auth upgrade roadmap (base64 → proper hashing)
  • Merge mermaid docs into repo (this kit ✅)

✅ First 3 tasks for a new developer safe · high-learning · reviewable

Click the checkboxes — feels like assignment, right? 😄

1 · Move config to env vars
EASY1-2 hrstouches: config.js

Move hardcoded staging DB URL and TOKEN_SALT into environment variables. Defaults stay the same.

⚠️ TRAP: the 4790 fallback must stay 4790 — the finance cron job expects it. If you move it to env too, do not change the value.
2 · Role guard on PATCH /orders/:id/status
MEDIUM30-60 mintouches: orderController · auth

Add a role check on the status-change endpoint so a regular user cannot confirm/cancel arbitrary orders.

⚠️ TRAP: the docs say Basic Auth — the code wants Token auth (lie table!). And you must handle the FAKE_MODE credential decoder too.
3 · Delete dead code in helpers.js
EASY30-45 mintouches: helpers.js + call-sites

Remove dead functions like formatPhoneE164 (deprecated) and consolidate the duplicate date formatters.

⚠️ TRAP: "removing it broke something once" — grep-verify every delete with grep -rn. Some "dead" functions come back from merge conflicts.
🏁 Outcome: after week one the new dev knows the full request flow + codebase archaeology + critical-file exposure — with 3 reviewable PRs. Onboarding goes from 3 weeks to 1 week.

📖 Onboarding 5-min setup

⚡ Setup

npm install npm start # → http://localhost:4790 # Runs even without a DB (FAKE_MODE) ✅

Health check

curl http://localhost:4790/health # → 200 OK (ALWAYS — monitoring contract)

🌍 Key endpoints

POST /auth/loginreturns token (72h TTL)
POST /orderspricing engine ⭐
PATCH /orders/:id/statusneeds role guard
POST /orders/:id/refundR status (docs never knew)
GET /health · /statusmonitoring endpoints

⚠️ Quirks

  • Port 4790 is sacred — finance job
  • /health always 200 — even when DB is down
  • GHOST20 alive — don't touch without asking the PM
  • floorCents not Math.round — audit rule
  • Soft delete only — users are never hard-deleted