Skip to content

Latest commit

Β 

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ Small Social Media

A modern social platform backend - Think Twitter/X, but built with Go!

Go Version PostgreSQL JWT License Vue.js

πŸš€ Overview

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.

✨ Key Features

  • πŸ” 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

πŸ—οΈ Architecture

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

πŸ› οΈ Tech Stack

Component Technology
Language Go 1.24.2
Framework Gin
Database PostgreSQL
DB Driver pgx with raw SQL
Authentication JWT + bcrypt
File Storage Upload Care

🚦 Getting Started

Prerequisites

  • Go 1.20 or higher
  • PostgreSQL 12+
  • Git
  • Docker
  • Node.js LTS (for frontend development)
  • Upload Care account (for file storage)

Installation

  1. Clone the repository

    git clone https://github.com/hc-b666/twitter-api.git
    cd twitter-api
  2. Set up environment variables

    cp .env.example .env
    # Edit .env with your upload care credentials
  3. Install dependencies

    go mod download
  4. Start the server

    go run cmd/main.go

The server will start on http://localhost:9999 πŸŽ‰

πŸ“‘ API Endpoints

Base URL: /api/v1

πŸ”§ Public Endpoints

GET  /api/v1/health                # Health check
POST /api/v1/create-admin          # Create admin user (setup)

πŸ” Authentication (/auth)

POST /api/v1/auth/register         # User registration
POST /api/v1/auth/login            # User login
POST /api/v1/auth/refresh          # Refresh JWT token

πŸ‘¨β€πŸ’Ό User Management (/user) πŸ”’

GET /api/v1/user/:userID           # Get user by ID
GET /api/v1/user/profile           # Get current user profile

πŸ“ Posts Management (/posts) πŸ”’

GET  /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 post

πŸ’¬ Comments System (/comments) πŸ”’

GET  /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 comment

πŸ›‘οΈ Admin Panel (/admin) πŸ”’πŸ‘‘

GET    /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 post

πŸ”‘ Authentication

All protected endpoints require JWT token in the Authorization header:

Authorization: Bearer <your_jwt_token>

User Roles

  • πŸ‘€ User: Can create, edit, and delete own content
  • πŸ‘¨β€πŸ’Ό Admin: Full access to all content and moderation tools

πŸ“‹ Request/Response Examples

Register New User

curl -X POST http://localhost:9999/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "john@example.com", 
    "password": "securepass123"
  }'

Environment Variables

UPLOADCARE_PUBLIC_KEY=your_public_key
UPLOADCARE_SECRET_KEY=your_secret_key

🀝 Contributing

We welcome contributions! Here's how you can help:

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/amazing-feature)
  3. πŸ’Ύ Commit your changes (git commit -m 'Add amazing feature')
  4. πŸ“€ Push to the branch (git push origin feature/amazing-feature)
  5. πŸ”„ Open a Pull Request

πŸ‘₯ Contributors

This project was developed by a dedicated team of 2 contributors:

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“ž Support

Having issues? We're here to help!


Built with ❀️ using Vue and Go

⭐ Star this repo if you found it helpful! ⭐

About

πŸ’¬ Small social media app made for Alif course project

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Used by

Contributors

Languages