- Initial Setup
- Environment Variables
- Database Setup
- Installing Shadcn UI Components
- Authentication Implementation
- Dashboard Implementation
- QR Code System
- Geolocation Validation
- Deployment
cd c:\Users\HP\Desktop\trinity-attend
npm installThis will install all required packages including:
- Next.js 16
- React 19
- Prisma
- Better Auth
- Shadcn UI dependencies
- All other libraries
Run these commands to generate secure keys:
# For AUTH_SECRET and BETTER_AUTH_SECRET
node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
# For QR_CODE_SECRET
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"-
DATABASE_URL
- Provider: Neon (Recommended)
- Steps:
- Create account at neon.tech
- Create new project
- Copy connection string
- Format:
postgresql://user:pass@host/db?sslmode=require
-
AUTH_SECRET
- Generate using the command above
- Must be at least 32 characters
-
QR_CODE_SECRET
- Generate using the command above
- Used for HMAC signing of QR codes
-
GOOGLE_CLIENT_ID & GOOGLE_CLIENT_SECRET
- For Google OAuth sign-in
- Get from: Google Cloud Console
-
APPLE_CLIENT_ID & APPLE_CLIENT_SECRET
- For Apple sign-in
- Get from: Apple Developer
-
RESEND_API_KEY
- For sending emails
- Get from: Resend
-
CLOUDINARY Credentials
- For profile picture uploads
- Get from: Cloudinary
# Copy from .env.example and fill in your values
DATABASE_URL="postgresql://user:pass@ep-xxx.region.aws.neon.tech/trinity?sslmode=require"
AUTH_SECRET="generated-secret-key-here"
QR_CODE_SECRET="generated-qr-secret-here"
NEXT_PUBLIC_APP_URL="http://localhost:3000"npm run db:pushThis creates all tables in your PostgreSQL database.
npm run db:seedThis creates:
- 3 Faculties (Science, Arts, Commercial)
- 8 Departments (Computer Science, Nursing, etc.)
- 20 Sample Courses (CSC 111, CSC 211, etc.)
- 2 Demo Users (1 teacher, 1 student)
npm run db:studioThis opens Prisma Studio where you can view and edit your database.
Shadcn UI components need to be installed individually. Here's how:
npx shadcn@latest init# Core UI Components
npx shadcn@latest add button
npx shadcn@latest add card
npx shadcn@latest add input
npx shadcn@latest add label
npx shadcn@latest add form
npx shadcn@latest add select
npx shadcn@latest add dialog
npx shadcn@latest add dropdown-menu
npx shadcn@latest add table
npx shadcn@latest add tabs
npx shadcn@latest add switch
npx shadcn@latest add progress
npx shadcn@latest add avatar
npx shadcn@latest add badge
npx shadcn@latest add separator
npx shadcn@latest add skeleton
npx shadcn@latest add checkbox
npx shadcn@latest add popover
# Toast Notifications (uses sonner, already configured)
# Already installed via package.jsonThese components will be added to src/components/ui/.
-
Auth Routes:
src/app/api/auth/[...all]/route.ts- Better Auth handlersrc/app/(auth)/layout.tsx- Auth pages layoutsrc/app/(auth)/role-selection/page.tsx- Choose Student/Teachersrc/app/(auth)/login/student/page.tsx- Student loginsrc/app/(auth)/login/teacher/page.tsx- Teacher loginsrc/app/(auth)/signup/student/page.tsx- Student signupsrc/app/(auth)/signup/teacher/page.tsx- Teacher signup
-
Server Actions:
src/actions/auth.actions.ts- Already created
Run the app and test the landing page:
npm run devVisit http://localhost:3000
src/app/(dashboard)/student/
├── layout.tsx # Student dashboard layout
├── page.tsx # Home dashboard
├── courses/
│ ├── page.tsx # Course list
│ └── [id]/page.tsx # Course details
├── attendance/
│ ├── page.tsx # Attendance overview
│ └── scan/page.tsx # QR scanner
├── history/page.tsx # Attendance history
├── profile/page.tsx # Student profile
└── settings/page.tsx # Settings
src/app/(dashboard)/teacher/
├── layout.tsx # Teacher dashboard layout
├── page.tsx # Home dashboard
├── courses/
│ ├── page.tsx # Course list
│ ├── create/page.tsx # Create course offering
│ └── [id]/
│ ├── page.tsx # Course management
│ └── attendance/page.tsx # Attendance table
├── analytics/page.tsx # Analytics dashboard
└── settings/page.tsx # Settings
- Teacher selects course and week number
- System captures teacher's geolocation (latitude, longitude)
- Generate QR data:
{ courseOfferingId: string, weekNumber: number, timestamp: number, expiresAt: number, latitude: number, // Teacher's location longitude: number, // Teacher's location signature: string // HMAC-SHA256 }
- Display QR code valid for 10 minutes
- QR expires or teacher regenerates
- Student requests geolocation permission
- Student scans QR code
- System validates:
- QR not expired
- HMAC signature valid
- Student enrolled in course
- Student within 100m of teacher's location
- If all valid, mark attendance
- Show success/error message
// In src/lib/utils.ts (Already created)
export function calculateDistance(
lat1: number, lon1: number,
lat2: number, lon2: number
): number {
// Haversine formula - returns distance in meters
}
export function isWithinAllowedRadius(
userLat: number, userLon: number,
targetLat: number, targetLon: number,
maxDistanceMeters: number = 100
): boolean {
const distance = calculateDistance(userLat, userLon, targetLat, targetLon);
return distance <= maxDistanceMeters;
}// Request user's location
navigator.geolocation.getCurrentPosition(
(position) => {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
// Use for QR scanning or generation
},
(error) => {
console.error("Geolocation error:", error);
}
);- HTTPS Required: Geolocation only works on HTTPS (or localhost)
- User Permission: Browser will ask for permission
- Accuracy: GPS accuracy varies (typically 5-50m)
- Timeout: Set reasonable timeout for location request
- Fallback: Handle cases where location is unavailable
In .env.local:
NEXT_PUBLIC_ENABLE_GEOLOCATION="true"
NEXT_PUBLIC_MAX_DISTANCE_METERS="100"- Hosting: Vercel (Next.js optimized)
- Database: Neon (PostgreSQL)
- File Storage: Cloudinary
- Email: Resend
-
Push to GitHub
git init git add . git commit -m "Initial commit" git branch -M main git remote add origin <your-repo-url> git push -u origin main
-
Deploy to Vercel
- Go to vercel.com
- Import your GitHub repository
- Add environment variables
- Deploy
-
Configure OAuth Redirects
- Update Google/Apple OAuth settings
- Add production URLs
-
Update Environment Variables
- Set
NEXT_PUBLIC_APP_URLto your production URL - Ensure all secrets are configured
- Set
# Start development server
npm run dev
# View database
npm run db:studio
# Push schema changes
npm run db:push
# Reseed database (if needed)
npm run db:seed# Lint code
npm run lint
# Build for production
npm run build
# Test production build
npm run start-
Module not found errors
rm -rf node_modules package-lock.json npm install
-
Prisma Client errors
npx prisma generate npm run db:push
-
Type errors
- Restart TypeScript server in VS Code
- Run
npx prisma generate
-
Database connection errors
- Check
DATABASE_URLin.env.local - Ensure database is running
- Verify SSL mode is correct
- Check
- ✅ Setup Complete (You are here)
- Week 1: Authentication pages (login/signup)
- Week 2: Student dashboard and course enrollment
- Week 3: Teacher dashboard and course management
- Week 4: QR code system with geolocation
- Week 5: Analytics and reporting
- Week 6: Excel/PDF export
- Week 7: Testing and deployment
- Check the README.md for setup instructions
- Review the code comments for implementation details
- Open an issue on GitHub
- Email: support@trinityattend.com
Your Trinity Attend project is now set up and ready for development! 🎉
Next step: Run npm run dev and visit http://localhost:3000 to see your landing page.