04 — HunterX Coding Standards

Status: Ratified Version: 1.0.0 Applies to: All Python code in src/hunterx/, plugins/, tools/, tests/, scripts/ Baseline config: pyproject.toml (ruff, line-length 120, target py311, E501 ignored)


1. Language & Runtime


2. Type Hints

from typing import Protocol, TypeGuard

class ResolvesTargets(Protocol):
    def resolve(self, scope: Scope) -> Sequence[Host]: ...

def is_authorized(actor: Actor, action: Action) -> TypeGuard[AuthorizedActor]:
    return actor.can(action)

3. Naming Conventions

Category Convention Example
Packages/modules snake_case, short hunterx/engines/
Classes PascalCase WorkflowEngine
Functions/methods snake_case, verb-first resolve_targets()
Variables snake_case finding_ids
Constants UPPER_SNAKE_CASE MAX_RETRIES
Private members single leading _ _normalize()
Protected (plugin SDK) public, documented execute(), parse()
Type aliases PascalCase suffix Type FindingId = str
Exceptions PascalCase suffix Error ScopeViolationError
Protocol types PascalCase (adjectival) ResolvesTargets
Enum members UPPER_SNAKE_CASE Severity.CRITICAL
Test functions test_<behavior>_<condition> test_parse_handles_missing_fields()
Bool getters is_, has_, can_ is_reachable(), can_execute()

Forbidden:


4. Logging


5. Exceptions


6. Architecture Rules

  1. Dependency rule: domain imports only stdlib + shared value types. application imports domain. infrastructure implements domain ports. Delivery (CLI/API) composes at the root. Enforced in CI.
  2. No framework imports in domain: no fastapi, sqlalchemy, pydantic, redis, requests, aiohttp, structlog, typer, click in domain/.
  3. AI isolation: only infrastructure/ai and engines/reasoning.py may import AI SDKs. Agents, skills, tools must go through the abstraction.
  4. DB isolation: only infrastructure/db may import ORM/driver SDKs. Engines use StorePort.
  5. Tool execution isolation: tool binaries are executed via tools/sandbox.py; adapters never shell out directly.
  6. Events over imports: cross-subsystem communication uses the Event Bus, not direct imports of another subsystem’s internals.
  7. No business logic in delivery: CLI/API handlers are thin; they validate, call use-cases, and render.
  8. No import * anywhere; no cyclic imports (enforced with import-linter).

7. Dependency Injection


8. SOLID

Principle Practice
S — SRP One class, one responsibility; controllers stay thin
O — OCP Extend via plugins/adapters; never fork core for a feature
L — LSP Subclasses honor base contracts; Protocol implementations satisfy behavior
I — ISP Small focused ports (ResolvesTargetsStoresTargets)
D — DIP Depend on abstractions; inject concrete at composition root

9. Clean Architecture Concretely


10. Async & Concurrency


11. Thread Safety


12. Performance


13. Configuration


14. Code Review Gates

Code is not merged unless:


15. Docstrings


16. Compatibility & Portability