AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

PlanSchema.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. // carousel: one row that scrolls sideways. large: 2 big cards across, like a magazine.
  165. 'product_grid' => ['grid', 'minimal', 'carousel', 'large'],
  166. // stacked: a wide photo on top, the words centred under it.
  167. 'featured_product' => ['image-left', 'image-right', 'stacked'],
  168. // statement: the body as one large statement, the heading as a small label.
  169. 'about' => ['simple', 'with-stats', 'statement'],
  170. // wall: cards of different heights packed in columns.
  171. 'testimonials' => ['cards', 'single', 'wall'],
  172. // list and two-column fold open; cards shows every answer in a grid.
  173. 'faq' => ['list', 'two-column', 'cards'],
  174. // split: a big heading beside the form, in the store's normal colours.
  175. 'newsletter' => ['banner', 'card', 'split'],
  176. 'contact' => ['simple', 'card'],
  177. // columns: store name and text, the footer links, and shop and help links.
  178. 'footer' => ['simple', 'centered', 'columns'],
  179. ];
  180. /**
  181. * Section types a page may contain. The header and footer are not here:
  182. * they live once at the top of the plan and appear on every page.
  183. *
  184. * @return array<string, list<string>>
  185. */
  186. public static function pageSections(): array
  187. {
  188. return array_diff_key(self::SECTIONS, ['header' => true, 'footer' => true]);
  189. }
  190. /** What a trust row item can be. */
  191. public const array TRUST_KINDS = ['shipping', 'payment', 'whatsapp', 'custom'];
  192. /** Icons a trust row item may use. */
  193. public const array TRUST_ICONS = ['truck', 'shield', 'chat', 'refresh', 'leaf', 'star', 'gift', 'clock', 'heart', 'award', 'map-pin', 'package'];
  194. /** Sections per page. */
  195. public const int MAX_SECTIONS = 20;
  196. public const int MAX_PAGES = 10;
  197. /**
  198. * Addresses inside a store that are not pages of the plan but still exist, so links to them are fine.
  199. *
  200. * @var list<string>
  201. */
  202. public const array BUILT_IN_PATHS = ['shop', 'products', 'cart'];
  203. /** The first page of every plan. */
  204. public const string HOME_PAGE = 'home';
  205. /**
  206. * Page ids the AI and merchants may not use, because the app has its own pages at these addresses.
  207. *
  208. * @var list<string>
  209. */
  210. public const array RESERVED_PAGE_IDS = ['shop', 'products', 'cart', 'checkout', 'orders', 'account', 'search'];
  211. /**
  212. * Links may only point inside the page, inside the site, or to safe outside targets.
  213. * This blocks things like "javascript:" links.
  214. */
  215. public const string LINK_PATTERN = '/^(#[A-Za-z0-9_-]*|\/(?!\/)[^\s]*|https:\/\/[^\s]+|mailto:[^\s]+|tel:[0-9+\-\s]+)$/';
  216. public const string COLOR_PATTERN = '/^#[0-9A-Fa-f]{6}$/';
  217. public const string PRODUCT_SLUG_PATTERN = '/^[a-z0-9]+(?:-[a-z0-9]+)*$/';
  218. /** Used for both section ids and page ids. */
  219. public const string SECTION_ID_PATTERN = '/^[a-z][a-z0-9-]{0,39}$/';
  220. /**
  221. * Validation rules for the content of one section type.
  222. * Keys are relative to the section's "content" object.
  223. *
  224. * @return array<string, list<string>>
  225. */
  226. public static function contentRules(string $type): array
  227. {
  228. $text = fn (int $max) => ['required', 'string', 'max:'.$max];
  229. $optionalText = fn (int $max) => ['nullable', 'string', 'max:'.$max];
  230. $link = ['required', 'string', 'max:300', 'regex:'.self::LINK_PATTERN];
  231. $price = ['required', 'numeric', 'min:0', 'max:999999'];
  232. return match ($type) {
  233. 'header' => [
  234. 'logoText' => $text(40),
  235. 'links' => ['present', 'array', 'max:6'],
  236. 'links.*.label' => $text(30),
  237. 'links.*.href' => $link,
  238. 'cta' => ['nullable', 'array'],
  239. 'cta.label' => ['required_with:cta', 'string', 'max:30'],
  240. 'cta.href' => ['required_with:cta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  241. ],
  242. 'hero' => [
  243. 'eyebrow' => $optionalText(60),
  244. 'headline' => $text(120),
  245. 'subheadline' => $text(300),
  246. 'primaryCta' => ['required', 'array'],
  247. 'primaryCta.label' => $text(30),
  248. 'primaryCta.href' => $link,
  249. 'secondaryCta' => ['nullable', 'array'],
  250. 'secondaryCta.label' => ['required_with:secondaryCta', 'string', 'max:30'],
  251. 'secondaryCta.href' => ['required_with:secondaryCta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  252. // "upload:12" (a photo uploaded in the Design tab) or "product:web-address-name" (a product's main photo).
  253. // Null means automatic: the store's own product photos are used.
  254. 'image' => ['nullable', 'string', 'max:140', 'regex:'.HeroImages::PATTERN],
  255. ],
  256. 'product_grid' => [
  257. 'heading' => $text(80),
  258. 'subheading' => $optionalText(200),
  259. 'items' => ['required', 'array', 'min:2', 'max:8'],
  260. 'items.*.name' => $text(80),
  261. 'items.*.price' => $price,
  262. 'items.*.badge' => $optionalText(20),
  263. ],
  264. 'featured_product' => [
  265. 'eyebrow' => $optionalText(60),
  266. 'name' => $text(80),
  267. 'description' => $text(500),
  268. 'price' => $price,
  269. 'bullets' => ['present', 'array', 'max:5'],
  270. 'bullets.*' => $text(100),
  271. 'cta' => ['required', 'array'],
  272. 'cta.label' => $text(30),
  273. 'cta.href' => $link,
  274. // The web-address name of one of the store's real products. When set, the store shows that
  275. // product's real name, price and photo instead of "name" and "price" above.
  276. 'productSlug' => ['nullable', 'string', 'max:120', 'regex:'.self::PRODUCT_SLUG_PATTERN],
  277. ],
  278. 'about' => [
  279. 'heading' => $text(80),
  280. 'body' => $text(1200),
  281. 'stats' => ['present', 'array', 'max:4'],
  282. 'stats.*.value' => $text(12),
  283. 'stats.*.label' => $text(40),
  284. ],
  285. 'trust_bar' => [
  286. 'items' => ['required', 'array', 'min:2', 'max:4'],
  287. // shipping, payment and whatsapp are written by the store itself from its real settings, so they
  288. // stay true when the merchant changes them. custom uses the title and text below.
  289. 'items.*.kind' => ['required', 'string', 'in:'.implode(',', self::TRUST_KINDS)],
  290. 'items.*.icon' => ['nullable', 'string', 'in:'.implode(',', self::TRUST_ICONS)],
  291. 'items.*.title' => ['required_if:items.*.kind,custom', 'nullable', 'string', 'max:40'],
  292. 'items.*.text' => ['nullable', 'string', 'max:80'],
  293. ],
  294. 'testimonials' => [
  295. 'heading' => $text(80),
  296. 'items' => ['required', 'array', 'min:1', 'max:6'],
  297. 'items.*.quote' => $text(400),
  298. 'items.*.name' => $text(60),
  299. 'items.*.role' => $optionalText(60),
  300. ],
  301. 'faq' => [
  302. 'heading' => $text(80),
  303. 'items' => ['required', 'array', 'min:1', 'max:10'],
  304. 'items.*.question' => $text(160),
  305. 'items.*.answer' => $text(600),
  306. ],
  307. 'newsletter' => [
  308. 'heading' => $text(80),
  309. 'body' => $optionalText(240),
  310. 'placeholder' => $text(40),
  311. 'buttonLabel' => $text(30),
  312. ],
  313. 'contact' => [
  314. 'heading' => $text(80),
  315. 'body' => $optionalText(300),
  316. 'email' => ['nullable', 'email', 'max:120'],
  317. 'phone' => $optionalText(30),
  318. 'whatsapp' => ['nullable', 'string', 'regex:/^[0-9]{8,15}$/'],
  319. 'address' => $optionalText(200),
  320. ],
  321. 'footer' => [
  322. 'text' => $text(160),
  323. 'links' => ['present', 'array', 'max:8'],
  324. 'links.*.label' => $text(30),
  325. 'links.*.href' => $link,
  326. ],
  327. default => [],
  328. };
  329. }
  330. }