Skip to content
karprabhaPublic

About

A Twitter-like social media API built with Go that allows users to create accounts, authenticate, and post short messages called "chirps".

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

26 Commits

Folders and files

Repository files navigation

Chirpy 🐦

A Twitter-like social media API built with Go that allows users to create accounts, authenticate, and post short messages called "chirps".

Features

  • 🔐 User Authentication - JWT-based authentication with refresh tokens
  • 📝 Chirp Management - Create, read, and delete chirps (max 140 characters)
  • 🔍 Content Filtering - Automatic profanity filtering
  • 👑 Premium Features - Chirpy Red subscription via webhooks
  • 📊 Admin Dashboard - Metrics and system management
  • 🗄️ PostgreSQL Database - Robust data persistence with migrations
  • 🚀 RESTful API - Clean HTTP API design

Tech Stack

  • Language: Go 1.24.4
  • Database: PostgreSQL
  • ORM: sqlc for type-safe SQL queries
  • Authentication: JWT tokens with bcrypt password hashing
  • Migrations: Goose for database schema management
  • Environment: dotenv for configuration

Quick Start

Prerequisites

  • Go 1.24.4 or higher
  • PostgreSQL database
  • Environment variables configured

Installation

  1. Clone the repository:
git clone https://github.com/karprabha/chirpy.git
cd chirpy
  1. Install dependencies:
go mod download
  1. Set up environment variables:
# Create a .env file in the root directory
DB_URL=postgres://username:password@localhost:5432/chirpy_db?sslmode=disable
JWT_SECRET=your-secret-key-here
POLKA_KEY=your-polka-webhook-key
PLATFORM=dev
  1. Run database migrations:
goose -dir sql/schema postgres "postgres://username:password@localhost/gator?sslmode=disable" up
  1. Start the server:
go run cmd/server/main.go

The server will start on port 8080.

API Documentation

Comprehensive API documentation is available in the /docs folder:

Project Structure

chirpy/
├── cmd/server/          # Application entry point
├── internal/
│   ├── auth/           # Authentication utilities
│   ├── config/         # Configuration management
│   ├── database/       # Database models and queries
│   ├── handler/        # HTTP handlers
│   └── middleware/     # HTTP middleware
├── sql/
│   ├── queries/        # SQL queries for sqlc
│   └── schema/         # Database migrations
├── docs/               # API documentation
└── assets/             # Static assets

Database Schema

The application uses PostgreSQL with the following main tables:

  • users - User accounts with authentication
  • chirps - User posts/messages
  • refresh_tokens - JWT refresh token management

Authentication

Chirpy uses JWT tokens for authentication:

  • Access tokens - Short-lived (1 hour) for API access
  • Refresh tokens - Long-lived (60 days) for token renewal
  • Password hashing - bcrypt for secure password storage

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

API Base URL

When running locally: http://localhost:8080

Health Check

Test if the server is running:

curl http://localhost:8080/api/healthz

Support

For questions or issues, please open an issue on GitHub.

About

A Twitter-like social media API built with Go that allows users to create accounts, authenticate, and post short messages called "chirps".

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages