https://github.com/khachatur/ecommerceapp
ECommerceApp is a full-stack web application built using .NET 6, demonstrating clean architecture principles.
https://github.com/khachatur/ecommerceapp
clean-architecture cqrs csharp dependency-injection dotnet-core entity-framework-core jwt-authentication restapi unit-testing
Last synced: about 1 month ago
JSON representation
ECommerceApp is a full-stack web application built using .NET 6, demonstrating clean architecture principles.
- Host: GitHub
- URL: https://github.com/khachatur/ecommerceapp
- Owner: khachatur
- Created: 2025-03-11T20:26:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-13T14:27:59.000Z (over 1 year ago)
- Last Synced: 2025-03-13T15:30:52.261Z (over 1 year ago)
- Topics: clean-architecture, cqrs, csharp, dependency-injection, dotnet-core, entity-framework-core, jwt-authentication, restapi, unit-testing
- Language: C#
- Homepage:
- Size: 895 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ECommerceApp
A simple e-commerce application built with ASP.NET Core, featuring a Razor Pages frontend and a Web API backend. Users can browse products, create orders, and view order history, with admin capabilities for managing products and orders.
## Features
- **Frontend**: Razor Pages with Bootstrap 5 for a responsive UI.
- **Backend**: RESTful Web API with JWT authentication.
- **Order Processing**: Transactional order creation with stock updates via a stored procedure.
- **Admin Area**: Role-based dropdown for managing products and orders.
- **Data Access**: EF Core with a repository pattern and CQRS (MediatR).
## Architecture
- **WebApp**: Client-side rendering with Razor Pages, communicates with WebApi via HTTP.
- **WebApi**: Handles business logic, persistence, and authentication.
- **Application**: CQRS commands/queries with MediatR.
- **Domain**: Entities and interfaces.
- **Infrastructure**: EF Core and repository implementations.
## Setup
### Prerequisites
- .NET 8 SDK
- SQL Server (LocalDB or full instance)
- Git
### Steps
1. **Clone the Repo**
```bash
git clone https://github.com/khachatur/ECommerceApp
cd ECommerceApp
```
2. **Configure Database**
Update ECommerceApp.WebApi/appsettings.json with your connection string.
Apply migrations:
```bash
Apply migrations:
dotnet ef migrations add InitialCreate -p src/ECommerceApp.Infrastructure -s src/ECommerceApp.WebApi -o Data/Migrations
dotnet ef database update -p src\ECommerceApp.Infrastructure -s src\ECommerceApp.WebApi
```
3. **Add Stored Procedure**
Run in SQL Server:
```sql
CREATE PROCEDURE UpdateProductStock
@ProductId INT,
@Quantity INT
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
UPDATE Products
SET Quantity = Quantity - @Quantity
WHERE Id = @ProductId AND Quantity >= @Quantity;
IF @@ROWCOUNT = 0
THROW 50001, 'Insufficient stock or product not found.', 1;
END TRY
BEGIN CATCH
THROW;
END CATCH
END
GO
```
4. **Set JWT Config**
In ECommerceApp.WebApi/appsettings.json:
```json
"Jwt": {
"Secret": "MySecretKeyHere1234567890MySecretKeyHere1234567890",
"Issuer": "ECommerceApp",
"Audience": "ECommerceApp",
"ExpirationInMinutes": "60"
}
```
5. **Run Locally**
- WebApi:
```bash
cd ECommerceApp.WebApi && dotnet run
```
- WebApp:
```bash
cd ECommerceApp.WebApp && dotnet run
```
- Visit WebApi at https://localhost:7051 and WebApp at https://localhost:7041.
**Docker Setup**
1. Docker Compose
- Run:
```
docker-compose up --build
```
- Apply migrations in webapi container
```
docker exec -it dotnet ef database update
```
**_CI/CD Setup_**
1. **GitHub Actions**
- Workflow: .github/workflows/ci-cd.yml builds, publishes, and pushes Docker images to Docker Hub.
- Add secrets in GitHub:
- DOCKER_USERNAME
- DOCKER_PASSWORD (access token)
2. Trigger: Pushes/PRs to main branch.
**_API Endpoints_**
- **POST** /api/auth/login: { "username": "string", "password": "string" } → { "token": "jwt" }
- **GET** /api/products: Returns product list.
- **POST** /api/orders: { "orderItems": [{ "productId": int, "quantity": int }] } → Order ID (requires JWT).
- **GET** /api/orders: Returns user’s orders (requires JWT).
**License**
- MIT License