mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-03-31 07:12:23 -07:00
1.5 KiB
1.5 KiB
name, description
| name | description |
|---|---|
| netalertx-code-standards | NetAlertX coding standards and conventions. Use this when writing code, reviewing code, or implementing features. |
Code Standards
File Length
Keep code files under 500 lines. Split larger files into modules.
DRY Principle
Do not re-implement functionality. Reuse existing methods or refactor to create shared methods.
Database Access
- Never access DB directly from application layers
- Use
server/db/db_helper.pyfunctions (e.g.,get_table_json) - Implement new functionality in handlers (e.g.,
DeviceInstanceinserver/models/device_instance.py)
MAC Address Handling
Always validate and normalize MACs before DB writes:
from plugin_helper import normalize_mac
mac = normalize_mac(raw_mac)
Subprocess Safety
MANDATORY: All subprocess calls must set explicit timeouts.
result = subprocess.run(cmd, timeout=60) # Minimum 60s
Nested subprocess calls need their own timeout—outer timeout won't save you.
Time Utilities
from utils.datetime_utils import timeNowDB
timestamp = timeNowDB()
String Sanitization
Use sanitizers from server/helper.py before storing user input.
Devcontainer Constraints
- Never
chmodorchownduring operations - Everything is already writable
- If permissions needed, fix
.devcontainer/scripts/setup.sh
Path Hygiene
- Use environment variables for runtime paths
/datafor persistent config/db/tmpfor runtime logs/api/nginx state- Never hardcode
/data/dbor use relative paths