|
| 1 | +## Sharp Blueprint |
| 2 | +A Sharp Blueprint is a detailed implementation plan that helps AI agents write correct Sharp code. It bridges the gap between requirements and implementation by providing a structured specification for Sharp's unique patterns. |
| 3 | + |
| 4 | +### Core Philosophy |
| 5 | +Sharp separates the data structure from its visual representation. A blueprint should clearly map domain models to Sharp components: |
| 6 | +- **Entity Lists**: The primary data table. |
| 7 | +- **Forms**: Data entry and validation. |
| 8 | +- **Show Pages**: Detailed read-only views. |
| 9 | +- **Commands**: Business logic triggers. |
| 10 | +- **State Handlers**: Lifecycle management. |
| 11 | + |
| 12 | +### Blueprint Structure |
| 13 | +When asking an AI to create a blueprint, it should produce: |
| 14 | +1. **User Flows**: Step-by-step navigation through the feature. |
| 15 | +2. **Commands**: Required Artisan commands for scaffolding. |
| 16 | +3. **Models**: Detailed attribute, relationship, and cast definitions. |
| 17 | +4. **Sharp Components**: Specific configurations for Lists, Forms, Shows, and Commands. |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## SaaS Invoicing System - Sharp Implementation Plan |
| 22 | + |
| 23 | +### Overview |
| 24 | +A single-tenant admin panel for managing customers, products, invoices with line items, and tracking payments. |
| 25 | + |
| 26 | +### User Flows |
| 27 | +#### Flow 1: Creating an Invoice |
| 28 | +1. User navigates to Invoices List -> "New" |
| 29 | +2. User selects a Customer (Select field with autocomplete) |
| 30 | +3. User sets invoice date and due date |
| 31 | +4. User adds line items via List field: |
| 32 | + - Select Product |
| 33 | + - Enter quantity |
| 34 | + - Line total auto-calculates (handled in model/transformer) |
| 35 | +5. Tax rate is entered |
| 36 | +6. Invoice saves as Draft status |
| 37 | + |
| 38 | +#### Flow 2: Sending an Invoice |
| 39 | +1. User views a Draft invoice in its Show Page |
| 40 | +2. User clicks "Send" (Instance Command) |
| 41 | +3. Confirmation modal appears |
| 42 | +4. On confirm: status -> Sent, notification sent |
| 43 | + |
| 44 | +### Models |
| 45 | +#### Model: Customer |
| 46 | +- **Attributes**: `name`, `email`, `phone`, `address`, `notes` |
| 47 | +- **Relationships**: `hasMany` Invoices |
| 48 | + |
| 49 | +#### Model: Invoice |
| 50 | +- **Attributes**: `invoice_number`, `status` (Enum), `invoice_date`, `due_date`, `tax_rate` |
| 51 | +- **Relationships**: `belongsTo` Customer, `hasMany` InvoiceItem, `hasMany` Payment |
| 52 | + |
| 53 | +### Sharp Components |
| 54 | + |
| 55 | +#### InvoiceEntity |
| 56 | +- **Location**: `App\Sharp\Entities\InvoiceEntity` |
| 57 | +- **Config**: |
| 58 | + - `list`: `InvoiceList` |
| 59 | + - `show`: `InvoiceShow` |
| 60 | + - `form`: `InvoiceForm` |
| 61 | + - `state`: `InvoiceStateHandler` |
| 62 | + |
| 63 | +#### InvoiceList |
| 64 | +- **Columns**: |
| 65 | + - `invoice_number`: label "Number", sortable |
| 66 | + - `customer:name`: label "Customer" |
| 67 | + - `invoice_date`: label "Date", sortable |
| 68 | + - `total`: label "Total", money format |
| 69 | + - `state`: label "Status", state badge |
| 70 | +- **Filters**: `InvoiceStatusFilter`, `DateRangeFilter` |
| 71 | + |
| 72 | +#### InvoiceForm |
| 73 | +- **Layout**: |
| 74 | + - Section "General": `customer_id`, `invoice_date`, `due_date` |
| 75 | + - Section "Items": `items` (List field) |
| 76 | + - Section "Totals": `tax_rate`, `notes` |
| 77 | +- **Fields**: |
| 78 | +@verbatim |
| 79 | +<code-snippet name="Invoice Form List Field" lang="php"> |
| 80 | +SharpFormListField::make('items') |
| 81 | + ->setLabel('Items') |
| 82 | + ->addItemField( |
| 83 | + SharpFormSelectField::make('product_id', $products)->setLabel('Product') |
| 84 | + ) |
| 85 | + ->addItemField( |
| 86 | + SharpFormTextField::make('quantity')->setLabel('Quantity')->setInputModeNumeric() |
| 87 | + ) |
| 88 | +</code-snippet> |
| 89 | +@endverbatim |
| 90 | + |
| 91 | +#### InvoiceShow |
| 92 | +- **Sections**: |
| 93 | + - Header: Number, Status, Customer Info |
| 94 | + - Content: `items` (Entity List section or List field) |
| 95 | + - Sidebar: `payments` (Entity List section) |
| 96 | +- **Commands**: `SendInvoiceCommand`, `RecordPaymentCommand` |
| 97 | + |
| 98 | +#### InvoiceStateHandler |
| 99 | +@verbatim |
| 100 | +<code-snippet name="Invoice State Handler" lang="php"> |
| 101 | +class InvoiceStateHandler extends SharpEntityStateHandler |
| 102 | +{ |
| 103 | + public function buildStates(): void |
| 104 | + { |
| 105 | + $this->addState('draft', 'Draft', 'gray') |
| 106 | + ->addState('sent', 'Sent', 'blue') |
| 107 | + ->addState('paid', 'Paid', 'green') |
| 108 | + ->addState('cancelled', 'Cancelled', 'red'); |
| 109 | + } |
| 110 | +} |
| 111 | +</code-snippet> |
| 112 | +@endverbatim |
0 commit comments