A Twitter-like social media API built with Go, PostgreSQL, and JWT authentication.
- 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
GET /api/healthz- Health check endpoint
POST /api/users- Create a new userPUT /api/users- Update user profile (authenticated)POST /api/login- User loginPOST /api/refresh- Refresh JWT tokenPOST /api/revoke- Revoke refresh token
POST /api/chirps- Create a new chirp (authenticated)GET /api/chirps- Get all chirpsGET /api/chirps/{chirpId}- Get a specific chirpDELETE /api/chirps/{chirpId}- Delete a chirp (authenticated, owner only)
GET /admin/metrics- View server metricsPOST /admin/reset- Reset server metrics and users
POST /api/polka/webhooks- Handle Polka payment webhooks
/app/- Serve static web application files/app/assets- Serve static assets
- Language: Go 1.24.5
- Database: PostgreSQL
- Authentication: JWT tokens with refresh token support
- Password Hashing: bcrypt
- Database Migrations: Goose
- Database Queries: SQLC
github.com/golang-jwt/jwt/v5- JWT token handlinggithub.com/google/uuid- UUID generationgithub.com/joho/godotenv- Environment variable loadinggithub.com/lib/pq- PostgreSQL drivergolang.org/x/crypto- Cryptographic functions
-
Clone the repository
git clone https://github.com/HellYeahOmg/Chirpy.git cd Chirpy -
Install dependencies
go mod download
-
Set up environment variables Create a
.envfile 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
-
Set up the database Run the database migrations using Goose:
goose -dir sql/schema postgres "your-db-url" up -
Run the server
go run .
The server will start on port 8080.
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
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
The project structure follows Go best practices:
internal/handlers/- HTTP handlersinternal/database/- Database queries and models (generated by SQLC)sql/schema/- Database migration filessql/queries/- SQL query files
This project is part of a learning exercise and is not intended for production use.