# Nop.Plugin.Misc.AIPlugin (FruitBank nopCommerce Plugin)

> For FruitBankHybridApp domain rules see: `../../../../../FruitBankHybridApp/.github/copilot-instructions.md`
> For Mango.Nop library docs see: `../../Libraries/README.md`

The **server-side nopCommerce plugin** for FruitBank. Runs inside nopCommerce 4.80.9 (net9.0). Handles admin UI, SignalR hubs, data access, measurements, orders, shipping, and AI services.

Project file: `Nop.Plugin.Misc.FruitBankPlugin.csproj`

## Folder Structure

| Folder | Purpose | Key Types |
|---|---|---|
| `Areas/Admin/Controllers/` | Admin-side MVC controllers — order, product, shipping, SignalR endpoints, file management | `CustomOrderController`, `CustomOrderSignalREndpoint`, `ShippingController`, `StockSignalREndpointServer`, `CustomProductController` |
| `Areas/Admin/Components/` | Admin ViewComponents — DevExtreme grids | `ShippingGridComponent`, `ShippingDocumentGridComponent`, `PartnersGridComponent`, `FileUploadGridComponent` |
| `Areas/Admin/Models/` | Admin view models — shipping, order, product, app download | `ShippingModel`, `ShippingSearchModel`, `OrderSearchModelExtended`, `GridBaseViewModel` |
| `Areas/Admin/Views/` | Admin Razor views |  |
| `Components/` | Public-side ViewComponents | |
| `Controllers/` | Public-side controllers | `CheckoutController`, `FruitBankDataController` |
| `Domains/` | Entity configuration + data layer | `CustomTable`, `FruitBankDbContext` |
| `Domains/DataLayer/` | DbTable classes — EF Core repository per entity | `ShippingDbTable`, `OrderDtoDbTable`, `ShippingItemPalletDbTable`, etc. |
| `Domains/DataLayer/Interfaces/` | Repository interfaces | `IShippingDbSet`, `IOrderDtoDbSet`, `IShippingItemPalletDbSet`, etc. |
| `Domains/EventConsumers/` | nopCommerce entity event handlers | `FruitBankEventConsumer` |
| `Factories/` | Model factories — build admin models from entities | `ShippingModelFactory`, `MgOrderModelFactory`, `MgProductModelFactory` |
| `Filters/` | MVC action filters | `PendingMeasurementCheckoutFilter` |
| `Helpers/` | Utility helpers | `TextHelper` |
| `Infrastructure/` | Plugin startup, routing, view engine | `PluginNopStartup`, `RouteProvider`, `ViewLocationExpander` |
| `Mapping/` | EF Core entity mapping builders | `PluginBuilder`, `NameCompatibility` |
| `Migrations/` | Database schema migrations | `SchemaMigration` |
| `Models/` | Shared models — AI chat, MgBase extensions | `AIChatMessage`, `MgOrderModelExtended`, `MgProductModelExtended` |
| `Models/Orders/` | Order-specific admin models | `OrderModelExtended`, `OrderAttributesModel`, `OrderRevisionModel` |
| `Models/Products/` | Product-specific admin models | `ProductModelExtended`, `ProductAttributesModel` |
| `Services/` | Business logic services | See below |

## Key Services

| Service | Purpose |
|---|---|
| `MeasurementService` / `IMeasurementService` | Shipping measurement logic (weighing pallets) |
| `OrderMeasurementService` | Order measurement logic (outbound weighing) |
| `FruitBankHub` | SignalR hub — real-time communication with FruitBankHybridApp clients |
| `FruitBankAttributeService` | GenericAttribute CRUD for FruitBank-specific attributes |
| `FileStorageService` / `IFileStorageProvider` | File upload/download, local storage |
| `LockService` / `ILockService` | Distributed locking |
| `CustomPriceCalculationService` | Custom price calculation override |
| `AICalculationService` | AI-powered calculations |
| `OpenAIApiService` / `OpenAIService` | OpenAI GPT integration |
| `CerebrasAPIService` | Cerebras AI API integration |
| `InnvoiceApiService` / `InnVoiceOrderService` | Billingo/Innvoice integration |
| `PdfToImageService` | PDF rendering to images |

## SignalR Endpoints

The plugin exposes SignalR endpoints consumed by FruitBankHybridApp:

| Endpoint | File | Role |
|---|---|---|
| `CustomOrderSignalREndpoint` | `Areas/Admin/Controllers/` | Order CRUD + measurement via SignalR |
| `StockSignalREndpointServer` | `Areas/Admin/Controllers/` | StockTaking CRUD via SignalR |
| `FruitBankHub` | `Services/` | Main SignalR hub |

## Dependencies

- `Mango.Nop.Core`, `Mango.Nop.Services` (ProjectReferences via `../../Libraries/`)
- `Nop.Services`, `Nop.Web` (nopCommerce ProjectReferences)
- DevExpress ASP.NET Core 25.1.3
- SignalR, EF Core 9.0, PdfPig, PDFtoImage
