Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Reddit Clone

A fully functional Reddit-style clone built in Go, featuring a high-performance server and a command-line client.
This project demonstrates modern backend design patterns, concurrency handling, and a modular API system — all without external databases.


✨ Features

  • 🔐 User System: Register, join/leave subreddits, track karma
  • 🌐 Subreddits: Create, subscribe, and manage communities
  • 📝 Posts & Comments: Threaded discussions with upvotes/downvotes
  • 💬 Direct Messaging: Send and reply to DMs with threads
  • 📰 Personalized Feed: Ranked feed based on subreddit subscriptions
  • 📊 Metrics: Real-time server performance stats (posts, comments, memory, requests/sec)
  • Concurrency & Rate Limiting: Built using Go’s sync primitives and token-bucket rate limiter
  • 🖥️ Simulation Mode: Generate activity with multiple simulated clients

🛠️ Tech Stack

  • Language: Go 1.21+
  • Server: Go HTTP server with actor-style state management
  • Client: CLI tool with colored output
  • Libraries:

📂 Project Structure

redditclone/
├── client.go         # CLI client (separate binary)
├── main.go           # Server (separate binary)
├── go.mod            # Go module
├── config.json       # Optional — server config (falls back to defaults if missing)
├── subscriptions.json # Created by client — local subscription cache
├── Readme.md         # This file
└── REPO_DEEP_DIVE.md # Technical deep dive for engineers

⚙️ Setup & Installation

  1. Clone the repository

    git clone https://github.com/yourusername/redditclone.git
    cd redditclone
  2. Install dependencies

    go mod tidy
  3. Run the server

    go run main.go
    • Default port: 8080
    • Optional config.json in project root (port, rate limit, log level, etc.)
    • Graceful shutdown on SIGINT/SIGTERM; writes final_metrics.json on exit
  4. Run the client

    go run client.go -action=help
    • Server must be running at http://localhost:8080

Build binaries:

go build -o server main.go
go build -o client client.go

📌 Client Usage Examples

Action Command
Register user go run client.go -action=register -username=alice
Create subreddit go run client.go -action=create_sub -subname=golang
Join subreddit go run client.go -action=join_sub -username=alice -subname=golang
Leave subreddit go run client.go -action=leave_sub -username=alice -subname=golang
Create post go run client.go -action=post -username=alice -subname=golang -title="Hello Go" -content="Excited!"
Comment go run client.go -action=comment -username=alice -post_id=1 -content="Nice post!"
Vote (upvote/downvote) go run client.go -action=vote -voter=alice -target_type=post -target_id=1 -vote_type=upvote
Get karma go run client.go -action=get_karma -username=alice
View feed go run client.go -action=feed -username=alice
Send DM go run client.go -action=dm -from=alice -to=bob -content="Hi!"
Reply to DM go run client.go -action=reply_dm -from=bob -to=alice -content="Hello!" -original_dm_id=1
List DMs go run client.go -action=list_dm -username=alice
Server metrics go run client.go -action=metrics
Simulate load go run client.go -action=simulate -simulate_clients=5 -actions_per_client=10

⚙️ Configuration

Optional config.json in the project root:

{
  "port": 8080,
  "rate_limit": 100.0,
  "rate_burst": 200,
  "log_level": "info",
  "metrics_update_interval": "10s",
  "request_timeout": "5s",
  "shutdown_grace_period": "10s"
}

Server flag: -config=config.json (config path).


📊 Metrics & Monitoring

HTTP endpoint:

curl http://localhost:8080/metrics

Example fields: total posts, comments, DMs, subreddits; active users; subreddit stats; karma distribution; requests/sec; memory usage; avg/max response times; rate limit exceeded count.

On graceful shutdown, metrics are also written to final_metrics.json.


📜 License

This project is licensed under the MIT License. Feel free to use, modify, and distribute.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages