A modern social platform backend - Think Twitter/X, but built with Go!
Comment API is a REST API service built with Go and Vue that powers a social media platform similar to Twitter/X. Users can register, create posts with file attachments, engage with content through comments, and administrators can moderate the entire ecosystem.
- π Secure Authentication - JWT-based auth with bcrypt password hashing
- π Social Posting - Create, edit, and delete posts with file attachments
- π¬ Interactive Comments - Full CRUD operations on comments with nested discussions
- π₯ Role-Based Access - User and Admin roles with different permissions
- π File Management - Upload and manage attachments (images, PDFs, documents)
- π Admin Dashboard - Comprehensive moderation tools and analytics
- π Advanced Filtering - Search and filter by user, date, and content
- π Pagination - Efficient data loading with page-based navigation
comment-api/
βββ π .github/ # GitHub workflows
βββ π cmd/
β βββ app/
β βββ main.go # Application entry point
βββ π db/ # Database configurations
βββ π frontend/ # Frontend written in Vue
βββ π internal/
β βββ π repo/ # Repository layer (Data Access)
β β βββ comment/
β β βββ post/
β β βββ token/
β β βββ user/
β βββ π rest/ # REST API handlers
β β βββ π handler/ # HTTP request handlers
β β β βββ comment/
β β β βββ health/
β β β βββ post/
β β β βββ token/
β β β βββ user/
β β βββ π middleware/ # HTTP middleware
β β βββ middleware.go
β βββ π service/ # Business logic layer
β βββ comment/
β βββ post/
β βββ token/
β βββ user/
βββ π pkg/ # Shared packages
β βββ π db/ # Database utilities
β βββ π errs/ # Error definitions
β βββ π logger/ # Logging utilities
β βββ π types/ # Common types
β βββ π utils/ # Utility functions
βββ π .env # Environment variables
βββ π .env.example # Environment template
βββ π .gitignore # Git ignore rules
βββ π .golangci.yml # Linter configuration
βββ π api.log # Application logs
βββ π coverage.out # Test coverage report
βββ π coverage.out.mods # Coverage modifications
βββ π docker-compose.yml # Docker compose config
βββ π go.mod # Go module dependencies
βββ π go.sum # Go module checksums
βββ π README.md # Project documentation
| Component | Technology |
|---|---|
| Language | Go 1.24.2 |
| Framework | Gin |
| Database | PostgreSQL |
| DB Driver | pgx with raw SQL |
| Authentication | JWT + bcrypt |
| File Storage | Upload Care |
- Go 1.20 or higher
- PostgreSQL 12+
- Git
- Docker
- Node.js LTS (for frontend development)
- Upload Care account (for file storage)
-
Clone the repository
git clone https://github.com/hc-b666/twitter-api.git cd twitter-api -
Set up environment variables
cp .env.example .env # Edit .env with your upload care credentials -
Install dependencies
go mod download
-
Start the server
go run cmd/main.go
The server will start on http://localhost:9999 π
Base URL:
/api/v1
GET /api/v1/health # Health check
POST /api/v1/create-admin # Create admin user (setup)POST /api/v1/auth/register # User registration
POST /api/v1/auth/login # User login
POST /api/v1/auth/refresh # Refresh JWT tokenGET /api/v1/user/:userID # Get user by ID
GET /api/v1/user/profile # Get current user profileGET /api/v1/posts # Get all posts
GET /api/v1/posts/u/:userID # Get posts by specific user
GET /api/v1/posts/:postID # Get specific post
POST /api/v1/posts # Create new post
PUT /api/v1/posts/:postID # Update existing post
POST /api/v1/posts/:postID # Soft delete postGET /api/v1/comments/:postID # Get all comments for a post
GET /api/v1/comments/u/:userID # Get comments by specific user
POST /api/v1/comments/:postID # Create new comment on post
PUT /api/v1/comments/:commentID # Update existing comment
POST /api/v1/comments/delete/:commentID # Soft delete commentGET /api/v1/admin/users # Get all users
GET /api/v1/admin/comments # Get all comments
DELETE /api/v1/admin/comment/:commentID # Hard delete comment
DELETE /api/v1/admin/post/:postID # Hard delete postAll protected endpoints require JWT token in the Authorization header:
Authorization: Bearer <your_jwt_token>- π€ User: Can create, edit, and delete own content
- π¨βπΌ Admin: Full access to all content and moderation tools
curl -X POST http://localhost:9999/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "securepass123"
}'UPLOADCARE_PUBLIC_KEY=your_public_key
UPLOADCARE_SECRET_KEY=your_secret_keyWe welcome contributions! Here's how you can help:
- π΄ Fork the repository
- πΏ Create a feature branch (
git checkout -b feature/amazing-feature) - πΎ Commit your changes (
git commit -m 'Add amazing feature') - π€ Push to the branch (
git push origin feature/amazing-feature) - π Open a Pull Request
This project was developed by a dedicated team of 2 contributors:
- Muhammadbobur - Full-Stack Developer & Architecture
- Nazokat - Backend Development & Testing
This project is licensed under the MIT License - see the LICENSE file for details.
Having issues? We're here to help!
- π Bug Reports: Create an issue
- π‘ Feature Requests: Submit a feature request
- π§ Contact: bobur0218programmer@gmail.com
Built with β€οΈ using Vue and Go
β Star this repo if you found it helpful! β