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.
- Architecture
- Entities
- Unit of Work
- Base Models
- Getting Started
- Technologies
- Cloud Storage
- API Endpoints
- Authentication and Authorization
- Contributing
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.
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.
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
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 typeTKey
(integer or string).
To get the project up and running, follow these steps:
- Clone the repository:
git clone https://github.com/r3troseer/XpressMart.git
- Navigate to the project directory:
cd XpressMart
- Build the project:
dotnet build
-
Install necessary database package
-
Configure the database connection string in the
appsettings.json
file. -
Apply database migrations:
dotnet ef database update
- Run the application:
dotnet run --project XpressMart.API
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.
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.
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.
Contributions to the project are welcome. Please follow these steps to contribute:
- Fork the repository
- Create a new branch for your feature or bug fix
- Make your changes and commit them with descriptive commit messages
- Push your changes to your forked repository
- 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.