Overview
Estudio Three is a Progressive Web Application (PWA) designed for student-athletes who need to balance demanding academic schedules with intensive physical training. The architecture prioritizes offline functionality, real-time AI assistance, and intelligent routine optimization.High-Level Architecture
Technology Stack
| Component | Technology | Purpose |
|---|---|---|
| Frontend | React 19 + TypeScript | Component architecture with type safety |
| Build Tool | Vite | Lightning-fast HMR and optimized builds |
| State Management | Zustand | Lightweight, modular store architecture |
| Styling | Tailwind CSS 3.0 | Atomic, responsive design system |
| Backend | Supabase | PostgreSQL + Auth + Row Level Security |
| AI Engine | Groq (Llama 3) | Ultra-fast, open-source LLM inference |
| AI Proxy | Vercel Serverless | Secure API key protection |
| PWA | Vite PWA Plugin | Offline support, auto-updates, installable |
| Testing | Vitest | Fast unit testing framework |
| i18n | i18next | Multi-language support (ES, EN, FR, IT) |
Architecture Decision Records (ADRs)
Zustand vs Redux
Decision: Zustand Rationale:- Application consists of highly divisible stores (Settings, Auth, Routine, Pomodoro, Tasks, etc.)
- Zustand provides modularization without Redux boilerplate
- Native
persistmiddleware integration is intuitive - Simpler learning curve for contributors
Groq vs OpenAI
Decision: Groq with Llama 3 Rationale:- Zero cost for development and production
- Open-source model (Llama 3)
- Dramatically lower latency on LPU infrastructure
- Critical for instant AI Coach responses
- No vendor lock-in
Supabase vs Firebase
Decision: Supabase Rationale:- Real PostgreSQL relational database (not NoSQL)
- Maintains data integrity for complex academic/routine management
- Powerful Row Level Security (RLS) for multi-tenant isolation
- SQL-based queries are more maintainable
- Open-source alternative to Firebase
Vite vs Create React App / Next.js
Decision: Vite Rationale:- Create React App is architecturally obsolete
- Next.js is too heavyweight and forces SSR
- Application is private (behind authentication), no SEO needed
- Vite provides instant Hot Module Reload
- Native PWA plugin integration is seamless
- Faster build times and smaller bundle sizes
Serverless Proxy for AI
Decision: Vercel Serverless Functions (/api/ai)
Rationale:
GROQ_API_KEYnever reaches client bundle- Prevents API key theft via reverse engineering
- Built-in rate limiting by IP
- Zero infrastructure management
- Automatic scaling
State Management Architecture
Estudio Three uses 14+ specialized Zustand stores for modular state management:Store Responsibilities
useAppStore - Core Application State
useAppStore - Core Application State
Purpose: Central hub for user profile and routine generationKey State:
- User profile (sleep schedule, class schedule, subjects, training)
- Current routine blocks
- Daily feedback
- Onboarding status
generateRoutine()- Triggers routine solver algorithmupdateProfile()- Syncs profile changes to SupabaseskipBlock()/completeBlock()- Routine interactions
useAuthStore - Authentication
useAuthStore - Authentication
Purpose: Manages Supabase authentication stateKey State:
- Current user session
- Loading states
- Error messages
signIn()/signUp()/signOut()resetPassword()- Auto-refresh token handling
usePomodoroStore - Focus Timer
usePomodoroStore - Focus Timer
Purpose: Pomodoro timer with task tracking and historyKey State:
- Timer mode (focus, short break, long break)
- Remaining time
- Active task reference
- Session history
startTimer()/pauseTimer()/resetTimer()completeSession()- Saves tofocus_sessionstableincrementPomodoro()- Updates task pomodoro count
useTaskStore - Task Management
useTaskStore - Task Management
Purpose: Full CRUD for tasks and subtasksKey State:
- Tasks array (with filters)
- Subtasks by task ID
- Loading/error states
fetchTasks()- Loads from SupabasecreateTask()/updateTask()/deleteTask()toggleSubtask()- Marks subtask completesetPriority()/setStatus()- Quick updates
Routine Solver Algorithm
The core differentiator of Estudio Three is its intelligent routine generation engine located insrc/features/routine/engine/solver.ts.
Algorithm Overview
Energy Cost System
duration (minutes) × energyCost
Heuristic Rules
- Fatigue Collision Avoidance: Never schedule high-difficulty academic tasks (difficulty 5) immediately after high-intensity training
-
Cognitive Load Cap: Daily cognitive load cannot exceed
MAX_DAILY_LOAD = 5500 - Task Fragmentation: If a task doesn’t fit in a single slot, split it into “Part 1” and “Part 2” across multiple slots
- Priority Scheduling: Tasks are sorted by difficulty/priority (higher difficulty = higher priority)
- Minimum Viable Slots: Slots smaller than 20 minutes are skipped
Data Flow
Security Architecture
API Key Protection
- Groq API key stored only in Vercel environment variables
- Never exposed to client-side JavaScript
- Proxy endpoint:
POST /api/ai - Rate limiting by IP address
Row Level Security (RLS)
Supabase enforces strict PostgreSQL RLS policies:- Users cannot read/write data where
user_id ≠ auth.uid() - JWT tokens are validated on every database query
- No backend API layer needed—RLS handles authorization
Authentication
- Supabase Auth (OAuth 2.0 + Magic Links)
- JWT tokens stored in
httpOnlycookies - Automatic token refresh
- No passwords stored in application code
Performance Optimizations
Code Splitting
- Parallel chunk downloads
- Smaller initial bundle
- Better browser caching
Lazy Loading
PWA Caching
Service Worker strategies:- Static Assets:
CacheFirst(logos, icons, fonts) - API Calls:
NetworkFirstwith offline fallback - Fonts:
CacheFirstwith 365-day expiration
Folder Structure
Build and Deployment
Development
Production
Docker Deployment
Key Metrics
- Bundle Size: ~800KB (with code splitting)
- Initial Load: Less than 2 seconds on 3G
- Lighthouse PWA Score: 100/100
- TypeScript Coverage: 100% (strict mode)
- Test Coverage: Core engine >90%