Introduction
Study Sync is a modern SaaS platform built with Next.js 16.1.0 (App Router) that enables students to create, share, and track study plans with integrated progress monitoring and collaboration features.Tech Stack
Frontend
- Framework: Next.js 16.1.0 with App Router architecture
- UI Library: React 19.2.3
- Language: JavaScript/JSX
- Styling: Tailwind CSS 4
- UI Components: Radix UI (accessible primitives), Lucide Icons
- Animations: Framer Motion 12
- Drag & Drop: @dnd-kit library
- Notifications: React Hot Toast & Sonner
- Theme: next-themes (dark/light mode)
Backend (Next.js API Routes)
- Runtime: Node.js
- Database: MongoDB 7.0.0 (Native Driver)
- Database Name:
study_sync - Connection: MongoDB Atlas with connection pooling
- Database Name:
- Authentication: Firebase Admin SDK 13.6.0
- Email Service: Nodemailer 7.0.12 (Gmail SMTP)
External Services
- YouTube Data API v3: Video and playlist metadata via googleapis 166.0.0
- Firebase: Client and server-side authentication
- Mixpanel: Analytics and event tracking
- Vercel: Hosting, analytics, and cron jobs for scheduled tasks
Application Architecture
Next.js App Router Structure
Key Architectural Patterns
1. Route Groups
The(auth) folder is a route group that shares a common layout without adding the group name to the URL path. This keeps authentication pages visually consistent.
Location: src/app/(auth)/layout.jsx:1
2. API Routes as Backend
Next.js API routes serve as the backend, handling:- Database operations
- Authentication verification
- External API integrations (YouTube, email)
- Business logic
src/app/api/study-plans/route.js:1
3. Server-Side Rendering (SSR)
Pages leverage Next.js App Router’s server components for optimal performance and SEO.Core Components
Database Layer
Connection Management (src/lib/mongodb.js:1)
src/lib/db.js:9)
Authentication Layer
Client-Side (src/providers/AuthProvider.jsx:1)
- Firebase Authentication SDK for user sign-in/sign-up
- Monitors auth state changes
- Fetches and caches ID tokens for API requests
- Enriches Firebase user with MongoDB profile data
src/lib/auth.js:4)
- Verifies Firebase ID tokens using Firebase Admin SDK
- Auto-creates MongoDB user records on first login
- Provides authentication middleware for API routes
Client-Server Communication
API Client (src/lib/api.js:1)
Data Flow
Creating a Study Plan
Tracking Progress
Key Architectural Decisions
1. Global Resource Pool
Problem: Prevent duplicate resources when the same YouTube video or PDF is used across multiple study plans. Solution: Resources are stored once in theresources collection with a unique URL index. Study plans reference resources by ObjectId.
Implementation: src/app/api/resources/route.js:238
2. Instance Snapshot Pattern
Problem: Users want instances independent from plan changes (e.g., creator removes resources). Solution: When creating an instance, snapshot the plan’s currentresourceIds array into instance.snapshotResourceIds.
Implementation: src/app/api/instances/route.js:174
3. Global Progress Tracking
Problem: Users may complete a resource in one instance but want it marked complete everywhere. Solution: Progress is tracked globally per(userId, resourceId) pair with a unique compound index, not per instance.
Implementation: src/app/api/user-progress/route.js:75
src/lib/db.js:60
4. Connection Pooling in Development
Problem: Next.js hot reloading creates multiple MongoDB connections, exhausting the connection pool. Solution: Cache the MongoDB client promise in a global variable during development. Implementation:src/lib/mongodb.js:18
5. Authentication Token Flow
Problem: Secure API access without session management complexity. Solution: Use Firebase ID tokens (JWT) inAuthorization: Bearer header, verified server-side with Firebase Admin SDK.
Implementation: src/lib/auth.js:11
Environment Variables
Performance Considerations
Database Indexes
All collections have strategic indexes for common query patterns:- Users:
firebaseUid,email(unique) - Study Plans:
createdBy,isPublic,courseCode,sharedWith.userId - Instances:
userId,studyPlanId, compound(userId, studyPlanId) - Resources:
url(unique),type - User Progress:
userId,resourceId, compound(userId, resourceId)(unique)
src/lib/db.js:35
Client-Side Optimizations
- Server Components for initial rendering
- Client Components only where interactivity needed
- Framer Motion for smooth, GPU-accelerated animations
- Optimistic UI updates for progress toggling
Deployment
The application is deployed on Vercel with:- Automatic CI/CD from Git
- Edge Network distribution
- Vercel Analytics for performance monitoring
- Vercel Cron for scheduled email reminders
vercel.json):
Next Steps
- Database Schema - Detailed collection schemas
- Authentication Flow - In-depth auth implementation
- Resource Pool - De-duplication strategy