Skip to content

taima4/Chirpy-Backend-API-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chirpy Backend API

High-Performance Social Media Backend API

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.

🚀 Features

  • 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.

🛠️ Tech Stack

  • Runtime: Node.js
  • Language: TypeScript
  • Framework: Express.js
  • Database: PostgreSQL
  • ORM: Drizzle ORM
  • Security: JSON Web Tokens (JWT), Dotenv

📋 Prerequisites

  • Node.js (v18 or higher)
  • PostgreSQL installed and running
  • npm or yarn

⚙️ Setup & Installation

  1. Clone the repository:

    git clone [https://github.com/taima4/Chirpy-Backend-API-)
    cd chirpy-server
  2. Install dependencies:

    npm install
  3. Environment Variables: Create a .env file 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
  4. Database Migration:

    npx drizzle-kit push
  5. Start the server:

    npm run dev

🛣️ API Endpoints (Quick Reference)

Authentication

  • POST /api/users - Register a new user
  • POST /api/login - Login and receive tokens
  • POST /api/refresh - Get a new access token using a refresh token

Chirps

  • GET /api/chirps - Fetch all chirps (Supports ?authorId=UUID and ?sort=asc|desc)
  • POST /api/chirps - Create a new chirp (Requires JWT)
  • DELETE /api/chirps/:id - Delete a chirp (Owner only)

Webhooks

  • POST /api/polka/webhooks - Secure endpoint for payment notifications (Requires API Key)

🛡️ Key Concepts Applied

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors