How skfh5970841/medimate-scheduler works
Project Type and Purpose
• This is a full-stack web application built with Next.js (React + Node) intended to run on Firebase Hosting/Functions (a “Firebase Studio” starter).
• Frontend: React pages and UI components (Tailwind CSS) under src/app and src/components.
• Backend: Next.js API routes (serverless functions) under src/app/api handling data, schedules, dispenser mappings, ESP32 LED control, and AI instance calls.
• External systems: OpenAI (via src/ai/ai-instance.ts) and ESP32 microcontroller devices (HTTP endpoints).
High-Level Architecture Components
a. Client (Browser)
b. Frontend (Next.js React App)
c. Serverless Backend (Next.js API Routes → deployed as Firebase Functions)
d. Data Store (JSON files in dev → Firestore/RTDB in prod)
e. AI Service (OpenAI API)
f. ESP32 Devices (HTTP-driven LED control)
g. Optional Authentication (Firebase Auth via .env keys)
Relationships and Data Flows
• The Browser renders React pages/components (src/app/layout.tsx → page.tsx → UI components).
• UI components invoke client-side hooks (src/hooks/use-toast.ts, use-mobile.tsx) or call Next.js API endpoints (/api/…) via fetch/Axios.
• API routes receive HTTP requests, perform business logic (src/lib/user-actions.ts, src/lib/ledState.ts, src/lib/utils.ts), read/write JSON or Firestore, call external services.
• For AI-driven features, API routes import and use src/ai/ai-instance.ts to forward prompts to OpenAI.
• For device control, API route “esp32/led/route.ts” issues HTTP commands to ESP32 over the local network or cloud endpoint.
• Scheduled tasks and supplement management APIs coordinate read/write operations on schedules.json and supplements.json (or their DB equivalents).
Architectural Patterns & Principles
• Separation of Concerns:
• UI layer (React + Tailwind)
• API layer (Next.js serverless functions)
• Data layer (dev JSON → production DB)
• Integration layer (AI, hardware)
• Component-Based Design: each UI widget is isolated under src/components/ui.
• Service Abstraction: business logic/services under src/services and src/lib.
• Progressive Enhancement: client and server share TypeScript types in src/types.ts.
• Scalability: easy to replace JSON files with Firestore collections and to scale serverless functions.