Wearable AI · MIT Reality Hack 2026

SmartSight

A Ray-Ban Meta study companion that sees your page and tutors you by voice.

  • Winner Gold Prize · MIT Reality Hack 2026 · Overall
  • Winner Best Use of the Meta Wearables Device Access Toolkit Showcasing a Hands-free Everyday Use Case · MIT Reality Hack 2026 · Sponsored by Meta

Backend lead (API, S3, database, auth, tests) · 5-person team · Jan 2026 hackathon build, continued as a startup

~13 s → ~5 s
Upload-and-analyze latency
0
Native deps in the audio pipeline (no ffmpeg)
7 / 78
Jest suites / cases, CI-gated
Watch the SmartSight demo
The SmartSight team at MIT Reality Hack 2026
The SmartSight team at MIT Reality Hack 2026
SmartSight app: the home dashboard and Luna, the AI tutor

From hackathon prototype to study coach.

After the hackathon the team kept building SmartSight as a startup. The companion app tracks progress toward the MCAT, and Luna, the AI tutor, recaps what the glasses captured and quizzes you on it.

Context

Glasses capture what a student is reading every few seconds, and the backend has to turn that into a tutor that keeps up.

The problem

Upload-and-analyze took ~13 s over cellular, the iOS audio format did not match what OpenAI Realtime accepts, and every analysis fired four side effects that could each crash the server. All three had to be solved without growing the lightweight EC2 deploy.

What I owned

I led the backend on a 5-person team and owned the API, AWS infrastructure, the database, auth and the tests, with a teammate building the realtime audio path. The team was Jayden Decambre, Dongchan Kim, Hyunseok Hwang, Xiaofan (Sylvan) Shen and Vivian Xin Shu, and the iOS client and glasses integration were built by teammates.

Backend

Node.jsExpressPrisma

AI

OpenAI Responses API (GPT-4.1 Vision)OpenAI Realtime API (WebSocket)

Infra

AWS EC2AWS S3 (SDK v3)PostgreSQL (RDS)

Auth

Google OAuthJWT rotation

Quality

JestGitHub Actions CI

Architecture

One endpoint takes the photo, S3 serves it straight to GPT-4.1 Vision, and the result feeds both the database and the live voice session.

13 s → 5 s Upload-Analyze + WebSocket Realtime Tutor + OAuth

swipe
Ray-Ban Meta GlassesExpress API ServerGoogle OAuth + JWTAWS S3 (image store)Presigned URL (1 h)GPT-4.1 Vision APISession & TopicTrackerPostgreSQL (RDS)OpenAI Realtime WSFire-and-ForgetWorkers
  1. Critical path
  2. Ray-Ban Meta Glasses
  3. →Express API Server
  4. →AWS S3 (image store)
  5. →Presigned URL (1 h)
  6. →GPT-4.1 Vision API
  7. →Session & Topic Tracker

Critical path in bold: image bytes never pass back through Node once they reach S3.

Key decisions

Three choices shaped the backend: one round-trip, no native audio binaries, and side effects that can never take the request down.

Decision 1

Collapse upload and analysis into one request

Problem
The client made three round-trips (upload, then analyze, then save) and waited on a blocking DB write, which took ~13 s on cellular.
Options
  • Keep the three-call flow
  • Proxy the image bytes through Node to OpenAI
  • A single POST /api/upload-and-analyze plus a presigned S3 read URL for OpenAI
Decision
One multipart endpoint. The server uploads to S3 and hands GPT-4.1 Vision a 1 h presigned read URL, so OpenAI fetches the image directly.
Result
Removing two client round-trips saved ~4 s and the presigned URL saved ~2 s. End to end went from ~13 s to ~5 s.
Trade-off
The presigned URL is readable by anyone holding it for an hour, and a slow S3 upload now blocks the whole request.

Decision 2

Resample audio in pure JS instead of shipping ffmpeg

Problem
iOS sends Float32 16 kHz mono, while OpenAI Realtime expects PCM16 24 kHz as Base64 JSON.
Options
  • Bundle ffmpeg on the EC2 host
  • Convert on the iOS client
  • A stateful pure-JS converter and resampler on the server
Decision
float32ToPcm16LE plus a stateful Resampler16kTo24k that carries prevSample and fractionalPos across 20 ms chunks, with a backpressure guard that drops frames above 100 KB buffered and closes the socket above 300 KB.
Result
No native binaries, so deploy stays npm install. Chunk boundaries do not click because interpolation state carries over.
Trade-off
Linear interpolation is simpler than a windowed-sinc filter, and backpressure drops audio rather than queueing it.

Decision 3

Fire-and-forget side effects, capped at 500 ms

Problem
Every ~3 s an analysis triggers a DB write, a topic upsert and a realtime context push, and one unhandled rejection would crash the process mid-session.
Options
  • Await every side effect before responding
  • Fire and forget with a race against a 500 ms timer
Decision
Promise.race([savePromise, timeout(500)]) returns analysisId when the DB is fast and null otherwise. Each side effect is try-caught on its own, and a trailing .catch(() => {}) prevents unhandled rejections.
Result
The response returns 200 whenever the vision analysis succeeds. A DB outage, a dropped WS or a bad topic only degrades its own feature.
Trade-off
Failed writes are swallowed silently, and clients sometimes get analysisId: null (see Limits).

Measurement

Collapsing three round-trips into one cut end-to-end upload-and-analyze latency from ~13 s to ~5 s.

Upload-and-analyze latency

Before
~13 s
After
~5 s

Reliability

Any one subsystem can fail and the analysis response still comes back, with 7 mocked Jest suites gating every merge.

  • 7 Jest suites (78 cases) cover controllers, services and middleware with S3, OpenAI and Prisma mocked. GitHub Actions runs them on every push and PR, and a failure blocks the merge.
  • Session validation returns 4xx before any S3 or OpenAI call is made.
  • S3 and OpenAI errors reach a global error middleware that returns structured JSON.
  • Auth returns 401 for a missing token, a blacklisted JTI or an invalid Google token. Refresh revokes and reissues inside one $transaction.
  • The realtime response_cancel_not_active race is ignored, and a failed context push is logged without breaking the analysis.
Edge cases covered (9)
  • session: missing sessionId (auto-create), inactive session (400), session not found (404)
  • upload/analyze: missing s3Key and file (400), no file in upload-and-analyze (400)
  • fire-and-forget: createImageAnalysis rejected → asserts 200 with analysisId: null
  • presigned URL: generatePresignedReadUrl(s3Key, 3600) and analyzeStudentPOV(presignedUrl) invocation verified
  • OpenAI: no output text, invalid JSON, missing contentAnalysis, missing required fields, APIError, nested output extraction
  • S3: missing S3_BUCKET, upload failure, presigned URL failure, PNG vs JPEG, prefix handling
  • middleware: sessionId from header vs body (header wins), 400 when inactive, 404 when not found, DB error passthrough
  • Prisma: createSession, endSession (P2025 → not found), createImageAnalysis (P2003 → invalid FK), getActiveSession null
  • multer: file too large → 400, non-image → 400

Limits and scale

These hackathon shortcuts are fine for a demo and would be the first things to change before real users.

TodayCORS allows * with custom headers.

At scaleAllow-list the app's origins and stop sending credentials to wildcard origins.

TodayWhen there is no JWT, optionalAuth trusts an X-User-Id header, so any client can act as any user.

At scaleDrop the fallback and require a verified token on every user-scoped route.

TodayBackground DB saves and topic upserts swallow their errors with .catch(() => {}), so lost writes are invisible.

At scaleLog and count every failure, and write side effects through an outbox table or an SQS queue with retries and a DLQ.

TodayActive topic state lives in an in-memory Map, which a restart wipes and a second instance cannot see.

At scaleMove session topic state to Redis with a TTL so instances can scale horizontally.

Engineering deep divePipelines, code flow and implementation notes

What it became

The prototype won both the Gold Prize and Meta's Best Use of the Meta Wearables Device Access Toolkit Showcasing a Hands-free Everyday Use Case at MIT Reality Hack 2026, and the team kept going as a startup: SmartSight, "an AI study coach for smart glasses" (getsmartsight.com).
The product now has four parts: passive capture of study materials through the glasses, AI coaching with next steps based on your gaps, auto-generated flashcards and quizzes, and a study story timeline in a companion app. It started with MCAT students and is taking a waitlist.

0. Server Bootstrap — server.js

markdown
HTTP Request
    │
    ├─ CORS (Allow-Origin: *, custom headers)
    ├─ express.json() + urlencoded + cookieParser
    ├─ optionalAuth (JWT verify + blacklist check ∥ X-User-Id fallback)
    │
    ├─ /api/upload/*          → uploadRoutes
    ├─ /api/upload-and-analyze → multer → uploadController.uploadAndAnalyze
    ├─ /api/analyze           → analyzeRoutes
    ├─ /api/session/*         → sessionRoutes
    ├─ /api/bookmark          → bookmarkRoutes
    ├─ /api/topic/*           → topicRoutes
    ├─ /api/help-count        → helpCountRoutes
    ├─ /api/admin/*           → adminRoutes
    ├─ /api/auth/*            → authRoutes
    ├─ /api-docs              → swagger-ui-express
    │
    ├─ Global Error Middleware → { success: false, error: { message } }
    ├─ 404 Handler
    │
    └─ http.createServer(app)
         └─ realtimeService.setupWebSocket(server) → WS /ws

1. Upload & Analyze Pipeline (13 s → 5 s) — the critical path

markdown
iOS Client (Ray-Ban Meta)
    │
    │  POST /api/upload-and-analyze  [multipart image, X-Session-Id?]
    ▼
  multer (memory, 10 MB, image-only filter)
    │
    ▼
  optionalAuth → req.user (JWT or X-User-Id)
    │
    ▼
  uploadController.uploadAndAnalyze()
    │
    ├─ analysisService.resolveSession(sessionId, userId)
    │    ├─ no sessionId → prismaService.createSession(userId)
    │    └─ sessionId    → prismaService.getSession() → assert 'active'
    │
    ├─ s3Service.uploadFile(buffer, null, mimetype)
    │    ├─ saveFileLocally()        ← local backup
    │    └─ S3 PutObjectCommand      ← cloud upload
    │
    ▼
  analysisService.analyzeAndPersist()
    │
    ├─ s3Service.generatePresignedReadUrl(s3Key, 3600)
    │    └─ GetObjectCommand + getSignedUrl (1 h TTL)
    │
    ├─ openaiService.analyzeStudentPOV(presignedUrl)
    │    ├─ OpenAI Responses API (GPT-4.1 Vision)
    │    │    └─ JSON Schema: { contentAnalysis: { isStudying, isActive,
    │    │         isDistracted, topic, subtopic, extractedText } }
    │    ├─ Parse + validate contentAnalysis
    │    └─ Context Bridge → realtimeService.updateSessionContext()
    │         └─ topic/subtopic/text → session.update to Realtime WS
    │
    ├─ normalizeContent() → topicEnum, isStudying, isActive, isDistracted
    │
    ├─ topicTracker.trackTopic(sessionId, topic)
    │    └─ in-memory Map + fire-and-forget DB upsert
    │
    └─ Fire-and-Forget DB Save
         ├─ prismaService.createImageAnalysis(sessionId, { ... })
         ├─ Promise.race([ savePromise, setTimeout(500ms) ])
         │    └─ returns analysisId if fast, null otherwise
         └─ savePromise.catch(() => {})  ← prevents unhandled rejection
    │
    ▼
  res.status(200).json({
    sessionId, s3Key, s3Url, analysis, analysisId, uploadedAt
  })

2. Zero-Dep Audio Pipeline — Float32 16 kHz → PCM16 24 kHz

markdown
iOS Client (Float32, 16 kHz, mono)
    │
    │  WS /ws binary frame
    ▼
  Validate: frame.length % 4 === 0 (Float32 = 4 bytes/sample)
    │
    ▼
  float32ToPcm16LE(frame)                          ── audioUtils.js
    │  for each sample:
    │    readFloatLE → clamp [-1, 1] → × 32767 → writeInt16LE
    │  Float32 (4 B/sample) → PCM16 (2 B/sample)
    │
    ▼
  accumulator = appendBuffer(accumulator, pcm16)
    │
    ▼
  drainPcm16Chunks(accumulator, 640 bytes)          ── 20 ms @ 16 kHz
    │  └─ { chunks: Buffer[], remainder: Buffer }
    │
    ▼
  Resampler16kTo24k.process(chunk)                  ── stateful across chunks
    │
    │  ┌─ prevSample: Int16       (last sample from previous chunk)
    │  ├─ fractionalPos: Float    (sub-sample position, carries over)
    │  │
    │  │  for each input sample:
    │  │    while (fractionalPos < 1):
    │  │      interpolated = prevSample + (current - prev) × fractionalPos
    │  │      outputSamples.push( clampInt16(round(interpolated)) )
    │  │      fractionalPos += 16000/24000  (= 0.6667 step)
    │  │    fractionalPos -= 1
    │  │    prevSample = current
    │  │
    │  └─ drain outputAccumulator into 960-byte chunks (20 ms @ 24 kHz)
    │
    ▼
  realtimeClient.sendAudioFrame(pcm24)
    │  ├─ backpressure check: bufferedAmount > 100 KB → drop
    │  ├─ backpressure check: bufferedAmount > 300 KB → close socket
    │  └─ toBase64(frame) → { type: 'input_audio_buffer.append', audio }
    │
    ▼
  OpenAI Realtime API (gpt-realtime, 24 kHz PCM16)
    │
    ├─ response.audio.delta → Base64 decode → ws.send(binary to iOS)
    ├─ speech_started → barge-in → response.cancel + notify client
    │
    ▼
  on close:
    ├─ savePcmToWav(inputBuffer,  16 kHz) → session-{id}-input-{ts}.wav
    └─ savePcmToWav(outputBuffer, 24 kHz) → session-{id}-output-{ts}.wav

3. Crash-Safe Async — every subsystem can fail, server never dies

markdown
Every ~3 s: image analysis triggers 4 async side-effects
    │
    ├─ 1. DB Save (can fail: connection timeout, constraint violation)
    │      │
    │      └─ analysisService.analyzeAndPersist()
    │           ├─ savePromise = (async () => {
    │           │     try { return (await prismaService.createImageAnalysis(...)).id; }
    │           │     catch (dbError) { return null; }         ← swallow
    │           │  })();
    │           ├─ Promise.race([ savePromise, timeout(500) ]) ← don't block
    │           │     └─ analysisId = id ∥ null
    │           └─ savePromise.catch(() => {})                 ← prevent crash
    │                 └─ background save continues after res.json()
    │
    ├─ 2. Topic Upsert (can fail: DB race condition on upsert)
    │      │
    │      └─ topicTracker.addToDailyStats()
    │           ├─ in-memory Map updated first                 ← always succeeds
    │           └─ try { await prismaService.upsertDailyTopicStudy(...) }
    │              catch (error) { /* swallow — in-memory still valid */ }
    │
    ├─ 3. Realtime Context Push (can fail: WS disconnected, no active conn)
    │      │
    │      └─ openaiService.analyzeStudentPOV()
    │           └─ try {
    │                realtimeService.updateSessionContext(sessionId, context);
    │                // returns false if no connection — not an error
    │              } catch (err) {
    │                console.warn('Failed to update realtime context');
    │                // never throw — analysis endpoint must not break
    │              }
    │
    └─ 4. Topic Tracking State (can fail: null topic, empty string)
           │
           └─ topicTracker.trackTopic()
                └─ const topic = newTopic?.trim() || 'Unknown'  ← normalize
  
  Result: all 4 can fail independently
    │
    └─ res.status(200).json({ success: true, data: { ... } })
         └─ ALWAYS returns 200 if OpenAI analysis itself succeeded
              DB down? → analysisId: null
              Realtime disconnected? → context skipped
              Topic upsert failed? → in-memory still tracks
              Null topic? → normalized to 'Unknown'

4. Auth Pipeline — Google OAuth + JWT Rotation + Blacklisting

markdown
── Login ────────────────────────────────────────────────────────────────
  POST /api/auth/google { idToken }
    │
    ├─ googleClient.verifyIdToken({ idToken, audience })
    │    └─ payload: { sub, email, name }
    ├─ prisma.user.upsert({ where: { email }, create/update })
    ├─ issueTokensForUser(user, sub)
    │    ├─ jwt.sign({ userId, email, jti }, JWT_SECRET, { expiresIn: '15m' })
    │    └─ crypto.randomBytes(48) → SHA256 → prisma.refreshToken.create()
    ├─ setAuthCookie(res, accessToken)   ← HTTP-only, sameSite: lax
    ├─ setRefreshCookie(res, refreshToken)
    └─ res.json({ userId, email, token, refreshToken })
  
  ── Refresh ──────────────────────────────────────────────────────────────
  POST /api/auth/refresh (cookie or body)
    │
    ├─ hashToken(rawRefreshToken) → findFirst({ tokenHash, !revoked, !expired })
    ├─ prisma.$transaction:
    │    ├─ revoke old: refreshToken.update({ revokedAt: now })
    │    └─ issue new: issueTokensForUser(user, tx)  ← atomic swap
    └─ new cookies + res.json({ token, refreshToken })
  
  ── Logout ───────────────────────────────────────────────────────────────
  POST /api/auth/logout
    │
    ├─ refreshToken → updateMany({ revokedAt: now })
    ├─ accessToken  → jwt.verify → tokenBlacklist.create({ jti, expiresAt })
    └─ clearCookie(auth_token, refresh_token)
  
  ── Middleware (every request) ────────────────────────────────────────────
  optionalAuth:
    ├─ extractToken (Bearer header ∥ auth cookie)
    ├─ jwt.verify → check tokenBlacklist by jti
    │    ├─ blacklisted → 401
    │    └─ valid → req.user = { id, email, name }
    └─ no token → fallback to X-User-Id header → next()

5. Session & Topic Analytics Pipeline

markdown
── Session Lifecycle ─────────────────────────────────────────────────────
  POST /api/session/start
    └─ prismaService.createSession(userId)
         ├─ getOrCreateDefaultUser() ∥ resolveUser(userId)
         ├─ sessionDay.upsert({ userId, date: 'YYYY-MM-DD' })
         └─ subSession.create({ sessionDayId })
              └─ → { sessionId, status: 'active', startedAt }
  
  POST /api/session/:id/end
    ├─ topicTracker.finalizeSession(sessionId, endTime)
    │    ├─ calculate remaining duration for current topic
    │    ├─ addToDailyStats() → DB upsert (fire-and-forget)
    │    └─ remove from active Map
    └─ prismaService.endSession(sessionId)
         └─ → { sessionId, endedAt, totalAnalyses, topicStats }
  
  ── Topic Tracking (hybrid: in-memory + DB) ──────────────────────────────
  Every image analysis:
    analysisService.analyzeAndPersist()
      └─ topicTracker.trackTopic(sessionId, topic, timestamp, userId)
           │
           ├─ First image   → create Map entry { currentTopic, startTime }
           ├─ Topic change  → accumulate duration, DB upsert, update entry
           └─ Same topic    → no-op (timer continues)
  
  Reads:
    GET /api/session/:id/topic-stats  → topicTracker.getSessionTopicStats()
    GET /api/today/topic-stats        → getDailyTopicStatsFromDB() + active sessions
    GET /api/topic/daily?date=...     → getDailyTopicStatsFromDB(date)
    GET /api/topic/weekly             → getWeeklyTopicStatsFromDB() → dailyBreakdown
  
  ── Data Model (Prisma / PostgreSQL) ─────────────────────────────────────
  User
    └─ SessionDay (userId + date, unique)
         └─ SubSession (startedAt, endedAt)
              └─ LearningEvent (s3Key, analysisResult, topicId, isActive, isDistracted)
                   └─ Bookmark (note)
         └─ DailyTopicStats (topicId, durationSec, active, passive, numDistracted)
  
  Topic (name, unique) → Subtopic (topicId + name, unique)
  RefreshToken (userId, tokenHash, expiresAt, revokedAt)
  TokenBlacklist (jti, expiresAt)
← All projects