Skip to content

Repository files navigation

Comment Service

A comprehensive comment microservice built with Go and MongoDB, featuring multi-tenant support, moderation workflow, reactions, and real-time notifications.

Features

Core Features

  • Comments & Replies: Nested comments with configurable depth limit
  • Reactions: Like, dislike, love, haha, wow, sad, angry
  • CRUD Operations: Create, read, update, soft delete comments
  • Multi-tenant Support: Isolate comments by tenant (shop, ticket system, blog, etc.)
  • Resource-based: Comments attached to any resource type/ID

Moderation

  • Approval Workflow: Comments can require approval before being visible
  • Bad Words Filter: Configurable list of blocked words
  • Pin Comments: Highlight important comments
  • Rejection Reasons: Track why comments were rejected
  • Bulk Moderation: Approve/reject multiple comments at once

Additional Features

  • Anonymous Comments: Optional anonymous posting
  • Edit History: Track all edits to comments
  • Search: Full-text search across comments
  • Statistics: Get comment counts and metrics
  • Rate Limiting: Prevent spam with configurable limits
  • Notifications: Integration with notifier service

Architecture

comment/
├── cmd/
│ └── main.go # Application entry point
├── config/
│ └── config.go # Configuration management
├── internal/
│ ├── client/
│ │ └── notifier_client.go # Notifier service client
│ ├── database/
│ │ └── mongodb.go # MongoDB connection & indexes
│ ├── handler/
│ │ ├── admin_handler.go # Admin endpoints
│ │ ├── comment_handler.go # Comment CRUD endpoints
│ │ ├── health_handler.go # Health check endpoints
│ │ └── reaction_handler.go # Reaction endpoints
│ ├── middleware/
│ │ ├── auth.go # Authentication middleware
│ │ ├── logging.go # Request logging
│ │ ├── rate_limit.go # Rate limiting
│ │ └── tenant.go # Tenant extraction
│ ├── models/
│ │ ├── comment.go # Domain models
│ │ └── dto.go # Request/Response DTOs
│ ├── repository/
│ │ ├── comment_repository.go # Comment data access
│ │ ├── reaction_repository.go # Reaction data access
│ │ ├── report_repository.go # Report data access
│ │ └── settings_repository.go # Settings data access
│ ├── router/
│ │ └── router.go # HTTP route setup
│ └── usecase/
│ ├── comment_usecase.go # Comment business logic
│ └── reaction_usecase.go # Reaction business logic
├── Dockerfile
├── docker-compose.yml
├── docker-compose.dev.yml
├── Makefile
└── go.mod

API Endpoints

Comments

MethodEndpointDescription
POST/api/v1/commentsCreate a comment
GET/api/v1/commentsList comments
GET/api/v1/comments/:idGet a comment
PUT/api/v1/comments/:idUpdate a comment
DELETE/api/v1/comments/:idDelete a comment
GET/api/v1/comments/:id/repliesGet replies
GET/api/v1/comments/searchSearch comments
GET/api/v1/comments/statsGet statistics

Reactions

MethodEndpointDescription
POST/api/v1/comments/:id/reactionsAdd/update reaction
DELETE/api/v1/comments/:id/reactionsRemove reaction
GET/api/v1/comments/:id/reactions/meGet user's reaction

Admin

MethodEndpointDescription
GET/api/v1/admin/comments/pendingGet pending comments
POST/api/v1/admin/comments/:id/moderateApprove/reject comment
POST/api/v1/admin/comments/:id/pinPin/unpin comment
DELETE/api/v1/admin/comments/:idHard delete comment
POST/api/v1/admin/comments/bulk-moderateBulk moderation

Health

MethodEndpointDescription
GET/healthFull health check
GET/readyReadiness probe
GET/liveLiveness probe

Configuration

Copy .env.example to .env and configure:

# ServerSERVER_PORT=5010# MongoDBMONGODB_URI=mongodb://localhost:27017MONGODB_DATABASE=minisource_comments# Auth ServiceAUTH_SERVICE_URL=http://localhost:5001AUTH_CLIENT_ID=comment-serviceAUTH_CLIENT_SECRET=comment-service-secret-key# ModerationMODERATION_REQUIRE_APPROVAL=trueMODERATION_BAD_WORDS_ENABLED=trueMODERATION_MAX_COMMENT_LENGTH=5000MODERATION_MAX_REPLY_DEPTH=5MODERATION_RATE_LIMIT_PER_MINUTE=10

Development

Prerequisites

  • Go 1.24+
  • MongoDB 7+
  • Docker (optional)

Running Locally

# Install dependencies
go mod download
# Run the service
make run

Docker

Images are published to Docker Hub on every successful build to main.

ImageTags
minisource/commentlatest, commit SHA
# Production (pre-built image)export TAG=latest
docker compose -f docker-compose.prod.yml up -d
# Development
docker compose -f docker-compose.dev.yml up -d

GitHub Actions secrets

  • DOCKERHUB_USERNAME — Docker Hub username
  • DOCKERHUB_TOKEN — Docker Hub access token

Testing

make test

Multi-tenant Usage

Set the tenant in request headers:

X-Tenant-ID: shop-tenant

Or as a query parameter:

GET /api/v1/comments?tenant_id=shop-tenant&resource_type=product&resource_id=123

Example Requests

Create Comment

curl -X POST http://localhost:5010/api/v1/comments \
-H "Authorization: Bearer <token>" \
-H "X-Tenant-ID: shop" \
-H "Content-Type: application/json" \
-d '{ "resource_type": "product", "resource_id": "product-123", "content": "Great product!", "rating": 5 }'

Add Reaction

curl -X POST http://localhost:5010/api/v1/comments/abc123/reactions \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{ "type": "like" }'

Moderate Comment

curl -X POST http://localhost:5010/api/v1/admin/comments/abc123/moderate \
-H "Authorization: Bearer <admin-token>" \
-H "Content-Type: application/json" \
-d '{ "status": "approved" }'

License

MIT

About

Comment service for user-generated comments and moderation

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages