Skip to content

A multi-tenant Loyalty & Rewards SaaS backend built with .NET and an event-driven architecture. Integrates with e-commerce platforms to calculate points using a deterministic rule engine, maintain an immutable ledger, and enable reward redemption. Designed for scalability, tenant isolation, and future extensibility.

Notifications You must be signed in to change notification settings

iaashu98/LoyaltyForge

Repository files navigation

LoyaltyForge

.NET CI/CD Unit Tests

A modern, event-driven multi-tenant Loyalty & Rewards SaaS platform built with .NET 9.0

πŸš€ Overview

LoyaltyForge is a production-ready microservices-based loyalty and rewards platform designed for e-commerce businesses. It features a complete Event-Driven Architecture (EDA) with CQRS, Saga patterns, and comprehensive testing.

Key Features

  • βœ… Event-Driven Architecture - RabbitMQ-based async communication
  • βœ… Multi-Tenant SaaS - Complete tenant isolation
  • βœ… Saga Pattern - Distributed transaction orchestration
  • βœ… CQRS - Command/Query separation
  • βœ… Outbox Pattern - Reliable event publishing
  • βœ… Comprehensive Testing - 28+ unit tests with CI/CD integration
  • βœ… E-commerce Integration - Shopify webhooks support
  • βœ… Points Engine - Flexible points earning and redemption
  • βœ… Rewards Catalog - Configurable reward management

πŸ—οΈ Architecture

Microservices

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Auth & Tenant  │────▢│   API Gateway    │◀────│   E-commerce    β”‚
β”‚    Service      β”‚     β”‚   (Ocelot)       β”‚     β”‚   Integration   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚                           β”‚
                               β”‚                           β–Ό
                        β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚  Points Engine  │◀─────│   RabbitMQ      β”‚
                        β”‚    Service      β”‚      β”‚  Message Bus    β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚                           β–²
                               β”‚                           β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
                        β”‚    Rewards      β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚    Service      β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Event-Driven Flows

Order Processing Flow:

Shopify β†’ OrderPlacedEvent β†’ Points Engine β†’ PointsEarnedEvent

Reward Redemption Flow (Saga):

Customer β†’ RedemptionSaga β†’ DeductPointsCommand β†’ Points Engine
                ↓
    PointsDeductedEvent / PointsDeductionFailedEvent
                ↓
        Redemption Complete/Failed

πŸ› οΈ Technology Stack

Backend

  • .NET 9.0 - Latest .NET framework
  • ASP.NET Core - Web API framework
  • Entity Framework Core - ORM
  • PostgreSQL - Primary database
  • RabbitMQ - Message broker
  • Serilog - Structured logging

Testing

  • xUnit - Testing framework
  • Moq - Mocking framework
  • FluentAssertions - Fluent test assertions
  • Codecov - Code coverage tracking

DevOps

  • Docker & Docker Compose - Containerization
  • GitHub Actions - CI/CD pipeline
  • Dependabot - Automated dependency updates

🚦 Getting Started

Prerequisites

  • .NET 9.0 SDK
  • Docker Desktop
  • PostgreSQL 16
  • RabbitMQ 3.x

Quick Start

See QUICKSTART.md for detailed commands and options.

# Build and run everything in one command
./scripts/run.sh -b

# Or run in background
./scripts/run.sh -b -d

# Run tests
./scripts/test.sh

Service URLs:

For detailed documentation on all available commands, see QUICKSTART.md.

  1. Clone the repository

    git clone https://github.com/iaashu98/LoyaltyForge.git
    cd LoyaltyForge
  2. Start infrastructure services

    docker-compose up -d postgres rabbitmq
  3. Run database migrations

    dotnet ef database update --project src/Services/AuthTenant/AuthTenant.Infrastructure
    dotnet ef database update --project src/Services/PointsEngine/PointsEngine.Infrastructure
    dotnet ef database update --project src/Services/Rewards/Rewards.Infrastructure
  4. Start all services

    # Terminal 1 - Auth & Tenant
    dotnet run --project src/Services/AuthTenant/AuthTenant.Api
    
    # Terminal 2 - E-commerce Integration
    dotnet run --project src/Services/EcommerceIntegration/EcommerceIntegration.Api
    
    # Terminal 3 - Points Engine
    dotnet run --project src/Services/PointsEngine/PointsEngine.Api
    
    # Terminal 4 - Rewards Service
    dotnet run --project src/Services/Rewards/Rewards.Api
  5. Access services


πŸ§ͺ Testing

Run Unit Tests

# Run all tests
dotnet test tests/Unit/**/*.csproj

# Run specific service tests
dotnet test tests/Unit/Rewards.Application.Tests/Rewards.Application.Tests.csproj
dotnet test tests/Unit/PointsEngine.Application.Tests/PointsEngine.Application.Tests.csproj

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

Test Coverage

  • Total Tests: 28+ unit tests
  • Coverage Goal: 70% overall, 90% for critical business logic
  • CI/CD: Tests run automatically on every push/PR

Tested Components:

  • βœ… Command Handlers (DeductPointsCommandHandler)
  • βœ… Event Handlers (OrderPlacedEventHandler)
  • βœ… Saga Orchestration (RedemptionSaga)
  • βœ… Domain Entities (RewardRedemption)

πŸ“š Documentation

Architecture & Design

Testing & Quality

API Documentation


πŸ”„ CI/CD Pipeline

Automated Workflows

Main Pipeline (.NET CI/CD)

  • βœ… Full solution build
  • βœ… Unit test execution with coverage
  • βœ… Multi-service parallel builds
  • βœ… Test result publishing
  • βœ… Codecov integration

Quick Feedback (Unit Tests Only)

  • βœ… Fast test execution on feature branches
  • βœ… PR test result comments

Automation (Dependabot)

  • βœ… Weekly dependency updates
  • βœ… Security vulnerability patches

Workflow Triggers

  • Main/Develop: Full CI/CD pipeline
  • Feature Branches: Quick unit tests
  • Pull Requests: Both workflows + test results

πŸ›οΈ Project Structure

LoyaltyForge/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Services/
β”‚   β”‚   β”œβ”€β”€ AuthTenant/              # Authentication & tenant management
β”‚   β”‚   β”œβ”€β”€ EcommerceIntegration/    # Shopify webhook integration
β”‚   β”‚   β”œβ”€β”€ PointsEngine/            # Points earning & deduction
β”‚   β”‚   β”œβ”€β”€ Rewards/                 # Reward catalog & redemption
β”‚   β”‚   └── ApiGateway/              # API gateway (Ocelot)
β”‚   └── Shared/
β”‚       β”œβ”€β”€ LoyaltyForge.Common/     # Shared utilities
β”‚       β”œβ”€β”€ LoyaltyForge.Contracts/  # Event & command contracts
β”‚       └── LoyaltyForge.Messaging/  # RabbitMQ infrastructure
β”œβ”€β”€ tests/
β”‚   └── Unit/
β”‚       β”œβ”€β”€ Rewards.Application.Tests/
β”‚       β”œβ”€β”€ PointsEngine.Application.Tests/
β”‚       └── LoyaltyForge.Messaging.Tests/
β”œβ”€β”€ docs/                            # Comprehensive documentation
└── .github/workflows/               # CI/CD pipelines

🎯 Key Patterns Implemented

1. Event-Driven Architecture (EDA)

  • Asynchronous communication via RabbitMQ
  • Event sourcing ready
  • Loose coupling between services

2. Saga Pattern

  • Orchestration-based distributed transactions
  • Compensation logic for failures
  • Idempotency handling

3. Outbox Pattern

  • Atomic message publishing
  • Guaranteed event delivery
  • Database transaction consistency

4. CQRS

  • Command/Query separation
  • Optimized read/write models
  • Event-driven updates

πŸ” Configuration

Environment Variables

# Database
ConnectionStrings__DefaultConnection=Host=localhost;Database=loyaltyforge_auth;...

# RabbitMQ
RabbitMQ__HostName=localhost
RabbitMQ__Port=5672
RabbitMQ__UserName=guest
RabbitMQ__Password=guest

# Logging
Serilog__MinimumLevel__Default=Information

appsettings.json

Each service has its own appsettings.json for service-specific configuration.


🀝 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

Development Guidelines

  • Write unit tests for new features
  • Follow existing code patterns
  • Update documentation
  • Ensure CI/CD passes

πŸ“Š Project Status

Completed βœ…

  • Multi-tenant architecture
  • Event-Driven Architecture (EDA)
  • Saga pattern implementation
  • Outbox pattern for reliability
  • Unit testing infrastructure (28+ tests)
  • CI/CD pipeline with automated testing
  • E-commerce integration (Shopify)
  • Points earning and redemption
  • Reward catalog management

In Progress 🚧

  • Integration tests
  • E2E tests
  • Analytics service
  • Admin dashboard
  • Mobile API optimization

Planned πŸ“‹

  • Event sourcing implementation
  • Read model optimization
  • Advanced reporting
  • Multi-platform integrations
  • Performance optimization

πŸ“„ License

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


πŸ‘€ Author

Ashutosh Ranjan


πŸ™ Acknowledgments

  • Event-Driven Architecture patterns from industry best practices
  • RabbitMQ for reliable message brokering
  • .NET community for excellent tooling and support

Built with ❀️ using .NET 9.0 and Event-Driven Architecture

About

A multi-tenant Loyalty & Rewards SaaS backend built with .NET and an event-driven architecture. Integrates with e-commerce platforms to calculate points using a deterministic rule engine, maintain an immutable ledger, and enable reward redemption. Designed for scalability, tenant isolation, and future extensibility.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •