Skip to content

nies14/E-Shop

Repository files navigation

E-Shop Microservices

This project is a microservices-based e-commerce application built with .NET 8.0. The implementation includes multiple microservices: Catalog, Basket, Ordering, and Discount services.

Technologies Used

Backend Technologies

  • .NET 8.0 - Core framework for all microservices
  • ASP.NET Core Web API - REST API endpoints
  • gRPC - Inter-service communication (Discount service)
  • MediatR - CQRS pattern implementation
  • Entity Framework Core - ORM for SQL Server (Ordering service)
  • Dapper - Micro-ORM for PostgreSQL (Discount service)

Databases

  • MongoDB - Document database for Catalog service
  • Redis - In-memory cache for Basket service
  • SQL Server - Relational database for Ordering service
  • PostgreSQL - Relational database for Discount service

Message Broker & Events

  • RabbitMQ - Message bus for event-driven communication
  • MassTransit - Distributed application framework for message-based systems

API Documentation & Versioning

  • Swagger/OpenAPI - API documentation and testing interface
  • API Versioning - Version management for REST APIs

Logging & Monitoring

  • Serilog - Structured logging across all services

Containerization & Orchestration

  • Docker - Containerization platform
  • Docker Compose - Multi-container application orchestration

Development Tools

  • Visual Studio 2022 / VS Code - IDE support
  • Git - Version control
  • Postman - API testing (optional)
  • Gemini CLI - AI-powered project analysis and documentation

Architecture Patterns

  • Microservices Architecture - Service decomposition
  • CQRS (Command Query Responsibility Segregation) - Data access pattern
  • Domain-Driven Design (DDD) - Domain modeling approach
  • Event-Driven Architecture - Asynchronous communication
  • Repository Pattern - Data access abstraction
  • Clean Architecture - Layered application structure

Project Structure

E-Shop/
β”œβ”€β”€ Catalog.API/          # REST API endpoints and controllers
β”œβ”€β”€ Catalog.Application/  # Application logic, CQRS commands/queries
β”œβ”€β”€ Catalog.Core/         # Domain entities and interfaces
└── Catalog.Infrastructure/ # Data access and implementations

Getting Started

Prerequisites

  • .NET 8.0 SDK
  • Docker Desktop
  • MongoDB (containerized)

Running the Application

  1. Start the containers:
docker compose -f docker-compose.yml -f docker-compose.override.yml up -d
  1. Access Swagger UI:
http://localhost:8000/swagger

API Endpoints

Products

Get All Products

  • GET /api/v1/Catalog/GetAllProducts
    • Gets all products with optional filtering, sorting, and pagination
    • Query Parameters:
      • PageIndex (int): Page number, starts at 1 (default: 1)
      • PageSize (int): Number of items per page, max 70 (default: 10)
      • BrandId (string): Filter by brand ID
      • TypeId (string): Filter by product type ID
      • Sort (string): Sort parameter (e.g., "price_asc", "price_desc", "name_asc")
      • Search (string): Search term to filter products
    • Example: /api/v1/Catalog/GetAllProducts?PageIndex=2&PageSize=20&BrandId=1&TypeId=2&Sort=price_asc&Search=gaming
    • Response Model:
      {
        "products": [
          {
            "id": "string",
            "name": "string",
            "description": "string",
            "price": 0.0,
            "pictureUrl": "string",
            "productBrand": "string",
            "productType": "string"
          }
        ]
      }

Get Product By ID

  • GET /api/v1/Catalog/GetProductById/{id}
    • Parameters: id (string)
    • Response Model:
      {
        "id": "string",
        "name": "string",
        "description": "string",
        "price": 0.0,
        "pictureUrl": "string",
        "productBrand": "string",
        "productType": "string"
      }

Get Product By Name

  • GET /api/v1/Catalog/GetProductByProductName/{productName}
    • Parameters: productName (string)
    • Response Model: Same as Get Product By ID

Get Products By Brand

  • GET /api/v1/Catalog/GetProductsByBrandName/{brand}
    • Parameters: brand (string)
    • Response Model:
      {
        "products": [
          {
            "id": "string",
            "name": "string",
            "description": "string",
            "price": 0.0,
            "pictureUrl": "string",
            "productBrand": "string",
            "productType": "string"
          }
        ]
      }

Create Product

  • POST /api/v1/Catalog/CreateProduct
    • Request Model:
      {
        "name": "string",
        "description": "string",
        "price": 0.0,
        "pictureUrl": "string",
        "productBrand": "string",
        "productType": "string"
      }
    • Response Model:
      {
        "id": "string",
        "name": "string",
        "description": "string",
        "price": 0.0,
        "pictureUrl": "string",
        "productBrand": "string",
        "productType": "string"
      }

Update Product

  • PUT /api/v1/Catalog/UpdateProduct
    • Request Model:
      {
        "id": "string",
        "name": "string",
        "description": "string",
        "price": 0.0,
        "pictureUrl": "string",
        "productBrand": "string",
        "productType": "string"
      }
    • Response: 200 OK

Delete Product

  • DELETE /api/v1/Catalog/{id}
    • Parameters: id (string)
    • Response: 200 OK

Brands

Get All Brands

  • GET /api/v1/Catalog/GetAllBrands
    • Response Model:
      {
        "brands": [
          {
            "id": "string",
            "name": "string"
          }
        ]
      }

Types

Get All Types

  • GET /api/v1/Catalog/GetAllTypes
    • Response Model:
      {
        "types": [
          {
            "id": "string",
            "name": "string"
          }
        ]
      }

Troubleshooting

MongoDB Connection Issues

If you're encountering MongoDB connection issues when running the application from Visual Studio:

  1. Make sure MongoDB is running in Docker with proper port mapping:

    docker run --name mongodb -d -p 27017:27017 mongo:latest
  2. Verify MongoDB Connection String:

    • When running in Docker: mongodb://catalogdb:27017
    • When running on localhost: mongodb://127.0.0.1:27017
  3. Check MongoDB logs:

    docker logs mongodb

Database Configuration

MongoDB connection settings in appsettings.json:

"DatabaseSettings": {
    "ConnectionString": "mongodb://catalogdb:27017",
    "DatabaseName": "CatalogDb",
    "CollectionName": "Products",
    "BrandsCollection": "Brands",
    "TypesCollection": "Types"
}

For local development (in appsettings.Development.json):

"DatabaseSettings": {
    "ConnectionString": "mongodb://127.0.0.1:27017",
    "DatabaseName": "CatalogDb",
    "CollectionName": "Products",
    "BrandsCollection": "Brands",
    "TypesCollection": "Types"
}

Docker Support

The application uses Docker Compose with two services:

  • catalogdb: MongoDB instance
  • catalog.api: .NET Web API application

Development

To run the application in development mode:

  1. Build the containers:
docker compose build
  1. Start the services:
docker compose -f docker-compose.yml -f docker-compose.override.yml up -d
  1. Stop the services:
docker compose down

Gemini CLI

This project includes a custom Gemini CLI for AI-powered analysis and documentation generation.

Setup Gemini CLI

  1. Get your Gemini API key from Google AI Studio
  2. Copy environment file:
    cp tools/gemini-cli/.env.example .env
  3. Add your API key to .env:
    GEMINI_API_KEY=your_gemini_api_key_here

Available Commands

# Analyze the entire project structure
npm run analyze

# Generate API documentation for services
npm run docs Catalog
npm run docs Basket
npm run docs Ordering
npm run docs Discount

# Generate test suggestions
npm run tests Catalog

# Optimize Dockerfiles
npm run optimize-docker

# Show help
node tools/gemini-cli/gemini-cli.js help

Features

  • πŸ” Project Analysis: AI-powered architecture analysis
  • πŸ“ Documentation Generation: Automatic API documentation
  • πŸ§ͺ Test Suggestions: AI-generated test recommendations
  • 🐳 Docker Optimization: Dockerfile analysis and suggestions

See tools/gemini-cli/CLI-README.md for detailed usage instructions.

About

E-Commerce Application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •