Skip to content

HellYeahOmg/Chirpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chirpy

A Twitter-like social media API built with Go, PostgreSQL, and JWT authentication.

Features

  • User registration and authentication
  • JWT-based authentication with refresh tokens
  • Create, read, and delete chirps (posts)
  • User profile updates
  • Webhook integration with Polka payment system
  • Admin metrics and reset functionality
  • Profanity filtering for chirps

API Endpoints

Health Check

  • GET /api/healthz - Health check endpoint

User Management

  • POST /api/users - Create a new user
  • PUT /api/users - Update user profile (authenticated)
  • POST /api/login - User login
  • POST /api/refresh - Refresh JWT token
  • POST /api/revoke - Revoke refresh token

Chirps

  • POST /api/chirps - Create a new chirp (authenticated)
  • GET /api/chirps - Get all chirps
  • GET /api/chirps/{chirpId} - Get a specific chirp
  • DELETE /api/chirps/{chirpId} - Delete a chirp (authenticated, owner only)

Admin

  • GET /admin/metrics - View server metrics
  • POST /admin/reset - Reset server metrics and users

Webhooks

  • POST /api/polka/webhooks - Handle Polka payment webhooks

Static Files

  • /app/ - Serve static web application files
  • /app/assets - Serve static assets

Tech Stack

  • Language: Go 1.24.5
  • Database: PostgreSQL
  • Authentication: JWT tokens with refresh token support
  • Password Hashing: bcrypt
  • Database Migrations: Goose
  • Database Queries: SQLC

Dependencies

  • github.com/golang-jwt/jwt/v5 - JWT token handling
  • github.com/google/uuid - UUID generation
  • github.com/joho/godotenv - Environment variable loading
  • github.com/lib/pq - PostgreSQL driver
  • golang.org/x/crypto - Cryptographic functions

Setup

  1. Clone the repository

    git clone https://github.com/HellYeahOmg/Chirpy.git
    cd Chirpy
  2. Install dependencies

    go mod download
  3. Set up environment variables Create a .env file in the root directory:

    DB_URL=postgres://username:password@localhost:5432/chirpy?sslmode=disable
    JWT_SECRET=your-jwt-secret-key
    POLKA_KEY=your-polka-webhook-key
  4. Set up the database Run the database migrations using Goose:

    goose -dir sql/schema postgres "your-db-url" up
  5. Run the server

    go run .

The server will start on port 8080.

Database Schema

The application uses PostgreSQL with the following main tables:

  • users: User accounts with email, password hash, and Chirpy Red status
  • chirps: User posts with body text and author reference
  • refresh_tokens: JWT refresh tokens with expiration

Authentication

The API uses JWT tokens for authentication:

  • Access tokens for API requests (short-lived)
  • Refresh tokens for obtaining new access tokens (longer-lived)
  • Passwords are hashed using bcrypt

Development

The project structure follows Go best practices:

  • internal/handlers/ - HTTP handlers
  • internal/database/ - Database queries and models (generated by SQLC)
  • sql/schema/ - Database migration files
  • sql/queries/ - SQL query files

License

This project is part of a learning exercise and is not intended for production use.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published