Skip to content

r2b89/reviews_challenge

Repository files navigation

Project description

The Product Reviews System is a RESTful API designed to manage product reviews. It enables users to create, update, delete, and retrieve reviews associated with products.

Features

Product Management:

Create a Product: Add new products to the system.
Retrieve Product: Get detailed information about a specific product by its unique identifier.
Update Product: Modify details of existing products (e.g., name, description, price).
Delete Product: Remove a product from the system.
List of Products: List of existing products with pagination

Review Management:

Create a Review: Submit reviews for products, including rating and optional text feedback.
Update a Review: Edit an existing review for a product, updating its rating or content.
Delete a Review: Remove a review for a specific product.
List of Reviews: List of existing reviews with pagination

Project Structure

├── cmd
│   ├── products-service # Entry point for the products service
│   └── reviews-service # Entry point for the reviews service
├── internal
│    ├── products
│    │   ├── database # Product-specific database initialization
│    │   ├── handlers # HTTP handlers for products service
│    │   ├── migrations # Product-specific database migrations
│    │   ├── repositories # Product-specific database calls
│    │   ├── routes # Products routes
│    │   └── services # Products service implementation
│    └── reviews
│        ├── database # Reviews-specific database initialization
│        ├── handlers # HTTP handlers for reviews service
│        ├── repositories # Review-specific database calls
│        ├── routes # Reviews routes
│        └── services # Reviews service implementation
└── dockerfile # Docker files of services
└── docs # Swagger documents (OpenAPI)
└── nginx # NGINX configuration
└── pkg
    ├── apimodels # Shared REST API models (for multiple services)
    ├── dbmodels # Database models (for multiple services)
    ├── natsmodels # NATS models (for multiple services)
    ├── constants # Constants
    ├── monitoring # Prometheus objects
    └── config # Configuration loading and parsing
└── prometheus # Configuration of prometheus

Build and Run

To work with project you can use commands from Makefile:

Build and start:

   make docker-up

Stop service:

   make docker-down

Linter:

   make install-lint #ONLY FOR FIRST CALL
   make lint

Test:

   make test

Swagger generation:

   make install-swag #ONLY FOR FIRST CALL
   make swagger

Swagger

localhost:81/swagger/index.html

Technologies

This project uses the following technologies, each chosen for a specific purpose:

  1. Redis – Caching and Fast Lookups

    • Storing reviews temporarily to improve response time and reduce database load.
    • Caching the list of products to speed up review operations.
    • Ensuring fast read operations, especially for frequently accessed data.
  2. NATS – Event-Driven Communication

    • Enables real-time notifications when a product or review is created, updated, or deleted.
    • Ensures services remain decoupled and scalable.
    • Uses JetStream for persistent storage, ensuring reliability.
  3. GORM with SQLite – Database Layer for Prototyping

    • GORM is a Go ORM that simplifies database interactions, reducing boilerplate code.
    • SQLite is used for prototyping because it's lightweight and requires minimal setup.
    • Supports easy migration to PostgreSQL or another database in production.
  4. Nginx – API Gateway with Access Control

    • Acts as a reverse proxy for routing requests to backend services.
    • Simulates simple access control, such as request filtering.
    • Improves security and centralizes request handling.
  5. Prometheus – Monitoring and Metrics

    • Collects and stores service metrics, such as API response times.
    • Helps identify performance bottlenecks and optimize system behavior.
    • Works with Grafana for visualization if needed.

Topology of services

                     +--------------------+
                     |    API Gateway     |
                     |       Nginx        |
                     +--------------------+
                               │
                 ┌─────────────┴─────────────┐
                 │                           │
       +-----------------+         +-----------------+
       |  Review Service |<------->| Product Service |
       |  (GORM + SQLite)|   NATS  |  (GORM + SQLite)|
       +-----------------+\        +-----------------+
                 │          \            │
       +-----------------+    \ +-----------------+
       |      Redis      |      |   Prometheus    |
       |   (Caching)     |      |  (Monitoring)   |
       +-----------------+      +-----------------+
                                     │       │
                                     ▼       ▼
                             (Monitoring both services)

When an authorized user creates, updates, or deletes a product, the service notifies the reviews service to invalidate its stored cache. This cache helps keep things in sync and prevents actions on unknown products.

Similarly, when an authorized user creates, updates, or deletes a review, we check the cache to update the average rating and send it to the products service to save in the product record.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors