A YouTube-based learning platform backend that tracks video watch progress, generates activity heatmaps, and provides comprehensive learning analytics.
- Google OAuth Authentication - Secure login with Google accounts
- YouTube Integration - Add videos and playlists from YouTube
- Progress Tracking - Resume videos from where you left off
- Activity Logging - Track watch time in 15-second intervals
- Analytics Dashboard - View learning statistics and heatmaps
- Multi-user Support - Multiple users can track the same courses independently
- Framework: Express.js with TypeScript
- Database: PostgreSQL with Drizzle ORM
- Authentication: Passport.js (Google OAuth 2.0) + JWT
- APIs: YouTube Data API v3
- Session Management: express-session
- Node.js (v18+)
- PostgreSQL database
- Google Cloud Console project with OAuth credentials
- YouTube Data API key
- Clone the repository
git clone <repository-url>
cd backend- Install dependencies
npm install- Configure environment variables
Create a .env file in the root directory:
DATABASE_URL=postgresql://user:password@localhost:5432/learntube
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/callback
YOUTUBE_API_KEY=your_youtube_api_key
JWT_SECRET=your_jwt_secret_key
SESSION_SECRET=your_session_secret_key
FRONTEND_URL=http://localhost:5173
NODE_ENV=development- Run database migrations
npm run db:migrate- Start the development server
npm run devThe server will start on http://localhost:3000
See API_DOCUMENTATION.md for complete endpoint documentation and frontend integration guide.
- Auth:
/auth/google,/auth/me - Courses:
/courses(CRUD operations) - Activity:
/activity/log,/activity/progress/:videoId - Analytics:
/activity/dashboard,/activity/heatmap
7-table architecture optimized for fast reads:
users- User accountscourses- Course metadatavideos- Video metadataprogress- Per-video resume positionsuser_activity- Raw activity logdaily_activity- Aggregated daily statscourse_progress- Aggregated course stats
npm run dev # Start development server with hot reload
npm run db:generate # Generate new migration
npm run db:migrate # Apply migrations to database
npm run db:studio # Open Drizzle Studio (database GUI)| Variable | Description | Required |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | ✅ |
GOOGLE_CLIENT_ID |
Google OAuth client ID | ✅ |
GOOGLE_CLIENT_SECRET |
Google OAuth client secret | ✅ |
GOOGLE_CALLBACK_URL |
OAuth callback URL | ✅ |
YOUTUBE_API_KEY |
YouTube Data API key | ✅ |
JWT_SECRET |
Secret for signing JWT tokens | ✅ |
SESSION_SECRET |
Secret for session encryption | ✅ |
FRONTEND_URL |
Frontend application URL | ✅ |
NODE_ENV |
Environment (development/production) | ❌ |
- Go to Google Cloud Console
- Create a new project or select existing
- Enable "Google+ API"
- Create OAuth 2.0 credentials
- Add authorized redirect URI:
http://localhost:3000/auth/google/callback
- In the same Google Cloud project
- Enable "YouTube Data API v3"
- Create API key under "Credentials"
Contributions are welcome! Please feel free to submit a Pull Request.
ISC