Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:777genius Agent teams ai Architecture Boundary Enforcement

From Leeroopedia
Knowledge Sources
Domains Architecture, Code_Quality, Linting
Last Updated 2026-10-22 00:00 GMT

Overview

Principle of using static analysis rules to enforce architectural boundaries — preventing modules from importing outside their allowed layer, keeping domain cores pure, and ensuring feature slices expose only public entrypoints.

Description

Architecture Boundary Enforcement is the practice of codifying architectural rules as lint-time constraints rather than relying on code review or documentation alone. In an Electron application with three processes (main, preload, renderer) and hexagonal feature slices (domain, application, adapters), boundary violations are easy to introduce accidentally — a renderer component importing a main module, or a domain layer importing Electron APIs.

By using `eslint-plugin-boundaries` and `no-restricted-imports` rules, the architecture becomes self-documenting and self-enforcing:

  • Process boundaries: The renderer cannot import from main, main cannot import from renderer, and preload is isolated to bridge code only. Each process layer can only import from itself and shared.
  • Feature slice public entrypoints: Feature internals (`core/domain`, `core/application`, `main`, `preload`, `renderer`) are hidden behind public barrel exports. External code must import from `@features/*/contracts`, `@features/*/main`, etc.
  • Domain purity: `core/domain` must not import Electron, fastify, child_process, or any process-specific module. `core/application` may depend on ports but not runtime adapters.
  • Safe IPC: Direct `webContents.send()` calls are banned via AST selectors, forcing use of a safe wrapper that checks for destroyed windows.

This approach catches architecture violations at lint time — before they reach code review or production — and provides actionable error messages that guide developers to the correct import path.

Usage

Apply this principle when a project has a multi-layer architecture (microservices, Electron processes, hexagonal slices) where accidental cross-layer imports would violate separation of concerns. Use ESLint's `no-restricted-imports` and `eslint-plugin-boundaries` to encode the rules.

Theoretical Basis

The core mechanism is a directed graph of allowed imports:

Allowed import graph (Electron three-process + features):

  main ──→ main, shared
  preload ──→ preload, shared
  renderer ──→ renderer, shared
  shared ──→ shared, main (type re-exports only)

Feature slice (hexagonal):
  core/domain ──→ (nothing platform-specific)
  core/application ──→ core/domain, contracts, ports
  main ──→ core/application, core/domain, contracts
  renderer ──→ core/application, contracts
  preload ──→ contracts

Violations are detected by matching import specifiers against the allowed set:

# Pseudo-code for boundary check (NOT real implementation)
for each import in file:
    source_layer = classify(file.path)  # main, preload, renderer, shared, feature-core-domain...
    target_layer = classify(import.source)
    if target_layer not in allowed_imports[source_layer]:
        error("Import violates architecture boundary: {source} → {target}")

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment