A modern, real-time polling application built with Next.js 16, featuring live results, beautiful visualizations, and seamless user experience.
- Real-time Polling - Live updates as votes come in
- Beautiful Charts - Interactive data visualizations
- Anonymous & User Polls - Create polls with or without accounts
- Advanced Settings - Customize poll behavior and privacy
- Responsive Design - Works perfectly on all devices
- Socket.io Integration - Instant real-time updates
- Dark/Light Mode - Full theme support
- Progress Tracking - Visual creation progress
- Quick Templates - Pre-built poll templates
- Social Sharing - Easy poll distribution
- Vote Analytics - Detailed insights and statistics
| Technology | Purpose | Version |
|---|---|---|
| Next.js 14 | React Framework | |
| TypeScript | Type Safety | |
| Tailwind CSS | Styling | |
| React Hook Form | Form Management | |
| Lucide React | Icons |
| Technology | Purpose | Version |
|---|---|---|
| Next.js API Routes | Serverless API | |
| Prisma | Database ORM | |
| Supabase PostgreSQL | Database | |
| Socket.io | Real-time Communication | |
| NextAuth.js | Authentication |
| Technology | Purpose |
|---|---|
| Redux Toolkit | Global State Management |
| React Query | Server State Management |
| Zod | Schema Validation |
| Date-fns | Date Utilities |
| Chart.js | Data Visualization |
| Technology | Purpose |
|---|---|
| Vercel | Hosting & Deployment |
| GitHub Actions | CI/CD Pipeline |
| Supabase | Managed PostgreSQL database |
pollify/
βββ app/ # Next.js 14 App Router
β βββ (auth)/ # Authentication routes
β βββ api/ # API routes
β β βββ auth/ # Authentication API
β β βββ polls/ # Polls API
β β βββ socket/ # Socket.io API
β βββ dashboard/ # User dashboard
β βββ polls/ # Poll management
β β βββ create/ # Create poll page
β β βββ edit/[id]/ # Edit poll page
β β βββ [id]/ # Poll detail page
β βββ layout.tsx # Root layout
βββ components/ # Reusable components
β βββ Auth/ # Base UI components
β βββ polls/ # Poll-specific components
β βββ ui/ # Data visualization
βββ features/ # Feature-based modules
β βββ auth/ # Authentication slice
β βββ polls/ # Polls slice
βββ hooks/ # Custom React hooks
βββ lib/ # Utility libraries
β βββ db.ts # Database configuration
β βββ auth.ts # Auth configuration
β βββ utils.ts # Helper functions
βββ store/ # Redux store configuration
βββ interfaces/ # TypeScript type definitions
βββ prisma/ # Database schema and migrations
- Node.js 18+
- Supabase project with a PostgreSQL database
- Git
-
Clone the repository
git clone https://github.com/lelisa21/alx-project-nexus cd alx-project-nexus -
Install dependencies
npm install
-
Environment Setup
cp .env.example .env.local
Configure your environment variables:
# Database - use the Supabase pooled or direct PostgreSQL connection string DATABASE_URL="postgresql://postgres:[YOUR-PASSWORD]@db.[PROJECT-REF].supabase.co:5432/postgres?schema=public" # Authentication NEXTAUTH_URL="http://localhost:3000" NEXTAUTH_SECRET="your-secret-key" # Optional: OAuth providers GOOGLE_CLIENT_ID="" GOOGLE_CLIENT_SECRET="" GITHUB_CLIENT_ID="" GITHUB_CLIENT_SECRET=""
-
Database Setup
npx prisma generate npx prisma db push npx prisma db seed
Supabase note: if
prisma db pushfails while using the Supabase pooler host, temporarily setDATABASE_URLto the direct connection string from Supabase Project Settings > Database > Connection string > Direct connection, then runnpx prisma db push. Use the pooler URL again for normal runtime deployments. -
Run Development Server
npm run dev
Visit http://localhost:3000
model User {
id String @id @default(uuid()) @db.Uuid
email String @unique
name String?
polls Poll[]
votes Vote[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Poll {
id String @id @default(uuid()) @db.Uuid
question String
description String?
isActive Boolean @default(true)
totalVotes Int @default(0)
views Int @default(0)
userId String? @db.Uuid // Author reference
options Option[]
settings PollSettings?
votes Vote[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Option {
id String @id @default(uuid()) @db.Uuid
text String
votes Int @default(0)
pollId String @db.Uuid
poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
}| Method | Endpoint | Description |
|---|---|---|
GET |
/api/polls |
Get all polls |
POST |
/api/polls |
Create new poll |
GET |
/api/polls/[id] |
Get specific poll |
PUT |
/api/polls/[id] |
Update poll |
POST |
/api/polls/[id]/vote |
Submit vote |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/auth/[...nextauth] |
NextAuth endpoints |
POST |
/api/auth/register |
User registration |
POST |
/api/auth/login |
User login |
- Button - Customizable button with variants
- Card - Content container with header/body/footer
- Input - Form input with validation
- Badge - Status and category indicators
- Toggle - Switch controls
- LoadingSpinner - Loading states
- PollCard - Poll preview card
- PollChart - Data visualization
- VoteButton - Voting interface
- ProgressTracker - Creation progress
// Protected API routes
export const GET = withAuth(async (req) => {
const session = await getServerSession(authOptions);
if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
// Handle request
});
// Protected pages
export default function Page() {
const { data: session } = useSession();
if (!session) return <div>Please sign in</div>;
return <Dashboard />;
}// Client-side socket connection
const socket = useSocket();
socket.emit('vote', { pollId, optionId });
socket.on('voteUpdate', (data) => {
// Update UI in real-time
});
// Server-side socket handling
io.on('connection', (socket) => {
socket.on('vote', handleVote);
socket.on('joinPoll', handleJoinPoll);
});# Unit tests
npm run test
# Integration tests
npm run test:integration
# E2E tests
npm run test:e2e
# Test coverage
npm run test:coverage- Connect your GitHub repository to Vercel
- Configure environment variables
- Deploy automatically on push to main
DATABASE_URL="postgresql://postgres:[YOUR-PASSWORD]@db.[PROJECT-REF].supabase.co:5432/postgres?schema=public"
NEXTAUTH_URL="https://yourdomain.vercel.app"
NEXTAUTH_SECRET="production-secret"- LCP: < 2.5s
- FID: < 100ms
- CLS: < 0.1
- Image Optimization - Next.js Image component
- Code Splitting - Dynamic imports
- Bundle Analysis - Webpack bundle analyzer
- CDN - Vercel edge network
We love contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
ALX and Their Community - for preparing this amazing Learning Platform and Project
- Next.js Team - Amazing React framework
- Vercel - Incredible hosting platform
- Prisma - Excellent database toolkit
- Tailwind CSS - Utility-first CSS framework
- Socket.io - Real-time communication library