# Code layout: the SyncSHOP packages

SyncSHOP ships as Composer packages, so a shop's own code never sits inside the code an update replaces. In this
repository the packages live under `packages/` and the development app requires them through a `path` repository
(symlinked into `vendor/syncshop/`).

| Package | Folder | Holds |
| --- | --- | --- |
| `syncshop/core` | `packages/core` | The modules (`src/Modules/<Name>`, namespace `SyncShop\Modules\<Name>`), the shared classes (`SyncShop\Enums\Permission`, `SyncShop\Models\User`, …), the core migrations, admin views, strings (`lang/`), SCSS, scripts, icons and fonts |
| `syncshop/theme-default` | `packages/theme-default` | The storefront theme: views (`store.*`, `<x-store.*>`, the store layout), SCSS and scripts |
| `syncshop/skeleton` | `packages/skeleton` | The project an on-premises shop starts from |
| `syncshop/saas` | `packages/saas` | The SaaS edition: one app, a database per shop ([The SaaS edition](saas.md)); only our SaaS host installs it |

The root `app/` holds only development and demo glue (`AppServiceProvider`, the base controller); the demo data is in
`database/seeders`.

## How the packages load

- `SyncShop\CoreServiceProvider` and `SyncShop\ThemeDefault\ThemeServiceProvider` are found by Laravel's package
  discovery. The core provider registers every module's provider (`SyncShop\Modules\Modules::PROVIDERS`), the core
  migrations and `<x-icon>`.
- Views and strings keep plain names: `view('catalog.products.index')`, `<x-form.input>`, `__('catalog.title')`.
  The packages add their folders after the app's own, so a file in the app's `resources/views` or a key in its
  `lang/` overrides the package's.
- Code inside the core that needs one of its own files uses `SyncShop\Support\Paths` (`Paths::resources('icons/…')`),
  never `resource_path()`, which points at the app.
- Vite builds the entries in `packages/core/resources` (admin) and `packages/theme-default/resources` (storefront).

## The stability contract

Only the core types marked `@api` are meant for code outside `syncshop/core`: every module's `Contracts\` and `Data\`
types (domain events are `Data\` classes), `SyncShop\Enums\Permission` and `PermissionGroup`, `SyncShop\Models\User`,
and `SyncShop\Testing\ApiContract`. They follow semantic versioning; everything else is internal and may change in
any release. The full list is generated into [Extension API](extension-api.md) by `composer api-docs`.

- A new type in a module's `Contracts\` or `Data\` gets `@api` in its class docblock (a test fails otherwise), and an
  `@api` type never takes or returns an internal one.
- An extension checks itself with `expect(SyncShop\Testing\ApiContract::violations(__DIR__.'/../src'))->toBe([])`; the
  core's own tests do the same for the sample extension in `packages/core/tests/Fixtures/extensions/sample`.

## Stored model types

Polymorphic columns (`media.model_type`, `tokenable_type`, `model_has_roles.model_type`, the activity log's subject and
causer) store an alias, never a class name, so a class can move without touching data. Each module maps its own models
in its provider's `register()` (`Relation::morphMap(['product' => Product::class])`), and the core requires the map:
storing an unmapped model throws `ClassMorphViolationException`. An alias never changes once released. Current aliases:
`user`, `customer`, `product`, `article`, `landing_page`, `role`, `scheduled_task`, `newsletter_subscriber`.

Rules for extensions, themes and updates: `_docs/DISTRIBUTION.md`.
