clean-apex
Provide opinionated, minimal clean-code guidance for Apex. Focus on readability, naming, architecture layering, error handling, and test separation. Avoid security checks, performance scoring, and broad best-practice audits unless explicitly requested.
Load References
Read these files before doing any work:
references/naming-conventions.md
references/architecture.md
references/error-handling.md
references/soql-di.md
references/validator-exceptions.md
Quick Workflow
- Clarify the task: review, generate, or both.
- Identify the layer(s): entry-point, service, OO, or test.
- Apply naming conventions from
references/naming-conventions.md.
- Enforce 3-tier responsibilities from
references/architecture.md.
- Apply error handling from
references/error-handling.md.
- Apply SOQL + DI constraints and test rules from
references/soql-di.md.
Generation Mode
When generating Apex:
- Use the 3-tier structure. Keep entry-point minimal; orchestrate in service; compute in OO.
- Put all DML in the static service layer only.
- Keep OO classes DML-free and focused on in-memory logic.
- Put SOQL in selector/query classes and inject into OO classes as properties.
- Follow naming conventions strictly.
- Avoid code comments unless they convey non-obvious intent or constraints that the code cannot express.
- Do not add auto-generated JavaDoc-style comments for classes or methods.
- Provide unit tests for OO classes with no DML; use DI to replace SOQL.
- Provide integration tests for entry-point/service behavior where DML is expected.
How To Use Clean-Apex
Use this exact generation flow:
- Read
templates/TEMPLATE_INDEX.md and select layer-appropriate files.
- Start from
CleanOrder* templates in templates/, including async and trigger packs.
- Run a sanitize check before final output and remove org-specific class names, object/field API names, IDs, endpoint domains, and business terms unless the user explicitly provides approved real names.
Templates
Check templates/TEMPLATE_INDEX.md first to see which templates map to each layer/test type.
If templates exist at templates/, prefer them. If missing or incomplete, ask the user for sample Apex templates before generating full files.
Use examples-sanitized/ for safe style references.
Sanitization Rules
- Do not copy user-provided org-specific source snippets directly into generated output.
- Treat any org-specific source material as private pattern input only.
- Use generic class/object/field names in output unless the user explicitly provides org-specific names.
- Prefer standard objects or obvious placeholders in generated templates/examples.
- Before producing shareable code, ensure names and terms are masked and user-reviewed.
Review Mode
When reviewing Apex:
- Flag naming violations with concrete rename suggestions.
- Flag layer violations (entry-point logic, service doing OO work, OO doing DML).
- Flag missing DI where OO relies on SOQL.
- Flag error handling that swallows exceptions without business justification.
- Flag OO tests that use DML or fail to mock SOQL.
- Flag unnecessary comments or auto-generated JavaDoc-style comments on classes/methods.
- Keep feedback concise and focused on readability and structure only.
Error Handling Rules
- Let exceptions bubble to entry-point and handle there.
- Do not swallow exceptions unless business requirements demand it; log before swallowing.
Testing Rules
- OO class unit tests must not use DML.
- When SOQL is required, inject a selector/query dependency to substitute the SOQL in tests.
- Use integration tests for entry-point/service flows that perform DML.
Out of Scope
Do not add security checks, performance tuning, or scoring unless the user explicitly requests them.
1---2name: clean-apex3description: Clean-code focused Apex guidance for readability, naming conventions, 3-tier architecture (entry-point, static service, OO), error handling, and unit vs integration testing. Use when reviewing or generating Apex for clarity and maintainable structure, excluding security/performance scoring.4---56# clean-apex78Provide opinionated, minimal clean-code guidance for Apex. Focus on readability, naming, architecture layering, error handling, and test separation. Avoid security checks, performance scoring, and broad best-practice audits unless explicitly requested.910## Load References1112Read these files before doing any work:1314- `references/naming-conventions.md`15- `references/architecture.md`16- `references/error-handling.md`17- `references/soql-di.md`18- `references/validator-exceptions.md`1920## Quick Workflow21221. Clarify the task: review, generate, or both.232. Identify the layer(s): entry-point, service, OO, or test.243. Apply naming conventions from `references/naming-conventions.md`.254. Enforce 3-tier responsibilities from `references/architecture.md`.265. Apply error handling from `references/error-handling.md`.276. Apply SOQL + DI constraints and test rules from `references/soql-di.md`.2829## Generation Mode3031When generating Apex:3233- Use the 3-tier structure. Keep entry-point minimal; orchestrate in service; compute in OO.34- Put all DML in the static service layer only.35- Keep OO classes DML-free and focused on in-memory logic.36- Put SOQL in selector/query classes and inject into OO classes as properties.37- Follow naming conventions strictly.38- Avoid code comments unless they convey non-obvious intent or constraints that the code cannot express.39- Do not add auto-generated JavaDoc-style comments for classes or methods.40- Provide unit tests for OO classes with no DML; use DI to replace SOQL.41- Provide integration tests for entry-point/service behavior where DML is expected.4243## How To Use Clean-Apex4445Use this exact generation flow:46471. Read `templates/TEMPLATE_INDEX.md` and select layer-appropriate files.482. Start from `CleanOrder*` templates in `templates/`, including async and trigger packs.493. Run a sanitize check before final output and remove org-specific class names, object/field API names, IDs, endpoint domains, and business terms unless the user explicitly provides approved real names.5051### Templates5253Check `templates/TEMPLATE_INDEX.md` first to see which templates map to each layer/test type.54If templates exist at `templates/`, prefer them. If missing or incomplete, ask the user for sample Apex templates before generating full files.55Use `examples-sanitized/` for safe style references.5657## Sanitization Rules5859- Do not copy user-provided org-specific source snippets directly into generated output.60- Treat any org-specific source material as private pattern input only.61- Use generic class/object/field names in output unless the user explicitly provides org-specific names.62- Prefer standard objects or obvious placeholders in generated templates/examples.63- Before producing shareable code, ensure names and terms are masked and user-reviewed.6465## Review Mode6667When reviewing Apex:6869- Flag naming violations with concrete rename suggestions.70- Flag layer violations (entry-point logic, service doing OO work, OO doing DML).71- Flag missing DI where OO relies on SOQL.72- Flag error handling that swallows exceptions without business justification.73- Flag OO tests that use DML or fail to mock SOQL.74- Flag unnecessary comments or auto-generated JavaDoc-style comments on classes/methods.75- Keep feedback concise and focused on readability and structure only.7677## Error Handling Rules7879- Let exceptions bubble to entry-point and handle there.80- Do not swallow exceptions unless business requirements demand it; log before swallowing.8182## Testing Rules8384- OO class unit tests must not use DML.85- When SOQL is required, inject a selector/query dependency to substitute the SOQL in tests.86- Use integration tests for entry-point/service flows that perform DML.8788## Out of Scope8990Do not add security checks, performance tuning, or scoring unless the user explicitly requests them.