A Reddit-style API built with Node.js, Express.js, Prisma & PostgreSQL that provides core Reddit functionalities including subreddits, posts, comments, and voting.
- Rate limiting
- Automate Deployments on Push (GitHub Workflow)
- 🔐 Authentication (Register, Login, Password Change)
- 📱 Subreddits (Create, Join, Leave)
- 📝 Posts (Create, Read, Update, Delete)
- 💬 Comments & Replies
- 🔍 Post & Comment Queries
- 🎯 Error Handling
- 🚦 Input Validation
- ⬆️ ⬇️ Voting System (Posts & Comments)
- Node.js >= 18.0.0
- PostgreSQL
- npm or yarn
- Clone the repository:
git clone https://github.com/tphaahla/specdit.git
cd specdit
- Install Dependencies
npm install
- Setup Environment Variables
DATABASE_URL=
JWT_SECRET=
PORT=
- Set up the database: 4.1 Generate Prisma client
npm run build
4.2 Run Migrations
npm run migrate
npm run dev
npm start
POST /api/auth/register
- Register new userPOST /api/auth/login
- Login userPOST /api/auth/logout
- Logout userPATCH /api/auth/change-password
- Change password
POST /api/subreddits
- Create subredditGET /api/subreddits
- Get all subredditsGET /api/subreddits/:id
- Get specific subredditPUT /api/subreddits/:id
- Update subredditDELETE /api/subreddits/:id
- Delete subreddit
POST /api/posts
- Create postGET /api/posts/:id
- Get post with commentsPUT /api/posts/:id
- Update postDELETE /api/posts/:id
- Delete postGET /api/posts/me
- Get current user's postsGET /api/posts/user/:username
- Get user's postsGET /api/posts/votes/me
- Get voted posts
POST /api/posts/:postId/comments
- Create commentGET /api/posts/:postId/comments
- Get post commentsDELETE /api/comments/:id
- Delete comment
POST /api/posts/:postId/vote
- Vote on postPOST /api/comments/:commentId/vote
- Vote on commentGET /api/posts/:postId/votes
- Get post votesGET /api/comments/votes/me
- Get voted comments
POST /api/subscriptions
- Subscribe to subredditDELETE /api/subscriptions/:subredditId
- UnsubscribeGET /api/subscriptions
- Get user subscriptions
The API uses JWT for authentication. Include the token in the Authorization header:
Authorization: Bearer <token>
The API returns consistent error responses:
{
"success": false,
"message": "Error message"
}