Skip to content

Simple CRUD based social media application users can create post, comment and follow each other.

Notifications You must be signed in to change notification settings

iamonah/gosocial

Repository files navigation

A Simple CRUD Social Networking API

GoSocial is a lightweight, modular social networking backend built with Go, featuring:

  • 🚀 RESTful API with Swagger documentation
  • ⚙️ Chi router for clean, fast routing
  • 🧠 Redis caching for performance
  • 🗄️ PostgreSQL (via Docker) for reliable data persistence
  • 📨 Email verification system
  • 🧩 Graceful shutdown and structured logging
  • ☁️ Deployable to Google App Engine (GAE)

📚 Features

User Management

  • Register, login, activate accounts via email
  • JWT-based authentication and authorization

Post Management

  • Create, update, and delete posts
  • Support for tags and versioning

Comments

  • Add comments to posts
  • Retrieve comments for a post

Feeds

  • View personalized feed:

    • Your own posts
    • Posts from users you follow

Follow System

  • Follow or unfollow other users
  • Feed updates automatically reflect follow relationships

Caching

  • Frequently accessed posts and feeds cached in Redis

Swagger API Docs

  • Auto-generated via swaggo/swag
  • Viewable in the browser at api/v1/swagger/

🧱 Tech Stack

Component Technology
Language Go (v1.23+)
Web Framework Chi Router
Database PostgreSQL (via Docker)
Cache Redis
Documentation Swagger (swaggo/swag)
Logging Uber Zap
Deployment Google App Engine
CI/CD GitHub Actions (optional)

⚙️ Environment Setup

Before running the application, export the following environment variables:

export PORT=8080
export SOCIAL_NETWORK_DB_DSN=postgres://admin:admin123@localhost/socialnetwork?sslmode=disable
export DB_MAX_OPEN_CONNS=30
export DB_MAX_IDLE_CONNS=30
export DB_MAX_IDLE_TIME=15m

export EXTERNAL_URL=localhost:8080
export ENV=development

# smtp Config (replace SMTP credentials)
export [email protected]
export SMTP_PORT=2525
export SMTP_HOST=sandbox.smtp.mailtrap.io
export USERNAME=your_mailtrap_username
export PASSWORD=your_mailtrap_password

# jwt Config
export AUTH_TOKEN_SECRET=supersecretkey
export AUD=social
export ISS=social
export EXP=3

💡 Remember to replace the SMTP credentials and email with your own before running.


🐘 Running PostgreSQL with Docker

If you don’t have PostgreSQL installed locally, you can spin it up easily with Docker:

docker run --name social-postgres \
  -e POSTGRES_USER=admin \
  -e POSTGRES_PASSWORD=admin123 \
  -e POSTGRES_DB=socialnetwork \
  -p 5432:5432 \
  -d postgres:16

Once it’s running, verify the connection:

psql postgres://admin:admin123@localhost:5432/socialnetwork

Then run your migrations (if applicable) or let your app auto-migrate on startup.


🚀 Running Redis (Optional)

For caching (if Redis is not already running):

docker run --name social-redis -p 6379:6379 -d redis:7

📘 API Documentation

Swagger docs are automatically generated from your Go annotations.

To regenerate docs after changes:

make gen/docs

☁️ Deployment (Google App Engine)

You can deploy this app to Google App Engine Standard or Flexible Environment.

Example app.yaml:

runtime: go123
env: standard
entrypoint: ./server
env_variables:
  PORT: 8080
  SOCIAL_NETWORK_DB_DSN: postgres://admin:admin123@/cloudsql/YOUR_INSTANCE_CONNECTION_NAME/socialnetwork
  AUTH_TOKEN_SECRET: supersecretkey
  ENV: production

Then deploy:

gcloud app deploy

🧾 License

This project is licensed under the MIT License

About

Simple CRUD based social media application users can create post, comment and follow each other.

Resources

Stars

Watchers

Forks

Packages

No packages published