Skip to content

E-commerce API built with ASP.NET 8 and following the Clean Architecture principles

Notifications You must be signed in to change notification settings

r3troseer/XpressMart

Repository files navigation

XpressMart

XpressMart is an e-commerce API built with ASP.NET Core and following the Clean Architecture principles. It provides endpoints for managing products, categories, orders, customers, deliveries, and administrative tasks.

Table of Contents

Architecture

The project follows the Clean Architecture approach, separating concerns into different layers:

  • XpressMart.API: This layer contains the API controllers, middleware configurations, and the entry point of the application. It also includes an Extensions folder for organizing service configurations.
  • XpressMart.Application: This layer contains application services, repositories, and interfaces.
  • XpressMart.Core: This layer contains the domain entities, enums, exceptions, value objects, and specifications.

Entities

The project includes the following entities:

  • ApplicationUser: Represents the user of the application, inheriting from IdentityUser.
  • Customer: Represents customer information, including name, email, phone, and address.
  • Order: Represents an order placed by a customer, containing order items, payment details, and delivery information.
  • OrderItem: Represents an individual item in an order, including the product and quantity.
  • Product: Represents a product in the e-commerce application, with properties like name, description, price, and category.
  • ProductImage: Represents an image associated with a product.
  • Category: Represents a product category, supporting hierarchical categories.
  • Payment: Represents the payment details for an order, including payment method, status, and amount.
  • Delivery: Represents the delivery information for an order, including address, status, and tracking details.

Unit of Work

The project utilizes the Unit of Work pattern, which provides a way to manage and coordinate multiple repository instances within a single database transaction. This pattern helps maintain data integrity and consistency by ensuring that all operations within a unit of work are committed or rolled back together.

The UnitOfWork class in the XpressMart.Application layer implements the IUnitOfWork interface and acts as a facade for managing repositories and database transactions. It contains methods for committing or rolling back transactions

Base Models

The project includes base models for requests and responses to maintain consistency and facilitate extensibility:

  • BaseResponse<'T'>: A generic base class for API responses, containing properties for success/failure status, message, errors, and data of type T.
  • BaseRequest<'TKey'>: A generic base class for API requests involving existing entities, containing a required Id property of type TKey (integer or string).

Getting Started

To get the project up and running, follow these steps:

  1. Clone the repository:
git clone https://github.com/r3troseer/XpressMart.git
  1. Navigate to the project directory:
cd XpressMart
  1. Build the project:
dotnet build
  1. Install necessary database package

  2. Configure the database connection string in the appsettings.json file.

  3. Apply database migrations:

dotnet ef database update
  1. Run the application:
dotnet run --project XpressMart.API

Technologies

The project utilizes the following technologies and libraries:

  • Entity Framework Core: An object-relational mapper (ORM) that enables working with databases using .NET objects.
  • AutoMapper: A convention-based object-to-object mapper that eliminates the need for manual mapping code.
  • ASP.NET Core Identity: A membership system that provides core user management functionality, including user authentication and authorization.
  • JWT (JSON Web Tokens): An open standard for securely transmitting information between parties as a JSON object.
  • Swagger: A tool for documenting and testing RESTful APIs.
  • ULID: A universally unique lexicographically sortable identifier for generating unique IDs.
  • B2Net: A C# client library for the Backblaze B2 Cloud Storage service.

Cloud Storage

The project uses the Backblaze B2 Cloud Storage service for storing product images. The B2Net library is utilized to interact with the Backblaze B2 API and perform operations such as uploading, downloading, and deleting files.

The FileStorageService and FileStorageRepository classes in the XpressMart.Application layer handle the logic for interacting with the Backblaze B2 storage. The FileStorageService provides methods for uploading, downloading, and deleting product images, while the FileStorageRepository encapsulates the Backblaze B2 SDK calls.

Authentication and Authorization

The project uses ASP.NET Core Identity for authentication and authorization. The ApplicationUser entity inherits from IdentityUser and represents the user of the application.

During application startup, the IdentityInitializer class creates the "Admin" role if it doesn't exist. The UserService class provides a method AssignAdminRoleAsync to assign the admin role to a user by email address.

JWT (JSON Web Tokens) authentication is implemented and configured in the JwtAuthenticationExtensions class.

Access to administrative endpoints is restricted to users with the "Admin" role using the [Authorize(Roles = "Admin")] attribute.

Contributing

Contributions to the project are welcome. Please follow these steps to contribute:

  1. Fork the repository
  2. Create a new branch for your feature or bug fix
  3. Make your changes and commit them with descriptive commit messages
  4. Push your changes to your forked repository
  5. Submit a pull request to the main repository

Please ensure that your code adheres to the project's coding standards and that you have added appropriate tests for your changes.

Releases

No releases published

Packages

 
 
 

Languages