A modern social media API built with Go, featuring posts, comments, followers, and real-time interactions.
- π High Performance: Built with Go for optimal performance
- π JWT Authentication: Secure user authentication and authorization
- π Posts & Comments: Full CRUD operations for social content
- π₯ Follow System: User following and follower relationships
- π Real-time Feed: Dynamic content feeds based on user interests
- π Pagination: Efficient data pagination for large datasets
- π·οΈ Tags: Content tagging and filtering system
- π³ Docker Ready: Fully containerized with Docker support
- π Monitoring: Health checks and observability features
- Language: Go 1.24.1
- Framework: Chi Router v5
- Database: PostgreSQL with migrations
- Authentication: JWT tokens
- Logging: Uber Zap
- Validation: Go Playground Validator
- Testing: Testify
- Containerization: Docker & Docker Compose
- Go 1.24.1 or higher
- PostgreSQL 14+
- Docker (optional)
-
Clone the repository
git clone https://github.com/yusuf-cirak/social-go.git cd social-go -
Set up environment variables
cp .envrc.example .envrc # Edit .envrc with your configuration source .envrc
-
Install dependencies
go mod download
-
Run database migrations
make migrate-up
-
Start the application
go run cmd/api/main.go
-
Build and run with Docker Compose
docker-compose up --build
-
Access the API
http://localhost:8080
GET /v1/healthPOST /v1/auth/register # Register new user
POST /v1/auth/login # Login user
POST /v1/auth/logout # Logout userGET /v1/users/{id} # Get user profile
PUT /v1/users/{id} # Update user profile
DELETE /v1/users/{id} # Delete user accountGET /v1/posts # Get posts feed
POST /v1/posts # Create new post
GET /v1/posts/{id} # Get specific post
PUT /v1/posts/{id} # Update post
DELETE /v1/posts/{id} # Delete postGET /v1/posts/{id}/comments # Get post comments
POST /v1/posts/{id}/comments # Add comment
PUT /v1/comments/{id} # Update comment
DELETE /v1/comments/{id} # Delete commentPOST /v1/users/{id}/follow # Follow user
DELETE /v1/users/{id}/follow # Unfollow user
GET /v1/users/{id}/followers # Get followers
GET /v1/users/{id}/following # Get following# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run tests with race detection
go test -race ./...# Create new migration
make migrate-create name=your_migration_name
# Run migrations
make migrate-up
# Rollback migrations
make migrate-down 1# Run linter
golangci-lint run
# Format code
go fmt ./...
# Security scan
gosec ./...The application uses PostgreSQL with the following main tables:
- users: User accounts and profiles
- posts: User posts with content and metadata
- comments: Comments on posts
- followers: User follow relationships
- tags: Content tags and associations
See cmd/migrate/migrations/ for detailed schema definitions.
Configuration is managed through environment variables:
# Server
PORT=8080
HOST=localhost
# Database
DB_ADDR=postgres://user:password@localhost/dbname?sslmode=disable
# JWT
JWT_SECRET=your-secret-key
JWT_EXPIRES_IN=24h
# Rate Limiting
RATE_LIMIT_ENABLED=true
RATE_LIMIT_RPS=10
RATE_LIMIT_BURST=20# Build image
docker build -t social-go .
# Run container
docker run -p 8080:8080 social-godocker-compose up -d- Use PostgreSQL in production
- Set up proper SSL/TLS termination
- Configure rate limiting appropriately
- Set up monitoring and logging
- Use container orchestration (Kubernetes/Docker Swarm)
- Fork the repository
- Create your 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
Please read our Contributing Guidelines for details.
- Unit Tests: Test individual functions and methods
- Integration Tests: Test API endpoints and database interactions
- Security Tests: Automated security scanning with CodeQL and Gosec
- Performance Tests: Load testing and benchmarks
- Health check endpoints
- Structured logging with Zap
- Error tracking and reporting
- Performance metrics
- JWT-based authentication
- Rate limiting to prevent abuse
- Input validation and sanitization
- SQL injection prevention
- Security headers
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or need help, please:
- Check the Issues page
- Create a new issue using the appropriate template
- Contact the maintainers
See Releases for a detailed changelog.
Made with β€οΈ by Yusuf Cirak