A robust Next.js application for managing hackathon participants using QR codes for meal tracking. This system combines the best features from both the unified scan flow and hackvision projects.
- QR Code Scanning: Real-time QR code scanning using device camera
- Participant Registration: Register participants by binding their info to QR codes
- Meal Allocation: Track and serve meals (breakfast, lunch, snacks, dinner) to participants
- Admin Dashboard: Comprehensive dashboard with statistics, logs, and participant management
- QR Code Generation: Generate bulk QR codes for participants
- Robust Security: Prevents duplicate meal serving using database constraints
- Real-time Updates: Auto-refreshing dashboard with live statistics
- Framework: Next.js 16 (App Router)
- Language: TypeScript
- Database: MongoDB with Mongoose
- Styling: Tailwind CSS
- UI Components: Custom components with shadcn/ui patterns
- QR Code: html5-qrcode for scanning, qrcode for generation
- Notifications: Sonner for toast notifications
- Node.js 18+
- MongoDB (local or cloud instance)
- npm or yarn
- Clone the repository and navigate to the project:
cd qr-meal-system- Install dependencies:
npm install- Create a
.env.localfile in the root directory:
MONGODB_URI=mongodb://localhost:27017/qr-meal-systemFor MongoDB Atlas (cloud), use:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/qr-meal-system- Start the development server:
npm run dev- Open http://localhost:3000 in your browser.
Navigate to /generate-qr to generate QR codes for participants:
- Enter the number of QR codes to generate
- Set the starting index
- Click "Generate QR Codes"
- QR code images will be saved in
/public/qr_codes/
- Go to the home page (
/) - Scan a QR code using the camera
- If the QR code is valid but not registered, you'll see the registration form
- Fill in participant details (name, team, college, phone)
- Submit to activate the QR code
- Scan a registered participant's QR code
- Select the meal type (breakfast, lunch, snacks, dinner)
- Confirm allocation
- The system prevents duplicate meal serving automatically
Navigate to /dashboard to see:
- Total QR codes and registered participants
- Meal distribution statistics
- Live scan logs
- Registered participants list
POST /api/validate-qr- Validate a QR code before registrationPOST /api/register- Register a participantPOST /api/check-participant- Check if participant is registeredPOST /api/scan-meal- Record a meal scanGET /api/stats- Get dashboard statisticsGET /api/logs- Get recent meal scan logsGET /api/registered- Get list of registered participantsGET /api/participant-meals/[participantId]- Get meals served to a participantPOST /api/generate-qr- Generate QR codes
participantId: String (unique, indexed)name: StringteamName: Stringcollege: Stringphone: StringqrActive: Boolean (indexed)createdAt: DateupdatedAt: Date
participantId: String (indexed)mealType: Enum ['breakfast', 'lunch', 'snacks', 'dinner']scannedBy: StringscanTime: Date- Unique constraint on (
participantId,mealType) to prevent duplicates
- Duplicate Prevention: Database unique constraint prevents serving the same meal twice to a participant
- QR Activation: QR codes must be activated during registration before they can be used
- Server-side Validation: All validations happen on the server, not client-side
- Race Condition Handling: Database constraints handle concurrent requests
qr-meal-system/
├── app/
│ ├── api/ # API routes
│ ├── dashboard/ # Admin dashboard page
│ ├── generate-qr/ # QR generation page
│ ├── layout.tsx # Root layout
│ ├── page.tsx # Main scanner page
│ └── globals.css # Global styles
├── components/
│ ├── ui/ # Reusable UI components
│ ├── QRScanner.tsx # QR scanner component
│ ├── RegistrationForm.tsx
│ └── MealAllocation.tsx
├── lib/
│ ├── db.ts # MongoDB connection
│ ├── qr-generator.ts # QR code generation utility
│ └── utils.ts # Utility functions
├── models/
│ ├── Participant.ts # Participant model
│ └── MealRecord.ts # Meal record model
└── public/
└── qr_codes/ # Generated QR code images
# Run development server
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Lint code
npm run lintMONGODB_URI: MongoDB connection string (required)
- QR codes are generated with format:
EVENT2026_P_XXXXXX(6-digit zero-padded number) - QR code images are saved as PNG files in
/public/qr_codes/ - The dashboard auto-refreshes every 5 seconds
- Camera permissions are required for QR scanning
MIT