# Module Creation Guide ## Style Reference When creating new modules, you MUST match the visual style of the existing project. Follow these steps IN ORDER: ### Step 1: Check for `docs/project-styles.md` - If the file exists → read it and use it as your style reference. DONE — skip to module creation. - If the file does NOT exist → continue to Step 2. ### Step 2: Determine if exploration is needed - Count modules in `template/estandar/modulos/` that have `builder.json` and do NOT start with `custom-` - If 3+ qualifying modules exist → continue to Step 3 - If fewer than 3 → skip exploration, create the module based on the user's description. The style will be defined as modules are created. ### Step 3: Explore and GENERATE the style guide (MANDATORY) - Read `index-base.tpl` and `style.css` of 3-4 representative modules (only those with `builder.json`, skip `custom-*`) - **You MUST then call `save_project_styles`** with a markdown summary including: - Primary/secondary/accent colors (hex values) - Font families and sizes used - Spacing scale (padding/margin patterns) - Common Tailwind classes and custom CSS patterns - Button styles, card styles, section layouts - Any recurring design patterns (gradients, shadows, borders, etc.) - This saves `docs/project-styles.md` which will be read by future module creation tasks — no re-exploration needed. **After creating a module:** if `docs/project-styles.md` does not exist yet and there are now 3+ modules, call `save_project_styles`. ## Module Structure Each module lives in `template/estandar/modulos//` with: - `index-base.tpl` — Twig template (source — EDIT THIS) - `style.css` — Module styles - `script.js` — Module JavaScript - `builder.json` — Compiled builder vars (auto-generated, do NOT edit) - `index.tpl` / `index-twig.tpl` — Compiled (auto-generated, do NOT edit) ## Creating a Module — Full Workflow If the module needs JavaScript, you MUST read `docs/css-js-conventions.md` before writing `index-base.tpl` or `script.js`. If the module needs server-side logic, dynamic data processing, form handling, or reusable backend behavior, you MUST read `docs/hooks-and-api.md` before creating `hook.php` or any global hook. If the module will call hooks from Twig, also review `docs/twig-filters.md` for the `hook` filter syntax. If `index-base.tpl` contains builder fields (`data-field-type`), you MUST review `docs/builder-fields.md` before writing the template. Hard rules for module files: - `index-base.tpl` is for HTML/Twig only - `script.js` is for module JavaScript - `style.css` is for module CSS - `hook.php` is for server-side logic - Do NOT embed `