Files
motovaultpro/backend
Eric Gullickson fdc34aee2f
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 1m49s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 43s
Deploy to Staging / Verify Staging (pull_request) Successful in 4s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 3s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
fix: coerce numeric/decimal columns in repository mappers (refs #241)
node-postgres returns numeric/decimal columns as JavaScript strings,
but the TypeScript interfaces for MaintenanceRecord and OwnershipCost
declare numeric fields as number. The mappers were passing values
through raw, breaking type-safe arithmetic and display (e.g. the
amount column on the vehicle summary screen was empty until the
recent frontend workaround in PR #240, and OwnershipCostsList silently
no-ops toLocaleString on the string).

Backend
- mapMaintenanceRecord: coerce cost via Number() when non-null.
- ownership-costs mapRow: coerce amount via Number().

Frontend (remove now-redundant workarounds)
- MaintenanceRecordsList: drop Number() coercion on cost and
  odometerReading; use the number values directly.
- VehicleDetailPage / VehicleDetailMobile: revert the PR #240 cost
  coercion to the simple typeof number guard now that the backend
  honors the type.

Scope notes
- Other repositories with the same pattern (stations, community-stations,
  fuel-logs enhanced methods) are tracked separately because they have
  unclear downstream consumers and warrant their own investigation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 21:06:24 -05:00
..
2025-12-27 16:38:28 -06:00
2026-02-05 21:49:35 -06:00
2025-12-29 18:51:41 -06:00
2025-08-09 12:47:15 -05:00
2025-11-04 18:38:06 -06:00

MotoVaultPro Backend

Modified Feature Capsule Architecture

Each feature is 100% self-contained in src/features/[name]/:

  • api/ - HTTP endpoints and routing
  • domain/ - Business logic and types
  • data/ - Database operations
  • migrations/ - Feature-specific schema
  • external/ - External API integrations
  • tests/ - All feature tests
  • docs/ - Feature documentation

Quick Start (Containerized)

# From project root directory
# Ensure a valid .env exists at project root (production values provided by your team)

# Build and start all services (including backend)
make setup

# View logs
make logs-backend

# Run migrations
make migrate

Available Commands (Containerized)

From project root:

  • make start - Build and start all services (production)
  • make migrate - Run database migrations
  • make logs-backend - View backend logs
  • make shell-backend - Open shell in backend container

Inside container (via make shell-backend):

  • npm run build - Build for production
  • npm start - Run production build
  • npm test - Run all tests
  • npm test -- features/vehicles - Test specific feature
  • npm test -- features/vehicles/tests/unit - Test specific test type
  • npm run test:watch - Run tests in watch mode
  • npm run schema:generate - Generate combined schema

Core Modules

Configuration (src/core/config/)

  • config-loader.ts - Environment variable loading and validation
  • database.ts - PostgreSQL connection pool
  • redis.ts - Redis client and cache service
  • user-context.ts - User context extraction utilities

Security (Fastify Plugins)

  • src/core/plugins/auth.plugin.ts - Auth0 JWT via JWKS (@fastify/jwt + get-jwks)
  • src/core/plugins/error.plugin.ts - Error handling
  • src/core/plugins/logging.plugin.ts - Request logging

Logging (src/core/logging/)

  • logger.ts - Structured logging with Winston

Middleware

  • src/core/middleware/user-context.ts - User ID extraction from JWT

Storage

  • src/core/storage/ - Storage abstractions
  • src/core/storage/adapters/minio.adapter.ts - MinIO S3-compatible adapter

Feature Development

To create a new feature capsule:

../scripts/generate-feature-capsule.sh feature-name

This creates the complete capsule structure with all necessary files.

Testing

Tests mirror the source structure:

features/vehicles/
├── domain/
│   └── vehicles.service.ts
└── tests/
    └── unit/
        └── vehicles.service.test.ts

Run tests (inside container via make shell-backend):

# All tests
npm test

# Specific feature
npm test -- features/vehicles

# Unit tests for specific feature
npm test -- features/vehicles/tests/unit

# Integration tests for specific feature
npm test -- features/vehicles/tests/integration

# Watch mode
npm run test:watch

# With coverage
npm test -- features/vehicles --coverage

Environment Variables

Ensure .env includes these key variables:

  • Database connection (DB_*)
  • Redis connection (REDIS_*)
  • Auth0 configuration (AUTH0_*) — backend validates JWTs via Auth0 JWKS (@fastify/jwt + get-jwks)
  • External API keys