feat(CP-27): dashboard projection API with Monte Carlo#14
Merged
Conversation
Wire the projection engine to REST endpoints that load all plan data, transform Prisma models to engine input types, and return chart-ready results for the frontend dashboard. - GET /api/plans/:planId/projection - deterministic 36-year projection - GET /api/plans/:planId/projection/monte-carlo - 1000-iteration MC sim - Monte Carlo engine (Box-Muller normal distribution on return rates) - Graceful handling of empty/partial plan data - OpenAPI/Swagger documentation registered - Unit tests for empty plan, minimal plan, edge cases, and MC output
ncamaa
added a commit
that referenced
this pull request
Apr 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GET /api/plans/:planId/projectionendpoint that loads all plan data from the database, transforms Prisma models into engine input types, runs the 36-year deterministic projection, and returns chart-ready arrays with a summary objectGET /api/plans/:planId/projection/monte-carloendpoint that runs 1000-iteration Monte Carlo simulation with randomized return rates (Box-Muller normal distribution) and returns success rate, median final value, and p5/p25/p50/p75/p95 percentile bandsrunMonteCarloSimulation()in the engine layer (src/engine/monteCarlo.ts) - pure function, no DB accessNew files
src/engine/monteCarlo.ts- Monte Carlo simulation enginesrc/api/projection/projectionModel.ts- Zod schemas for request/responsesrc/api/projection/projectionService.ts- Data loading, Prisma-to-engine transformation, reference data loadingsrc/api/projection/projectionController.ts- Request handlerssrc/api/projection/projectionRouter.ts- Express routes + OpenAPI registrysrc/engine/__tests__/monteCarlo.test.ts- MC engine unit testssrc/api/projection/__tests__/projectionService.test.ts- Projection data transformation + edge case testsModified files
src/engine/index.ts- ExportrunMonteCarloSimulationsrc/server.ts- Mount projection routersrc/api-docs/openAPIDocumentGenerator.ts- Register projection registryTest plan
pnpm buildsucceeds (prisma generate + tsc + tsup)