software development•v1.0.0•3 min read
Vite Application Development
Use when building or verifying a Vite web application.
Trigger
Use when creating, extending, or verifying a Vite application, especially React interfaces with user-editable calculations or other business logic.
Workflow
- Inspect the target directory and package tooling before creating files. Pick a dedicated, descriptive application directory.
- Scaffold explicitly:
npm create vite@latest <app-directory> -- --template react(or the requested template). - The scaffold command creates the application directory but does not change the shell working directory. Run
npm installfrom<app-directory>, not the parent directory. - Inspect generated
package.json, source entrypoint, app component, global styles, and Vite config before replacing starter code. - For non-trivial business logic, extract a dependency-free module under
src/and test it with Vitest. Addvitestand atestpackage script when missing. - Follow RED-GREEN-REFACTOR: add one missing behavior test, run it to observe the expected failure, implement the smallest change, then rerun the suite.
- Build the UI from the tested module. Keep user input state in the component and treat calculated values as derived state.
- Provide labels, keyboard-accessible controls, inline validation, reset behavior, responsive layout, and currency/number formatting appropriate to the domain.
- Verify completion with the full test suite, lint,
npm run build, and a browser smoke check where available.
Calculator and estimator rules
- Keep math, input normalization, and validation out of JSX.
- Do not silently present a valid-looking estimate for invalid inputs. Return validation errors with the calculation result and surface them in the UI.
- For percentage-to-headcount allocation, independent
Math.roundcalls can over- or under-allocate. Use largest-remainder allocation: floor every raw amount, then distribute the remaining people to the largest fractional remainders. Break ties using the original tier order. - Test default/example figures, annualization, configurable fees, invalid distributions, and the invariant that allocated headcount equals requested headcount.
- Use
Intl.NumberFormatfor displayed currencies; do not hard-code locale-specific number formatting.
Verification checklist
- Dependencies installed in the generated application directory.
- Package scripts include test, lint, dev, and build as appropriate.
- New business-logic tests were observed failing before the implementation change.
-
npm testpasses. -
npm run lintpasses. -
npm run buildpasses. - The browser shows the intended default state and no console errors.
- Key edited values update the calculated result.
Pitfalls
- Do not chain
npm installafter a scaffold command without changing directories; it will search for a parentpackage.jsonand fail. - Do not use rounded per-tier values when the sum must exactly equal a total.
- Do not add a production dependency merely for testable pure calculations.
- Do not stop after a successful dev server start: unit tests and a production build catch different failures.
References
references/pricing-calculation-patterns.md— reusable allocation, validation, and test cases for usage-based pricing calculators.