A robust, scalable social media backend server built with Node.js, TypeScript, and PostgreSQL. This project demonstrates a complete implementation of modern backend concepts, from secure authentication to database-level filtering and webhook integration.
- User Management: Complete registration and login system with password hashing (BCrypt).
- Secure Authentication: Dual-token system using JWT (Access Tokens) and Refresh Tokens stored in the database.
- Chirp Engine: Full CRUD operations for "Chirps" with built-in profanity filtering.
- Advanced Filtering: Dynamic sorting (
asc/desc) and author-based filtering implemented directly at the database level. - Webhook Integration: Secure payment processing simulation using Polka Webhooks with API Key authentication.
- Database Excellence: Built with PostgreSQL and Drizzle ORM for type-safe database interactions and migrations.
- Runtime: Node.js
- Language: TypeScript
- Framework: Express.js
- Database: PostgreSQL
- ORM: Drizzle ORM
- Security: JSON Web Tokens (JWT), Dotenv
- Node.js (v18 or higher)
- PostgreSQL installed and running
npmoryarn
-
Clone the repository:
git clone [https://github.com/taima4/Chirpy-Backend-API-) cd chirpy-server -
Install dependencies:
npm install
-
Environment Variables: Create a
.envfile in the root directory and add your configurations:PORT=8080 DATABASE_URL=postgres://user:password@localhost:5432/chirpy JWT_SECRET=your_super_secret_key POLKA_KEY=f271c81ff7084ee5b99a5091b42d486e
-
Database Migration:
npx drizzle-kit push
-
Start the server:
npm run dev
POST /api/users- Register a new userPOST /api/login- Login and receive tokensPOST /api/refresh- Get a new access token using a refresh token
GET /api/chirps- Fetch all chirps (Supports?authorId=UUIDand?sort=asc|desc)POST /api/chirps- Create a new chirp (Requires JWT)DELETE /api/chirps/:id- Delete a chirp (Owner only)
POST /api/polka/webhooks- Secure endpoint for payment notifications (Requires API Key)
- Idempotency: Ensuring webhook handlers can process the same request multiple times safely.
- Middleware: Custom request logging and authentication guards.
- Clean Architecture: Separation of concerns between database queries, route handlers, and business logic.