AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PlanSchema.php 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <?php
  2. namespace App\StorePlan;
  3. /**
  4. * The single definition of what a "store plan" may contain.
  5. *
  6. * A store plan is the saved design of a store:
  7. * - a theme (colours, fonts, corner radius)
  8. * - one header and one footer, shared by every page
  9. * - one or more pages, each an ordered list of sections. The first page is always "home".
  10. * It belongs to us, not to any AI provider. Whoever writes a plan (a person, Claude,
  11. * DeepSeek, anything later) must produce this shape, and PlanValidator checks it.
  12. *
  13. * Keep this file in step with resources/js/storefront/types.ts.
  14. */
  15. final class PlanSchema
  16. {
  17. public const int VERSION = 2;
  18. /**
  19. * Theme colours every plan must define, as 6-digit hex values.
  20. *
  21. * @var list<string>
  22. */
  23. public const array COLORS = [
  24. 'background',
  25. 'surface',
  26. 'foreground',
  27. 'muted',
  28. 'primary',
  29. 'primaryForeground',
  30. 'accent',
  31. 'border',
  32. ];
  33. /**
  34. * Fonts the storefront can load. Key is what the plan stores, value is the font family name.
  35. *
  36. * @var array<string, string>
  37. */
  38. public const array FONTS = [
  39. 'inter' => 'Inter',
  40. 'dm-sans' => 'DM Sans',
  41. 'poppins' => 'Poppins',
  42. 'manrope' => 'Manrope',
  43. 'space-grotesk' => 'Space Grotesk',
  44. 'playfair-display' => 'Playfair Display',
  45. 'lora' => 'Lora',
  46. 'fraunces' => 'Fraunces',
  47. // Added in Step 9 part 4, for more personality.
  48. 'cormorant-garamond' => 'Cormorant Garamond',
  49. 'dm-serif-display' => 'DM Serif Display',
  50. 'libre-baskerville' => 'Libre Baskerville',
  51. 'bricolage-grotesque' => 'Bricolage Grotesque',
  52. 'syne' => 'Syne',
  53. 'unbounded' => 'Unbounded',
  54. 'archivo-black' => 'Archivo Black',
  55. 'bebas-neue' => 'Bebas Neue',
  56. 'outfit' => 'Outfit',
  57. 'jost' => 'Jost',
  58. 'nunito' => 'Nunito',
  59. 'caveat' => 'Caveat',
  60. ];
  61. /**
  62. * Fonts that only suit big headings: one weight, all capitals or handwriting. Never for body text.
  63. *
  64. * @var list<string>
  65. */
  66. public const array HEADING_ONLY_FONTS = ['archivo-black', 'bebas-neue', 'caveat', 'dm-serif-display'];
  67. /**
  68. * The look of the whole store, beyond colours and fonts. Every option is optional; an old plan without
  69. * "style" uses the defaults, which look exactly like stores did before.
  70. *
  71. * - buttons: solid, outline (a line around, filled on hover) or shadow (a solid offset shadow, playful and bold)
  72. * - cards: border (thin line), shadow (soft lift), plain (no edge) or hard (thick line and solid offset shadow)
  73. * - spacing: compact, normal or airy (room between sections)
  74. * - headings: normal, uppercase (spaced capitals, elegant) or heavy (extra bold and tight)
  75. * - backgrounds: plain, or alternate (every other section on a soft band)
  76. * - motion: none, or gentle (sections fade up as they come into view; never for visitors who ask for less motion)
  77. *
  78. * @var array<string, list<string>>
  79. */
  80. public const array STYLE_OPTIONS = [
  81. 'buttons' => ['solid', 'outline', 'shadow'],
  82. 'cards' => ['border', 'shadow', 'plain', 'hard'],
  83. 'spacing' => ['compact', 'normal', 'airy'],
  84. 'headings' => ['normal', 'uppercase', 'heavy'],
  85. 'backgrounds' => ['plain', 'alternate'],
  86. 'motion' => ['none', 'gentle'],
  87. ];
  88. /** @var array<string, string> */
  89. public const array STYLE_DEFAULTS = [
  90. 'buttons' => 'solid',
  91. 'cards' => 'border',
  92. 'spacing' => 'normal',
  93. 'headings' => 'normal',
  94. 'backgrounds' => 'plain',
  95. 'motion' => 'none',
  96. ];
  97. /**
  98. * Ready-made looks for the Design tab's Style box. Each sets the style, corner roundness and fonts;
  99. * colours stay as they are.
  100. *
  101. * @var array<string, array{label: string, hint: string, radius: string, fonts: array{heading: string, body: string}, style: array<string, string>}>
  102. */
  103. public const array STYLE_PRESETS = [
  104. 'minimal' => [
  105. 'label' => 'Minimal',
  106. 'hint' => 'Clean, lots of space, quiet details',
  107. 'radius' => 'small',
  108. 'fonts' => ['heading' => 'manrope', 'body' => 'inter'],
  109. 'style' => ['buttons' => 'solid', 'cards' => 'plain', 'spacing' => 'airy', 'headings' => 'normal', 'backgrounds' => 'plain', 'motion' => 'gentle'],
  110. ],
  111. 'soft' => [
  112. 'label' => 'Soft',
  113. 'hint' => 'Rounded, gentle shadows, friendly',
  114. 'radius' => 'large',
  115. 'fonts' => ['heading' => 'outfit', 'body' => 'nunito'],
  116. 'style' => ['buttons' => 'solid', 'cards' => 'shadow', 'spacing' => 'airy', 'headings' => 'normal', 'backgrounds' => 'alternate', 'motion' => 'gentle'],
  117. ],
  118. 'elegant' => [
  119. 'label' => 'Elegant',
  120. 'hint' => 'Serif headings, fine lines, premium',
  121. 'radius' => 'none',
  122. 'fonts' => ['heading' => 'cormorant-garamond', 'body' => 'jost'],
  123. 'style' => ['buttons' => 'outline', 'cards' => 'plain', 'spacing' => 'airy', 'headings' => 'uppercase', 'backgrounds' => 'plain', 'motion' => 'gentle'],
  124. ],
  125. 'bold' => [
  126. 'label' => 'Bold',
  127. 'hint' => 'Heavy type, hard shadows, loud',
  128. 'radius' => 'none',
  129. 'fonts' => ['heading' => 'archivo-black', 'body' => 'space-grotesk'],
  130. 'style' => ['buttons' => 'shadow', 'cards' => 'hard', 'spacing' => 'normal', 'headings' => 'heavy', 'backgrounds' => 'alternate', 'motion' => 'gentle'],
  131. ],
  132. 'playful' => [
  133. 'label' => 'Playful',
  134. 'hint' => 'Round shapes, fun type, lively',
  135. 'radius' => 'full',
  136. 'fonts' => ['heading' => 'bricolage-grotesque', 'body' => 'dm-sans'],
  137. 'style' => ['buttons' => 'shadow', 'cards' => 'shadow', 'spacing' => 'normal', 'headings' => 'heavy', 'backgrounds' => 'alternate', 'motion' => 'gentle'],
  138. ],
  139. 'classic' => [
  140. 'label' => 'Classic',
  141. 'hint' => 'How stores looked before: simple and safe',
  142. 'radius' => 'medium',
  143. 'fonts' => ['heading' => 'manrope', 'body' => 'inter'],
  144. 'style' => self::STYLE_DEFAULTS,
  145. ],
  146. ];
  147. /**
  148. * How rounded corners are.
  149. *
  150. * @var list<string>
  151. */
  152. public const array RADII = ['none', 'small', 'medium', 'large', 'full'];
  153. /**
  154. * Section types and the layout variants each one supports.
  155. *
  156. * @var array<string, list<string>>
  157. */
  158. public const array SECTIONS = [
  159. 'header' => ['simple', 'centered'],
  160. // centered: text only. split: text beside a photo. image-full: a full-width photo with the text on it.
  161. 'hero' => ['centered', 'split', 'image-full'],
  162. // A row of short reassurances, such as free shipping and secure payment. row: a band. boxed: small cards.
  163. 'trust_bar' => ['row', 'boxed'],
  164. // The store's collections as round photos (circles) or larger photo tiles (tiles).
  165. 'shop_by' => ['circles', 'tiles'],
  166. // Tiles of different sizes for products, collections, offers and stories. mosaic: the first tile is big.
  167. 'bento' => ['mosaic', 'even'],
  168. // A YouTube or Vimeo video. wide: full width under the heading. split: words beside the video.
  169. 'video' => ['wide', 'split'],
  170. // carousel: one row that scrolls sideways. large: 2 big cards across, like a magazine.
  171. 'product_grid' => ['grid', 'minimal', 'carousel', 'large'],
  172. // stacked: a wide photo on top, the words centred under it.
  173. 'featured_product' => ['image-left', 'image-right', 'stacked'],
  174. // statement: the body as one large statement, the heading as a small label.
  175. 'about' => ['simple', 'with-stats', 'statement'],
  176. // wall: cards of different heights packed in columns.
  177. 'testimonials' => ['cards', 'single', 'wall'],
  178. // list and two-column fold open; cards shows every answer in a grid.
  179. 'faq' => ['list', 'two-column', 'cards'],
  180. // split: a big heading beside the form, in the store's normal colours.
  181. 'newsletter' => ['banner', 'card', 'split'],
  182. 'contact' => ['simple', 'card'],
  183. // columns: store name and text, the footer links, and shop and help links.
  184. 'footer' => ['simple', 'centered', 'columns'],
  185. ];
  186. /**
  187. * Section types a page may contain. The header and footer are not here:
  188. * they live once at the top of the plan and appear on every page.
  189. *
  190. * @return array<string, list<string>>
  191. */
  192. public static function pageSections(): array
  193. {
  194. return array_diff_key(self::SECTIONS, ['header' => true, 'footer' => true]);
  195. }
  196. /** What a trust row item can be. */
  197. public const array TRUST_KINDS = ['shipping', 'payment', 'whatsapp', 'custom'];
  198. /** Icons a trust row item may use. */
  199. public const array TRUST_ICONS = ['truck', 'shield', 'chat', 'refresh', 'leaf', 'star', 'gift', 'clock', 'heart', 'award', 'map-pin', 'package'];
  200. /** Sections per page. */
  201. public const int MAX_SECTIONS = 20;
  202. public const int MAX_PAGES = 10;
  203. /**
  204. * Addresses inside a store that are not pages of the plan but still exist, so links to them are fine.
  205. *
  206. * @var list<string>
  207. */
  208. public const array BUILT_IN_PATHS = ['shop', 'products', 'cart', 'collections'];
  209. /** The first page of every plan. */
  210. public const string HOME_PAGE = 'home';
  211. /**
  212. * Page ids the AI and merchants may not use, because the app has its own pages at these addresses.
  213. *
  214. * @var list<string>
  215. */
  216. public const array RESERVED_PAGE_IDS = ['shop', 'products', 'cart', 'checkout', 'orders', 'account', 'search', 'collections'];
  217. /**
  218. * Links may only point inside the page, inside the site, or to safe outside targets.
  219. * This blocks things like "javascript:" links.
  220. */
  221. public const string LINK_PATTERN = '/^(#[A-Za-z0-9_-]*|\/(?!\/)[^\s]*|https:\/\/[^\s]+|mailto:[^\s]+|tel:[0-9+\-\s]+)$/';
  222. public const string COLOR_PATTERN = '/^#[0-9A-Fa-f]{6}$/';
  223. /** YouTube (watch, shorts, youtu.be) and Vimeo addresses only, so no other site can be embedded. */
  224. public const string VIDEO_PATTERN = '~^https://(?:(?:www\.|m\.)?youtube\.com/(?:watch\?v=|shorts/)[A-Za-z0-9_-]{6,20}|youtu\.be/[A-Za-z0-9_-]{6,20}|(?:www\.)?vimeo\.com/[0-9]{5,12})(?:[?&#][^\s]*)?$~';
  225. public const string PRODUCT_SLUG_PATTERN = '/^[a-z0-9]+(?:-[a-z0-9]+)*$/';
  226. /** Used for both section ids and page ids. */
  227. public const string SECTION_ID_PATTERN = '/^[a-z][a-z0-9-]{0,39}$/';
  228. /**
  229. * Validation rules for the content of one section type.
  230. * Keys are relative to the section's "content" object.
  231. *
  232. * @return array<string, list<string>>
  233. */
  234. public static function contentRules(string $type): array
  235. {
  236. $text = fn (int $max) => ['required', 'string', 'max:'.$max];
  237. $optionalText = fn (int $max) => ['nullable', 'string', 'max:'.$max];
  238. $link = ['required', 'string', 'max:300', 'regex:'.self::LINK_PATTERN];
  239. $price = ['required', 'numeric', 'min:0', 'max:999999'];
  240. return match ($type) {
  241. 'header' => [
  242. 'logoText' => $text(40),
  243. 'links' => ['present', 'array', 'max:6'],
  244. 'links.*.label' => $text(30),
  245. 'links.*.href' => $link,
  246. 'cta' => ['nullable', 'array'],
  247. 'cta.label' => ['required_with:cta', 'string', 'max:30'],
  248. 'cta.href' => ['required_with:cta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  249. ],
  250. 'hero' => [
  251. 'eyebrow' => $optionalText(60),
  252. 'headline' => $text(120),
  253. 'subheadline' => $text(300),
  254. 'primaryCta' => ['required', 'array'],
  255. 'primaryCta.label' => $text(30),
  256. 'primaryCta.href' => $link,
  257. 'secondaryCta' => ['nullable', 'array'],
  258. 'secondaryCta.label' => ['required_with:secondaryCta', 'string', 'max:30'],
  259. 'secondaryCta.href' => ['required_with:secondaryCta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  260. // "upload:12" (a photo uploaded in the Design tab) or "product:web-address-name" (a product's main photo).
  261. // Null means automatic: the store's own product photos are used.
  262. 'image' => ['nullable', 'string', 'max:140', 'regex:'.HeroImages::PATTERN],
  263. ],
  264. 'product_grid' => [
  265. 'heading' => $text(80),
  266. 'subheading' => $optionalText(200),
  267. 'items' => ['required', 'array', 'min:2', 'max:8'],
  268. 'items.*.name' => $text(80),
  269. 'items.*.price' => $price,
  270. 'items.*.badge' => $optionalText(20),
  271. ],
  272. 'featured_product' => [
  273. 'eyebrow' => $optionalText(60),
  274. 'name' => $text(80),
  275. 'description' => $text(500),
  276. 'price' => $price,
  277. 'bullets' => ['present', 'array', 'max:5'],
  278. 'bullets.*' => $text(100),
  279. 'cta' => ['required', 'array'],
  280. 'cta.label' => $text(30),
  281. 'cta.href' => $link,
  282. // The web-address name of one of the store's real products. When set, the store shows that
  283. // product's real name, price and photo instead of "name" and "price" above.
  284. 'productSlug' => ['nullable', 'string', 'max:120', 'regex:'.self::PRODUCT_SLUG_PATTERN],
  285. ],
  286. 'about' => [
  287. 'heading' => $text(80),
  288. 'body' => $text(1200),
  289. 'stats' => ['present', 'array', 'max:4'],
  290. 'stats.*.value' => $text(12),
  291. 'stats.*.label' => $text(40),
  292. ],
  293. 'trust_bar' => [
  294. 'items' => ['required', 'array', 'min:2', 'max:4'],
  295. // shipping, payment and whatsapp are written by the store itself from its real settings, so they
  296. // stay true when the merchant changes them. custom uses the title and text below.
  297. 'items.*.kind' => ['required', 'string', 'in:'.implode(',', self::TRUST_KINDS)],
  298. 'items.*.icon' => ['nullable', 'string', 'in:'.implode(',', self::TRUST_ICONS)],
  299. 'items.*.title' => ['required_if:items.*.kind,custom', 'nullable', 'string', 'max:40'],
  300. 'items.*.text' => ['nullable', 'string', 'max:80'],
  301. ],
  302. 'shop_by' => [
  303. 'heading' => $text(80),
  304. 'subheading' => $optionalText(200),
  305. // Web-address names of the store's collections, in order. An empty list shows every collection.
  306. 'collections' => ['present', 'array', 'max:8'],
  307. 'collections.*' => ['string', 'max:80', 'regex:'.self::PRODUCT_SLUG_PATTERN],
  308. ],
  309. 'bento' => [
  310. 'heading' => $optionalText(80),
  311. 'tiles' => ['required', 'array', 'min:3', 'max:6'],
  312. 'tiles.*.title' => $text(60),
  313. 'tiles.*.text' => $optionalText(140),
  314. 'tiles.*.href' => $link,
  315. // A photo name like a hero's ("product:..." or "upload:..."), or null for a colour tile.
  316. 'tiles.*.image' => ['nullable', 'string', 'max:140', 'regex:'.HeroImages::PATTERN],
  317. 'tiles.*.tone' => ['nullable', 'string', 'in:primary,accent,dark,surface'],
  318. ],
  319. 'video' => [
  320. 'heading' => $text(80),
  321. 'text' => $optionalText(300),
  322. // A YouTube or Vimeo address. It only loads when the shopper presses play.
  323. 'videoUrl' => ['required', 'string', 'max:300', 'regex:'.self::VIDEO_PATTERN],
  324. 'cta' => ['nullable', 'array'],
  325. 'cta.label' => ['required_with:cta', 'string', 'max:30'],
  326. 'cta.href' => ['required_with:cta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  327. ],
  328. 'testimonials' => [
  329. 'heading' => $text(80),
  330. 'items' => ['required', 'array', 'min:1', 'max:6'],
  331. 'items.*.quote' => $text(400),
  332. 'items.*.name' => $text(60),
  333. 'items.*.role' => $optionalText(60),
  334. ],
  335. 'faq' => [
  336. 'heading' => $text(80),
  337. 'items' => ['required', 'array', 'min:1', 'max:10'],
  338. 'items.*.question' => $text(160),
  339. 'items.*.answer' => $text(600),
  340. ],
  341. 'newsletter' => [
  342. 'heading' => $text(80),
  343. 'body' => $optionalText(240),
  344. 'placeholder' => $text(40),
  345. 'buttonLabel' => $text(30),
  346. ],
  347. 'contact' => [
  348. 'heading' => $text(80),
  349. 'body' => $optionalText(300),
  350. 'email' => ['nullable', 'email', 'max:120'],
  351. 'phone' => $optionalText(30),
  352. 'whatsapp' => ['nullable', 'string', 'regex:/^[0-9]{8,15}$/'],
  353. 'address' => $optionalText(200),
  354. ],
  355. 'footer' => [
  356. 'text' => $text(160),
  357. 'links' => ['present', 'array', 'max:8'],
  358. 'links.*.label' => $text(30),
  359. 'links.*.href' => $link,
  360. ],
  361. default => [],
  362. };
  363. }
  364. }