A fullstack Reddit clone built with Next.js 14, TypeScript, Prisma, PostgreSQL, and Tailwind CSS.
- 🔐 User authentication (sign up, login, logout)
- 👥 User profiles
- 🏘️ Create and join communities (subreddits)
- 📝 Create posts (text, link, or image)
- ⬆️⬇️ Vote on posts and comments
- 💬 Comment system with nested replies
- 🔍 Search communities
- 📱 Responsive design
- Frontend: Next.js 14 (App Router), React, TypeScript
- Styling: Tailwind CSS, Radix UI components
- Backend: Next.js API Routes
- Database: PostgreSQL with Prisma ORM
- Authentication: NextAuth.js
- Password Hashing: bcryptjs
- Node.js 18+ and npm/yarn
- PostgreSQL database
- Clone the repository:
git clone <your-repo-url>
cd Reddit-Clone- Install dependencies:
npm install- Set up environment variables:
cp .env.example .envEdit .env and add your database URL and NextAuth secret:
DATABASE_URL="postgresql://user:password@localhost:5432/reddit_clone?schema=public"
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-secret-key-here"- Set up the database:
npx prisma db push
npx prisma generate- Run the development server:
npm run dev- Open http://localhost:3000 in your browser.
├── app/ # Next.js app directory
│ ├── api/ # API routes
│ │ ├── auth/ # Authentication endpoints
│ │ ├── communities/ # Community endpoints
│ │ ├── posts/ # Post endpoints
│ │ └── comments/ # Comment endpoints
│ ├── r/ # Community pages
│ ├── user/ # User profile pages
│ ├── create-post/ # Create post page
│ ├── create-community/ # Create community page
│ ├── login/ # Login page
│ └── register/ # Register page
├── components/ # React components
│ ├── ui/ # Reusable UI components
│ ├── Header.tsx # Navigation header
│ ├── PostCard.tsx # Post display component
│ └── CommentSection.tsx # Comment thread component
├── lib/ # Utility functions
│ ├── prisma.ts # Prisma client
│ ├── auth.ts # Authentication helpers
│ └── utils.ts # General utilities
├── prisma/ # Database schema
│ └── schema.prisma # Prisma schema
└── types/ # TypeScript type definitions
- User: User accounts with authentication
- Community: Subreddit-like communities
- Post: Posts within communities (text, link, or image)
- Comment: Comments on posts with nested replies
- Vote: Upvotes/downvotes on posts and comments
- Subscription: User subscriptions to communities
POST /api/auth/register- Register new userPOST /api/auth/[...nextauth]- NextAuth endpoints
GET /api/communities- List communities (with search)POST /api/communities- Create communityGET /api/communities/[name]- Get community detailsPOST /api/communities/[name]/subscribe- Subscribe/unsubscribe
GET /api/posts- List posts (optionally filtered by community)POST /api/posts- Create postGET /api/posts/[id]- Get post detailsPOST /api/posts/[id]/vote- Vote on post
GET /api/comments?postId=...- Get comments for a postPOST /api/comments- Create commentPOST /api/comments/[id]/vote- Vote on comment
See DEPLOYMENT.md for detailed deployment instructions.
Option 1: Vercel + Supabase (Recommended - Free)
- Push code to GitHub
- Deploy to Vercel (connects to GitHub)
- Create free database at Supabase
- Add environment variables in Vercel dashboard
- Deploy!
Option 2: Railway (All-in-One)
- Push code to GitHub
- Create project on Railway
- Add PostgreSQL service
- Deploy!
Option 3: Docker (Self-Hosting)
- Use the included
Dockerfileanddocker-compose.yml - Deploy to any VPS (DigitalOcean, AWS, etc.)
- See DEPLOYMENT.md for detailed instructions
DATABASE_URL: PostgreSQL connection stringNEXTAUTH_URL: Your app URL (e.g., http://localhost:3000)NEXTAUTH_SECRET: Secret key for NextAuth (generate withopenssl rand -base64 32)
Contributions are welcome! Please feel free to submit a Pull Request.
MIT