A Reddit-like application built with Go, providing a REST API for managing threads, posts, and comments.
- π Create and manage discussion threads
- π¬ Create posts within threads
- π¨οΈ Add comments to posts
- π Voting system for posts and comments
- π RESTful API endpoints
- ποΈ PostgreSQL database integration
This application follows a clean architecture pattern with:
- Domain Models: Core entities (Thread, Post, Comment) defined in
goreddit.go - Store Layer: Database operations with interfaces for easy testing
- Web Layer: HTTP handlers using Chi router
- Database: PostgreSQL with migrations
- Language: Go 1.25.2
- Web Framework: Chi v5 (HTTP router)
- Database: PostgreSQL
- Database Driver: lib/pq
- Query Builder: sqlx
- ID Generation: Google UUID
βββ cmd/
β βββ main.go # Application entry point
βββ migrations/
β βββ 01_create_tables.up.sql # Database schema
β βββ 01_create_tables.down.sql # Rollback migrations
βββ stores/
β βββ store.go # Store interface implementations
β βββ thread_store.go # Thread database operations
β βββ post_store.go # Post database operations
β βββ comment_store.go # Comment database operations
βββ web/
β βββ handler.go # HTTP request handlers
βββ goreddit.go # Domain models and interfaces
βββ go.mod # Go module dependencies
βββ Makefile # Build and development commands
- Go 1.25.2 or later
- PostgreSQL
- Docker (optional, for running PostgreSQL)
- golang-migrate (for database migrations)
git clone https://github.com/pnlinh/goreddit.git
cd goredditgo mod downloadUsing Docker:
make dbOr start your own PostgreSQL instance with:
- Host: localhost
- Port: 5432
- Database: postgres
- Username: postgres
- Password: secret
make migrate.upgo run cmd/main.goThe server will start on http://localhost:8081
GET /threads- List all threadsPOST /threads- Create a new thread- Form parameters:
title,description
- Form parameters:
DELETE /threads/{id}- Delete a thread by ID
A Yaak REST client collection is provided in rest/yaak.goreddit.json with pre-configured requests for testing all API endpoints.
To use the collection:
- Install Yaak REST Client
- Import the collection file:
File > Import > rest/yaak.goreddit.json - The collection includes sample requests for:
- Creating threads
- Listing threads
- Deleting threads
The collection is configured to work with the default server running on http://localhost:8081.
The application uses three main tables:
-
threads: Discussion topics
id(UUID, Primary Key)title(Text)description(Text)
-
posts: Posts within threads
id(UUID, Primary Key)thread_id(UUID, Foreign Key)title(Text)content(Text)votes(Integer)
-
comments: Comments on posts
id(UUID, Primary Key)post_id(UUID, Foreign Key)content(Text)votes(Integer)
make db # Run PostgreSQL in Docker
make adminer # Run Adminer database management tool
make migrate.up # Apply database migrations
make migrate.down # Rollback database migrations
make dev # Run with live reload (requires air)For development with live reload, install air:
go install github.com/cosmtrek/air@latestThen run:
make devRun the test suite with:
go test ./...You can use Adminer to manage your database:
make adminerThen visit http://localhost:8080 and connect with:
- System: PostgreSQL
- Server: localhost
- Username: postgres
- Password: secret
- Database: postgres
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is open source and available under the MIT License.
- Add authentication and user management
- Implement post and comment endpoints
- Add voting functionality
- Add pagination for list endpoints
- Add input validation and error handling
- Add comprehensive test coverage
- Add API documentation (OpenAPI/Swagger)
- Add Docker support for the application
- Add CI/CD pipeline