Skip to content

Commit ce0669d

Browse files
SniderVirgil
andcommitted
docs: add CLAUDE.md project instructions
Co-Authored-By: Virgil <virgil@lethean.io>
1 parent 347b7b8 commit ce0669d

1 file changed

Lines changed: 63 additions & 55 deletions

File tree

CLAUDE.md

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## What This Is
66

7-
`host-uk/core-commerce` - A Laravel package providing orders, subscriptions, invoices, and payment processing. Namespace: `Core\Mod\Commerce`.
7+
`lthn/php-commerce` A Laravel package providing orders, subscriptions, invoices, and payment processing. This is a **package** (not a standalone app), tested with Orchestra Testbench.
88

99
## Commands
1010

@@ -13,13 +13,21 @@ composer run lint # vendor/bin/pint
1313
composer run test # vendor/bin/pest
1414
vendor/bin/pint --dirty # Format changed files only
1515
vendor/bin/pest --filter=CheckoutFlowTest # Run single test file
16+
vendor/bin/pest --filter="checkout" # Run tests matching name
1617
```
1718

1819
## Architecture
1920

21+
### Dual Namespace System
22+
23+
The package has two PSR-4 roots, serving different purposes:
24+
25+
- `Core\Mod\Commerce\` (root `./`) — The module: models, services, events, Livewire components, routes. `Boot.php` extends `ServiceProvider` with event-driven lazy-loading via `$listens`.
26+
- `Core\Service\Commerce\` (root `./Service/`) — The service definition layer: implements `ServiceDefinition` for the platform's service registry (admin menus, entitlements, versioning).
27+
2028
### Boot & Event System
2129

22-
This is a **Laravel package** (not a standalone app). `Boot.php` extends `ServiceProvider` and uses the Core Framework's event-driven lazy-loading:
30+
`Boot.php` uses the Core Framework's event-driven lazy-loading — handlers only fire when the relevant subsystem initialises:
2331

2432
```php
2533
public static array $listens = [
@@ -30,83 +38,83 @@ public static array $listens = [
3038
];
3139
```
3240

33-
### Service Layer
41+
Livewire components are registered inside `onAdminPanel()` and `onWebRoutes()`, not auto-discovered. All components use the `commerce.admin.*` or `commerce.web.*` naming prefix.
3442

35-
Business logic lives in `Services/`. All services are registered as singletons in `Boot::register()`:
43+
### Payment Gateways
3644

37-
- **CommerceService** - Order orchestration
38-
- **SubscriptionService** - Subscription lifecycle
39-
- **InvoiceService** - Invoice generation
40-
- **TaxService** - Jurisdiction-based tax calculation
41-
- **CouponService** - Discount validation and application
42-
- **CurrencyService** - Multi-currency support with exchange rates
43-
- **DunningService** - Failed payment retry logic
44-
- **UsageBillingService** - Metered/usage-based billing
45-
- **ReferralService** - Affiliate tracking and commissions
46-
- **PaymentMethodService** - Stored payment methods
45+
Pluggable via `PaymentGatewayContract` in `Services/PaymentGateway/`:
46+
- `BTCPayGateway` — Cryptocurrency (default when enabled)
47+
- `StripeGateway` — Card payments (SaaS)
4748

48-
### Payment Gateways
49+
The default gateway is resolved by checking `config('commerce.gateways.btcpay.enabled')` — BTCPay takes priority when enabled.
50+
51+
### Multi-Entity Hierarchy (Commerce Matrix)
4952

50-
Pluggable via `PaymentGatewayContract`:
51-
- `StripeGateway` - Primary (SaaS)
52-
- `BTCPayGateway` - Cryptocurrency
53+
The system supports a three-tier entity model configured in `config.php` under `matrix` and `entities`:
54+
- **M1 (Master Company)** — Owns the product catalogue, source of truth
55+
- **M2 (Facade/Storefront)** — Selects from M1 catalogue, can override content
56+
- **M3 (Dropshipper)** — Full catalogue inheritance, no management responsibility
57+
58+
`PermissionMatrixService` controls cross-entity access. It has a "training mode" (prompts for undefined permissions) and "strict mode" (undefined = denied).
59+
60+
### SKU System
61+
62+
SKUs encode entity lineage: `{m1_code}-{m2_code}-{master_sku}`. `SkuParserService` decodes them; `SkuBuilderService` constructs them; `SkuLineageService` tracks provenance.
5363

5464
### Domain Events
5565

5666
Events in `Events/` trigger listeners for loose coupling:
57-
- `OrderPaid` - Payment succeeded
58-
- `SubscriptionCreated`, `SubscriptionRenewed`, `SubscriptionUpdated`, `SubscriptionCancelled`
67+
- `OrderPaid``CreateReferralCommission`
68+
- `SubscriptionCreated``RewardAgentReferralOnSubscription`
69+
- `SubscriptionRenewed``ResetUsageOnRenewal`
70+
- `SubscriptionCancelled`, `SubscriptionUpdated`
71+
72+
`ProvisionSocialHostSubscription` is a subscriber (listens to multiple events).
5973

6074
### Livewire Components
6175

6276
Located in `View/Modal/` (not `Livewire/`):
63-
- `View/Modal/Web/` - User-facing (checkout, invoices, subscription management)
64-
- `View/Modal/Admin/` - Admin panel (managers for orders, coupons, products, etc.)
77+
- `View/Modal/Web/` — User-facing (checkout, invoices, subscription management)
78+
- `View/Modal/Admin/` — Admin panel (managers for orders, coupons, products, etc.)
79+
80+
### Scheduled Commands
81+
82+
`Console/` has artisan commands registered in `onConsole()`: dunning processing, renewal reminders, exchange rate refresh, usage sync to Stripe, referral commission maturation, expired order cleanup, and tree planting for subscribers.
6583

6684
## Key Directories
6785

6886
```
69-
Boot.php # ServiceProvider, event registration
70-
config.php # Currencies, gateways, tax rules
71-
Models/ # Eloquent models (Order, Subscription, Invoice, etc.)
72-
Services/ # Business logic layer
73-
View/Modal/ # Livewire components
87+
Boot.php # ServiceProvider, event registration, singleton bindings
88+
config.php # Currencies, gateways, tax, dunning, fraud, matrix settings
89+
Service/Boot.php # ServiceDefinition for platform registry (admin menus, entitlements)
90+
Models/ # Eloquent models
91+
Services/ # Business logic (singletons registered in Boot::register())
92+
Services/PaymentGateway/ # Gateway contract + implementations
93+
Contracts/ # Interfaces (e.g., Orderable)
94+
Events/ # Domain events
95+
Listeners/ # Event handlers
96+
View/Modal/ # Livewire components (Admin/ and Web/)
7497
Routes/ # web.php, api.php, admin.php, console.php
7598
Migrations/ # Database schema
76-
Events/ # Domain events
77-
Listeners/ # Event subscribers
78-
tests/Feature/ # Pest feature tests
99+
Console/ # Artisan commands
100+
tests/ # Pest tests using Orchestra Testbench
79101
```
80102

81103
## Conventions
82104

83-
- **UK English** - colour, organisation, centre
105+
- **UK English** colour, organisation, centre, behaviour
84106
- **PSR-12** via Laravel Pint
85107
- **Pest** for testing (not PHPUnit syntax)
86-
- **Strict types** - `declare(strict_types=1);` in all files
87-
- **Livewire + Flux Pro** for UI components
108+
- **Strict types**`declare(strict_types=1);` in all files
109+
- **Final classes** by default unless inheritance is intended
110+
- **Type hints** on all parameters and return types
111+
- **Livewire + Flux Pro** for UI components (not vanilla Alpine)
88112
- **Font Awesome Pro** for icons (not Heroicons)
113+
- **Naming** — Models: singular PascalCase; Tables: plural snake_case; Livewire: `{Feature}Page`, `{Feature}Modal`
89114

90-
## Namespaces
91-
92-
```php
93-
use Core\Mod\Commerce\Models\Order;
94-
use Core\Mod\Commerce\Services\SubscriptionService;
95-
use Core\Service\Commerce\SomeUtility; // Alternative service namespace
96-
```
97-
98-
## Testing
115+
## Don't
99116

100-
Tests are in `tests/` with Pest:
101-
102-
```php
103-
test('user can checkout', function () {
104-
// ...
105-
});
106-
```
107-
108-
Run a specific test:
109-
```bash
110-
vendor/bin/pest --filter="checkout"
111-
vendor/bin/pest tests/Feature/CheckoutFlowTest.php
112-
```
117+
- Don't use Heroicons (use Font Awesome Pro)
118+
- Don't use vanilla Alpine components (use Flux Pro)
119+
- Don't create controllers for Livewire pages
120+
- Don't use American English spellings

0 commit comments

Comments
 (0)