Django Technical Audit
This skill guides a rigorous technical audit in Django applications, focusing on security, patterns, performance, and quality.
Language Note: You should perform the audit and generate the report in the same language the user is using (e.g., if the user asks in Portuguese, the report should be in Portuguese).
How to Work
- Scan: Identify the main files of the target directory/app (models, views, urls, forms/serializers, templates, admin, services, tests, migrations).
- Evaluation: Read and evaluate file by file, pointing out inconsistencies with reference to the path and, when possible, the method/class name.
- Classification: Classify each finding by Severity (CRITICAL, URGENT, MEDIUM, LOW) and Category (Security, Bugs, Django best practices, Performance, DB, Tests, Architecture, Maintainability, Observability, DX/DevOps).
- Focus: Focus on incremental and safe fixes. Do not invent files.
Audit Checklist
1. Security (Mandatory)
- Authentication & Authorization: Check use of
@login_required, permission_required, group checks, user.is_staff, user.is_superuser.
- Data Exposure: Check for exposure of tokens, secrets, logs, or debug info.
- Vulnerabilities:
- SQL Injection: Use of
.extra(), raw(), f-strings in SQL, or direct concatenation.
- XSS: Templates without escaping or improper use of
safe/mark_safe filters.
- CSRF: Unprotected views in form submissions.
- Settings: Check
DEBUG=True in production, loose ALLOWED_HOSTS, missing SECURE_* headers, cookies without Secure/HttpOnly/SameSite.
2. Django Patterns & Architecture
- Models: Normalization, validations (
clean), choices, constraints, indexes.
- Views: Logic separation (View vs Service/Layer), avoid excessive business logic in views.
- Forms/Serializers: Adequate validation.
- Admin: Permissions,
list_display, search_fields.
- Transactions: Use of
transaction.atomic() for operations involving multiple tables.
- Signals: Avoid uncontrolled side effects.
3. Performance & Database
- N+1 Queries: Lack of
select_related or prefetch_related.
- Indexes: Absence in FKs and frequent filter fields.
- Queries: Heavy queries inside loops or lack of pagination in listings.
4. Tests & Quality
- Coverage: Existence of tests for critical rules and main flows.
- Security: Tests for authorization and permissions.
- Style: PEP 8, docstrings, exception handling (avoid
except: pass).
Report Format (Deliverable)
The final report must be in Markdown with the following structure:
📌 Executive Summary
- 5 to 10 key points focusing on CRITICAL/URGENT risks.
✅ Analyzed Inventory
- List of reviewed directories and files (with paths).
🚨 Findings by Severity
CRITICAL
- [Category] path/file.py::ClassOrFunction
- Impact: ...
- Risk: ...
- How to fix: Detailed steps.
- Suggested Test: How to validate the fix.
(Repeat for URGENTE, MÉDIO and BAIXO as needed)
🧪 Recommended Test Plan
- List of new tests to create, grouped by area.
🛠️ Suggested Fixes (Prioritized)
- Ordered checklist from most critical to least critical.
🧭 Next Steps
- Recommendations for incremental improvement (refactor, patterns, tooling).
🛠️ Utility Scripts
The skill includes a script to facilitate the execution of audit tools:
scripts/audit_check.py: Runs automatic checks (Django deploy check, Bandit, Ruff, pip-audit).
- Automation: The script creates an isolated virtual environment (
.audit_venv), installs audit tools, and attempts to install project dependencies (requirements.txt) for a complete and safe analysis.
- Usage:
python scripts/audit_check.py [app_dir]
Source: dmslabsbr/ia_skills — distributed by TomeVault.
1---2name: django-audit3description: Performs a complete technical audit of Django applications, covering security, architecture patterns, performance, database, and code quality. Use this skill whenever you need to review a Django app for bugs, security risks, or technical debt. Supports both English and Portuguese. Use when this capability is needed.4---56# Django Technical Audit78This skill guides a rigorous technical audit in Django applications, focusing on security, patterns, performance, and quality.910**Language Note**: You should perform the audit and generate the report in the same language the user is using (e.g., if the user asks in Portuguese, the report should be in Portuguese).1112## How to Work13141. **Scan**: Identify the main files of the target directory/app (models, views, urls, forms/serializers, templates, admin, services, tests, migrations).152. **Evaluation**: Read and evaluate file by file, pointing out inconsistencies with reference to the path and, when possible, the method/class name.163. **Classification**: Classify each finding by **Severity** (CRITICAL, URGENT, MEDIUM, LOW) and **Category** (Security, Bugs, Django best practices, Performance, DB, Tests, Architecture, Maintainability, Observability, DX/DevOps).174. **Focus**: Focus on incremental and safe fixes. Do not invent files.1819## Audit Checklist2021### 1. Security (Mandatory)22- **Authentication & Authorization**: Check use of `@login_required`, `permission_required`, group checks, `user.is_staff`, `user.is_superuser`.23- **Data Exposure**: Check for exposure of tokens, secrets, logs, or debug info.24- **Vulnerabilities**:25 - **SQL Injection**: Use of `.extra()`, `raw()`, f-strings in SQL, or direct concatenation.26 - **XSS**: Templates without escaping or improper use of `safe`/`mark_safe` filters.27 - **CSRF**: Unprotected views in form submissions.28- **Settings**: Check `DEBUG=True` in production, loose `ALLOWED_HOSTS`, missing `SECURE_*` headers, cookies without `Secure/HttpOnly/SameSite`.2930### 2. Django Patterns & Architecture31- **Models**: Normalization, validations (`clean`), choices, constraints, indexes.32- **Views**: Logic separation (View vs Service/Layer), avoid excessive business logic in views.33- **Forms/Serializers**: Adequate validation.34- **Admin**: Permissions, `list_display`, `search_fields`.35- **Transactions**: Use of `transaction.atomic()` for operations involving multiple tables.36- **Signals**: Avoid uncontrolled side effects.3738### 3. Performance & Database39- **N+1 Queries**: Lack of `select_related` or `prefetch_related`.40- **Indexes**: Absence in FKs and frequent filter fields.41- **Queries**: Heavy queries inside loops or lack of pagination in listings.4243### 4. Tests & Quality44- **Coverage**: Existence of tests for critical rules and main flows.45- **Security**: Tests for authorization and permissions.46- **Style**: PEP 8, docstrings, exception handling (avoid `except: pass`).4748## Report Format (Deliverable)4950The final report must be in Markdown with the following structure:5152## 📌 Executive Summary53- 5 to 10 key points focusing on CRITICAL/URGENT risks.5455## ✅ Analyzed Inventory56- List of reviewed directories and files (with paths).5758## 🚨 Findings by Severity5960### CRITICAL61- **[Category]** path/file.py::ClassOrFunction62- **Impact**: ...63- **Risk**: ...64- **How to fix**: Detailed steps.65- **Suggested Test**: How to validate the fix.6667*(Repeat for URGENTE, MÉDIO and BAIXO as needed)*6869## 🧪 Recommended Test Plan70- List of new tests to create, grouped by area.7172## 🛠️ Suggested Fixes (Prioritized)73- Ordered checklist from most critical to least critical.7475## 🧭 Next Steps76- Recommendations for incremental improvement (refactor, patterns, tooling).7778---7980## 🛠️ Utility Scripts8182The skill includes a script to facilitate the execution of audit tools:8384- `scripts/audit_check.py`: Runs automatic checks (Django deploy check, Bandit, Ruff, pip-audit).85 - **Automation**: The script creates an isolated virtual environment (`.audit_venv`), installs audit tools, and attempts to install project dependencies (`requirements.txt`) for a complete and safe analysis.86 - Usage: `python scripts/audit_check.py [app_dir]`8788---89> Source: [dmslabsbr/ia_skills](https://github.com/dmslabsbr/ia_skills) — distributed by [TomeVault](https://tomevault.io).90<!-- tomevault:4.0:skill_md:2026-06-16 -->