A comprehensive comment microservice built with Go and MongoDB, featuring multi-tenant support, moderation workflow, reactions, and real-time notifications.
- 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
- 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
- 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
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
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/comments | Create a comment |
| GET | /api/v1/comments | List comments |
| GET | /api/v1/comments/:id | Get a comment |
| PUT | /api/v1/comments/:id | Update a comment |
| DELETE | /api/v1/comments/:id | Delete a comment |
| GET | /api/v1/comments/:id/replies | Get replies |
| GET | /api/v1/comments/search | Search comments |
| GET | /api/v1/comments/stats | Get statistics |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/comments/:id/reactions | Add/update reaction |
| DELETE | /api/v1/comments/:id/reactions | Remove reaction |
| GET | /api/v1/comments/:id/reactions/me | Get user's reaction |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/admin/comments/pending | Get pending comments |
| POST | /api/v1/admin/comments/:id/moderate | Approve/reject comment |
| POST | /api/v1/admin/comments/:id/pin | Pin/unpin comment |
| DELETE | /api/v1/admin/comments/:id | Hard delete comment |
| POST | /api/v1/admin/comments/bulk-moderate | Bulk moderation |
| Method | Endpoint | Description |
|---|---|---|
| GET | /health | Full health check |
| GET | /ready | Readiness probe |
| GET | /live | Liveness probe |
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- Go 1.24+
- MongoDB 7+
- Docker (optional)
# Install dependencies
go mod download
# Run the service
make runImages are published to Docker Hub on every successful build to main.
| Image | Tags |
|---|---|
minisource/comment | latest, 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 -dDOCKERHUB_USERNAME— Docker Hub usernameDOCKERHUB_TOKEN— Docker Hub access token
make testSet 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
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 }'curl -X POST http://localhost:5010/api/v1/comments/abc123/reactions \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{ "type": "like" }'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" }'MIT