A secure and scalable Express.js API for generating learning roadmaps and YouTube playlists using Google's Gemini AI and YouTube Data API.
- π£οΈ Learning Roadmap Generation: Create structured learning paths using Gemini AI
- πΊ YouTube Playlist Generation: Find relevant YouTube videos for learning topics
- π Comprehensive Logging: Request logging, error tracking, and monitoring
- Rate Limiting: Prevents API abuse with configurable limits
- Input Validation: Sanitizes and validates all user inputs
- Security Headers: Uses Helmet.js for security headers
- CORS Protection: Configurable cross-origin resource sharing
- Request Sanitization: Removes malicious content from requests
- Comprehensive Logging: Tracks all requests and errors
- Node.js (v18 or higher)
- npm or yarn
- Google Cloud Platform account
- YouTube Data API v3 enabled
-
Clone the repository
git clone <your-repo-url> cd skillspark-backend
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env
Edit
.envand add your API keys:GEMINI_API_KEY=your_gemini_api_key_here YOUTUBE_API_KEY=your_youtube_api_key_here
-
Start the development server
npm run dev
-
Test the API
curl http://localhost:8001/health
http://localhost:8001/api
POST /api/roadmaps/generate
Content-Type: application/json
{
"topic": "React Native development"
}Response:
{
"success": true,
"data": {
"id": "roadmap_abc123",
"topic": "react native",
"title": "React Native Development Roadmap",
"description": "Complete learning path for react native development",
"points": [...],
"progress": {
"completedPoints": 0,
"totalPoints": 12,
"percentage": 0
}
}
}POST /api/playlists/generate
Content-Type: application/json
{
"topic": "React Native",
"pointTitle": "State Management"
}Response:
{
"success": true,
"data": [
{
"id": "playlist_xyz789",
"title": "React Native State Management Tutorial",
"videoUrl": "https://youtube.com/watch?v=...",
"duration": "N/A",
"description": "Learn state management in React Native..."
}
]
}GET /healthGET /api/status| Variable | Required | Default | Description |
|---|---|---|---|
GEMINI_API_KEY |
Yes | - | Google Gemini AI API key |
YOUTUBE_API_KEY |
Yes | - | YouTube Data API v3 key |
PORT |
No | 8001 | Server port |
NODE_ENV |
No | development | Environment mode |
ALLOWED_ORIGINS |
No | - | Comma-separated list of allowed CORS origins |
- General API: 100 requests per 15 minutes per IP
- Roadmap Generation: 5 requests per minute per IP
- Playlist Generation: 10 requests per minute per IP
The API automatically sets security headers including:
- Content Security Policy (CSP)
- HTTP Strict Transport Security (HSTS)
- X-Content-Type-Options
- X-Frame-Options
- X-XSS-Protection
src/
βββ middleware/ # Security and validation middleware
βββ models/ # Data models and validation
βββ routes/ # API route handlers
βββ services/ # External service integrations
βββ utils/ # Utility functions and helpers
npm start- Start production servernpm run dev- Start development server with auto-reload
All errors are consistently formatted:
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Human readable message",
"details": "Additional error details"
}
}Logs are written to:
- Console (development)
logs/access.log(access logs)logs/error.log(error logs)
export NODE_ENV=production
export GEMINI_API_KEY=your_production_key
export YOUTUBE_API_KEY=your_production_key
export ALLOWED_ORIGINS=https://yourdomain.com- Set
NODE_ENV=production - Configure
ALLOWED_ORIGINSfor CORS - Set up reverse proxy (nginx/Apache)
- Configure SSL/TLS certificates
- Set up log rotation
- Configure monitoring and alerts
Example nginx configuration:
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:8001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}- Visit Google AI Studio
- Create a new API key
- Add the key to your
.envfile
- Go to Google Cloud Console
- Create a new project or select existing
- Enable YouTube Data API v3
- Create credentials (API key)
- Add the key to your
.envfile
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the ISC License.
For support, please create an issue in the repository or contact the development team.