A comprehensive backend system for the Smart India Hackathon (SIH) registration portal built with Next.js API Routes, MongoDB, Firebase Authentication, and Cloudinary for file storage
- Framework: Next.js 15 with App Router
- Database: MongoDB with Mongoose ODM
- Authentication: Firebase Admin SDK + Custom JWT
- File Storage: Cloudinary
- Email: Nodemailer (SMTP)
- File Processing: multer, xlsx for Excel processing
- Validation: Custom validation utilities
- Team Leader: Can register teams, access team portal, submit tasks
- Admin/Evaluator: Manage teams, problem statements, assign tasks, send emails
- Team Members: Information collected during registration (no login required)
βββ app/api/ # API Routes
β βββ auth/ # Authentication endpoints
β β βββ admin-register/ # Admin registration
β β βββ verify/ # User verification
β βββ admin/ # Admin-only endpoints
β β βββ teams/ # Team management
β β βββ problem-statements/ # PS management
β β βββ tasks/ # Task management
β βββ problem-statements/ # Public PS endpoints
β βββ teamRegistration/ # Team registration
β βββ upload/ # File upload utility
βββ lib/ # Core utilities
β βββ firebase-admin.ts # Firebase config
β βββ mongodb.ts # Database connection
β βββ middleware/ # Auth middleware
β βββ utils/ # Utility functions
βββ models/ # Database models
βββ User.ts # User model
βββ Team.ts # Team model
βββ ProblemStatement.ts # Problem Statement model
βββ Task.ts # Task model
Create a .env.local file with the following variables:
# MongoDB Atlas (M0 Free Tier - Perfect for 50 teams!)
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/sih-reg?retryWrites=true&w=majority
# OR MongoDB Local (For Development)
# MONGODB_URI=mongodb://localhost:27017/sih-reg
# Firebase Configuration
FIREBASE_API_KEY=your-firebase-api-key
FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_MESSAGING_SENDER_ID=your-sender-id
FIREBASE_APP_ID=your-app-id
FIREBASE_MEASUREMENT_ID=your-measurement-id
# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/sih-reg
# JWT Secret
JWT_SECRET=your-super-secret-jwt-key
# Admin Registration Secret Keys (Role-Based)
EVALUATOR_REGISTRATION_SECRET=your-evaluator-secret-key
SUPER_ADMIN_REGISTRATION_SECRET=your-super-admin-secret-key
# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret
# Email Configuration
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password
EMAIL_FROM=SIH Registration <your-email@gmail.com>interface IUser {
email: string;
name: string;
role: "leader" | "admin";
firebaseUid: string;
team?: ObjectId; // Reference to Team
}interface ITeam {
teamName: string;
leader: ObjectId; // Reference to User
members: ITeamMember[]; // Array of 5 members
problemStatement: ObjectId; // Reference to ProblemStatement
status: "registered" | "selected" | "rejected" | "finalist";
tasks: ITaskSubmission[];
}interface IProblemStatement {
psNumber: string;
title: string;
description: string;
domain: string;
link: string;
teamCount: number;
maxTeams: number; // Default: 3
isActive: boolean;
}interface ITask {
title: string;
description: string;
fields: ITaskField[]; // Dynamic form fields
assignedTo: ObjectId[]; // Array of Team references
dueDate?: Date;
isActive: boolean;
createdBy: ObjectId; // Reference to admin User
}- User signs in with Google
- Firebase returns user info
- Backend creates/updates User record with role 'leader'
- JWT token issued for API access
- Admin provides email, password, and secret key
- Backend validates secret key and determines role:
EVALUATOR_REGISTRATION_SECRETβ creates evaluator accountSUPER_ADMIN_REGISTRATION_SECRETβ creates super-admin account
- Firebase user created with email/password
- User record created with appropriate role
- Custom token generated for immediate login
POST /api/auth/admin-register- Register admin accountGET /api/auth/verify- Verify current userPOST /api/auth/verify- Sync user after Google OAuth
POST /api/teamRegistration- Register new teamGET /api/teamRegistration- Get leader's team info
GET /api/problem-statements- Get available problem statementsGET /api/admin/problem-statements- Admin: Get all PSsPOST /api/admin/problem-statements- Admin: Bulk upload PSsPUT /api/admin/problem-statements- Admin: Toggle PS active statusGET /api/admin/problem-statements/template- Download Excel template
GET /api/admin/teams- Get all teams (with pagination/filtering)PUT /api/admin/teams- Update team status
GET /api/admin/tasks- Get all tasksPOST /api/admin/tasks- Create and assign tasksPUT /api/admin/tasks- Update task status
POST /api/upload- Upload files to Cloudinary
- Team Size: Exactly 6 members (1 leader + 5 members)
- Gender Diversity: At least 1 female member required
- Unique Constraints: Team name, member emails must be unique
- Problem Statement Availability: Max 3 teams per PS
- Bulk Problem Statement Upload: Excel/CSV file processing
- Dynamic Task Creation: Configurable form fields
- Team Status Management: Update registration status
- Email Notifications: Automated emails for registration/tasks
- Firebase Authentication: Secure token-based auth
- Input Sanitization: All user inputs validated and sanitized
- File Upload Security: Type and size validation
- Rate Limiting: Built-in protection (can be added)
Sent automatically when team registers successfully:
- Team details confirmation
- Problem statement information
- Next steps guidance
Sent when admin assigns tasks to teams:
- Task title and description
- Due date (if specified)
- Portal login instructions
| psNumber | title | description | domain | link | maxTeams |
|----------|-------|-------------|--------|------|----------|
| SIH001 | ... | ... | ... | ... | 3 |
- Admin downloads template from
/api/admin/problem-statements/template - Fills in problem statement data
- Uploads via admin panel
- System validates and imports data
- Duplicate detection and error reporting
-
Clone and Install
git clone <repository-url> cd sih-reg npm install
-
Environment Configuration
- Copy
.env.exampleto.env.local - Update all environment variables
- Copy
-
Firebase Setup
- Create Firebase project
- Enable Authentication (Google Sign-In, Email/Password)
- Download service account key
- Place in
lib/firebase-admin-key.json
-
MongoDB Setup
- Install MongoDB locally or use MongoDB Atlas
- Update
MONGODB_URIin environment
-
Cloudinary Setup
- Create Cloudinary account
- Get API credentials
- Update environment variables
-
Start Development Server
npm run dev
Ensure all production environment variables are properly configured:
- Strong JWT secrets
- Production MongoDB connection string
- Verified email SMTP settings
- Cloudinary production credentials
- Use HTTPS in production
- Implement rate limiting
- Regular security audits
- Monitor file upload sizes
- Validate all user inputs
# Test admin registration (evaluator)
curl -X POST http://localhost:3000/api/admin/register \
-H "Content-Type: application/json" \
-d '{"name":"Evaluator","email":"evaluator@test.com","password":"password","secretKey":"your-evaluator-secret"}'
# Test admin registration (super-admin)
curl -X POST http://localhost:3000/api/admin/register \
-H "Content-Type: application/json" \
-d '{"name":"Super Admin","email":"admin@test.com","password":"password","secretKey":"your-super-admin-secret"}'
# Test problem statements
curl http://localhost:3000/api/problem-statements- Use MongoDB Compass for database inspection
- Test data validation rules
- Verify indexes are created properly
- All API endpoints include error logging
- User authentication events logged
- File upload activities tracked
- Connection status monitoring
- Query performance tracking
- Index usage analysis
- Real-time Notifications: WebSocket implementation
- Advanced Analytics: Team performance metrics
- Mobile App Support: API optimization for mobile
- Caching Layer: Redis implementation for better performance
- Advanced Security: Rate limiting, DDoS protection
- Backup System: Automated database backups
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, email support@sih-portal.com or create an issue in the repository.
Built with β€οΈ for Smart India Hackathon 2025