Skip to content

husseldin/Lab7-PersonalityTest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

44 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Personality Test Platform

A production-ready MBTI-inspired personality assessment platform with freemium/premium monetization, built with Next.js 14, TypeScript, Prisma, and Stripe.

๐Ÿš€ Features

Core Functionality

  • 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

Authentication & Security ๐Ÿ”

  • 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 Experience

  • 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 Features ๐Ÿ‘จโ€๐Ÿ’ผ

  • 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

Email Notifications ๐Ÿ“ง

  • 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

Technical Highlights

  • 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

๐Ÿ“‹ Prerequisites

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Next.js 14 Full-Stack Application  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚  React UI   โ”‚   โ”‚  API Routes โ”‚ โ”‚
โ”‚  โ”‚  (App Dir)  โ”‚โ—„โ”€โ–บโ”‚  (Backend)  โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚  Prisma ORM         โ”‚  Stripe    โ”‚
    โ”‚  (SQLite/Postgres)  โ”‚            โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Quick Start

1. Clone and Configure

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

2. Set Up Database

# Generate Prisma Client
npx prisma generate

# Run database migrations
npx prisma migrate dev

# (Optional) Open Prisma Studio to view data
npx prisma studio

3. Start Development Server

npm run dev

4. Access the Application

๐Ÿ› ๏ธ Development Commands

# 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 GUI

๐Ÿ“ฆ Project Structure

Lab7-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

๐Ÿ”‘ Environment Variables

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"

๐Ÿ“Š Database Schema

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

๐Ÿ“„ API Routes

Authentication Endpoints

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

Test Endpoints

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)

Payment Endpoints

POST   /api/payments/checkout              # Create Stripe checkout session
POST   /api/payments/webhook               # Stripe webhook handler

User Profile Endpoints

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

Admin Endpoints (Admin Only)

GET    /api/admin/analytics                # Get platform analytics
GET    /api/admin/users                    # List all users
PATCH  /api/admin/users                    # Update user (activate/deactivate, change role)

Social Sharing Endpoints

POST   /api/share/create                   # Create share link for test result
GET    /api/share/[code]                   # Get shared test result

๐Ÿ” Security Features

  • 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

๐Ÿงช Testing

The platform includes a comprehensive test suite built with Vitest and React Testing Library.

Running Tests

# 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

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

CI/CD Testing

All tests run automatically on push via GitHub Actions:

  • Linting
  • Type checking
  • Unit tests
  • Build verification

๐Ÿ“„ Legal Disclaimer

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.

๐Ÿ“œ License

This project is licensed under the MIT License.

๐Ÿš€ Deployment

Vercel (Recommended)

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel

# Add environment variables in Vercel dashboard
# Update DATABASE_URL to use PostgreSQL for production

Database Migration for Production

For production, switch from SQLite to PostgreSQL:

  1. Update prisma/schema.prisma:
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
  1. Update DATABASE_URL in your production environment:
DATABASE_URL="postgresql://user:password@host:5432/dbname"
  1. Run migrations:
npx prisma migrate deploy

Built with โค๏ธ using Next.js 14, TypeScript, Prisma, and Stripe

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages