Chirpy is a robust backend API for a social network application similar to Twitter. This project demonstrates the implementation of a scalable web server using TypeScript and modern Node.js practices, focusing on type safety, database management and secure authentication.
- Language: TypeScript
- Runtime: Node.js
- Framework: Express.js
- Database: PostgreSQL
- ORM: Drizzle ORM (with
drizzle-kitfor migrations) - Authentication: JWT, Argon2
- Testing: Vitest
- Tooling: npm
- User Authentication: Secure signup and login flows using Argon2 for password hashing and JWTs (JSON Web Tokens) for session management. Includes refresh token rotation and revocation strategies.
- Chirps (Posts): Full CRUD (Create, Read, Update, Delete) capabilities for user posts, known as "chirps".
- Membership Tiering: Integration with webhooks to handle premium user upgrades ("Chirpy Red").
- Admin Tools: Dedicated endpoints for system metrics and database management (reset functionality for development).
- Database Management: Utilizes PostgreSQL with Drizzle ORM for type-safe database interactions and schema migrations.
- Middleware: Custom middleware for request logging, error handling, and metric tracking.
Building Chirpy provided deep insights into backend development:
- Architecting a RESTful API: Designed and implemented a clean, RESTful API structure separating concerns between routing, controllers, and database logic.
- TypeScript Mastery: Leveraged TypeScript's static typing to catch errors early and ensure type safety across the entire application, from database models to API responses.
- Database Integration: Gained hands-on experience with PostgreSQL and Drizzle ORM, including defining schemas, running migrations, and writing complex queries.
- Security Best Practices: Implemented industry-standard security measures, including password hashing with Argon2 and stateless authentication using JWTs.
- Webhook Integration: Handled external events via webhooks to simulate real-world payment processing and user status updates.
- Testing: Wrote comprehensive unit and integration tests using Vitest to ensure code reliability and prevent regressions.
- Node.js (v20+ recommended)
- npm
- PostgreSQL database
-
Clone the repository:
git clone https://github.com/yourusername/chirpy.git cd chirpy -
Install dependencies:
npm install
-
Set up environment variables: Create a
.envfile in the root directory with the following variables:PORT=8080 PLATFORM=dev DB_URL=postgres://user:password@localhost:5432/chirpy SECRET=your_jwt_secret_key POLKA_KEY=your_mock_payment_api_key
-
Run database migrations:
npm run migrate
-
Development Mode (with hot reload):
npm run dev
-
Production Build:
npm run build npm start
-
Run Tests:
npm test
POST /api/login: Authenticate a user.POST /api/users: Create a new user.PUT /api/users: Update user details.POST /api/refresh: Refresh an access token.POST /api/revoke: Revoke a refresh token.
GET /api/chirps: Retrieve all chirps (optional sorting).GET /api/chirps/:chirpId: Retrieve a specific chirp.POST /api/chirps: Create a new chirp.DELETE /api/chirps/:chirpId: Delete a chirp.
POST /api/polka/webhooks: Handle events from Polka (payment provider).
GET /admin/metrics: View server metrics.POST /admin/reset: Reset the database (dev only).
This project was built as part of the backend engineering curriculum at Boot.dev.