> **Note**: This skill incorporates the comprehensive static analysis, security, and clean architecture standards required for enterprise deployments, open-source releases, and commercial marketplace submissions (such as Envato / CodeCanyon).
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Envato Review Guidelines?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/polyxgo-envato-review-guidelines)
# Skill: Code Quality, Security & Static Analysis (Perfex Module)
> **Note**: This skill incorporates the comprehensive static analysis, security, and clean architecture standards required for enterprise deployments, open-source releases, and commercial marketplace submissions (such as Envato / CodeCanyon).
## Purpose
This skill defines the software engineering standards, security best practices (OWASP/CWE), static analysis compliance, and Clean Code principles required to build robust, maintainable, and enterprise-grade Perfex CRM modules.
Following these rules ensures zero security vulnerabilities, optimal concurrency, and smooth automated static analysis scans (SonarQube, AST linters, automated marketplace review bots).
## When to Use
- When developing, refactoring, or code-reviewing any Perfex CRM module.
- When performing security audits and static code analysis (SonarQube, AST scanners, bot linters).
- When preparing production release archives (`deploy.ps1` or build pipelines).
- When resolving performance bottlenecks, race conditions, or PHP session locking issues.
---
## Core Software Engineering & Quality Standards
### 1. Separation of Concerns (Zero Inline JS & CSS)
- **Architectural Rule**: Strict decoupling between Presentation (HTML views), Behavior (JavaScript logic), and Styling (CSS).
- **Prohibited Patterns**:
- Inline `<script>` tags inside PHP view templates containing business logic, DOM manipulation, event listeners, or AJAX calls.
- Inline `<style>` blocks or `style="..."` attributes on HTML tags (both in module views and documentation guides).
- Hardcoded CSS string arrays declared inside JavaScript files. All styles belong in dedicated `.css` stylesheets.
- **Standard Practice**:
- All JavaScript must reside in standalone `.js` files in `assets/js/` (and compiled/minified to `dist/assets/js/`).
- All CSS must reside in standalone `.css` files in `assets/css/` (and compiled/minified to `dist/assets/css/`).
- Scripts and stylesheets must be enqueued via Perfex CRM hooks (`app_admin_head`, `app_admin_footer`, `app_customers_head`, `app_customers_footer`).
- Pass server-side configurations to frontend via centralized localization objects hooked to `app_admin_head` (e.g. `window.{MODULE_UPPERCASE}_CONFIG = ...; window.{MODULE_UPPERCASE}_LANG = ...;`) or semantic HTML5 data attributes (`data-*` / `data-config='...'`) on the root container.
### 2. Static Analysis & AST Scanner Neutrality
Security scanners and static analysis bots (SonarQube, AST parsers, marketplace review bots) inspect source code for suspicious signatures. Ambiguous or high-risk terminology can trigger false-positive security warnings:
- **High-Risk Tokens to Avoid**:
- `inject`, `injection`, `injectStyles`: Often flagged as Script / SQL Injection patterns.
- `seeder`: Often flagged by automated bots looking for unauthorized database tampering backdoors.
- `bypass`, `backdoor`, `eval`, `unserialize`: Direct security red flags across all static analysis tools.
- **Recommended Professional Terminology**:
- Use `extend` (e.g. `extendTinyMCEStyles`) or `apply` instead of `inject`.
- Use `demo_data` or `sample_generator` instead of `seeder`.
- Use `allow` or `permit` instead of `bypass`.
### 3. Safe Dynamic Stylesheet Loading (TinyMCE & Iframes)
When styling rich text editors or dynamically injected iframes:
- **NEVER** insert dynamic `<style>` textContent strings containing hardcoded raw CSS.
- **Native Editor API**:
```javascript
if (editor.dom && typeof editor.dom.loadCSS === 'function') {
editor.dom.loadCSS(siteUrl + 'modules/{module}/dist/assets/css/{module}_editor.min.css');
}
```
- **Fallback via Link Element Cloning**:
```javascript
var parentLink = document.querySelector('link[href*="{module}_editor"]');
if (parentLink && doc.head && !doc.getElementById('{module}-tinymce-styles')) {
var linkEl = doc.createElement('link');
linkEl.id = '{module}-tinymce-styles';
linkEl.rel = 'stylesheet';
linkEl.href = parentLink.href;
doc.head.appendChild(linkEl);
}
```
### 4. JavaScript Scope Isolation & Conflict Prevention
Prevent race conditions, jQuery namespace clashes, and global scope pollution:
- Enclose 100% of admin scripts in a window load listener and strict IIFE:
```javascript
window.addEventListener('load', function () {
(function ($) {
'use strict';
// Scoped module logic here
})(typeof jQuery !== 'undefined' ? jQuery : window.$);
});
```
- Keep the global `window` scope pristine. Only expose strictly necessary public APIs under a unified module namespace.
### 5. High-Concurrency & PHP Session Lock Prevention
- In PHP and CodeIgniter, active sessions hold exclusive file locks. Autocomplete lookups, live searches, and read-only AJAX endpoints can cause thread blocking and interface lag when multiple requests queue up.
- Always release the session lock at the start of read/search controller actions:
```php
// Release PHP session file lock immediately for non-blocking concurrent queries
session_write_close();
```
### 6. Clean Release Packaging & Artifact Isolation
- Separate development dependencies and test tooling from production runtime artifacts.
- **Strictly Exclude from Production Distribution**:
- Development build files: `package.json`, `package-lock.json`, `webpack.config.js`.
- Testing & scratch code: `tests/`, `test/`, `scratch/`, `*_debug.php`, benchmark scripts.
- Raw uncompiled assets if using bundled/minified `dist/`.
- Version control and IDE artifacts: `.git`, `.ai`, `.agents`, `heraspec`, internal project notes.
- Use packaging scripts (`deploy.ps1` or build scripts) with strict exclusion filters (`/XD`, `/XF`).
### 7. Defensive PHP Security & Database Best Practices
- **Direct Access Guard**: 100% of PHP files must begin with:
```php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
```
- **Standard PHP Tags**: Never use short open tags `<?=` or `<?`. Always use standard `<?php echo ...; ?>`.
- **SQL Injection Prevention (OWASP)**: Never concatenate user input directly into SQL queries. Always use CodeIgniter Query Builder with automatic parameter escaping or `$this->db->escape_str()`.
- **CSRF Protection**: All POST forms and AJAX requests modifying state must include CSRF tokens:
```php
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
```
And in AJAX:
```javascript
$.ajaxSetup({ data: { [csrf_token_name]: csrf_hash } });
```
### 8. DOM XSS Prevention (CWE-79)
- Never assign raw, unescaped user-controlled strings directly to `.innerHTML`.
- Use `.textContent`, `.innerText`, `document.createElement()`, or helper functions with strict HTML entity escaping (`escapeHtml()`).
- Always sanitize rich user-generated content using HTMLPurifier before rendering.
### 9. Enterprise Internationalization (i18n & l10n)
- **Zero Hardcoded Strings**: 100% of labels, headings, buttons, tooltips, placeholders, and error/feedback messages must use `_l('key')`.
- Maintain complete parity across supported language catalogs:
- `language/english/{module}_lang.php`
- `language/vietnamese/{module}_lang.php` (and other target locales)
- Never hardcode raw strings like `'Item deleted'` or `'Unauthorized'` in controllers; use centralized language keys.
### 10. Professional Software DNA & Clean Typography
- 0 emojis in backend PHP, JavaScript, CSS, view templates, comments, or documentation.
- Maintain a clean, professional, enterprise-grade look and feel consistent with core CRM aesthetics.
---
## Reference Implementation
- `modules/crosstag/`: Production reference adhering to dual-engine search, `extendTinyMCEStyles()`, Webpack dist bundling, session lock release, and 100% passing automated test assertions.