Sign inSign up

peekaboo51490/emart-rating-service

By peekaboo51490

•Updated 6 months ago

Rating Service

Image
API management
0

375

peekaboo51490/emart-rating-service repository overview

⁠Rating Service

A production-ready NestJS microservice for handling product ratings in e-commerce systems.

⁠Features

  • Product Rating API: Add and retrieve product ratings (0.1-5 range)
  • Precomputed Aggregates: Optimized read performance with summary tables
  • Observability: Health checks, Prometheus metrics, structured logging with traceId/spanId
  • Security: Helmet headers, CORS configuration, input validation
  • Documentation: Swagger/OpenAPI integration

⁠Quick Start

⁠Using Docker Compose
version: '3.8'
services:
  rating-service:
    image: peekaboo51490/rating-service:latest
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgresql://user:pass@postgres:5432/rating_service
      - PORT=3000
      - NODE_ENV=production
    depends_on:
      - postgres
    healthcheck:
      test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/rating/api/v1/health/liveness')"]
      interval: 30s
      timeout: 3s
      retries: 3

  postgres:
    image: postgres:15-alpine
    environment:
      - POSTGRES_DB=rating_service
      - POSTGRES_USER=rating
      - POSTGRES_PASSWORD=rating
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data:
⁠Environment Variables
VariableDescriptionDefaultRequired
DATABASE_URLPostgreSQL connection string-Yes
PORTApplication port3000No
NODE_ENVEnvironment modeproductionNo
ALLOWED_ORIGINSCORS allowed origins (comma-separated)*No

⁠API Endpoints

⁠Ratings
MethodEndpointDescription
POST/rating/api/v1/product/{productId}Add a rating for a product
GET/rating/api/v1/product/{productId}Get rating summary for a product
⁠Health & Monitoring
MethodEndpointDescription
GET/rating/api/v1/healthFull health check (includes database)
GET/rating/api/v1/health/livenessKubernetes liveness probe
GET/rating/api/v1/health/readinessKubernetes readiness probe
GET/rating/api/v1/metricsPrometheus metrics
GET/api-docsSwagger API documentation

⁠Example Usage

⁠Add a Rating
curl -X POST http://localhost:3000/rating/api/v1/product/123 \
  -H "Content-Type: application/json" \
  -d '{"rating": 4.5}'

Response:

{
  "message": "Rating added successfully"
}
⁠Get Rating Summary
curl http://localhost:3000/rating/api/v1/product/123

Response:

{
  "productId": 123,
  "averageRating": 4.5,
  "totalRatings": 1
}

⁠Architecture

  • Framework: NestJS with TypeScript
  • Database: PostgreSQL with Drizzle ORM
  • Validation: class-validator with custom error responses
  • Logging: Custom logger with traceId/spanId (Spring Boot pattern)
  • Testing: Jest with Testcontainers for E2E tests

⁠Health Checks

The service includes comprehensive health checks:

  • Liveness: Returns 200 if the application is running
  • Readiness: Returns 200 if the application is ready to serve traffic (includes database connectivity)
  • Metrics: Prometheus-compatible metrics endpoint

⁠Security

  • Helmet.js for security headers
  • CORS configuration for cross-origin requests
  • Input validation with detailed error responses
  • Non-root user in Docker container

⁠Support

For issues and feature requests, please use the GitHub issue tracker.

Tag summary

Content type

Image

Digest

sha256:2017cd4bb…

Size

87.8 MB

Last updated

6 months ago

docker pull peekaboo51490/emart-rating-service:b85fca3