Modern manufacturing industries require high precision inventory tracking, strict internal access controls, and absolute database consistency. This .NET 8 Web API is engineered as a complete, transactional backend system for an electronics assembly factory. By utilizing advanced design patterns, the API secures operations andautomates complex logistical workflows from component procurement to finished goods assembly and general ledger accounting.
Architectural Layout
The system is built upon Clean Architecture (Onion Architecture) principles to separate concerns, keep business logic independent of external frameworks, and make unit testing effortless.
- Domain Project (Core): Contains pure database entities (Products, Suppliers, BOMs, AssemblyOrders, Customers, SalesOrders, FinanceTransactions, Employees, Roles, RolePermissions, AuditLogs) and base entities. Zero external references.
- Application Project (Business Rules): Defines the DTO schemas (Data Transfer Objects), AutoMapper profiles, business service interfaces, and core business rule implementations.
- Infrastructure Project (Data Persistence): Contains the Entity Framework Core DbContext, DB Migrations, Token Generation Services, and Repository implementations.
- Web API Project (Presentation): Exposes clean, secure REST endpoints configured with JWT authentication middleware and Swagger UI.
Core Architectural Patterns Implemented
- Generic Repository & Unit of Work Patterns:
Instead of writing redundant SQL or EF Core queries for each table, a central Generic Repository handles all CRUD actions. The Unit of Work pattern manages a central DbContext transaction. If a multi-step operation (like assembly) fails midway, the entire transaction is rolled back, preventing orphaned rows and data leaks.
2. Dynamic Database-Driven Access Matrix (RBAC):
Unlike static, hardcoded role configurations, this API implements a fully dynamic Role-Permissions Matrix. Admins can create roles and check/uncheck permissions (View, Create, Update, Delete) across 14 modules. The backend verifies these permissions using a custom [HasPermission] filter that dynamically inspects JWT claims.
3. Atomic Assembly & Bill of Materials (BOM) Algorithm:
The assembly engine checks raw component stocks against the selected finished good's BOM. If stock is sufficient, it deducts parts, places the product in Pending QA status, and logs a successful production order in a single transaction.
4. Accounts Payable & Receivable General Ledger (Finance):
Tracks outstanding balances. When a Sales Order (AR) or Purchase Order (AP) is created, the system logs outstanding balances. Financial payments dynamically reconcile these balances, log double-entry cashbook transactions, and recalculate available company capital.
5. Chronological Security Audit Trail:
Every sensitive write operation automatically triggers an immutable security audit log capturing the username, action, module category, timestamp, and IP address.
Database Schema & Performance Optimization
- Designed on Microsoft SQL Server 2025.
- Configured using Fluent API to restrict cascade deletes on critical tables (Customers, Suppliers, Products) to preserve financial and operational logs.
- Utilizes sequential indexing on transaction codes (Invoices, POs, and Receipts).