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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. ];
  48. /**
  49. * How rounded corners are.
  50. *
  51. * @var list<string>
  52. */
  53. public const array RADII = ['none', 'small', 'medium', 'large', 'full'];
  54. /**
  55. * Section types and the layout variants each one supports.
  56. *
  57. * @var array<string, list<string>>
  58. */
  59. public const array SECTIONS = [
  60. 'header' => ['simple', 'centered'],
  61. 'hero' => ['centered', 'split'],
  62. 'product_grid' => ['grid', 'minimal'],
  63. 'featured_product' => ['image-left', 'image-right'],
  64. 'about' => ['simple', 'with-stats'],
  65. 'testimonials' => ['cards', 'single'],
  66. 'faq' => ['list', 'two-column'],
  67. 'newsletter' => ['banner', 'card'],
  68. 'contact' => ['simple', 'card'],
  69. 'footer' => ['simple', 'centered'],
  70. ];
  71. /**
  72. * Section types a page may contain. The header and footer are not here:
  73. * they live once at the top of the plan and appear on every page.
  74. *
  75. * @return array<string, list<string>>
  76. */
  77. public static function pageSections(): array
  78. {
  79. return array_diff_key(self::SECTIONS, ['header' => true, 'footer' => true]);
  80. }
  81. /** Sections per page. */
  82. public const int MAX_SECTIONS = 20;
  83. public const int MAX_PAGES = 10;
  84. /**
  85. * Addresses inside a store that are not pages of the plan but still exist, so links to them are fine.
  86. *
  87. * @var list<string>
  88. */
  89. public const array BUILT_IN_PATHS = ['shop', 'products', 'cart'];
  90. /** The first page of every plan. */
  91. public const string HOME_PAGE = 'home';
  92. /**
  93. * Page ids the AI and merchants may not use, because the app has its own pages at these addresses.
  94. *
  95. * @var list<string>
  96. */
  97. public const array RESERVED_PAGE_IDS = ['shop', 'products', 'cart', 'checkout', 'orders', 'account', 'search'];
  98. /**
  99. * Links may only point inside the page, inside the site, or to safe outside targets.
  100. * This blocks things like "javascript:" links.
  101. */
  102. public const string LINK_PATTERN = '/^(#[A-Za-z0-9_-]*|\/(?!\/)[^\s]*|https:\/\/[^\s]+|mailto:[^\s]+|tel:[0-9+\-\s]+)$/';
  103. public const string COLOR_PATTERN = '/^#[0-9A-Fa-f]{6}$/';
  104. /** Used for both section ids and page ids. */
  105. public const string SECTION_ID_PATTERN = '/^[a-z][a-z0-9-]{0,39}$/';
  106. /**
  107. * Validation rules for the content of one section type.
  108. * Keys are relative to the section's "content" object.
  109. *
  110. * @return array<string, list<string>>
  111. */
  112. public static function contentRules(string $type): array
  113. {
  114. $text = fn (int $max) => ['required', 'string', 'max:'.$max];
  115. $optionalText = fn (int $max) => ['nullable', 'string', 'max:'.$max];
  116. $link = ['required', 'string', 'max:300', 'regex:'.self::LINK_PATTERN];
  117. $price = ['required', 'numeric', 'min:0', 'max:999999'];
  118. return match ($type) {
  119. 'header' => [
  120. 'logoText' => $text(40),
  121. 'links' => ['present', 'array', 'max:6'],
  122. 'links.*.label' => $text(30),
  123. 'links.*.href' => $link,
  124. 'cta' => ['nullable', 'array'],
  125. 'cta.label' => ['required_with:cta', 'string', 'max:30'],
  126. 'cta.href' => ['required_with:cta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  127. ],
  128. 'hero' => [
  129. 'eyebrow' => $optionalText(60),
  130. 'headline' => $text(120),
  131. 'subheadline' => $text(300),
  132. 'primaryCta' => ['required', 'array'],
  133. 'primaryCta.label' => $text(30),
  134. 'primaryCta.href' => $link,
  135. 'secondaryCta' => ['nullable', 'array'],
  136. 'secondaryCta.label' => ['required_with:secondaryCta', 'string', 'max:30'],
  137. 'secondaryCta.href' => ['required_with:secondaryCta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  138. ],
  139. 'product_grid' => [
  140. 'heading' => $text(80),
  141. 'subheading' => $optionalText(200),
  142. 'items' => ['required', 'array', 'min:2', 'max:8'],
  143. 'items.*.name' => $text(80),
  144. 'items.*.price' => $price,
  145. 'items.*.badge' => $optionalText(20),
  146. ],
  147. 'featured_product' => [
  148. 'eyebrow' => $optionalText(60),
  149. 'name' => $text(80),
  150. 'description' => $text(500),
  151. 'price' => $price,
  152. 'bullets' => ['present', 'array', 'max:5'],
  153. 'bullets.*' => $text(100),
  154. 'cta' => ['required', 'array'],
  155. 'cta.label' => $text(30),
  156. 'cta.href' => $link,
  157. ],
  158. 'about' => [
  159. 'heading' => $text(80),
  160. 'body' => $text(1200),
  161. 'stats' => ['present', 'array', 'max:4'],
  162. 'stats.*.value' => $text(12),
  163. 'stats.*.label' => $text(40),
  164. ],
  165. 'testimonials' => [
  166. 'heading' => $text(80),
  167. 'items' => ['required', 'array', 'min:1', 'max:6'],
  168. 'items.*.quote' => $text(400),
  169. 'items.*.name' => $text(60),
  170. 'items.*.role' => $optionalText(60),
  171. ],
  172. 'faq' => [
  173. 'heading' => $text(80),
  174. 'items' => ['required', 'array', 'min:1', 'max:10'],
  175. 'items.*.question' => $text(160),
  176. 'items.*.answer' => $text(600),
  177. ],
  178. 'newsletter' => [
  179. 'heading' => $text(80),
  180. 'body' => $optionalText(240),
  181. 'placeholder' => $text(40),
  182. 'buttonLabel' => $text(30),
  183. ],
  184. 'contact' => [
  185. 'heading' => $text(80),
  186. 'body' => $optionalText(300),
  187. 'email' => ['nullable', 'email', 'max:120'],
  188. 'phone' => $optionalText(30),
  189. 'whatsapp' => ['nullable', 'string', 'regex:/^[0-9]{8,15}$/'],
  190. 'address' => $optionalText(200),
  191. ],
  192. 'footer' => [
  193. 'text' => $text(160),
  194. 'links' => ['present', 'array', 'max:8'],
  195. 'links.*.label' => $text(30),
  196. 'links.*.href' => $link,
  197. ],
  198. default => [],
  199. };
  200. }
  201. }