$npx -y skills add totvs/engpro-advpl-tlpp-skills --skill mvc-generatorGenerate Protheus MVC (Model-View-Controller) screen structures including ModelDef, ViewDef, MenuDef, and BrowseDef functions. Supports single-entity (Modelo 1) and master-detail (Modelo 3) patterns with FWFormModel, FWFormView, FWFormBrowse, validations, triggers, and entry poin
| 1 | # Protheus MVC Generator |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Generate complete Protheus MVC screen implementations following the TOTVS framework patterns. Protheus MVC separates business rules (Model), visual presentation (View), and navigation/actions (Controller/Browse) using the `FWFormModel`, `FWFormView`, and `FWFormBrowse` framework classes. This skill generates the three mandatory functions (`ModelDef`, `ViewDef`, `MenuDef`) plus the Browse function that composes them. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - Creating a new CRUD screen for a Protheus table |
| 12 | - Building a master-detail form (e.g., invoice header + items) |
| 13 | - Generating MVC boilerplate from a table alias |
| 14 | - Adding validations, triggers, and entry point hooks to MVC screens |
| 15 | - Migrating legacy AxCadastro/Mbrowse screens to MVC |
| 16 | |
| 17 | --- |
| 18 | |
| 19 | ## MVC Architecture in Protheus |
| 20 | |
| 21 | ### Core Components |
| 22 | |
| 23 | ``` |
| 24 | ┌─────────────────────────────────────────┐ |
| 25 | │ Main Function (e.g., MYMOD01) │ |
| 26 | │ ├── MenuDef() → Menu actions │ |
| 27 | │ └── FWFormBrowse → Browse grid │ |
| 28 | │ ├── ModelDef() → Business rules │ |
| 29 | │ │ ├── FWFormStruct → Schema │ |
| 30 | │ │ ├── FWFormFieldsModel (Form) │ |
| 31 | │ │ ├── FWFormGridModel (Grid) │ |
| 32 | │ │ └── Validations / Triggers │ |
| 33 | │ └── ViewDef() → Visual layout │ |
| 34 | │ ├── FWFormStruct → Schema │ |
| 35 | │ ├── Form panels │ |
| 36 | │ └── Grid panels │ |
| 37 | └─────────────────────────────────────────┘ |
| 38 | ``` |
| 39 | |
| 40 | ### User Function Responsibilities |
| 41 | |
| 42 | | Function | Purpose | Returns | |
| 43 | | ------------- | -------------------------------------------------------------------- | -------------------- | |
| 44 | | `ModelDef()` | Defines the data model: fields, validations, relationships, triggers | `FWFormModel` object | |
| 45 | | `ViewDef()` | Defines the visual layout: panels, grids, field arrangement | `FWFormView` object | |
| 46 | | `MenuDef()` | Defines available actions: Include, Edit, Delete, View, Copy | Array of menu items | |
| 47 | | Main Function | Creates `FWFormBrowse` and activates the screen | — | |
| 48 | |
| 49 | --- |
| 50 | |
| 51 | ## Bundled Reference Files |
| 52 | |
| 53 | This skill uses progressive disclosure. The SKILL.md body covers the architecture, generation workflow, the checklist, and troubleshooting. Detailed code templates and API references are in the `references/` directory — read them on demand based on the scenario: |
| 54 | |
| 55 | | Reference File | When to Read | Content | |
| 56 | | --- | --- | --- | |
| 57 | | [references/mvc-code-templates.md](references/mvc-code-templates.md) | Generating **MVC code** — Single Entity (Modelo 1) or Master-Detail (Modelo 3) templates, event handlers, validation/commit patterns | Full code templates for both MVC patterns, ModelDef/ViewDef/MenuDef boilerplate, validation handlers, commit handlers | |
| 58 | | [references/mvc-api-reference.md](references/mvc-api-reference.md) | Customizing **FWFormStruct**, adjusting **View layout** (boxes, tabs), configuring **MenuDef** actions, or adding custom menu buttons | FWFormStruct parameters, structure customization (RemoveField, SetProperty, FWBuildFeature), HBox/VBox/Folder layout, action codes table, custom actions | |
| 59 | |
| 60 | > Also refer to [references/sonarqube-rules-reference.md](../references/sonarqube-rules-reference.md) for the complete SonarQube rules reference shared across skills. |
| 61 | |
| 62 | --- |
| 63 | |
| 64 | ## Generation Workflow |
| 65 | |
| 66 | ### Step 1: Gather Requirements |
| 67 | |
| 68 | Determine the generation pattern from the user's request: |
| 69 | |
| 70 | | Scenario | MVC Pattern | Key Characteristic | |
| 71 | | --- | --- | --- | |
| 72 | | Simple CRUD (single table) | Single Entity (Modelo 1) | `AddFields` only, no grid | |
| 73 | | Master-detail (header + items) | Master-Detail (Modelo 3) | `AddFields` + `AddGrid` + `SetRelation` | |
| 74 | | Legacy migration (AxCadastro/Mbrowse) | Depends on current structure | Analyze existing code to choose pattern | |
| 75 | |
| 76 | Read the appropriate reference files based on the pattern identified: |
| 77 | - **Code generation** → read [references/mvc-code-templates.md](references/mvc-code-templates.md) |
| 78 | - **Structure customization or layout** → read [references/mvc-api-reference.md](references/mvc-api-reference.md) |
| 79 | |
| 80 | ### Step 2: Generate Code |
| 81 | |
| 82 | Using the selected template from the reference files, adapt it to the user's specific requirements: |
| 83 | - Replace table aliases (`ZZ1`, `ZZ2`, `ZZ3`) with actual table aliases |
| 84 | - Replace function/model IDs (`MYMOD01`, |