Ultra-lightweight vanilla JavaScript finance agent with TypeScript design-time validation and zero-build architecture.
- Pure JavaScript ES2022+ - Modern ES modules with esbuild production bundling
- JSDoc + TypeScript - Compile-time type checking in pure .js files
- Minimal dependencies - Only 3 carefully chosen utilities (tree-shakeable imports)
- < 25kb bundle - Ultra-lightweight with tree-shaking and minification (8.42KB gzipped)
- Native DOM APIs - No framework overhead, zero-build development
- Educational Code - Every function includes financial formula explanations
┌─────────────────────────────────────────────────────────────┐
│ UI Layer (src/ui/) │
├─────────────────────────────────────────────────────────────┤
│ financial-inputs.js │ phase-tables.js │
│ summary-cards.js │ wealth-chart.js │
│ calculation-controller.js │ theme-manager.js │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ State Management (src/state/) │
├─────────────────────────────────────────────────────────────┤
│ financial-data.js │ simulation-results.js │
│ defaults.js │ observers.js │
│ validation.js │ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Business Logic (src/lib/) │
├─────────────────────────────────────────────────────────────┤
│ simulate-wealth.js │ retirement.js │
│ phase-organization.js │ optimal-retirement.js │
│ investments.js │ allocations.js │
│ expenses.js │ growth.js │
│ currency.js │ tax.js │
│ validators.js │ simulation-helpers.js │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Utilities (src/utils/) │
├─────────────────────────────────────────────────────────────┤
│ dom-helpers.js │ formatting/ │
│ │ currency.js │
│ │ display.js │
│ │ growth.js │
│ │ accessibility.js │
└─────────────────────────────────────────────────────────────┘
- Input Layer: User interactions captured by
financial-inputs.js - Validation: TypeBox schemas validate all user input data
- State Management:
financial-data.jspersists data,observers.jsnotifies changes - Business Logic:
simulate-wealth.jsorchestrates financial calculations - Results Caching:
simulation-results.jsprovides LRU cache for expensive calculations - Display: UI modules render formatted results with
formatters/utilities
- Lazy Loading: Chart module loads only when needed (
wealth-chart.js) - Intelligent Caching: LRU cache with 100-entry limit prevents recalculation
- Debounced Updates: Input changes trigger calculations after 300ms delay
- Tree Shaking: Only used functions included in production bundle
- Memory Management: Automatic cleanup of event listeners and observers
npm test # Run all tests
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage report# Option 1: Production build + server
npm run build # Build the production bundle first
npm run dev # Start HTTP server on localhost:3000 (serves dist/)
# Option 2: Development with source files
# Serve the project root with any HTTP server to use index.html (dev version)
python3 -m http.server 8000 # Then visit http://localhost:8000npm run check # Run all quality checks (type, lint, test, bundle size)
npm run precommit # Same as check - use before committing
# For commits: Use ./scripts/auto-commit.sh "detailed commit message"
npm run release # Automated GitHub release with assets
npm run type-check # Check types with TypeScript (no emit)
npm run type-check:watch # Check types in watch mode
npm run lint # Check code with ESLint
npm run lint:fix # Fix ESLint issues automaticallyCommit & Release Workflow:
# 1. Run quality checks
npm run check
# 2. Stage changes and commit with detailed message
git add .
./scripts/auto-commit.sh "feat: implement advanced feature X
Detailed description of what was changed and why.
Include business context and impact analysis."
# 3. Create GitHub release
npm run releasenpm run build # Build production bundle with esbuild (minified, tree-shaken)
npm run build:check # Build and validate bundle size
npm run build:dev # Development build (CSS modularized, JS copied)src/
├── lib/ # Pure business logic functions
│ ├── simulate-wealth.js # Core wealth simulation engine
│ ├── phase-organization.js # Financial phase management
│ ├── optimal-retirement.js # Retirement age optimization
│ ├── investments.js # Investment growth calculations
│ ├── retirement.js # Retirement planning functions
│ ├── allocations.js # Financial allocation strategies
│ ├── expenses.js # Expense management functions
│ ├── growth.js # Compound growth calculations
│ ├── currency.js # Currency conversion utilities
│ ├── tax.js # Tax calculation functions
│ ├── validators.js # TypeBox validation helpers
│ ├── simulation-helpers.js # Wealth simulation utilities
│ ├── *.test.js # Co-located unit tests for each module
│ └── integration.test.js # Cross-module integration tests
├── ui/ # UI creation modules
│ ├── financial-inputs.js # Income/expense input forms
│ ├── summary-cards.js # Financial overview displays
│ ├── phase-tables.js # Year-by-year breakdown tables
│ ├── wealth-chart.js # Interactive wealth trajectory chart
│ ├── calculation-controller.js # Orchestrates UI updates
│ ├── theme-manager.js # Dark/light theme management
│ ├── app-layout.js # Main application layout
│ ├── app-controllers.js # Application lifecycle management
│ ├── input-field.js # Reusable input field component
│ ├── input-section.js # Input section container
│ ├── phase-tables-container.js # Container for phase tables
│ ├── phase-table-helpers.js # Table cell creation utilities
│ ├── chart-loader.js # Lazy loading for chart module
│ ├── financial-inputs-extended.js # Extended input functionality
│ ├── *.test.js # UI component tests
│ └── integration.test.js # UI integration tests
├── state/ # State management modules
│ ├── financial-data.js # User input persistence
│ ├── simulation-results.js # Intelligent result caching
│ ├── defaults.js # Default financial values
│ ├── observers.js # Observer pattern implementation
│ ├── validation.js # Data validation and migration
│ └── *.test.js # State management tests
├── utils/ # Utility functions
│ ├── dom-helpers.js # DOM manipulation utilities
│ └── formatting/ # Formatting utilities
│ ├── currency.js # Currency formatting
│ ├── display.js # General display formatting
│ ├── growth.js # Growth percentage formatting
│ ├── accessibility.js # Accessibility formatting
│ └── *.test.js # Formatting tests
├── styles/ # Modular CSS architecture
│ ├── main.css # CSS imports and custom properties
│ ├── base.css # Base typography and reset
│ ├── layout.css # Grid layout and structure
│ ├── forms.css # Form styling and inputs
│ ├── tables.css # Table styling and responsive design
│ └── results.css # Results display styling
└── main.js # Application entry point
simulate-wealth.js- Core financial simulation engine with multi-phase planningphase-organization.js- Manages debt elimination → emergency fund → retirement phasesoptimal-retirement.js- Calculates optimal retirement age based on financial goalsinvestments.js- Investment growth calculations with compound interestallocations.js- Dynamic allocation strategies based on financial phaseexpenses.js- Expense categorization and emergency fund calculationsgrowth.js- Pure compound growth mathematics with educational formulascurrency.js- USD → EUR → THB conversion chain for cost-of-living calculationstax.js- Tax calculations with multi-year progression supportvalidators.js- TypeBox validation schemas for all financial data
financial-inputs.js- Dynamic form generation with auto-save and validationsummary-cards.js- Financial overview cards with milestone summariesphase-tables.js- Year-by-year breakdown with delta calculationswealth-chart.js- Interactive wealth trajectory visualization with μPlotcalculation-controller.js- Debounced calculation orchestrationtheme-manager.js- Dark/light theme with CSS custom properties
financial-data.js- localStorage persistence with observer notificationssimulation-results.js- LRU cache for expensive simulation resultsdefaults.js- Default financial values and constantsobservers.js- Publisher-subscriber pattern for state changesvalidation.js- Data migration and schema validation
dom-helpers.js- Performance-optimized DOM manipulationformatting/- Currency, percentage, and display formatting utilities
Testing Standards:
- Mandatory Co-location: Every
.jsfile with functions must have a.test.jsfile in the same directory - Integration Tests:
integration.test.jsfiles test module interactions and complete data flows - 100% Coverage: All functions must be tested with comprehensive test cases
- No
__tests__folders: Tests are placed directly adjacent to source files
Currency Handling:
- User Input: All user expense inputs are in EUR (not THB)
- Default Values: All default expense values are in EUR
- Conversions: USD → EUR → THB conversion chain for Thai cost-of-living calculations
- Display: Local currency formatting respects user's currency preferences
- Multi-Phase Planning: Debt elimination → Emergency fund → Retirement optimization
- Currency Conversion: USD salary → EUR expenses → THB cost-of-living calculations
- Tax Progression: Multi-year tax scenarios with tax-free vs. taxed periods
- Compound Growth: Investment returns with configurable annual growth rates
- Emergency Fund: 6-month expense rule with dynamic target calculations
- Optimal Retirement: Algorithm finds ideal retirement age based on financial goals
Every financial calculation includes:
- Step-by-step formula breakdowns in JSDoc comments
- Real-world context explaining financial concepts
- Practical examples with sample calculations
- Edge case handling with clear error messages
- Interactive exploration of financial scenarios
- Intelligent Caching: LRU cache prevents recalculation of expensive simulations
- Debounced Input: 300ms delay aggregates rapid user input changes
- Lazy Chart Loading: Chart module loads only when visualization is needed
- Memory Management: Automatic cleanup prevents memory leaks
- Bundle Optimization: Tree-shaking ensures minimal production size (8.42KB gzipped)
- lodash-es - Utility functions (tree-shakeable)
- date-fns - Date manipulation utilities
- uplot - High-performance charting library
- eslint - Code linting
- esbuild - Production bundling with minification and tree-shaking
- typescript - Type checking (compile-time only)
- knip - Unused dependency detection
- Write Tests First - Follow TDD methodology with co-located test files
- Design Types - Use JSDoc comments for TypeScript inference
- Implement Functions - Pure functions with TypeScript type safety
- Document Thoroughly - Educational comments explaining formulas
- Integration Testing - Test module interactions and complete data flows
- Quality Gate - AI agent runs
npm run precommit(validates everything) - Analyze Changes - AI agent examines all staged changes and generates detailed commit message
- Automated Commit - AI agent runs
./scripts/auto-commit.sh "detailed message"with comprehensive description - Automated Release - AI agent runs
npm run release(GitHub release with assets) - Complete Workflow - AI agent must use direct script calls for detailed commit messages
Commit Message Requirements:
- Detailed Analysis: Must analyze all file changes and explain what/why/impact
- Semantic Format: Use
feat:,fix:,docs:,refactor:,test:,perf:, etc. - Business Context: Explain motivation and architectural decisions
- Impact Description: How changes affect users, performance, or development
- Multi-paragraph: Include summary, detailed description, motivation, and impact
Example commit workflow:
# After making changes...
npm run check # Validate all quality gates
git add . # Stage all changes
# Generate detailed commit message and commit
./scripts/auto-commit.sh "feat: implement advanced caching with LRU eviction strategy
Add intelligent simulation result caching to src/state/simulation-results.js with
memory-bounded LRU cache (max 100 entries), deterministic key generation, and
performance tracking. Includes comprehensive test suite with 13 test cases.
Motivation: Expensive simulation calculations were being repeated unnecessarily
when users made minor input adjustments, causing UI lag and poor UX.
Impact: Reduces calculation time by 80% for repeated scenarios, improves
responsiveness, and maintains memory efficiency through automatic eviction."
# Create GitHub release
npm run releaseTesting Requirements:
- Every
.jsfile with functions MUST have a corresponding.test.jsfile - Integration tests required for testing module interactions
- Tests co-located with source files (no separate test directories)
- 100% test coverage with comprehensive edge case testing
- Bundle Size: 8.42KB gzipped (well under 25KB target) ✅
- Time to Interactive: 166ms on 3G (under 300ms target) ✅
- Runtime Dependencies: 3 packages (minimal footprint) ✅
- Test Coverage: 544 tests passing, 98%+ coverage ✅
- Tree Shaking: Optimal - only used functions included ✅
- Type Safety: 100% TypeScript compliance with JSDoc annotations
- Code Quality: ESLint passing with zero warnings
- Test Coverage: All modules have co-located comprehensive tests
- Performance Budget: Automated bundle size validation in CI
- Educational Code: Every function includes formula explanations
All code follows comprehensive standards defined in .cursor/rules/:
- Educational commenting with formula breakdowns
- JSDoc comments with type annotations
- Basic runtime validation for critical edge cases
- Pure functions with SOLID principles
- Zero magic - every line explained
- ESLint must pass before task completion
This project evolved from a single Thailand.html file into a modular architecture while maintaining 100% feature parity.
- Modularization: Split 1,500+ line file into focused, testable modules
- Testing: Added comprehensive test suite with 544+ tests
- Performance: Reduced bundle size and improved load times
- Maintainability: Each module has single responsibility
- Documentation: Added educational comments throughout
- All calculations: Identical financial formulas and results
- User Interface: Same dark theme design and responsive layout
- Default Values: Same starting financial assumptions
- Data Persistence: Same localStorage behavior
- Currency Handling: Same USD → EUR → THB conversion chain
- Testability: Every function has comprehensive unit tests
- Performance: Intelligent caching and lazy loading
- Type Safety: TypeScript validation without runtime overhead
- Code Quality: ESLint enforcement and educational documentation
- Maintainability: Clear separation of concerns and module boundaries
- Quality Gates: Automated validation before every commit
- Test-Driven Development: Write tests before implementation
- Performance Monitoring: Bundle size validation and optimization
- Educational Code: Every function explains financial concepts
- Automated Releases: GitHub releases with detailed changelogs