How thehalfbldprinc3/smartmirror works
Project type and purpose
• This is a full-stack, single-page dashboard application (“SmartMirror V2”) built on Next.js (App Router) and TypeScript.
• Purpose: drive a wall-mounted “smart mirror” UI that displays calendar events, weather, news, and hosts an AI-powered voice assistant (Google Gemini + Chrome Web Speech API).
File structure
• Top-level “smart-mirror/app” folder holds both UI pages (layout.tsx, page.tsx, sessionWrapper.tsx) and serverless API routes under “app/api”:
• auth/[...nextauth]/route.ts → NextAuth authentication endpoints
• events/route.ts → Google Calendar integration
• weather/route.ts → weather API fetch
• news/route.ts → news API fetch
• gemini/route.ts → proxy to Google Gemini AI
• “smart-mirror/components” contains React widget components (CalendarWidget, WeatherWidget, NewsWidget, ClockWidget, VoiceChatWidget, etc.).
• Configuration files: next.config.ts, tsconfig.json, eslint/postcss configs, package.json.
• No dedicated database folder, implying stateless serverless functions and external-API driven data.
README for additional insights
• Confirms tech stack: Next.js, TypeScript, Google Gemini, Chrome Web Speech API, custom React components.
• Features: voice assistant, calendar integration (Google Calendar), weather, news, clock.
• No mention of an internal DB—authentication and state likely managed via NextAuth (JWT or OAuth session).
a. Main components
• Client / Mirror Device (Browser)
• React UI (Widgets + Layout)
• Chrome Web Speech API (voice capture)
• Session wrapper (NextAuth client)
• Next.js Server (hosted on Vercel or similar)
• Frontend SSR/SSG (serves pages)
• Serverless API Routes: Auth, Events, Weather, News, Gemini
• External Services
• Google Gemini API
• Google Calendar API
• Public Weather API (e.g., OpenWeatherMap)
• News API (e.g., NewsAPI.org)
• OAuth Provider (Google) for NextAuth
b. Relationships and interactions
1. User speaks into mic → Web Speech API captures audio → VoiceChatWidget sends transcript to /api/gemini
2. /api/gemini authenticates requests (via NextAuth session), forwards to Google Gemini → receives AI response → returns to client
3. On page load or at intervals, UI calls /api/events, /api/weather, /api/news
4. Each route fetches from its external API, then passes JSON back to React widgets
5. Authentication flows via NextAuth endpoint (/api/auth), interacts with OAuth provider, manages session cookies/JWT
c. Architectural patterns & design principles
• Client-server separation: React client vs. serverless API
• Modular widget-based UI: each piece (news/weather/calendar) is its own component calling its own route
• API façade/gateway: Next.js routes centralize all external API calls and hide keys from the client
• Stateless serverless functions: horizontal scaling, minimal infra
d. Key technologies & frameworks
• Next.js App Router (React + SSR/SSG + API Routes)
• NextAuth for authentication/session management
• TypeScript for type safety
• Chrome Web Speech API (client side)
• Google Gemini API (AI backend)
• Third-party data APIs: Calendar, Weather, News