# TANRAIL ONE — Phase 3 Implementation Plan

## 1. Implementation Order
The Core must be built in strict dependency order, starting from the most foundational entities.

1. **Phase 3A: Master Data Foundation**
   - Customer, Supplier, Unit, Tax Category.
2. **Phase 3B: Catalog Architecture**
   - Item (Product/Service).
3. **Phase 3C: Inventory Engine**
   - StockLocation, StockBalance, StockMovement.
4. **Phase 3D: Sales & Ordering**
   - Order, OrderLine.
5. **Phase 3E: Invoicing & Billing**
   - Invoice, InvoiceLine.
6. **Phase 3F: Financials & Payments**
   - Payment, Expense.
7. **Phase 3G: Core Integration Testing**
   - End-to-end transaction loops proving Core operates independently.

## 2. Testing Architecture
The Core testing strategy guarantees isolation and integrity.

- **Scope Isolation Tests:** Prove `Business Unit A` cannot read `Business Unit B`'s orders, even using the exact same Core logic.
- **Transaction Tests:** Prove that if a Payment fails, the Invoice status rolls back and the Order remains unpaid.
- **Polymorphic Tests:** Prove that a Customer can belong to the Organization globally, while an Order belongs strictly to the Business Unit.

## 3. AI Development Safety Rules
To prevent AI agents (or human developers) from violating the architecture, the following rules are strictly enforced:

**FORBIDDEN IN `app/Domains/Core/*`:**
- Creating models named `Restaurant*`, `Catering*`, `Water*`, `Transport*`.
- Creating fields named `table_number`, `event_date`, `delivery_driver`.
- Creating logic specific to physical vs digital goods (Core handles abstract `Items`).
- Referencing namespaces outside of `App\Domains\Core` (except standard Laravel/System classes).

**Mandatory Action for AI Agents:**
If a feature request requires business-specific data (e.g., tracking "Dietary Requirements" for a meal), the agent MUST NOT add this column to the Core `Order` table. It must create an Extension table (e.g., `catering_order_details`) that belongs to the Core `Order`.
