A robust RESTful API built with ASP.NET Core 8 for comprehensive inventory management, featuring clean architecture, advanced security, and automated workflows.
- Product Management: Complete CRUD operations for products with detailed specifications
- Category Management: Hierarchical category organization and management
- Transaction Tracking: Real-time inventory transactions with audit trails
- Low-Stock Alerts: Automated notifications when inventory levels drop below thresholds
- JWT Authentication: Secure token-based authentication system
- Role-Based Access Control (RBAC): Granular permissions for different user roles
- ASP.NET Identity Integration: Comprehensive user management
- User Registration: Automated account creation with email verification
- Password Reset: Secure password recovery via email
- System Alerts: Real-time notifications for critical inventory events
- SMTP Email Services: Reliable email delivery for all automated communications
This project follows Clean Architecture principles with CQRS pattern implementation:
├── API Layer (Controllers, Middleware)
├── Application Layer (Commands, Queries, Handlers)
├── Domain Layer (Entities, Exceptions, Repositories, Specifications, Value Objects)
└── Infrastructure Layer (Data Access, Migrations, External Services)
- Clean Architecture: Separation of concerns with dependency inversion
- CQRS (Command Query Responsibility Segregation): Separate models for read and write operations
- MediatR: In-process messaging for decoupled communication
- Repository Pattern: Abstracted data access layer
The system uses Microsoft SQL Server with the following core entities and relationships:
erDiagram
Category {
int id PK
string name
string description
}
Product {
int id PK
int category_id FK
string name
string description
decimal price
int stock_qty
string supplier
datetime create_at
datetime update_at
}
LowStockAlert {
int id PK
int product_id FK
int threshold
boolean alert_sent
datetime create_at
datetime sent_at
datetime last_alert
}
Transaction {
int id PK
int product_id FK
string create_by FK
int quantity
enum type "Purchase/Sale"
datetime create_date
datetime update_date
decimal total_amount
enum status "Success/Pending/Rejected"
datetime cancelled_date
string cancelled_reason
string cancelled_by
}
Payment {
int id PK
int transaction_id FK
decimal amount
string method
enum status
datetime created_at
}
User {
string user_id PK
string first_name
string last_name
string address
string phone_number
string image_path
string email_confirmed_token
string email_confirmed_code
string email_confirmed_code_expires
string password_confirmed_token
string password_confirmed_code
string password_confirmed_code_expires
}
RefreshToken {
int id PK
string user_id FK
string token
datetime expiration_on
datetime create_on
datetime revoked_on
}
Category ||--o{ Product : "has many"
Product ||--o{ Transaction : "has many"
Product ||--o| LowStockAlert : "has one"
Transaction ||--o| Payment : "has one"
User ||--o{ Transaction : "creates many"
User ||--o{ RefreshToken : "has many"
- Category → Product: One-to-Many (A category can have multiple products)
- Product → Transaction: One-to-Many (A product can have multiple transactions)
- Product → LowStockAlert: One-to-One (Each product can have one active alert)
- Transaction → Payment: One-to-One (Each transaction can have one payment record)
- User → Transaction: One-to-Many (A user can create multiple transactions)
- User → RefreshToken: One-to-Many (A user can have multiple refresh tokens)
- Framework: ASP.NET Core 8
- Language: C#
- Architecture: Clean Architecture, CQRS
- ORM: Entity Framework Core
- Database: Microsoft SQL Server
- Authentication: ASP.NET Identity + JWT
- Validation: Fluent Validation
- Mapping: AutoMapper
- Logging: Serilog
- Messaging: MediatR
- Email: SMTP Email Services
- .NET 8 SDK
- Microsoft SQL Server (LocalDB or full instance)
- Visual Studio 2022 or VS Code
- Git
git clone https://github.com/yourusername/InventoryManagementSystme.git
cd InventoryManagementSystmeUpdate the connection string in appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=InventoryManagementDB;Trusted_Connection=true;MultipleActiveResultSets=true"
}
}Add the JWT configuration in appsettings.json:
{
"JwtOptions": {
"SecretKey": "your-secret-key",
"Issuer": "InventoryAPI",
"Audience": "InventoryClients",
"ExpirationInMinutes": 60
}
}Add SMTP configuration in appsettings.json:
{
"EmailSettings": {
"Host": "smtp.gmail.com",
"Port": 587,
"Email": "your-email@gmail.com",
"Password": "your-app-password",
"DisplayName": "Abdalrhman Gamal"
}
}dotnet ef database updatedotnet runThe API will be available at https://localhost:7036 or http://localhost:5086.
Once the application is running, access the interactive API documentation:
- Swagger UI:
https://localhost:7036/swagger
POST /api/auth/register- User registration with email confirmationPOST /api/auth/login- User login with JWT token responseGET /api/auth/email-confirmation- Confirm email with verification codeGET /api/auth/resend-confirmation- Resend confirmation emailPOST /api/auth/forget-password- Initiate password resetPOST /api/auth/reset-password- Complete password resetGET /api/auth/refreshToken- Refresh JWT tokenPOST /api/auth/revokeToken- Revoke refresh token
GET /api/account- Get current user profilePUT /api/account- Update user profilePATCH /api/account/change-password- Change user passwordDELETE /api/account- Delete user accountPOST /api/account/image- Upload profile imageDELETE /api/account/image- Delete profile image
GET /api/account/admin/users- Get all users (paginated, sortable)POST /api/account/admin/role- Add user to roleDELETE /api/account/admin/role- Remove user from role
GET /api/products- Get all products (paginated, sortable, filterable)POST /api/products- Create new productGET /api/products/{id}- Get product by IDPUT /api/products/{id}- Update productDELETE /api/products/{id}- Delete product
GET /api/categories- Get all categories (paginated)POST /api/categories- Create new categoryPUT /api/categories/{id}- Update categoryDELETE /api/categories/{id}- Delete category
GET /api/transactions- Get transaction history (paginated, sortable, date filterable)POST /api/transactions- Create new transaction (Purchase/Sale)GET /api/transactions/{id}- Get transaction by IDPUT /api/transactions/{id}- Update transactionDELETE /api/transactions/cancel/{id}- Cancel transaction with reason
POST /api/lowstockalerts- Create low stock alert for productGET /api/lowstockalerts/{id}- Get low stock alert by IDGET /api/lowstockalerts/product/{productId}- Get alert by product IDPUT /api/lowstockalerts/{id}- Update alert threshold
{
"email": "admin@gmail.com",
"userName": "admin",
"roles": ["Admin"],
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"tokenExpiration": "2025-07-27T19:50:03Z",
"refreshToken": "4H%O60FYYbp1AiJL51Wc2wHljgD9v4uoyKBSLsRfO14=",
"refreshTokenExpiration": "2025-08-03T21:48:53.6963819+03:00"
}{
"id": 1,
"name": "Dell Laptop",
"description": "High-performance laptop",
"category": "Electronics",
"price": 1100.00,
"stockQuantity": 7,
"supplier": "Tech Supplier Inc",
"createdAt": "2025-08-10T11:42:41.1491153",
"updatedAt": null
}{
"id": 4,
"productId": 4,
"productName": "Dell Laptop",
"createdBy": "John Doe",
"status": "Success",
"createdDate": "2025-08-10T11:45:44.9577731",
"updatedDate": "2025-08-10T11:47:09.3101133",
"transactionType": "Sale",
"quantity": 3,
"totalAmount": 3300.00
}{
"id": 2,
"productId": 4,
"productName": "Dell Laptop",
"currentStock": 1,
"threshold": 3,
"alertSent": true,
"createdAt": "2025-08-14T08:28:02.6090022",
"sentAt": "2025-08-14T13:48:41.679634",
"lastAlertSent": "2025-08-14T13:48:41.679634"
}The API uses JWT (JSON Web Tokens) for authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
- Admin: Full system access
- Manager: Inventory management and reporting
- User: Limited read access and basic operations
All list endpoints support pagination and sorting:
GET /api/products?PageSize=10&PageNumber=1&SortBy=price&SortDirection=Ascending
GET /api/transactions?startDate=2025-08-01&endDate=2025-08-31&TransactionType=Purchase
- Transaction Types: Purchase (stock increase) and Sale (stock decrease)
- Status Tracking: Success, Pending, Rejected with full audit trail
- Cancellation: Soft delete with reason tracking for audit compliance
The application uses Serilog for structured logging. Logs are written to:
- Console
- File:
Logs/log-.txt