Skip to content

IbrahimS11/StoreManagementSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

30 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏬 Store Management System - Backend

πŸ“Œ Project Overview

The Store Management System is a robust backend solution designed to handle real-world retail operations with a strong focus on clean architecture, scalability, and maintainability.

It manages the complete business workflow, starting from supplier purchases and inventory tracking, through product management with categories, variations, and pricing, and ending with customer orders and payment processing.

The system is built using a layered architecture where responsibilities are clearly separated between controllers, services, and repositories. Business logic is centralized in the service layer, while data access is handled through repositories using Entity Framework Core.

Security is implemented using ASP.NET Identity and JWT-based authentication, ensuring protected API endpoints and role-based authorization. The backend is fully integrated with an Angular frontend to demonstrate real-world usage, secure token handling, and controlled access through CORS policies.

With a normalized database design, generic repository pattern, centralized response handling, and global exception management, the project reflects enterprise-level backend development practices.


πŸš€ Key Features

  • Clean layered architecture with clear separation between Controllers, Services, and Repositories
  • Business logic handled exclusively in the Service layer
  • Generic Repository for common CRUD operations with virtual methods for extensibility
  • Dependency Injection for DbContext, services, and repositories
  • Centralized result handling using ResultService
  • Global exception handling for consistent error responses
  • Secure Authentication & Role-based Authorization

πŸ›  Technologies & Concepts Used

πŸ“‚ Database & ORM

  • SQL Server - Entity Framework Core (EF Core) - LINQ

βš™ Backend & API Development

  • ASP.NET Core Web API - RESTful API Design - DTOs - Pagination - Middleware - Filters - AutoMapper - Global Exception Handling - Swagger - Postman

🧱 Architecture & Design Patterns

  • SOLID Principles - Repository Pattern - Unit of Work Pattern - Service Layer

πŸ” Security & Authentication

  • ASP.NET Identity - JWT (JSON Web Tokens) - Authentication & Authorization - CORs

🧩 Dependency & Infrastructure

  • Dependency Injection (DI) - Logging

πŸ“Š System Design

Use Case Flow

Store Management System ERD

ERD (Logical Database Design)

Store Management System ERD

πŸ—„ Database Implementation Diagram (Implemented Using Code-First Approach)

Database Implementation Diagram


πŸ“‚ Project Structure

  • The project follows a clean and organized structure to ensure scalability, maintainability, and clear separation of concerns.

StoreManagementSystem/
β”‚
β”œβ”€β”€ AutoMapper/
β”‚   └── Mapping profiles
β”‚
β”œβ”€β”€ Controllers/
β”‚   └── API controllers (REST endpoints)
β”‚
β”œβ”€β”€ Data/
β”‚   β”œβ”€β”€ Config/
β”‚   β”‚   └── Entity configurations (Fluent API)
β”‚   └── AppDbContext.cs
β”‚
β”œβ”€β”€ DTOs/
β”‚   └── Data Transfer Objects
β”‚
β”œβ”€β”€ Filters/
β”‚   └── Custom filters & exception handling
β”‚
β”œβ”€β”€ Identity/
β”‚   └── Identity setup
β”‚
β”œβ”€β”€ Migrations/
β”‚   └── EF Core migrations
β”‚
β”œβ”€β”€ Models/
β”‚   └── Domain entities
β”‚
β”œβ”€β”€ Repositories/
β”‚   β”œβ”€β”€ Interfaces/
β”‚   └── Implementations/
β”‚
β”œβ”€β”€ Services/
β”‚   β”œβ”€β”€ Interfaces/
β”‚   └── Implementations/
|   └── ResultService.cs 
|
β”œβ”€β”€ assets/
β”‚   └── Project diagrams and documentation images
β”‚
β”œβ”€β”€ GlobalUsing.cs
β”‚
β”œβ”€β”€ Program.cs
β”‚
└── appsettings.json

πŸ“˜ Domain Models Structure

  • The domain layer groups related entities into the same folders to improve organization, readability, and ease of maintenance.
Models/
β”‚
β”œβ”€β”€ Customers/
β”‚   β”œβ”€β”€ Customer.cs
β”‚   β”œβ”€β”€ CustomerAddress.cs
β”‚   └── CustomerPayment.cs
β”‚
β”œβ”€β”€ Inventories/
β”‚   β”œβ”€β”€ Inventory.cs
β”‚   β”œβ”€β”€ Purchase.cs
β”‚   β”œβ”€β”€ PurchaseItem.cs
β”‚   └── PurchaseStatus.cs
β”‚
β”œβ”€β”€ Locations/
β”‚   β”œβ”€β”€ City.cs
β”‚   └── Street.cs
β”‚
β”œβ”€β”€ Orders/
β”‚   β”œβ”€β”€ Order.cs
β”‚   β”œβ”€β”€ OrderItem.cs
β”‚   └── OrderStatus.cs
β”‚
β”œβ”€β”€ Products/
β”‚   β”œβ”€β”€ Category.cs
β”‚   β”œβ”€β”€ Product.cs
β”‚   β”œβ”€β”€ ProductFlavor.cs
β”‚   └── ProductUnitPrice.cs
β”‚
└── Suppliers/
    β”œβ”€β”€ Supplier.cs
    β”œβ”€β”€ SupplierAddress.cs
    └── SupplierPayment.cs
 

🧠 Design Notes

  • The domain layer groups related entities into the same folders

  • The same folder structure is consistently applied across:

    • DTOs
    • EF Core Configurations
    • Repositories
    • Services

This design approach ensures:

βœ” Better organization and readability
βœ” Easier maintenance
βœ” High cohesion
βœ” Low coupling
βœ” Scalability for future features


πŸ— Clean Architecture & Code Quality

The backend is built with a strong focus on clean code principles and maintainable architecture.

Key design decisions include:

  • Clear separation of layers:

    • Controllers for handling HTTP requests

    • Services for business logic and validations

    • Repositories for data access

  • Business logic is fully encapsulated within the Service layer, ensuring thin controllers.

  • A Generic Repository is implemented to handle common CRUD operations, with virtual methods that allow overriding behavior in specialized repositories when needed.

  • Full reliance on Dependency Injection (DI) for:

    • AppDbContext

    • Services

    • Repositories

    ensuring loose coupling and easier testing.

  • A centralized ResultService in path : Services \ ResultService.cs is used to standardize API responses and improve communication between services and controllers.

  • Global Exception Handling middleware ensures consistent error handling and prevents application crashes.


⚑ Performance & Data Consistency

  • A Unit of Work pattern is implemented to control:

    • Database context lifecycle

    • SaveChangesAsync() operations

    • Transactions and commits

  • The Unit of Work is injected into the Service layer to ensure consistent and controlled database operations and to help prevent race condition issues.

  • All database interactions are implemented using asynchronous operations to:

    • Improve performance

    • Avoid blocking requests

    • Ensure better scalability under load

This approach ensures reliable data consistency while maintaining high application responsiveness.


πŸ”— API Integration & Authentication Flow

The backend API is fully integrated with an Angular frontend to demonstrate real-world usage and secure communication.

βœ… Swagger API Testing

image image image

A Swagger UI screenshot is included to confirm:

  • Some endpoints
  • API responses are returned as expected

🌐 CORS Policy Configuration

To enhance security, the backend CORS policy allows requests only from:

http://localhost:4200

ensuring controlled access from the Angular frontend.

  • And Can you change accessability to endpoints from Program.cs
  builder.Services.AddCors(options =>
  {
      options.AddPolicy("Users", policy =>
      {
          policy.WithOrigins("http://localhost:4200") 
                .AllowAnyMethod()
                .AllowAnyHeader();
      });
  });

πŸ” JWT Authentication with Angular

The Angular application includes:

  • A login component for user authentication
  • An authentication service responsible for handling login requests and token storage
  • Secure client-side storage of the JWT token
  • An HTTP interceptor that automatically attaches the token to request headers for authorized API calls

The screenshot below demonstrates the complete end-to-end data flow:

Database Implementation Diagram

A frontend snapshot showing:

  • A successful login process
  • The JWT token printed in the browser console (for testing purposes only)
  • API responses received in the ProductService
  • Products displayed in the ProductComponent

This confirms: βœ” Secure authentication flow βœ” Proper token handling βœ” Authorized access to protected endpoints βœ” Successful frontend-backend integration


β–Ά How to Run the Project

  1. Clone the repository
  2. Configure connection string in appsettings.json
  3. Run database migrations:
  4. Run the project using Visual Studio

βš™ Configuration

  • SQL Server connection string
  • JWT settings (Secret Key, Issuer, Audience)
  • Logging configuration

πŸ‘¨β€πŸ’» Author

Ibrahim Samir
Software Engnieer (.Net) - Back-End Developer