# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Project Overview This is a Manufacturing Execution System (MES) built with .NET 8.0. The solution consists of two main projects: - **MES.Service**: Service layer containing business logic, data access, and DTOs - **MESApplication**: Web API application layer with controllers and HTTP endpoints ## Database Environment Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production - PL/SQL Release 11.2.0.1.0 - Production - CORE 11.2.0.1.0 Production - TNS for 64-bit Windows: Version 11.2.0.1.0 - Production - NLSRTL Version 11.2.0.1.0 - Production **IMPORTANT**: All code must be compatible with Oracle 11g Release 11.2.0.1.0 ## Architecture ### Database Layer - Uses **SqlSugar ORM** for data access with Oracle database - Connection string configured in `appsettings.json` and loaded via `AppsettingsUtility.Settings.DataBaseConn` - Three database access patterns available: - `Repository` (MES.Service/DB/Repository.cs:6) - Base class for all Manager classes, extends SqlSugar's SimpleClient with Oracle configuration and transaction support via `UseTransaction()` method - `DbContext` (MES.Service/DB/DbContext.cs:10) - Generic repository pattern for SqlServer (legacy, not actively used) - `SqlSugarHelper` (MES.Service/DB/SqlSugarHelper.cs:6) - Static Oracle helper with `GetInstance()` and `UseTransactionWithOracle()` methods - **IMPORTANT**: Most services inherit from `Repository`, which provides pre-configured Oracle connection and built-in transaction management ### Service Layer Structure - **BasicData**: Core business entities (customers, items, suppliers, etc.) - **QC**: Quality control services (PCB testing, inspections) - **Warehouse**: Inventory management and warehouse operations - **Dto**: Data Transfer Objects split into: - `service/`: Internal service DTOs - `webApi/`: External API DTOs for ERP integration ### API Layer - ASP.NET Core Web API with Swagger documentation (available in Development mode) - Controllers organized by domain (BasicData, QC, Warehouse, FBSDB) - Newtonsoft.Json for serialization with camelCase naming (configured in Startup.cs:46) - CORS enabled for cross-origin requests - Custom ActionFilter (MESApplication/Filter/ActionFilter.cs) for global request/response logging - All endpoints use `[HttpPost]` by convention, even for read operations - Route pattern: `api/[controller]/[action]` ## Common Development Commands ### Build and Run ```bash # Build the entire solution dotnet build # Build specific project dotnet build MESApplication/MESApplication.csproj dotnet build MES.Service/MES.Service.csproj # Run the web application dotnet run --project MESApplication # Run in specific configuration dotnet run --project MESApplication --configuration Release ``` ### Development ```bash # Restore NuGet packages dotnet restore # Clean build artifacts dotnet clean # Publish for deployment dotnet publish MESApplication -c Release -o ./publish ``` ## Key Configuration ### Database Connection - Oracle database connection configured in `appsettings.json` - Connection string: `AppSettings.DataBaseConn` - Database type switches between Oracle (SqlSugarHelper) and SqlServer (DbContext) ### ERP Integration - Test URL: `AppSettings.TestErpUrl` - Production URL: `AppSettings.ProductionErpUrl` - Located in `MESApplication/appsettings.json` ## Important Patterns ### Repository Pattern All business logic follows the Manager pattern with inheritance-based repository access: - **Managers** in `MES.Service/service/` inherit from `Repository` and handle business operations - Example: `MesCustomerManager : Repository` (47 Manager classes total) - Managers use `UseTransaction(db => {...})` for transactional operations - Directly access SqlSugar methods via inherited SimpleClient functionality - **Controllers** in `MESApplication/Controllers/` handle HTTP requests and instantiate Manager classes - Controllers manually create Manager instances (e.g., `new MesCustomerManager()`) - Use `ResponseResult` utility class for standardized API responses - Controllers wrap Manager calls in try-catch blocks and log to MessageCenter - **Models** in `MES.Service/Modes/` represent database entities with SqlSugar attributes ### Service Registration and Response Format Services are manually instantiated rather than using dependency injection containers: - Controllers directly instantiate Managers: `private readonly MesCustomerManager m = new();` - Startup.cs configures `AppSettings` from appsettings.json into static `AppsettingsUtility.Settings` - No DI container for business logic - all service creation is explicit All API endpoints return `ResponseResult` (MES.Service/util/ResponseResult.cs:7) with structure: ```csharp { status: 0, // 0 = success, 1 = failure message: "OK", // error message or "OK" data: object, // response payload wrapped in ExpandoObject TotalCount: 0 // optional pagination count } ``` ### Error Handling - `ActionFilter` (MESApplication/Filter/ActionFilter.cs:13) handles global request/response processing - Logs all requests with headers and body parameters - Logs all responses with execution time - Catches exceptions and logs via `ErrorLog.Write()` - SQL logging enabled via SqlSugar AOP for debugging (prints to Console) - All Controller methods catch exceptions and return `ResponseResult.ResponseError(ex)` - ERP integration operations logged to `MessageCenter` table with status tracking ## API Documentation API documentation is available in the `MESApplication/Docs/` folder: - `Spi_API.md` - SPI (Solder Paste Inspection) API documentation - `Aoi_API.md` - AOI (Automated Optical Inspection) API documentation ## Testing No test projects are currently configured in this solution. When adding tests, create separate test projects following .NET testing conventions. ## Key Utilities - `AppsettingsUtility` (MES.Service/util/AppsettingsUtility.cs:6) - Loads configuration into static `Settings` property - `ResponseResult` (MES.Service/util/ResponseResult.cs:7) - Standardized API response wrapper - `ErrorLog` - Custom error logging utility used by ActionFilter