A production-ready MBTI-inspired personality assessment platform with freemium/premium monetization, built with Next.js 14, TypeScript, Prisma, and Stripe.
- 60-Question MBTI-Inspired Test: Scientifically balanced across E/I, S/N, T/F, J/P dimensions
- Dual-Tier Reports: Free basic report + premium complete report with career insights
- PDF Export: Server-side PDF generation with beautiful layouts
- Test History: Track all past attempts with detailed scores and analytics
- Social Sharing: Share results with customizable privacy settings and expiration dates
- Email Verification: Secure email verification with token-based system
- Password Reset Flow: Complete password reset with secure tokens and email templates
- Rate Limiting: Built-in protection against brute force attacks
- Activity Logging: Track user activities for security and analytics
- Secure Tokens: Cryptographically secure token generation for all sensitive operations
- User Profile Management: Edit profile information, bio, and profile pictures
- Activity Dashboard: View personal activity history and statistics
- Profile Settings: Comprehensive settings page with tabs for profile, activity, and security
- Test Retake Tracking: Monitor how personality types evolve over time
- Responsive Design: Mobile-first design with beautiful gradients and animations
- Admin Dashboard: Comprehensive analytics and user management
- User Management: View, search, and manage users with role-based access
- Platform Analytics: Track user growth, test completion rates, and revenue
- Activity Monitoring: View all platform activities and user behavior patterns
- Personality Distribution: Visual analytics of personality type distribution
- Welcome Emails: Beautiful HTML emails for new users
- Verification Emails: Professional email templates for account verification
- Password Reset Emails: Secure password reset with styled email templates
- Test Completion Notifications: Automated emails when tests are completed
- Modern Full-Stack: Next.js 14 App Router with Server Components and API Routes
- Security First: bcryptjs password hashing, NextAuth JWT authentication, rate limiting
- Type-Safe: Full TypeScript implementation with Zod validation throughout
- Modern Stack: Next.js 14, React 18, Prisma ORM, SQLite/PostgreSQL
- Payment Integration: Stripe Checkout with webhook handling
- Testing: Comprehensive test suite with Vitest and React Testing Library (80%+ coverage)
- CI/CD: GitHub Actions pipeline with automated testing and builds
- Production Ready: PDF generation, logging, error handling, database migrations
- Node.js 20+
- npm or yarn
- PostgreSQL (optional, SQLite works for development)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Next.js 14 Full-Stack Application โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ React UI โ โ API Routes โ โ
โ โ (App Dir) โโโโบโ (Backend) โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโผโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ Prisma ORM โ Stripe โ
โ (SQLite/Postgres) โ โ
โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโ
git clone <repository-url>
cd Lab7-PersonalityTest
# Install dependencies
npm install
# Copy environment template
cp .env.example .env
# Edit .env with your settings (Stripe keys, NextAuth secret, etc.)
nano .env# Generate Prisma Client
npx prisma generate
# Run database migrations
npx prisma migrate dev
# (Optional) Open Prisma Studio to view data
npx prisma studionpm run dev- Application: http://localhost:3000
- Prisma Studio: http://localhost:5555 (if running)
# Start development server
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Run linter
npm run lint
# Testing
npm run test # Run tests in watch mode
npm run test:run # Run tests once
npm run test:ui # Run tests with UI
npm run test:coverage # Generate coverage report
# Prisma commands
npx prisma generate # Generate Prisma Client
npx prisma migrate dev # Run migrations in development
npx prisma studio # Open Prisma Studio GUILab7-PersonalityTest/
โโโ app/
โ โโโ api/ # API Routes (Backend)
โ โ โโโ auth/ # Authentication endpoints
โ โ โ โโโ register/ # User registration
โ โ โ โโโ verify-email/ # Email verification
โ โ โ โโโ resend-verification/ # Resend verification email
โ โ โ โโโ forgot-password/ # Password reset request
โ โ โ โโโ reset-password/ # Password reset completion
โ โ โโโ test/ # Test submission & results
โ โ โโโ payments/ # Stripe integration
โ โ โโโ user/ # User profile & activity
โ โ โ โโโ profile/ # Profile management
โ โ โ โโโ activity/ # Activity logs
โ โ โโโ admin/ # Admin endpoints
โ โ โ โโโ analytics/ # Platform analytics
โ โ โ โโโ users/ # User management
โ โ โโโ share/ # Social sharing
โ โโโ auth/ # Auth pages
โ โ โโโ signin/ # Sign in page
โ โ โโโ signup/ # Sign up page
โ โ โโโ verify-email/ # Email verification page
โ โ โโโ forgot-password/ # Password reset request
โ โ โโโ reset-password/ # Password reset page
โ โโโ test/ # Test taking page
โ โโโ profile/ # User profile settings
โ โโโ dashboard/ # User dashboard
โ โโโ about/ # About page
โ โโโ layout.tsx # Root layout
โ โโโ page.tsx # Home page
โโโ lib/ # Utility functions & libraries
โ โโโ auth.ts # NextAuth configuration
โ โโโ pdf-generator.ts # PDF generation logic
โ โโโ email.ts # Email service & templates
โ โโโ tokens.ts # Token generation & validation
โ โโโ activity-logger.ts # Activity tracking
โ โโโ rate-limit.ts # Rate limiting
โ โโโ validation.ts # Input validation schemas
โโโ test/ # Test suite
โ โโโ setup.ts # Test configuration
โ โโโ lib/ # Unit tests
โ โโโ validation.test.ts # Validation tests
โ โโโ rate-limit.test.ts # Rate limiting tests
โโโ prisma/
โ โโโ schema.prisma # Database schema
โ โโโ migrations/ # Database migrations
โ โโโ dev.db # SQLite database (dev)
โโโ .github/
โ โโโ workflows/
โ โโโ ci.yml # CI/CD pipeline
โโโ public/
โ โโโ data/
โ โโโ questions.json # 60-question test bank
โโโ vitest.config.ts # Vitest configuration
โโโ .env.example # Environment variables template
โโโ package.json
โโโ README.md
Critical environment variables (see .env.example for full list):
# Database
DATABASE_URL="file:./prisma/dev.db"
# NextAuth
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-nextauth-secret-key-change-this-in-production"
# Stripe
STRIPE_SECRET_KEY="sk_test_xxx"
STRIPE_PUBLISHABLE_KEY="pk_test_xxx"
STRIPE_WEBHOOK_SECRET="whsec_xxx"
# Application
NEXT_PUBLIC_BASE_URL="http://localhost:3000"See ARCHITECTURE.md for complete ERD and schema details.
Key entities:
- Users: Authentication and profiles
- TestAttempts: Test sessions with scores
- Questions: Versioned question bank
- Payments: Stripe payment tracking
- Entitlements: Premium report access
- Shares: Social sharing functionality
- Invitations: Friend invites
POST /api/auth/register # Create new user account
POST /api/auth/[...nextauth] # NextAuth endpoints (signin, callback, etc.)
POST /api/auth/verify-email # Verify email address
GET /api/auth/verify-email?token=... # Check if verification token is valid
POST /api/auth/resend-verification # Resend verification email
POST /api/auth/forgot-password # Request password reset
POST /api/auth/reset-password # Reset password with token
GET /api/auth/reset-password?token=... # Check if reset token is valid
POST /api/test/submit # Submit test answers
GET /api/test/history # Get user's test history
GET /api/test/result/[id] # Get specific test result
GET /api/test/result/[id]/pdf # Download PDF report (premium only)
POST /api/payments/checkout # Create Stripe checkout session
POST /api/payments/webhook # Stripe webhook handler
GET /api/user/profile # Get current user profile
PATCH /api/user/profile # Update user profile
DELETE /api/user/profile # Delete user account
GET /api/user/activity # Get user activity logs
GET /api/user/activity?stats=true # Get activity statistics
GET /api/admin/analytics # Get platform analytics
GET /api/admin/users # List all users
PATCH /api/admin/users # Update user (activate/deactivate, change role)
POST /api/share/create # Create share link for test result
GET /api/share/[code] # Get shared test result
- Password Hashing: bcryptjs with salt rounds
- JWT Authentication: NextAuth with secure session handling
- Email Verification: Token-based email verification system
- Rate Limiting: Protection against brute force attacks on sensitive endpoints
- Activity Logging: Complete audit trail of user actions
- Input Validation: Zod schema validation on all API routes
- SQL Injection Prevention: Prisma ORM with parameterized queries
- XSS Protection: React automatic escaping + Next.js built-in protections
- CSRF Protection: NextAuth built-in CSRF tokens
- Type Safety: Full TypeScript implementation
- Secure Tokens: Cryptographically secure random token generation
The platform includes a comprehensive test suite built with Vitest and React Testing Library.
# Run tests in watch mode
npm run test
# Run tests once
npm run test:run
# Run tests with UI
npm run test:ui
# Generate coverage report
npm run test:coverage- Utility Functions: 80%+ coverage for validation, rate limiting, tokens, etc.
- API Routes: Integration tests for critical endpoints
- Components: Unit tests for key UI components
All tests run automatically on push via GitHub Actions:
- Linting
- Type checking
- Unit tests
- Build verification
Important: This application provides an MBTI-inspired personality assessment and is not affiliated with, endorsed by, or connected to The Myers-Briggs Company, the publisher of the official MBTIยฎ assessment. The terms "MBTI" and "Myers-Briggs Type Indicator" are trademarks or registered trademarks of The Myers & Briggs Foundation.
This tool uses a 16-type personality framework for educational and entertainment purposes only and should not be considered a substitute for professional psychological assessment.
This project is licensed under the MIT License.
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel
# Add environment variables in Vercel dashboard
# Update DATABASE_URL to use PostgreSQL for productionFor production, switch from SQLite to PostgreSQL:
- Update
prisma/schema.prisma:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}- Update
DATABASE_URLin your production environment:
DATABASE_URL="postgresql://user:password@host:5432/dbname"- Run migrations:
npx prisma migrate deployBuilt with โค๏ธ using Next.js 14, TypeScript, Prisma, and Stripe