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.
- 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.
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
- .NET 8 SDK
- Visual Studio or any other C# IDE
- SQL Server or other databases (optional, based on your implementation)
Follow these steps to set up the project:
-
Clone the repository:
git clone https://github.com/yourusername/ECommerceApp.git cd ECommerceApp
-
Install dependencies:
Run the following command to restore all required packages:
dotnet restore
-
Build the project:
Build the project using the following command:
dotnet build
-
Run the application:
Start the application:
dotnet run
-
Access the API:
Once the app is running, you can access the API at:
http://localhost:5000
-
Swagger Documentation:
Visit the Swagger UI for API documentation:
http://localhost:5000/swagger
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 orderGET /orders
: Get all ordersGET /orders/{id}
: Get order by ID
The Products module manages the product catalog and exposes product data to other modules via a shared interface.
Key Endpoints:
GET /products
: Get all productsGET /products/{id}
: Get product by ID
The Customers module handles customer data and services.
Key Endpoints:
GET /customers
: Get all customersGET /customers/{id}
: Get customer by ID
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 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.
If you'd like to contribute, feel free to fork the repository and submit a pull request. Issues and feature requests are welcome.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Create a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.