Skip to content

Latest commit

ย 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฆ StockFlow

A full-stack Inventory Management System built with React + Vite on the frontend and ASP.NET Core Web API + Entity Framework Core + SQL Server on the backend.

StockFlow is designed to demonstrate practical backend and full-stack development concepts such as JWT authentication, role-based authorization, layered architecture, inventory validation, atomic stock operations, audit logging, database constraints, dependency injection, and RESTful API design.


๐Ÿš€ Features

๐Ÿ” Authentication & Authorization

  • JWT-based stateless authentication
  • BCrypt password hashing
  • Role-based access control with Admin and Employee roles
  • Backend authorization using [Authorize]
  • Admin-only operations protected at the API level
  • JWT stored and attached to requests by Axios on the frontend
  • Unauthorized actions return appropriate 401 / 403 responses

๐Ÿ“ฆ Product Management

  • Create, view, update, and delete products
  • Unique SKU validation
  • Product search
  • Pagination
  • Minimum stock level configuration

๐Ÿข Warehouse Management

  • Create, view, update, and delete warehouses
  • Store warehouse location details
  • Manage inventory across multiple warehouses

๐Ÿ“Š Inventory Management

  • View current inventory levels
  • Stock-in operations
  • Stock-out operations
  • Prevent stock from becoming negative
  • Low-stock detection based on minimum stock level
  • Track inventory separately for each product and warehouse

๐Ÿ“ Stock Movement History

  • Record every stock-in and stock-out operation
  • Store product, warehouse, user, quantity, movement type, and timestamp
  • Preserve historical movement records using restricted delete behavior

๐Ÿ›ก๏ธ Backend Reliability

  • Custom global exception handling middleware
  • Dependency Injection
  • EF Core migrations and database seeding
  • LINQ-based database queries
  • SQL Server constraints and indexes
  • Consistent API error responses
  • Built-in logging using ILogger

๐Ÿ“š API Documentation

  • Swagger / OpenAPI integration
  • Interactive API testing through Swagger UI
  • Clearly separated REST endpoints for authentication, products, warehouses, inventory, and stock movements

๐Ÿ—๏ธ Architecture

                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ”‚      React Client     โ”‚
                         โ”‚     Vite + Axios      โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                     โ”‚
                           HTTP + JWT Bearer
                                     โ”‚
                                     โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚     ASP.NET Core Web API    โ”‚
                    โ”‚                             โ”‚
                    โ”‚  CORS / Exception Middlewareโ”‚
                    โ”‚             โ”‚               โ”‚
                    โ”‚             โ–ผ               โ”‚
                    โ”‚       Controllers           โ”‚
                    โ”‚             โ”‚               โ”‚
                    โ”‚             โ–ผ               โ”‚
                    โ”‚        Services             โ”‚
                    โ”‚     Business Logic          โ”‚
                    โ”‚             โ”‚               โ”‚
                    โ”‚             โ–ผ               โ”‚
                    โ”‚        EF Core              โ”‚
                    โ”‚         DbContext            โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                                  โ–ผ
                            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                            โ”‚  SQL Server โ”‚
                            โ”‚ StockFlowDb โ”‚
                            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”„ Request Flow

Client Request
     โ”‚
     โ–ผ
Axios
     โ”‚
     โ–ผ
JWT Bearer Token
     โ”‚
     โ–ผ
ASP.NET Core Middleware
     โ”‚
     โ”œโ”€โ”€ Exception Handling
     โ””โ”€โ”€ CORS
     โ”‚
     โ–ผ
Controller
     โ”‚
     โ”œโ”€โ”€ Authentication / Authorization
     โ””โ”€โ”€ Request Validation
     โ”‚
     โ–ผ
Service Layer
     โ”‚
     โ”œโ”€โ”€ Business Rules
     โ”œโ”€โ”€ Inventory Validation
     โ”œโ”€โ”€ LINQ Queries
     โ””โ”€โ”€ Stock Movement Logging
     โ”‚
     โ–ผ
EF Core DbContext
     โ”‚
     โ–ผ
SQL Server

๐Ÿ› ๏ธ Technology Stack

Layer Technology
Frontend React
Build Tool Vite
Frontend Language JavaScript ES6+
Routing React Router DOM
HTTP Client Axios
Styling Vanilla CSS
Backend ASP.NET Core Web API
Language C#
Framework .NET 8
ORM Entity Framework Core 8
Database Microsoft SQL Server
Authentication JWT Bearer
Password Hashing BCrypt.Net-Next
API Documentation Swagger / OpenAPI
Logging ILogger

๐Ÿ—„๏ธ Database Design

StockFlow uses five main tables in SQL Server.

erDiagram

    Users {
        int Id PK
        string Username UK
        string Email UK
        string PasswordHash
        string Role
        datetime CreatedAt
    }

    Products {
        int Id PK
        string Name
        string SKU UK
        string Description
        decimal Price
        int MinimumStockLevel
        datetime CreatedAt
        datetime UpdatedAt
    }

    Warehouses {
        int Id PK
        string Name
        string Location
        datetime CreatedAt
    }

    Inventory {
        int Id PK
        int ProductId FK
        int WarehouseId FK
        int Quantity
        datetime LastUpdated
    }

    StockMovements {
        int Id PK
        int ProductId FK
        int WarehouseId FK
        int UserId FK
        int MovementType
        int Quantity
        datetime CreatedAt
    }

    Users ||--o{ StockMovements : records
    Products ||--o{ Inventory : stores
    Products ||--o{ StockMovements : traces
    Warehouses ||--o{ Inventory : houses
    Warehouses ||--o{ StockMovements : logs
Loading

๐Ÿ”‘ Database Constraints

  • Unique indexes

    • Users.Username
    • Users.Email
    • Products.SKU
  • Composite unique constraint

    • Inventory(ProductId, WarehouseId)
    • Ensures one inventory record exists for a product within a warehouse.
  • Historical integrity

    • StockMovements uses restricted deletion behavior so historical records are not accidentally orphaned.

๐Ÿ” Authentication & RBAC

StockFlow uses JWT (JSON Web Tokens) for authentication.

Authentication Flow

Login
  โ”‚
  โ–ผ
Validate Username + Password
  โ”‚
  โ–ผ
Verify BCrypt Password Hash
  โ”‚
  โ–ผ
Generate JWT
  โ”‚
  โ–ผ
Return Token + Username + Role
  โ”‚
  โ–ผ
Frontend Stores Authentication Data
  โ”‚
  โ–ผ
Axios Sends:
Authorization: Bearer <token>

๐Ÿ‘ฅ Role Authorization Matrix

Action Admin Employee
Login โœ… โœ…
View Products โœ… โœ…
Create / Edit / Delete Products โœ… โŒ
View Warehouses โœ… โœ…
Create / Edit / Delete Warehouses โœ… โŒ
View Inventory โœ… โœ…
Stock In โœ… โœ…
Stock Out โœ… โœ…
View Stock Movement History โœ… โœ…
Create User Accounts โœ… โŒ

Important: Frontend role checks only control the UI. The backend remains the final authority for authorization.


๐Ÿ“ก API Endpoints

๐Ÿ”‘ Authentication

Method Endpoint Authorization Description
POST /api/auth/login Public Validate credentials and return JWT

๐Ÿ‘ค Users

Method Endpoint Authorization Description
POST /api/users Admin Create a new user

๐Ÿ“ฆ Products

Method Endpoint Authorization Description
GET /api/products All Users Get products with search and pagination
GET /api/products/{id} All Users Get product by ID
POST /api/products Admin Create a product
PUT /api/products/{id} Admin Update a product
DELETE /api/products/{id} Admin Delete a product

Example search:

GET /api/products?search=mouse

๐Ÿข Warehouses

Method Endpoint Authorization Description
GET /api/warehouses All Users Get all warehouses
GET /api/warehouses/{id} All Users Get warehouse by ID
POST /api/warehouses Admin Create a warehouse
PUT /api/warehouses/{id} Admin Update a warehouse
DELETE /api/warehouses/{id} Admin Delete a warehouse

๐Ÿ“Š Inventory

Method Endpoint Authorization Description
GET /api/inventory All Users Get current inventory
GET /api/inventory/low-stock All Users Get low-stock products
POST /api/inventory/stock-in All Users Add stock and record movement
POST /api/inventory/stock-out All Users Remove stock after validation

๐Ÿ“ Stock Movement History

Method Endpoint Authorization Description
GET /api/stock-movements All Users Get stock movement history

โš™๏ธ Stock Operations

๐Ÿ“ฅ Stock In

Stock In Request
      โ”‚
      โ–ผ
Find Product + Warehouse
      โ”‚
      โ–ผ
Increase Inventory Quantity
      โ”‚
      โ–ผ
Create StockMovement Record
      โ”‚
      โ–ผ
Save Changes

๐Ÿ“ค Stock Out

StockFlow validates available inventory before removing stock.

Current Stock = 10
Requested Stock Out = 15

        โ†“

Insufficient Quantity

        โ†“

โŒ 400 Bad Request

This prevents negative inventory values.

๐Ÿ“‰ Low-Stock Detection

A product is considered low-stock when:

Current Quantity <= Minimum Stock Level

Low-stock products are highlighted on the Dashboard and Inventory page.


๐Ÿงพ Stock Movement Audit Trail

Every stock operation records:

Product
Warehouse
User
Movement Type
Quantity
Timestamp

Example:

Employee โ†’ Warehouse A โ†’ Laptop โ†’ STOCK_IN โ†’ +20
Employee โ†’ Warehouse A โ†’ Laptop โ†’ STOCK_OUT โ†’ -5

This provides a basic audit history of inventory changes.


๐Ÿ›ก๏ธ Global Exception Handling

StockFlow uses custom exception handling middleware to provide consistent API responses.

Example:

{
  "success": false,
  "message": "An unexpected error occurred."
}

Detailed exception information is logged using ILogger, while the client receives a controlled response.


๐Ÿ“š Swagger API Documentation

Once the backend is running, open:

http://localhost:5045/swagger

Swagger provides an interactive interface for:

  • Viewing API endpoints
  • Inspecting request models
  • Testing API operations
  • Checking response codes
  • Testing authenticated endpoints

๐Ÿงช Verification & Testing

The project includes practical verification scenarios for important business rules.

โœ… Test 1 โ€” Global Exception Handling

Trigger an invalid entity request or an unhandled service error.

Expected:

Controlled API error response
+
Exception logged on the server

โœ… Test 2 โ€” Stock-Out Validation

Try to remove more stock than currently available.

Example:

Available Stock: 5
Stock Out:       10

Expected:

400 Bad Request

The inventory quantity remains unchanged.

โœ… Test 3 โ€” Low-Stock Indicator

If:

Quantity <= MinimumStockLevel

the product is highlighted on the Dashboard and Inventory page.


๐Ÿ“ Project Structure

StockFlow/
โ”‚
โ”œโ”€โ”€ Backend/
โ”‚   โ”œโ”€โ”€ Controllers/
โ”‚   โ”œโ”€โ”€ Services/
โ”‚   โ”œโ”€โ”€ Models/
โ”‚   โ”œโ”€โ”€ Data/
โ”‚   โ”œโ”€โ”€ Middleware/
โ”‚   โ”œโ”€โ”€ Migrations/
โ”‚   โ””โ”€โ”€ Program.cs
โ”‚
โ”œโ”€โ”€ Frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ”œโ”€โ”€ context/
โ”‚   โ”‚   โ””โ”€โ”€ services/
โ”‚   โ”œโ”€โ”€ public/
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ””โ”€โ”€ README.md

๐Ÿš€ Getting Started

๐Ÿ“‹ Prerequisites

Install the following:


1๏ธโƒฃ Clone the Repository

git clone <your-repository-url>
cd StockFlow

2๏ธโƒฃ Set Up the Backend

cd Backend
dotnet restore

Apply EF Core migrations:

dotnet ef database update

This creates the StockFlowDb database and applies the existing migrations with seed data.


3๏ธโƒฃ Run the Backend API

dotnet run

Backend:

http://localhost:5045

Swagger:

http://localhost:5045/swagger

4๏ธโƒฃ Run the Frontend

Open a new terminal:

cd Frontend
npm install
npm run dev

Frontend:

http://localhost:5173

๐Ÿ”‘ Demo Credentials

Seeded accounts are available for testing both roles.

Role Username Password
๐Ÿ‘‘ Admin admin Admin@123
๐Ÿ‘ค Employee employee Employee@123

โš ๏ธ These credentials are intended for local/demo usage only.


๐Ÿ’ก Key Design Decisions

1. Layered Architecture

Business logic is separated from HTTP request handling.

Controller
    โ†“
Service
    โ†“
DbContext
    โ†“
SQL Server

This keeps controllers lightweight and makes the backend easier to maintain.

2. Dependency Injection

ASP.NET Core Dependency Injection is used to provide services and database dependencies where required.

3. EF Core + LINQ

Entity Framework Core handles database access while LINQ is used for queries such as:

  • Product search
  • Pagination
  • Inventory retrieval
  • Low-stock filtering
  • Stock movement history

4. Backend-First Authorization

Although the React UI hides restricted actions, authorization is enforced on the API itself.

This prevents users from bypassing UI restrictions by directly calling endpoints.

5. Inventory Integrity

Stock-out operations validate available quantity before modifying inventory, preventing negative stock.


๐Ÿ”ฎ Future Improvements

Planned improvements include:

  • ๐Ÿ”„ JWT refresh tokens
  • ๐Ÿ”€ Multi-warehouse stock transfers
  • ๐Ÿ—‘๏ธ Soft deletes for products and warehouses
  • ๐Ÿ“Š Advanced inventory analytics
  • ๐Ÿ“ˆ More detailed reporting
  • ๐Ÿ”Ž More advanced inventory filtering

๐Ÿ“Œ Project Status

Status: โœ… Completed

Current implementation includes:

  • โœ… JWT authentication
  • โœ… Admin / Employee RBAC
  • โœ… Product CRUD
  • โœ… Warehouse CRUD
  • โœ… Inventory management
  • โœ… Stock-in / stock-out
  • โœ… Low-stock detection
  • โœ… Stock movement history
  • โœ… BCrypt password hashing
  • โœ… EF Core migrations
  • โœ… SQL Server database
  • โœ… Global exception handling
  • โœ… Dependency Injection
  • โœ… Swagger / OpenAPI
  • โœ… React + Vite frontend

๐Ÿ‘จโ€๐Ÿ’ป Author

Yash Barai

MCA Student | Full-Stack Developer

Built as a practical full-stack project to demonstrate ASP.NET Core Web API, C#, EF Core, SQL Server, React, authentication, authorization, inventory business logic, and clean backend architecture.


โญ If you found this project useful, consider giving the repository a star!

About

Full-stack inventory management system built with React, ASP.NET Core Web API, EF Core, and SQL Server. Features JWT authentication, role-based access, multi-warehouse inventory, stock tracking, and movement history.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages