A modern, mobile-friendly math suite built with React, Vite, and Tailwind CSS. The project is organized with a feature-first architecture for scalability and clean ownership.
jarvis-cali/
โโโ server/
โ โโโ index.js # Secure Gemini proxy API (server-side key)
โโโ src/
โ โโโ app/
โ โ โโโ App.jsx # App shell + view switching + global state
โ โโโ features/
โ โ โโโ calculator/
โ โ โ โโโ components/
โ โ โ โ โโโ SimpleCalculatorPage.jsx # Main calculator UI + modes + history sheet
โ โ โ โ โโโ UnitConverter.jsx # Multi-category unit conversion
โ โ โ โ โโโ DateCalculator.jsx # Date difference and add/subtract calculator
โ โ โ โ โโโ CalendarWidget.jsx # Date picker for calculator flows
โ โ โ โ โโโ GraphingCalculator.jsx # Function plotting view
โ โ โ โโโ hooks/
โ โ โ โ โโโ useCalendarNavigation.js # Calendar month/year/view state logic
โ โ โ โโโ services/
โ โ โ โโโ calculatorHistoryService.js # Calculator history persistence
โ โ โโโ tutor/
โ โ โ โโโ components/
โ โ โ โ โโโ AiTutorPage.jsx # AI tutor (typed math, drawing, image input)
โ โ โ โโโ hooks/
โ โ โ โ โโโ useTutorHistory.js # Tutor history persistence
โ โ โ โโโ services/
โ โ โ โโโ tutorService.js # Gemini request/response handling
โ โ โโโ practice/
โ โ โ โโโ components/
โ โ โ โ โโโ PracticeMode.jsx # AI-generated quiz flow + scoring
โ โ โ โโโ hooks/
โ โ โ โ โโโ usePracticeOptions.js # Practice option constants
โ โ โ โโโ services/
โ โ โ โโโ practiceQuestionsService.js # Gemini quiz generation logic
โ โ โโโ settings/
โ โ โโโ components/
โ โ โ โโโ SettingsModal.jsx # Theme, API key, model selection, PWA install
โ โ โโโ hooks/
โ โ โ โโโ useDebouncedValue.js # Debounced input handling
โ โ โโโ services/
โ โ โโโ geminiModelsService.js # Fetch available Gemini models
โ โโโ shared/
โ โ โโโ assets/
โ โ โ โโโ logo.svg
โ โ โโโ components/
โ โ โ โโโ MathRenderers.jsx # KaTeX/math rendering helpers
โ โ โโโ hooks/
โ โ โ โโโ useSwipeGesture.js # Reusable swipe navigation hook
โ โ โโโ utils/
โ โ โโโ constants.js # Math keyboard + shared constants
โ โ โโโ dateUtils.js # Date parsing/formatting helpers
โ โโโ assets/
โ โ โโโ logo.png
โ โโโ index.css
โ โโโ main.jsx
โโโ public/
โ โโโ manifest.json
โ โโโ sw.js
โโโ .env.example
โโโ jsconfig.json # Alias mapping for editor tooling
โโโ vite.config.js # Vite config + alias mapping
โโโ tailwind.config.js
โโโ postcss.config.js
โโโ README.md
- Node.js 16+
- npm
- Install dependencies:
npm install --legacy-peer-deps- Create your local environment file:
cp .env.example .env- Add your Gemini API key in
.env:
GEMINI_API_KEY=your_api_key_here- Start the dev server:
npm run devApp runs at http://localhost:5173.
- Build for production:
npm run build- Preview production build:
npm run previewAPI key resolution priority:
- User-saved key from Settings (optional override)
GEMINI_API_KEYon backend server (.env)VITE_PUBLIC_GEMINI_API_KEY(risky static fallback)
Notes:
- ๐ The default key stays server-side and is never bundled into frontend code.
- ๐ If user clears their custom key, requests use secure server default key.
- ๐ On static hosting without backend (for example GitHub Pages), users must provide their own Gemini key in Settings.
- ๐ Gateway behavior: app first tries backend proxy, then falls back to direct Gemini calls when a user key is available.
Security note:
- In secure mode (
VITE_BACKEND_PROXY_BASE), no Gemini key is bundled in frontend code. - In risky mode (
VITE_PUBLIC_GEMINI_API_KEY), key is bundled and exposed. - Direct browser calls use user key when provided, otherwise public fallback key if configured.
Risky fallback option:
- Set
VITE_PUBLIC_GEMINI_API_KEYonly if you intentionally want a default key on static hosting. - This key is exposed in frontend bundle and can be extracted.
- If you enable it, lock down hard:
- API restriction: Generative Language API only.
- HTTP referrer allowlist: your exact domains only.
- Strict quotas and billing alerts.
If you want all users to get AI responses on GitHub Pages without entering their own key, while keeping your key secret, use a serverless proxy (Cloudflare Worker).
How it works:
- User opens app on GitHub Pages.
- Frontend sends requests to your Worker URL (
VITE_BACKEND_PROXY_BASE). - Worker uses secret
GEMINI_API_KEY(stored in Cloudflare secrets). - If user enters their own key in Settings, that key is used as override.
This gives you:
- โ Default key for all users
- โ Optional user key override
- โ No key in frontend bundle
Files included for this flow:
edge/cloudflare-worker.jsedge/wrangler.toml.example
Quick setup:
- Install Wrangler and login:
npm i -D wrangler
npx wrangler login- Create
edge/wrangler.tomlfrom example and deploy worker:
cp edge/wrangler.toml.example edge/wrangler.toml
cd edge
npx wrangler secret put GEMINI_API_KEY
npx wrangler deploy- Set frontend to use Worker URL in
.env:
VITE_BACKEND_PROXY_BASE=https://your-worker-name.your-subdomain.workers.dev- Rebuild and deploy frontend:
npm run deploy- Multi-view app shell with smooth animated transitions.
- Universal swipe gestures for intuitive back navigation on mobile.
- Dark/light theme support from Settings.
- Standard and scientific calculator modes.
- Local expression evaluation with support for trig, log/ln, factorial, powers, constants, and angle unit switching (DEG/RAD).
- Live result preview while typing.
- History drawer with expandable mobile sheet behavior.
- Unit converter (Area, Length, Temperature, Volume, Mass, Data, Speed, Time).
- Date calculator with:
- Date difference mode
- Add/subtract years/months/days
- Interactive calendar widget
- Graphing calculator powered by function plotting.
- Supports typed math input with structured math keyboard tabs.
- Supports handwritten/drawing mode on canvas.
- Supports image upload and camera capture for problem input.
- Gemini-powered step-by-step solution generation.
- KaTeX-based rendering for math expressions and explanations.
- Persistent tutor history with re-openable attempts.
- AI-generated quizzes based on topic, difficulty, and question count.
- Curated question bank with difficulty tags and curriculum mapping (General, Common Core, IGCSE, SAT).
- Hybrid generation strategy: approved curated items first, then AI fallback for missing coverage.
- Built-in solution quality review queue for AI-generated questions (approve / needs work workflow).
- Topic presets: Algebra, Calculus, Geometry, Trigonometry, Arithmetic, Statistics.
- Per-question feedback with explanation.
- End-of-quiz summary with score/percentage and retry flow.
- Save personal Gemini API key override.
- Auto-detect available Gemini models via secure backend proxy.
- Select and persist preferred model.
- Theme toggling.
- Progressive Web App install prompt integration when available.
- Offline action queue for tutor/practice requests.
- Background sync trigger for queued actions when connectivity returns.
- Conflict-safe queue replay strategy (last-write-wins per conflict key).
- In-app update toast when a new service worker version is available.
curatedQuestionBank.jsstores approved baseline content with metadata:topicdifficultycurriculumTagquality.status
questionBankService.jshandles filtering and review override state.qualityReviewService.jstracks generated-question review queue and outcomes.
- Feature-first folder structure (
features/*) for domain ownership. - Internal separation into:
componentsfor UIhooksfor reusable state logicservicesfor IO/API and persistence logic
- Shared cross-domain layer in
src/shared. - Backend proxy layer in
server/index.jsfor secure Gemini communication. - Import aliases for clean paths:
@app@features@shared@
npm run dev- run proxy server + Vite together ๐npm run server- run secure proxy server only ๐npm run build- create production bundle ๐๏ธnpm run test- run smoke tests โnpm run preview- preview production build locally ๐npm run lint- run ESLint ๐งนnpm run deploy- deploydistto GitHub Pages ๐
GitHub Actions workflows included:
.github/workflows/ci.yml- Runs lint, tests, and production build on push/PR.
.github/workflows/preview-artifact.yml- Builds PR preview artifact (
dist) for quick QA download.
- Builds PR preview artifact (
.github/workflows/uptime.yml- Scheduled uptime checks for live web URL and optional API health URL.
.github/workflows/release.yml- Auto-generates GitHub release notes for
v*tags.
- Auto-generates GitHub release notes for
Optional monitoring:
- Frontend Sentry via
VITE_SENTRY_DSN.
npm run deployThe predeploy script runs production build automatically.
You can deploy the generated dist/ folder to Vercel, Netlify, Cloudflare Pages, or any static host.
- Status: Accepted
- Decision: Organize code by feature (
calculator,tutor,practice,settings) withcomponents,hooks, andservices. - Rationale: Keeps business logic close to UI and reduces cross-feature coupling.
- Status: Accepted
- Decision: Keep common assets, hooks, components, and utilities in
src/shared. - Rationale: Enables reuse without blurring feature boundaries.
- Status: Accepted
- Decision: Use aliases (
@app,@features,@shared,@) in Vite and jsconfig. - Rationale: Improves readability and minimizes brittle relative imports.
Contributions are welcome.
- Fork the repo
- Create a feature branch
- Commit your changes
- Open a pull request