# The project website

syncshop.ro is served by the SaaS app, as elvpro.eu serves ELVPro's site, its owner admin and every yard
(`_docs/DISTRIBUTION.md` › Task 5c). One app, one database, three kinds of host:

| Host | Serves | Routes |
| --- | --- | --- |
| `SAAS_PLATFORM_DOMAIN` (syncshop.ro) | the website, and our admin under `/admin` | `packages/saas/routes/site.php`, `routes/central.php` |
| `SAAS_REPOSITORY_DOMAIN` (repo.syncshop.ro) | the package server, for installed shops | `packages/saas/routes/repository.php` |
| `<shop>.syncshop.ro`, a shop's own domain | that shop: its storefront and its own `/admin` | the core's |

These routes are bound to their host and registered before every other (`SaasServiceProvider`), so on syncshop.ro
`/` and `/admin` are ours, and on a shop's host the core's. A shop's route never answers on syncshop.ro or
repo.syncshop.ro (a 404 there, the site's own page on syncshop.ro), and `www.` is ours too. Only `/up` answers
everywhere. The code is in `packages/saas`: the pages in `resources/views/site`, their copy in
`lang/{ro,en}/site.php`, the classes in `src/Site` and `src/Http/Site`, the package server in `src/Packages` and
`src/Http/Repository`, the styles and script in `resources/site` (built by the app's Vite). The documentation it
publishes is this `docs/` folder.

## The admin

`syncshop.ro/admin` is for the SyncSHOP team, with our own accounts (`central_admins`, never a shop's staff):
**Magazine** (the hosted shops), **Licențe**, **Versiuni**, **Descărcări**, **Date legale**, **Echipa** and
**Setări**. Sign-in takes the password and a code from an authenticator app; colleagues are invited from Echipa;
only the very first account is made on the server (`php artisan saas:admin <email>`). See [SaaS](saas.md) for the
shops, the team and the sign-in.

## The package server (repo.syncshop.ro)

Installed shops ask repo.syncshop.ro for their updates; it answers nothing else (no session, no cookie, every answer
`X-Robots-Tag: noindex, nofollow`, `robots.txt` disallows everything, 120 requests a minute per address).

| Request | Who | Answer |
| --- | --- | --- |
| `GET /packages.json` | Composer, HTTP basic: the licence key and the shop's domain | Composer metadata for the versions the licence may install |
| `GET /dist/<vendor>/<package>/<version>.zip` | Composer, the same credentials | The zip, if allowed; each download logged (an HMAC of the address) |
| `GET /api/v1/updates?installed=<version>` | The core's daily check, bearer key | `{latest, allowed, entitlement_ends_at, security, changelog_url}` |
| `GET /feeds/<name>.json` | The core's feed sync, bearer key | `{payload, signature}` (Ed25519), or 402 once updates have ended |

Which versions a licence gets is `SyncShop\Saas\Packages\Entitlements` (DISTRIBUTION.md › Which versions a key may
download): every release while updates are included or after a rejoin; after a lapse, the releases up to the end date
plus the security patches of those release lines for `SECURITY_WINDOW_MONTHS` (24) after the line's first release;
nothing for hosted (SaaS) or revoked licences. In the admin: **Licențe** (create with a generated key, change, extend
a year, rejoin, revoke; downloads and allowed versions), **Versiuni** (upload the zips `composer release` makes, one
per package, read from each zip's composer.json), **Descărcări**, **Date legale** (publish a VAT or SGR feed version,
signed with `FEED_SIGNING_KEY`, behind the password again; the page shows the public key, which ships in the core's
`FeedVerifier::RELEASE_KEYS`). Release zips are kept in `storage/app/private/releases`. The tables are
`package_licences`, `package_releases`, `package_release_files`, `package_downloads` and `package_feeds`, shared by
no shop.

## Settings

**Setări** (`/admin/setari`, behind the password again) holds what used to be edited in `.env`, in a table of its own
(`platform_settings`, spatie settings repository `platform`), never a shop's:

| Settings class | Holds | Overrides |
| --- | --- | --- |
| `SyncShop\Saas\Site\Settings\SiteSettings` | operator name, CUI, trade register number, registered office, offer and security addresses, demo address | `saas.site.company.*`, `saas.site.offer_to`, `saas.site.security_contact`, `saas.site.demo_url` |
| `SyncShop\Saas\Site\Settings\MailSettings` | SMTP host, port, STARTTLS or SSL/TLS, username, password (encrypted, write-only), sender | `mail.mailers.smtp.*`, `mail.from.*` |

They apply on syncshop.ro's pages and admin (`UsePlatformSettings`), never on a shop's. Text saved for display is
written with ș and ț: ş and ţ with a cedilla are converted on save (`RomanianText`). An empty setting keeps the
`.env` value, and if the settings cannot be read the site runs on `.env` alone. **Send a test e-mail** checks the
SMTP settings with a message to the signed-in account.

## Addresses

- Romanian at the bare URL, English under `/en`: `SyncShop\Saas\Site\Site::PATHS` maps each page to its slug in both
  languages, and every page links the other language with `hreflang`. The language comes from the address
  (`SetLocale`; a 404 is in the address's language too).
- The docs are English and live once, under `/docs`; `/en/docs` redirects there. `/docs/<page>.md` (and
  `/docs/index.md`) return the Markdown as written, with `X-Robots-Tag: noindex`.
- `robots.txt`, `sitemap.xml` (pages with their alternates, every doc with its date), `llms.txt` (the site and the
  docs in Markdown) and `/.well-known/security.txt` (an expiry eleven months ahead) are generated by
  `SeoController`, per host: a shop's are the core's. The web server must pass `/robots.txt` to the app (no static
  `public/robots.txt`: every host shares `public/`).

## The docs

`DocsLibrary` reads `docs/` (`SITE_DOCS_PATH`, `base_path('docs')` by default): the navigation is `README.md`'s `##`
sections and their `- [Title](page.md)` lines (a line whose page does not exist is left out), and every other `.md`
file is still published and in the sitemap. `Markdown` renders with CommonMark and GitHub-flavoured Markdown, raw HTML
escaped: the first `#` heading becomes the title, the others get ids (repeated ones numbered) for the page's
contents, and links are rewritten: `page.md#anchor` to `/docs/page#anchor`, `CHANGELOG.md` to the releases page.
A link to anything else in the repository keeps its text and loses its address, because the repository is
private. Paths are checked against `[a-z0-9-]` segments and resolved inside `docs/` only. The site shows the docs
of the commit deployed.

## Cookies and the offer form

Every page but the licence page runs without a session (the routes drop `StartSession`, the CSRF check and the
cookie middleware), so it sets no cookie and needs no consent question. The licence page holds the request for an
offer, which asks how the shop wants to run SyncSHOP (hosted by us, on its own server, or not sure yet:
`OfferRequest::VARIANTS`): it is validated (`OfferRequest`), limited to five an hour per address (`offers` rate
limiter), has a hidden field that bots fill and people leave empty, and is e-mailed in Romanian to the offer address
with the visitor as the reply-to (`OfferRequested`). Nothing is stored; if the e-mail cannot be sent, the visitor
gets the address to write to.

## What the copy may say

SyncSHOP is a paid product sold two ways, hosted by us on a subscription (SaaS) or on the shop's own server with a
licence per shop; the copy names both with the same features. Never "open source", "MIT" or "free", no prices (they
are in the offer), no customers, ratings or figures that do not exist. The integrations page lists only services
whose driver is in the product (`Integrations`; a name that is a description rather than a brand is a
`saas::site.` lang key). The examples on the home page (the order flow, the profit ledger) are marked as made-up
data. Structured data comes from real values only: no `offers`, no ratings.

## Settings in `.env`

| Key | What |
|---|---|
| `SAAS_PLATFORM_DOMAIN`, `SAAS_REPOSITORY_DOMAIN` | syncshop.ro and repo.syncshop.ro |
| `SITE_OFFER_EMAIL`, `SITE_SECURITY_EMAIL`, `SYNCSHOP_DEMO_URL`, `SITE_COMPANY_*` | the first values of Setări (the admin holds them after) |
| `FEED_SIGNING_KEY`, `SECURITY_WINDOW_MONTHS` | the package server |

## Tests

`tests/Saas/Site` and `tests/Saas/Packages`, in the SaaS suite (`composer test:saas`): each test's rows rolled back,
the docs and changelog read from `tests/Fixtures/site`.
