Skip to content

Commit 60474b4

Browse files
committed
feat: Mindscape AI - 3D STEM Learning Platform & Interactive AI Tutor
0 parents  commit 60474b4

184 files changed

Lines changed: 43045 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
name: Lint & Test
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [20.x, 22.x]
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
cache: npm
27+
28+
- name: Install dependencies
29+
run: npm ci
30+
31+
- name: Run ESLint
32+
run: npm run lint
33+
34+
- name: Run test suite
35+
run: npm test
36+
env:
37+
# Use dummy keys so tests that check for env vars don't fail
38+
GEMINI_API_KEY: test_key_placeholder
39+
GROQ_API_KEY: test_key_placeholder
40+
JWT_SECRET: test_jwt_secret_for_ci_only_not_real
41+
42+
security:
43+
name: Security Audit
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
- uses: actions/setup-node@v4
48+
with:
49+
node-version: 20.x
50+
cache: npm
51+
- run: npm ci
52+
- name: Audit for high/critical vulnerabilities
53+
run: npm audit --audit-level=high

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.venv/
2+
.mplconfig/
3+
.pytest_cache/
4+
__pycache__/
5+
.cache/
6+
.keras/
7+
.local/
8+
.claude/
9+
models/tf_gesture/
10+
node_modules/
11+
.env
12+
.env.*
13+
.env.local
14+
scratch/
15+
*.key
16+
*.pem
17+
18+
.playwright-cli/
19+
output/
20+
docs/
21+
.codex-runtime/
22+
output.txt
23+
test_output.txt

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Multi-stage production Dockerfile for Mindscape (Node.js + Hono)
2+
3+
FROM node:20-alpine AS dependencies
4+
WORKDIR /app
5+
COPY package*.json ./
6+
RUN npm ci --only=production
7+
8+
FROM node:20-alpine AS runner
9+
WORKDIR /app
10+
ENV NODE_ENV=production
11+
ENV PORT=3000
12+
13+
COPY --from=dependencies /app/node_modules ./node_modules
14+
COPY . .
15+
16+
EXPOSE 3000
17+
CMD ["npm", "start"]

Mindscape_Pitch_Deck.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# Mindscape: An Intelligent, Gestural 3D Spatial Reasoning Tutor
2+
**Author:** Solo Researcher & AI Systems Architect
3+
**Technical Whitepaper & PhD-Level Project Report**
4+
5+
---
6+
7+
## Abstract
8+
In STEM education, a persistent cognitive friction exists when representing three-dimensional spatial mathematical and physical systems (e.g., vector calculus, electromagnetism, stereometry) on traditional two-dimensional mediums. This paper presents **Mindscape**, an intelligent, hands-free 3D spatial reasoning tutor that dynamically generates interactive mathematical environments from natural language prompts or visual worksheets. Mindscape implements a decoupled client-server architecture combining a local computer vision pipeline (running Google MediaPipe WebAssembly) for bare-hand spatial gesture tracking, a client-side WebGL engine (Three.js) for mathematical scene projection, and a hybrid AI reasoning engine on the backend. The backend utilizes a deterministic regex-based mathematical parser alongside high-speed LLM inference (Llama 3 70B via Groq LPUs and Gemini 2.0 Flash via Hono) with strict structural guardrails (Pre-Schema Anchoring and Strict Math Mode) to mitigate hallucinatory proofs. All 169 unit test assertions verified a 100% pass rate with sub-second scene construction latencies.
9+
10+
---
11+
12+
## 1. Introduction & Theoretical Foundation
13+
Traditional STEM pedagogy relies on flat, 2D projections (e.g., whiteboards, textbooks) to convey 3D mathematical realities. This mismatch triggers high cognitive load as students must mentally execute rotational transforms to resolve spatial concepts.
14+
15+
According to Paivio’s *Dual-Coding Theory* and Sweller’s *Cognitive Load Theory*, when visual representations align with physical manipulation, semantic integration is significantly accelerated. Mindscape addresses this by converting static inputs into interactive, physical sandbox models.
16+
17+
This project explores:
18+
1. **AI-Driven Scene Scaffolding**: How LLMs can be constrained to output mathematically valid, parseable rendering blueprints.
19+
2. **Zero-Latency HCI**: Mapping bare-hand monocular camera frames to high-fidelity 3D WebGL transformations.
20+
3. **Hybrid Logic Pipelines**: Decoupling deterministic mathematical solvers from generative reasoning modules to eliminate AI latency and hallucination.
21+
22+
```mermaid
23+
graph TD
24+
A[User Input: Text/Worksheet Image] --> B{Complexity Evaluator}
25+
B -- Simple Textbook Query --> C[Deterministic Geometry Parser]
26+
B -- Complex/Multi-part Query --> D[Hybrid AI Planning Engine]
27+
C --> E[3D Scene Specification JSON]
28+
D --> E
29+
E --> F[WebGL Renderer Three.js]
30+
G[Webcam Feed] --> H[MediaPipe WASM Tracker]
31+
H --> I[Raycasting & Interaction Pipeline]
32+
I --> F
33+
F --> J[Interactive 3D Visual Scene]
34+
```
35+
36+
---
37+
38+
## 2. System Architecture & Mathematical Formulation
39+
40+
### 2.1 Deterministic Parsing vs. Generative Planning
41+
To minimize API dependency and achieve zero-hallucination for standard vectors, Mindscape utilizes a deterministic regex-based interceptor (`analytic.js`). When a query matches parametric formats, Javascript computes the geometric components directly.
42+
43+
#### Mathematical Solver for Skew Lines
44+
Given two lines $L_1$ and $L_2$ in $\mathbb{R}^3$ defined parameterically:
45+
$$\mathbf{r}_1(t) = \mathbf{p}_1 + t\mathbf{v}_1$$
46+
$$\mathbf{r}_2(s) = \mathbf{p}_2 + s\mathbf{v}_2$$
47+
48+
The algorithm checks for parallel alignment by computing the cross-product:
49+
$$\mathbf{n} = \mathbf{v}_1 \times \mathbf{v}_2$$
50+
51+
If $\|\mathbf{n}\| = 0$, the lines are parallel. If not parallel, we solve the linear system for intersection by setting $\mathbf{r}_1(t) = \mathbf{r}_2(s)$:
52+
$$\mathbf{p}_1 + t\mathbf{v}_1 = \mathbf{p}_2 + s\mathbf{v}_2 \implies t\mathbf{v}_1 - s\mathbf{v}_2 = \mathbf{p}_2 - \mathbf{p}_1$$
53+
54+
If the system is inconsistent, the lines are skew. The shortest distance $d$ between them is then calculated by projecting the vector connecting their anchor points onto the common normal $\mathbf{n}$:
55+
$$d = \frac{|(\mathbf{p}_2 - \mathbf{p}_1) \cdot \mathbf{n}|}{\|\mathbf{n}\|}$$
56+
57+
Mindscape computes this instantly, rendering helper points at the closest approach coordinates $\mathbf{c}_1$ and $\mathbf{c}_2$.
58+
59+
### 2.2 Client-Side Spatial Interaction Pipeline
60+
The computer vision pipeline runs client-side using WebAssembly (WASM). Google MediaPipe Hand Landmarker extracts $21$ keypoints in 3D camera space $\mathbf{P}_i = (x_i, y_i, z_i)$.
61+
62+
```
63+
(8) Index Tip (12) Middle Tip
64+
\ /
65+
(7) \ / (11)
66+
\ /
67+
(6) [Knuckles] (10)
68+
\ /
69+
(5) (9)
70+
(4) \ /
71+
\ \ /
72+
Thumb\________\/ (0) Wrist
73+
```
74+
75+
#### Euclidean Pinch Metric
76+
The Euclidean distance $D_{\text{pinch}}$ between the thumb tip ($\mathbf{P}_4$) and index tip ($\mathbf{P}_8$) determines the selection intent:
77+
$$D_{\text{pinch}} = \sqrt{(x_8 - x_4)^2 + (y_8 - y_4)^2 + (z_8 - z_4)^2}$$
78+
79+
An active selection (grab/pinch) is registered when:
80+
$$D_{\text{pinch}} < \theta_{\text{pinch}} \quad (\text{where } \theta_{\text{pinch}} = 0.04 \text{ units})$$
81+
82+
#### Raycasting Projection
83+
Coordinates from the monocular 2D camera viewport $(x_{\text{cam}}, y_{\text{cam}})$ are projected into the 3D WebGL scene using the projection matrix $\mathbf{M}_{\text{proj}}$ and view matrix $\mathbf{M}_{\text{view}}$ of the Three.js perspective camera. A ray $\mathbf{R}(u) = \mathbf{o} + u\mathbf{d}$ is cast from the camera origin $\mathbf{o}$ in direction $\mathbf{d}$:
84+
$$\mathbf{d} = \mathbf{M}_{\text{proj}}^{-1} \mathbf{M}_{\text{view}}^{-1} \begin{bmatrix} x_{\text{ndc}} \\ y_{\text{ndc}} \\ 1 \\ 1 \end{bmatrix}$$
85+
where $(x_{\text{ndc}}, y_{\text{ndc}})$ represent Normalized Device Coordinates. The system checks for intersection with bounding spheres and boxes of geometric meshes in the scene.
86+
87+
---
88+
89+
## 3. Advanced Prompt Engineering & Guardrails
90+
91+
To prevent LLM mathematical hallucinations, Mindscape implements two primary prompt guardrails:
92+
93+
### 3.1 Pre-Schema Anchoring
94+
To avoid the attention attenuation observed in long-context generation, all logical execution constraints are positioned at the absolute beginning of the system prompt (`prompts.js`).
95+
96+
Specifically, the model is instructed to solve the mathematical constraints (e.g., verifying vector intersections or performing cross-products) *before* constructing the scene specification object. This enforces logical consistency before the model allocates tokens for structural JSON keys.
97+
98+
### 3.2 Strict Math Mode
99+
When solving pure algebraic vector calculus, the model enters a restricted mathematical persona. It disables conversational fillers and focuses solely on numeric outputs.
100+
101+
This prevents **Generative Collapse**, a phenomenon where the LLM repeats "volume is 0" or fails to complete JSON arrays because it attempts to visually interpret 1D/2D lines as 3D volumes.
102+
103+
---
104+
105+
## 4. Decoupled Dual-Model Modality Split
106+
To bypass API rate-limiting and minimize latency, Mindscape implements a decoupled multi-model architecture:
107+
108+
* **Inference & Structure Solver**: Powered by Groq's LPUs running **Llama 3 70B** to generate structured JSON blueprints in less than a second.
109+
* **Conversational Assistant**: Powered by **Gemini 2.0 Flash** via Hono stream wrappers (`chatService.js`) to provide real-time explanations without blocking the primary structure generator.
110+
111+
```
112+
+-------------------------------------------------------------+
113+
| Client Request |
114+
+-------------------------------------------------------------+
115+
|
116+
+------------------+------------------+
117+
| |
118+
v v
119+
+-----------------------+ +-----------------------+
120+
| Groq LPU (Llama 3) | | Gemini 2.0 Flash |
121+
| 3D Scene Generator | | Tutor Conversation |
122+
| (JSON blue print) | | (Chat Stream SSE) |
123+
+-----------------------+ +-----------------------+
124+
```
125+
126+
---
127+
128+
## 5. Architectural Resiliency & Fail-Safe Mechanisms
129+
130+
Mindscape incorporates several defensive programming strategies to ensure stability:
131+
132+
### 5.1 Mono-Camera Gesture Loop Recovery
133+
The computer vision loop in `app.js` runs at 60fps. To prevent application crashes when a hand leaves the webcam view, the tracking logic is wrapped in a dynamic try/catch frame skip block:
134+
```javascript
135+
try {
136+
const results = handLandmarker.detectForVideo(webcamEl, timestamp);
137+
if (!results.landmarks || results.landmarks.length === 0) {
138+
flushInteractionOverlays();
139+
} else {
140+
processHandLandmarks(results.landmarks);
141+
}
142+
} catch (error) {
143+
console.warn("MediaPipe frame skipped:", error.message);
144+
flushInteractionOverlays();
145+
}
146+
```
147+
148+
### 5.2 Multi-Tier Failover Sequence
149+
When generating plans, Mindscape implements a multi-tier fallback sequence:
150+
151+
```
152+
[Gemini Vision preferred] ──(Quota Hit)──> [Llama 3.2 Vision on Groq] ──(Failed)──> [Llama 3.3 70B Text-Only Inference] ──(Failed)──> [Local Deterministic Heuristic Plan]
153+
```
154+
155+
This sequence guarantees that an interactive 3D layout is rendered even during total API outages.
156+
157+
---
158+
159+
## 6. Implementation & Verification Results
160+
161+
The implementation was validated using automated test scripts and linting tools:
162+
163+
* **Linter Validation**: The codebase passes `eslint .` with zero errors or warnings.
164+
* **Test Suite Verification**: Running `npm test` executes **169 unit tests** with a 100% pass rate in `1593ms`.
165+
* **API Capabilities Check**: Returns preferred model routes and backup capabilities correctly.
166+
* **Voice Pipeline Verification**: Tests verify that conversational history is normalized and the Web Speech API strips formatting before speech synthesis.
167+
168+
---
169+
170+
## 7. Educational Impact & Constructivist Learning
171+
From a constructivist learning perspective, Mindscape enables **Active Inquiry**. Instead of receiving static answers, students interact with the concepts:
172+
173+
1. **Observe**: Review the initial geometric coordinates.
174+
2. **Predict**: Formulate a hypothesis (e.g., the intersection point coordinates).
175+
3. **Check**: Move vectors and points using hand gestures to test the hypothesis.
176+
4. **Reflect**: Receive immediate feedback from the tutor chatbot based on the new scene state.
177+
178+
This loop supports deeper visual intuition, helping students master abstract geometries without expensive VR equipment.
179+
180+
---
181+
182+
## 8. Conclusion & Future Directions
183+
Mindscape demonstrates that hands-free, interactive 3D spatial reasoning is achievable using standard web technologies.
184+
185+
Future work will focus on integrating real-time stereoscopic WebXR rendering for head-mounted displays and exploring multi-user collaborative sandboxes for remote classrooms.

README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Mindscape
2+
3+
Mindscape turns a static maths or physics worksheet into an interactive 3D lesson. Learners upload a diagram or type a question, inspect and manipulate the generated scene, then explain their reasoning to receive focused feedback rather than just an answer.
4+
5+
The flagship flow is a surface-area lesson: worksheet to labelled 3D solid, then exploration, prediction, explanation, and a follow-up challenge.
6+
7+
## Try the judge-safe demo
8+
9+
Start the app and open [http://localhost:3000/?demo=true](http://localhost:3000/?demo=true). The guided cuboid surface-area lesson runs through the local planner and does not require API keys. It is designed for a reliable demo recording or judge review.
10+
11+
## Local setup
12+
13+
### Requirements
14+
15+
- Node.js 20+
16+
- npm
17+
- Webcam for hand tracking
18+
- Microphone for push-to-talk voice mode
19+
20+
### Install
21+
22+
```bash
23+
npm install
24+
pip install -r requirements.txt
25+
```
26+
27+
### Environment
28+
29+
Create `.env.local` in the project root:
30+
31+
```env
32+
GEMINI_API_KEY=your_google_ai_studio_key
33+
GROQ_API_KEY=your_groq_api_key
34+
```
35+
36+
The app requires these keys for vision (Gemini), conversational tutoring (Groq), and transcription (Groq).
37+
38+
## Run
39+
40+
```bash
41+
npm run dev
42+
```
43+
44+
Then open `http://localhost:3000`. Use `?demo=true` for the no-key guided worksheet demo.
45+
46+
## Verify
47+
48+
```bash
49+
npm run quality
50+
```
51+
52+
This runs linting and the complete automated test suite.
53+
54+
## Built with Codex and GPT-5.6
55+
56+
Codex and GPT-5.6 were used to stabilize the interactive lesson flow, repair the streaming voice lifecycle, add a no-key demo path, strengthen test coverage, and refine the submission-ready product experience. The project keeps deterministic lesson and scene fallbacks so the core learning journey remains demonstrable when external model services are unavailable.
57+
58+
## Architecture
59+
60+
### High-level system design
61+
62+
```text
63+
+---------------------------------------------------------------+
64+
| Frontend |
65+
| Vanilla JS + Three.js |
66+
| |
67+
| - Question input (text, image, screenshot) |
68+
| - 3D scene rendering |
69+
| - Tutor panel |
70+
| - Voice UI (Browser Web Speech API) |
71+
| - Hand tracking |
72+
| - KaTeX rendering |
73+
| - Real-time "Limited Mode" alerts |
74+
+---------------------------------------------------------------+
75+
|
76+
| HTTP / SSE
77+
v
78+
+---------------------------------------------------------------+
79+
| Backend |
80+
| Node.js + Hono API |
81+
| |
82+
| - Request validation |
83+
| - Gemini & Groq Hybrid integration |
84+
| - 3-Tier Model Failover (Gemini -> Groq 70B -> Groq 8B) |
85+
| - Text-as-Vision Fallback (Rescues scene interpretation) |
86+
| - SceneSpec generation (Strict JSON enforcement) |
87+
| - Tutor streaming |
88+
| - Voice pipeline coordination (Whisper STT) |
89+
+---------------------------------------------------------------+
90+
|
91+
+--------------+--------------+
92+
v v
93+
+-----------------------+ +-----------------------+
94+
| Google Gemini | | Groq (Llama 3) |
95+
| | | |
96+
| - Primary Vision | | - Primary Reasoning |
97+
| - Primary Planning | | - Whisper STT (v3) |
98+
| - Failover Chat | | - 70B Scene Planning |
99+
| | | - Visual Failover |
100+
+-----------------------+ +-----------------------+
101+
```
102+
103+
## Hardened Failover System
104+
105+
The system is built for hackathon-grade resiliency:
106+
- **Vision Fallback**: If Gemini 2.0 Flash hits quota or fails, the system automatically falls back to **Llama 3.2 11B Vision** on Groq.
107+
- **Interpretation Fallback**: If all vision models fail to interpret a diagram, the system uses the high-capacity **Llama 3.3 70B** to interpret the question text alone, ensuring a valid 3D scene is still built.
108+
- **Search Fallback**: Semantic search (Gemini Embeddings) automatically falls back to **Lexical Keyword Search** if the API key is restricted or out of quota.
109+
- **Transparency**: The UI displays a "Limited Mode" warning in the evidence panel whenever the system is operating in a fallback state.

assets/judge-demo-cylinder.png

19.1 KB
Loading

data/mindscape.db

20 KB
Binary file not shown.

0 commit comments

Comments
 (0)