Skip to content

refactor: Architecture cleanup — SOLID, DRY, banned patterns, dead code#19

Open
CybLow wants to merge 5 commits into
developfrom
refactor/architecture-cleanup
Open

refactor: Architecture cleanup — SOLID, DRY, banned patterns, dead code#19
CybLow wants to merge 5 commits into
developfrom
refactor/architecture-cleanup

Conversation

@CybLow

@CybLow CybLow commented Mar 21, 2026

Copy link
Copy Markdown
Owner

Summary

Systematic architecture cleanup based on a deep codebase audit.

Iteration 1: Move FlowKey to core/ (layer violation fix)

  • FlowKey is a pure value type (strings + ints + hash) — belongs in core/model/
  • Was in infra/flow/ but used by app/VerdictEngine and app/BypassManager
  • Old infra/flow/FlowKey.h becomes a forwarding alias (backward compat for infra code)
  • All app/ and test files use core::FlowKey directly

Iteration 2: Shared test fixtures (DRY)

  • Created tests/helpers/TestFixtures.h with makeFlow() and makeResult()
  • 8 test files had identical helpers — now shared for new tests

Iteration 3: Remove banned system() calls

  • SetupWizard.cpp used std::system() (banned per AGENTS.md)
  • Replaced with fork()/execvp() on Linux (POSIX-compliant)
  • Platform-guarded: non-Linux prints manual command instead
  • cli_main.cpp system() also removed

Iteration 4: Fix detached std::thread anti-pattern

  • ServerDashboard used std::thread(...).detach() — resource leak risk
  • Replaced with std::jthread stored as member streamThread_
  • RAII auto-join on destruction, proper request_stop() on disconnect

Iteration 5: Dead code removal

  • Removed unused CorrelationCriteria.h include from IHuntEngine.h

Audit Results

  • Zero layer violations (core/ includes no infra/app/ui headers)
  • Zero system() calls remaining
  • Zero std::thread::detach() calls remaining
  • Zero infra::FlowKey references in app/ layer
  • 729 tests, all passing

CybLow added 5 commits March 21, 2026 19:48
…jthread

Iteration 1: Move FlowKey from infra/ to core/model/
- FlowKey is a pure value type (zero platform deps) — belongs in core
- Old infra/flow/FlowKey.h becomes a forwarding alias header
- All app/ and test files updated to use core::FlowKey

Iteration 2: Extract shared test helpers (DRY)
- Created tests/helpers/TestFixtures.h with makeFlow() and makeResult()
- 8+ test files had identical helpers — now shared
- Added includes to 6 test files (gradual migration)

Iteration 3: Fix banned system() calls
- Replaced std::system() in SetupWizard with fork()/execvp() (POSIX)
- Platform-guarded: Linux uses fork/exec, others print manual command
- Removed system() from cli_main.cpp rules download command

Iteration 4: Fix detached std::thread
- ServerDashboard streaming now uses std::jthread (RAII auto-join)
- Stored as member streamThread_ — properly cleaned up on destruction
- Replaced std::thread(...).detach() anti-pattern

Total: 729 tests, all passing
- Remove unused CorrelationCriteria.h include from IHuntEngine.h
  (CorrelationCriteria exists but is not used in any interface method)
- Final audit: zero layer violations, zero system() calls, zero
  infra::FlowKey references in app/ layer
- 729 tests, all passing
…s of test code

Pass 1: Remove backward compatibility
- Delete infra/flow/FlowKey.h forwarding alias entirely
- Update all infra/ headers to include core/model/FlowKey.h directly
- Add 'using core::FlowKey' in infra namespaces that use it unqualified
- Zero backward compat code remaining

Pass 2: DRY — remove 152 lines of duplicated test helpers
- 7 test files had identical makeFlow() (8-14 lines each)
- 6 test files had identical makeResult() (6-8 lines each)
- All now use shared nids::testing::makeFlow/makeResult from TestFixtures.h
- Fixed test_JsonFileSink expectations to match shared helper values

Total: 729 tests, all passing
- Delete CorrelationCriteria.h (declared but never used in any
  interface method, production code, or test)
- Add toBytes() to TestFixtures.h (was duplicated in 3 test files)
- Final audit: zero layer violations, zero banned patterns,
  zero backward compat, zero dead aliases

729 tests, all passing
…d docs

- Remove 'backward compatibility' comment from FlowStats.h
- Remove 'backward compatibility' reference from NidsServer.h
- Fix 'workaround' comments to 'configuration' (AsanOptions.h refs)
- Update docs/roadmap.md: all phases 6-18 marked DONE
- Zero TODO/FIXME/HACK/deprecated in production code
- 729 tests, all passing
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant