Skip to content

An implementation of the Modular Monolith using .Net 8 and C#

Notifications You must be signed in to change notification settings

ilroberts/DotNetModularMonolith

Repository files navigation

Modular Monolith E-Commerce Application

Overview

ECommerceApp is a modular monolith built with .NET 8 that serves as an example of how to build an e-commerce system using a modular architecture. The application is structured into three primary modules:

  • Orders: Manages customer orders and interacts with the product catalog to create orders.
  • Products: Handles the product catalog, exposing product information.
  • Customers: Manages customer information.

Key Features

  • Modular Monolith Architecture: The application is divided into modules (Orders, Products, Customers) with loose coupling.
  • Dependency Injection: The modules interact using shared interfaces for decoupled communication.
  • Shared Contracts: Contracts are placed in a separate project to avoid circular dependencies between modules.
  • Logging: Integrated logging using ILogger.
  • Swagger UI: API documentation and testing via Swagger.

Table of Contents

Project Structure

The project follows a modular monolith structure, where each module is self-contained but part of a single application.

ECommerceApp/
│
├── ECommerce.Contracts/                # Shared interfaces and DTOs
│   ├── Interfaces/
│   ├── DTOs/
│
├── ECommerce.Modules.Orders/           # Orders module
│   ├── Services/
│   ├── Endpoints/
│   ├── Extensions/
│
├── ECommerce.Modules.Products/         # Products module
│   ├── Services/
│   ├── Endpoints/
│   ├── Extensions/
│
├── ECommerce.Modules.Customers/        # Customers module
│   ├── Services/
│   ├── Endpoints/
│   ├── Extensions/
│
└── Program.cs                          # Application entry point

Requirements

Setup and Installation

Follow these steps to set up the project:

  1. Clone the repository:

    git clone https://github.com/yourusername/ECommerceApp.git
    cd ECommerceApp
  2. Install dependencies:

    Run the following command to restore all required packages:

    dotnet restore
  3. Build the project:

    Build the project using the following command:

    dotnet build
  4. Run the application:

    Start the application:

    dotnet run
  5. Access the API:

    Once the app is running, you can access the API at:

    http://localhost:5000
  6. Swagger Documentation:

    Visit the Swagger UI for API documentation:

    http://localhost:5000/swagger

Usage

Orders Module

The Orders module allows for creating, retrieving, and managing customer orders. It depends on the Products module for product data.

Key Endpoints:

  • POST /orders: Create a new order
  • GET /orders: Get all orders
  • GET /orders/{id}: Get order by ID

Products Module

The Products module manages the product catalog and exposes product data to other modules via a shared interface.

Key Endpoints:

  • GET /products: Get all products
  • GET /products/{id}: Get product by ID

Customers Module

The Customers module handles customer data and services.

Key Endpoints:

  • GET /customers: Get all customers
  • GET /customers/{id}: Get customer by ID

Logging

Logging is integrated using ILogger. Example of usage:

public async Task CreateOrderAsync(Guid customerId, List<OrderItem> items)
{
    _logger.LogInformation("Creating order for customer {CustomerId}", customerId);
    // business logic here
    _logger.LogInformation("Order created for customer {CustomerId}", customerId);
}

Logs are written to the console, and you can extend this to use other logging providers (e.g., file logging, cloud logging).

Swagger Integration

Swagger is integrated to allow easy API documentation and testing. To access Swagger, go to:

http://localhost:5000/swagger

You can interact with all the API endpoints directly from the Swagger UI.

Contributing

If you'd like to contribute, feel free to fork the repository and submit a pull request. Issues and feature requests are welcome.

Steps to Contribute

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Commit your changes (git commit -m 'Add new feature').
  4. Push to the branch (git push origin feature-branch).
  5. Create a pull request.

License

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

About

An implementation of the Modular Monolith using .Net 8 and C#

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages