Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

42 Commits

Folders and files

Repository files navigation

Jarvis-Cali React - Multi-File Structure ๐Ÿš€

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.

๐Ÿ—‚๏ธ Project Structure

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

๐Ÿ“ฆ Installation & Setup

โœ… Prerequisites

  • Node.js 16+
  • npm

๐Ÿ› ๏ธ Steps

  1. Install dependencies:
npm install --legacy-peer-deps
  1. Create your local environment file:
cp .env.example .env
  1. Add your Gemini API key in .env:
GEMINI_API_KEY=your_api_key_here
  1. Start the dev server:
npm run dev

App runs at http://localhost:5173.

  1. Build for production:
npm run build
  1. Preview production build:
npm run preview

๐Ÿ” Environment & API Key Behavior

API key resolution priority:

  1. User-saved key from Settings (optional override)
  2. GEMINI_API_KEY on backend server (.env)
  3. 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_KEY only 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.

๐ŸŒ Secure Default Key Without Traditional Server

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:

  1. User opens app on GitHub Pages.
  2. Frontend sends requests to your Worker URL (VITE_BACKEND_PROXY_BASE).
  3. Worker uses secret GEMINI_API_KEY (stored in Cloudflare secrets).
  4. 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.js
  • edge/wrangler.toml.example

Quick setup:

  1. Install Wrangler and login:
npm i -D wrangler
npx wrangler login
  1. Create edge/wrangler.toml from example and deploy worker:
cp edge/wrangler.toml.example edge/wrangler.toml
cd edge
npx wrangler secret put GEMINI_API_KEY
npx wrangler deploy
  1. Set frontend to use Worker URL in .env:
VITE_BACKEND_PROXY_BASE=https://your-worker-name.your-subdomain.workers.dev
  1. Rebuild and deploy frontend:
npm run deploy

โœจ Key Features

๐ŸŽฏ Core Experience

  • Multi-view app shell with smooth animated transitions.
  • Universal swipe gestures for intuitive back navigation on mobile.
  • Dark/light theme support from Settings.

๐Ÿงฎ Calculator Feature

  • 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.

๐Ÿค– AI Tutor Feature

  • 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.

๐Ÿง  Practice Mode Feature

  • 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.

โš™๏ธ Settings & PWA Feature

  • 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.

๐Ÿงช Content Quality Workflow

  • curatedQuestionBank.js stores approved baseline content with metadata:
    • topic
    • difficulty
    • curriculumTag
    • quality.status
  • questionBankService.js handles filtering and review override state.
  • qualityReviewService.js tracks generated-question review queue and outcomes.

๐Ÿ—๏ธ Architecture Highlights

  • Feature-first folder structure (features/*) for domain ownership.
  • Internal separation into:
    • components for UI
    • hooks for reusable state logic
    • services for IO/API and persistence logic
  • Shared cross-domain layer in src/shared.
  • Backend proxy layer in server/index.js for secure Gemini communication.
  • Import aliases for clean paths:
    • @app
    • @features
    • @shared
    • @

๐Ÿ“œ Scripts

  • 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 - deploy dist to GitHub Pages ๐ŸŒ

๐Ÿ” Professional DevOps

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.
  • .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.

Optional monitoring:

  • Frontend Sentry via VITE_SENTRY_DSN.

๐Ÿšข Deployment

๐Ÿ™ GitHub Pages (configured)

npm run deploy

The predeploy script runs production build automatically.

โ˜๏ธ Other Platforms

You can deploy the generated dist/ folder to Vercel, Netlify, Cloudflare Pages, or any static host.

๐Ÿ“ Architecture Decisions (ADR)

ADR-001: Feature-Based Modules ๐Ÿงฉ

  • Status: Accepted
  • Decision: Organize code by feature (calculator, tutor, practice, settings) with components, hooks, and services.
  • Rationale: Keeps business logic close to UI and reduces cross-feature coupling.

ADR-002: Shared Core Layer โ™ป๏ธ

  • Status: Accepted
  • Decision: Keep common assets, hooks, components, and utilities in src/shared.
  • Rationale: Enables reuse without blurring feature boundaries.

ADR-003: Path Alias Strategy ๐Ÿงญ

  • Status: Accepted
  • Decision: Use aliases (@app, @features, @shared, @) in Vite and jsconfig.
  • Rationale: Improves readability and minimizes brittle relative imports.

๐Ÿค Contributing

Contributions are welcome.

  1. Fork the repo
  2. Create a feature branch
  3. Commit your changes
  4. Open a pull request

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages