Skip to content

Yemresalcan/E-commerceAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ E-Commerce API - Enterprise Level Microservices Architecture

.NET C# PostgreSQL Elasticsearch Redis RabbitMQ Docker CI/CD Monitoring

Modern, scalable, and production-ready E-Commerce API built with .NET 9, implementing Clean Architecture, CQRS, Event Sourcing, and Microservices patterns.

πŸ‡ΉπŸ‡· TΓΌrkΓ§e DokΓΌmantasyon | πŸ“– English Documentation


πŸš€ Live Demo Screenshots

πŸ“Š Enterprise Monitoring Stack

Monitoring Overview

🎯 Production-Ready Infrastructure

Infrastructure Monitoring

🌟 Key Features

πŸ—οΈ Architecture & Design Patterns

  • Clean Architecture with clear separation of concerns
  • CQRS (Command Query Responsibility Segregation) for optimal read/write operations
  • Event-Driven Architecture with real-time synchronization
  • Domain-Driven Design (DDD) principles
  • Repository Pattern with Unit of Work
  • Mediator Pattern using MediatR
  • Specification Pattern for complex queries

πŸš€ Technology Stack

  • .NET 9 - Latest framework with performance improvements
  • Entity Framework Core 9 - Advanced ORM with change tracking
  • PostgreSQL - Primary database for ACID transactions
  • Elasticsearch - High-performance search and analytics
  • Redis - Distributed caching and session management
  • RabbitMQ - Message broker for event-driven communication
  • AutoMapper - Object-to-object mapping
  • FluentValidation - Input validation with fluent interface
  • Serilog - Structured logging with multiple sinks

πŸ”§ Advanced Features

  • Real-time Stock Management with event synchronization
  • Advanced Product Search with faceted filtering
  • Distributed Caching with Redis
  • Health Checks for all services
  • API Versioning with backward compatibility
  • Comprehensive Logging with correlation IDs
  • Exception Handling with global middleware
  • Performance Monitoring with custom metrics
  • Swagger/OpenAPI documentation

πŸ“Š System Architecture

graph TB
    subgraph "Presentation Layer"
        API[Web API Controllers]
        MW[Middleware Pipeline]
    end
    
    subgraph "Application Layer"
        MED[MediatR]
        CMD[Commands]
        QRY[Queries]
        VAL[Validators]
        BEH[Behaviors]
    end
    
    subgraph "Domain Layer"
        ENT[Entities]
        VO[Value Objects]
        AGG[Aggregates]
        DOM[Domain Services]
    end
    
    subgraph "Infrastructure Layer"
        REPO[Repositories]
        CACHE[Cache Service]
        MSG[Message Bus]
        EXT[External Services]
    end
    
    subgraph "Data Stores"
        PG[(PostgreSQL)]
        ES[(Elasticsearch)]
        RD[(Redis)]
        RMQ[RabbitMQ]
    end
    
    API --> MW
    MW --> MED
    MED --> CMD
    MED --> QRY
    CMD --> VAL
    QRY --> VAL
    VAL --> BEH
    BEH --> DOM
    DOM --> ENT
    DOM --> REPO
    REPO --> PG
    CACHE --> RD
    MSG --> RMQ
    EXT --> ES
Loading

πŸ—„οΈ Database Schema

erDiagram
    CUSTOMERS {
        uuid id PK
        string email UK
        string first_name
        string last_name
        string phone
        timestamp created_at
        timestamp updated_at
        boolean is_active
    }
    
    CUSTOMER_ADDRESSES {
        uuid id PK
        uuid customer_id FK
        string address_line1
        string address_line2
        string city
        string state
        string postal_code
        string country
        boolean is_default
        timestamp created_at
    }
    
    CATEGORIES {
        uuid id PK
        string name UK
        string description
        uuid parent_category_id FK
        int level
        boolean is_active
        timestamp created_at
        timestamp updated_at
    }
    
    PRODUCTS {
        uuid id PK
        string name
        string description
        string sku UK
        decimal price
        string currency
        int stock_quantity
        int minimum_stock_level
        uuid category_id FK
        boolean is_active
        boolean is_featured
        decimal average_rating
        int review_count
        timestamp created_at
        timestamp updated_at
    }
    
    PRODUCT_REVIEWS {
        uuid id PK
        uuid product_id FK
        uuid customer_id FK
        int rating
        string comment
        timestamp created_at
    }
    
    ORDERS {
        uuid id PK
        string order_number UK
        uuid customer_id FK
        string status
        decimal total_amount
        string currency
        string shipping_address
        string billing_address
        timestamp created_at
        timestamp updated_at
    }
    
    ORDER_ITEMS {
        uuid id PK
        uuid order_id FK
        uuid product_id FK
        string product_name
        int quantity
        decimal unit_price
        string currency
        decimal total_price
    }
    
    STOCK_MOVEMENTS {
        uuid id PK
        uuid product_id FK
        int quantity_change
        string movement_type
        string reason
        int stock_after_movement
        timestamp created_at
    }
    
    CUSTOMERS ||--o{ CUSTOMER_ADDRESSES : has
    CUSTOMERS ||--o{ PRODUCT_REVIEWS : writes
    CUSTOMERS ||--o{ ORDERS : places
    CATEGORIES ||--o{ CATEGORIES : contains
    CATEGORIES ||--o{ PRODUCTS : categorizes
    PRODUCTS ||--o{ PRODUCT_REVIEWS : receives
    PRODUCTS ||--o{ ORDER_ITEMS : included_in
    PRODUCTS ||--o{ STOCK_MOVEMENTS : tracks
    ORDERS ||--o{ ORDER_ITEMS : contains
Loading

πŸ”„ Event-Driven Workflow

sequenceDiagram
    participant Client
    participant API
    participant MediatR
    participant Handler
    participant Repository
    participant EventBus
    participant Elasticsearch
    participant Cache
    
    Client->>API: POST /api/v1/orders
    API->>MediatR: PlaceOrderCommand
    MediatR->>Handler: Handle Command
    
    Handler->>Repository: Get Product
    Repository-->>Handler: Product Data
    
    Handler->>Repository: Update Stock
    Repository->>EventBus: ProductStockUpdatedEvent
    
    EventBus->>Elasticsearch: Sync Stock Data
    EventBus->>Cache: Invalidate Cache
    
    Handler->>Repository: Create Order
    Repository-->>Handler: Order Created
    
    Handler-->>MediatR: Success Response
    MediatR-->>API: Order DTO
    API-->>Client: 201 Created
    
    Note over EventBus: Asynchronous Processing
    EventBus->>Elasticsearch: Update Search Index
    EventBus->>Cache: Update Product Cache
Loading

πŸš€ Quick Start

Prerequisites

  • .NET 9 SDK
  • PostgreSQL 16+
  • Elasticsearch 8.0+
  • Redis 7.0+
  • RabbitMQ 3.12+
  • Docker (optional)

1. Clone Repository

git clone https://github.com/Yemresalcan/ecommerce-api.git
cd ecommerce-api

2. Setup Infrastructure (Docker)

docker-compose up -d postgres elasticsearch redis rabbitmq

3. Configure Application

cp src/Presentation/ECommerce.WebAPI/appsettings.example.json src/Presentation/ECommerce.WebAPI/appsettings.json
# Edit connection strings and configurations

4. Run Migrations

dotnet ef database update --project src/Infrastructure/ECommerce.Infrastructure --startup-project src/Presentation/ECommerce.WebAPI

5. Start Application

dotnet run --project src/Presentation/ECommerce.WebAPI

6. Access API


πŸ“ Project Structure

src/
β”œβ”€β”€ Core/
β”‚   β”œβ”€β”€ ECommerce.Domain/           # Domain entities, value objects, aggregates
β”‚   └── ECommerce.Application/      # Use cases, DTOs, interfaces
β”œβ”€β”€ Infrastructure/
β”‚   β”œβ”€β”€ ECommerce.Infrastructure/   # Data access, external services
β”‚   └── ECommerce.ReadModel/        # Elasticsearch, read-side queries
└── Presentation/
    └── ECommerce.WebAPI/           # Controllers, middleware, configuration

tests/
β”œβ”€β”€ ECommerce.Domain.Tests/         # Domain unit tests
β”œβ”€β”€ ECommerce.Application.Tests/    # Application unit tests
β”œβ”€β”€ ECommerce.Infrastructure.Tests/ # Infrastructure unit tests
└── ECommerce.WebAPI.Tests/         # Integration tests

πŸ”§ Configuration

Database Configuration

{
  "ConnectionStrings": {
    "DefaultConnection": "Host=localhost;Database=ecommerce;Username=postgres;Password=password"
  }
}

Elasticsearch Configuration

{
  "Elasticsearch": {
    "Uri": "http://localhost:9200",
    "IndexPrefix": "ecommerce",
    "Username": "",
    "Password": ""
  }
}

Redis Configuration

{
  "ConnectionStrings": {
    "Redis": "localhost:6379"
  }
}

πŸ“Š Live Monitoring Screenshots

🎯 Grafana Dashboard - Real-time System Monitoring

Grafana Dashboard Professional monitoring dashboard showing CPU, Memory, Network, and Disk metrics in real-time

πŸ“ˆ Prometheus Metrics Collection

Prometheus Targets Prometheus successfully collecting metrics from all monitoring targets

🐳 Container Monitoring with cAdvisor

cAdvisor Container Monitoring Detailed container resource usage and performance metrics

πŸ› οΈ Container Management with Portainer

Portainer Dashboard Professional container management interface for Docker environments

🐰 Message Queue Monitoring

RabbitMQ Management RabbitMQ management interface showing queue status and message flow

πŸ›’ E-Commerce API Documentation

API Documentation Comprehensive Swagger/OpenAPI documentation with interactive testing

πŸ“Š Performance Metrics

Endpoint Avg Response Time Throughput
GET /products 45ms 2,000 req/s
POST /orders 120ms 500 req/s
GET /orders/{id} 25ms 3,000 req/s
GET /search 80ms 1,200 req/s

πŸ§ͺ Testing

Run Unit Tests

dotnet test tests/ECommerce.Domain.Tests/
dotnet test tests/ECommerce.Application.Tests/

Run Integration Tests

dotnet test tests/ECommerce.WebAPI.Tests/

Test Coverage

dotnet test --collect:"XPlat Code Coverage"

πŸ“ˆ Monitoring & Observability

Health Checks

  • Database connectivity
  • Elasticsearch cluster health
  • Redis availability
  • RabbitMQ connection
  • External service dependencies

Logging

  • Structured logging with Serilog
  • Correlation IDs for request tracking
  • Performance metrics
  • Error tracking and alerting

Metrics

  • Request/response times
  • Database query performance
  • Cache hit/miss ratios
  • Event processing metrics

πŸ”’ Security Features

  • Input validation with FluentValidation
  • SQL injection prevention with parameterized queries
  • XSS protection with output encoding
  • CORS configuration
  • Rate limiting
  • API versioning
  • Health check security

πŸš€ Deployment

Docker Deployment

docker build -t ecommerce-api .
docker run -p 8080:8080 ecommerce-api

Kubernetes Deployment

kubectl apply -f k8s/

CI/CD Pipeline

  • GitHub Actions workflow
  • Automated testing
  • Docker image building
  • Deployment to staging/production

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Your Name


πŸ™ Acknowledgments

  • Clean Architecture by Robert C. Martin
  • Domain-Driven Design by Eric Evans
  • Microsoft .NET Documentation
  • Elasticsearch Documentation
  • Redis Documentation

πŸ“š Additional Resources


🎯 Production Screenshots Gallery

Monitoring Dashboard Container Management API Documentation
Grafana Portainer API Docs
Real-time Metrics Container Control Interactive API
System Health Message Queue Container Analytics
Prometheus RabbitMQ cAdvisor
Target Monitoring Queue Management Resource Analytics

⭐ If you found this project helpful, please give it a star! ⭐

πŸš€ Ready for Production β€’ πŸ“Š Enterprise Monitoring β€’ πŸ›’ Scalable E-Commerce

About

πŸ›’ .NET 9 E-Commerce API - Enterprise Level Microservices Architecture

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages