mvc-generator
Skill138 starsChanged 6 months agoMITView on GitHub
Generate 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 point hooks. Use when user says 'create MVC screen', 'ModelDef ViewDef', 'FWFormModel', 'master-detail screen'.
In this repository36 other files it gives its agents.
- AGENTS.mdAGENTS.md
- instructions/AGENTS.mdAGENTS.md
- instructions/CLAUDE.mdCLAUDE.md
- advpl-tlpp-compileSkill
- advpl-tlpp-sddSkill
- advpl-to-tlpp-migrationSkill
- code-reviewSkill
- context-mapSkill
- create-implementation-planSkill
- data-dictionary-lookupSkill
- documentation-writerSkill
- entry-point-designerSkill
- fwmsexcelxlsx-generatorSkill
- fwrest-client-generatorSkill
- query-builderSkill
- refactor-method-complexity-reduceSkill
- refactorSkill
- sql-code-reviewSkill
- sql-optimizationSkill
- tir-test-generatorSkill
- tlpp-rest-endpoint-generatorSkill
- utf8-to-cp1252-conversionSkill
- brainstormingSkill
- dispatching-parallel-agentsSkill
- executing-plansSkill
- finishing-a-development-branchSkill
- receiving-code-reviewSkill
- requesting-code-reviewSkill
- subagent-driven-developmentSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- using-git-worktreesSkill
- using-superpowersSkill
- verification-before-completionSkill
- writing-plansSkill
- writing-skillsSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 4 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 21
Use this skill when:
- Distinctive: line 88
Read the appropriate reference files based on the pattern identified:
- Distinctive: line 97
Add/remove fields, validations, and triggers as needed
- Distinctive: line 102
Run through the MVC Generation Checklist below to verify completeness.
- Very specific: line 166
ModelDef/ViewDef mismatch: Every field ID added to FWFormModel must have a corresponding entry in FWFormView.
- Very specific: line 167
Grid rows not saving: Ensure FWFormCommit(oModel) is called in the commit block.
- Very specific: line 168
Browse shows no records: Verify FWFormBrowse():SetAlias() points to the correct table alias and that the table is accessible from the …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Protheus MVC Generator
Overview
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.
When to Use
Use this skill when:
- Creating a new CRUD screen for a Protheus table
- Building a master-detail form (e.g., invoice header + items)
- Generating MVC boilerplate from a table alias
- Adding validations, triggers, and entry point hooks to MVC screens
- Migrating legacy AxCadastro/Mbrowse screens to MVC
MVC Architecture in Protheus
Core Components
┌─────────────────────────────────────────┐
│ Main Function (e.g., MYMOD01) │
│ ├── MenuDef() → Menu actions │
│ └── FWFormBrowse → Browse grid │
│ ├── ModelDef() → Business rules │
│ │ ├── FWFormStruct → Schema │
│ │ ├── FWFormFieldsModel (Form) │
│ │ ├── FWFormGridModel (Grid) │
│ │ └── Validations / Triggers │
│ └── ViewDef() → Visual layout │
│ ├── FWFormStruct → Schema │
│ ├── Form panels │
│ └── Grid panels │
└─────────────────────────────────────────┘User Function Responsibilities
| Function | Purpose | Returns |
ModelDef() | Defines the data model: fields, validations, relationships, triggers | FWFormModel object |
ViewDef() | Defines the visual layout: panels, grids, field arrangement | FWFormView object |
MenuDef() | Defines available actions: Include, Edit, Delete, View, Copy | Array of menu items |
| Main Function | Creates FWFormBrowse and activates the screen | — |
Bundled Reference Files
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:
| Reference File | When to Read | Content |
| 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 |
| 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 |
Also refer to references/sonarqube-rules-reference.md for the complete SonarQube rules reference shared across skills.
Generation Workflow
Step 1: Gather Requirements
Determine the generation pattern from the user's request:
| Scenario | MVC Pattern | Key Characteristic |
| Simple CRUD (single table) | Single Entity (Modelo 1) | AddFields only, no grid |
| Master-detail (header + items) | Master-Detail (Modelo 3) | AddFields + AddGrid + SetRelation |
| Legacy migration (AxCadastro/Mbrowse) | Depends on current structure | Analyze existing code to choose pattern |
Read the appropriate reference files based on the pattern identified:
- Code generation → read references/mvc-code-templates.md
- Structure customization or layout → read references/mvc-api-reference.md
Step 2: Generate Code
Using the selected template from the reference files, adapt it to the user's specific requirements:
- Replace table aliases (
ZZ1,ZZ2,ZZ3) with actual table aliases - Replace function/model IDs (
MYMOD01,MYMOD01M) with actual routine names - Add/remove fields, validations, and triggers as needed
- Adjust View layout proportions and structure
Step 3: Validate Against Checklist
Run through the MVC Generation Checklist below to verify completeness.
MVC Generation Checklist
Model (ModelDef)
FWFormStruct(1, "XXX")loaded for each table- Fields removed/customized as needed
- Model created with
MPFormModel():New("UNIQUE_ID") AddFieldscalled for form sectionsAddGridcalled for grid sections (master-detail)- Relationship defined with
SetRelationfor grids - Model and sub-model descriptions set
SetPrimaryKey({})called- Validation handlers registered (
SetVldActive,SetCommit) - Grid line validation registered (
SetVldLine)
View (ViewDef)
- Model loaded with
FWLoadModel("ROUTINE_NAME") FWFormStruct(2, "XXX")loaded for each tableFWFormView():New()created- Model set with
SetModel(oModel) AddFieldand/orAddGridcalled for each visual section- Layout boxes created (
CreateHorizontalBox,CreateVerticalBox) - Views assigned to boxes with
SetOwnerView - Screen proportions make sense (header vs. detail)
MenuDef
- Standard CRUD operations included (1-5)
- Custom actions added if needed
- Menu item names match
VIEWDEF.ROUTINE_NAME
General
#include "fwmvcdef.ch"present#include "totvs.ch"present- Browse function creates
FWFormBrowseand sets alias - Legends added to browse if the table has status fields
- Validation messages use
Help()function FWFormCommit(oModel)called in commit handler for standard persistence- Custom tables registered in SX2/SX3 data dictionary before use
SonarQube Compliance
FWFormCommit(oModel)is used for persistence — never override theFormCommitmethod directly; useFWModelEventto intercept commit behavior- No UI calls (
MsgAlert,MsgYesNo,Aviso,Help,Pergunte,ParamBox) inside commit/validation handlers that execute within a transaction - Error handling uses
Try-Catch, notErrorBlock - Logging via
FWLogMsg(), notConOut() - No
IIF()in expressions — useIf/Else/EndIf - Includes in lowercase (e.g.,
#include "totvs.ch") GetMV()/ExistBlock()results cached before loops (especially in grid validations)- No direct access to SX3 via
DbSelectArea— useFWFormStruct()orFWSX3Util()
Refer to references/sonarqube-rules-reference.md for the complete SonarQube rules reference.
Troubleshooting
- "Field not found in SX3": The field referenced in
FWFormStructmust exist in the data dictionary (SX3). RunCFGX023()or use SIGACFG to register missing fields. - ModelDef/ViewDef mismatch: Every field ID added to
FWFormModelmust have a corresponding entry inFWFormView. Verify that model and view structures reference the same field set. - Grid rows not saving: Ensure
FWFormCommit(oModel)is called in the commit block. For master-detail, the grid model must be added withAddGrid()and linked viaSetOwner(). - Browse shows no records: Verify
FWFormBrowse():SetAlias()points to the correct table alias and that the table is accessible from the current branch/company. - Validation not triggering: Field-level validators must be registered in SX3 (X3_VALID) or via
SetFieldAction()on the model. Check that the trigger field ID matches exactly.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

