agentleFS
exchanetexchanet/method_enterprise_builder_planning/.cursor/rules/ENTERPRISE_ARCHITECTURE.md

method_enterprise_builder_planning / rules

Cursor rule2 starsChanged 9 months agoMITView on GitHub

Reference guide for architectural patterns, decision trees, and Architecture Decision Records (ADR) in enterprise systems. Use this tree to select the correct architectural pattern: When to use: Single deployment unit with clear module boundaries. Easier to operate, test, and refactor than microservices. Preferred starting architecture. Non-negotiable rules: - Modules communicate only through public interfaces, never through internal types - No circular dependencies between modules - Database schema per module (logical separation minimum, physical preferred) - Each module independently testable in…

The file

We split this ENTERPRISE_ARCHITECTURE.md into the rules it gives an agent

8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this tree to select the correct architectural pattern:

    line 9
  2. Distinctive:

    No circular dependencies between modules

    line 59
  3. Distinctive:

    All external dependencies injected through ports

    line 106
  4. Distinctive:

    When to use: Read and write models are significantly different in complexity or performance requirements.

    line 113
  5. Distinctive:

    Read models are rebuilt from events if corrupted

    line 128
  6. Distinctive:

    Use when: ≤3 services involved, low coupling required

    line 160
  7. Distinctive:

    Use when: ≥4 services, complex compensation logic, compliance audit required

    line 165
  8. Distinctive:

    Use C4 model for all architecture documentation:

    line 198

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
ENTERPRISE_ARCHITECTURE.md

ENTERPRISE_ARCHITECTURE

Reference guide for architectural patterns, decision trees, and Architecture Decision Records (ADR) in enterprise systems.


Architectural Pattern Decision Tree

Use this tree to select the correct architectural pattern:

Is the system a single product by one team?
├── YES → Is domain complexity high (many business rules)?
│         ├── YES → Modular Monolith (start here, extract later)
│         └── NO  → Simple Layered Architecture
└── NO  → Are teams fully autonomous per bounded context?
          ├── YES → Microservices
          └── NO  → Modular Monolith with service interfaces
Does the system require event replay or audit of all state changes?
├── YES → Event Sourcing + CQRS
└── NO  → Are reads and writes radically different in load?
          ├── YES → CQRS (without full Event Sourcing)
          └── NO  → Standard repository pattern
Are there long-running, distributed transactions across services?
├── YES → Saga Pattern (Choreography or Orchestration)
└── NO  → Local ACID transactions

Pattern Specifications

Modular Monolith (recommended for most enterprise systems)

When to use: Single deployment unit with clear module boundaries. Easier to operate, test, and refactor than microservices. Preferred starting architecture.

Structure:

src/
├── core/           ← Shared infrastructure (no business logic)
├── modules/
│   ├── billing/    ← Complete billing domain
│   │   ├── domain/
│   │   ├── application/
│   │   ├── infrastructure/
│   │   └── interface/
│   └── users/      ← Complete users domain
└── shared/         ← Cross-cutting concerns

Non-negotiable rules:

  • Modules communicate only through public interfaces, never through internal types
  • No circular dependencies between modules
  • Database schema per module (logical separation minimum, physical preferred)
  • Each module independently testable in isolation

ADR required: Yes — document why Modular Monolith was chosen over Microservices.


Microservices

When to use: Teams are independent, deployment cadences differ significantly, services have radically different scaling needs.

Non-negotiable rules:

  • Each service owns its own database (no shared DB)
  • Service communication via async events (preferred) or sync REST/gRPC with Circuit Breaker
  • Each service independently deployable and rollback-able
  • Service contracts (OpenAPI / AsyncAPI) versioned and backward compatible

Required patterns:

  • Circuit Breaker (Resilience4j / Polly / opossum)
  • Bulkhead (isolate thread pools per downstream service)
  • Retry with exponential backoff + jitter
  • Dead Letter Queue for failed async messages
  • Distributed tracing (OpenTelemetry)

ADR required: Yes — document service boundaries and why each service is separate.


Hexagonal Architecture (Ports & Adapters)

When to use: Business logic must be testable without external infrastructure. Long-term maintainability is a priority.

Structure:

domain/           ← Pure business logic, zero dependencies
application/      ← Use cases, orchestration
ports/
├── inbound/      ← Interfaces that trigger use cases (e.g., HTTP, CLI, Queue)
└── outbound/     ← Interfaces the app calls externally (DB, email, API)
adapters/
├── inbound/      ← HTTP controllers, CLI handlers, message consumers
└── outbound/     ← DB repositories, email clients, external API clients

Non-negotiable rules:

  • Domain layer has ZERO imports from infrastructure
  • All external dependencies injected through ports
  • Business logic unit-testable without any infrastructure

CQRS (Command Query Responsibility Segregation)

When to use: Read and write models are significantly different in complexity or performance requirements.

Pattern:

Command side:                    Query side:
├── Command handlers             ├── Query handlers
├── Domain aggregates            ├── Read models (denormalized)
├── Write DB (normalized)        └── Read DB (optimized projections)
└── Event publisher ──────────────────────→ Event handler
                                              └── Projects to read DB

Non-negotiable rules:

  • Commands validate all inputs before executing
  • Commands are idempotent (same command twice = same result)
  • Read models are rebuilt from events if corrupted
  • Eventual consistency between write and read sides is explicitly documented

Event Sourcing

When to use: Full audit trail of all state changes is required (financial, compliance, regulated systems).

Core concepts:

  • State is derived from a sequence of immutable events
  • Current state = replay of all events from beginning
  • Snapshots optimize replay performance (every N events)
  • Events are immutable — never deleted or modified

Event store requirements:

  • Append-only writes
  • Optimistic concurrency control (version numbers)
  • Efficient range queries by aggregate ID and version
  • Snapshot support for long-lived aggregates

ADR required: Yes — Event Sourcing significantly increases complexity. Document the justification.


Saga Pattern

When to use: Distributed transactions span multiple services or databases.

Choreography Saga

  • Services emit events and react to other services' events
  • Simpler to implement, harder to debug
  • Use when: ≤3 services involved, low coupling required

Orchestration Saga

  • Central saga orchestrator coordinates all steps
  • Easier to debug and monitor
  • Use when: ≥4 services, complex compensation logic, compliance audit required

Compensation template:

Step 1: Reserve inventory     → Compensation: Release inventory
Step 2: Charge payment        → Compensation: Refund payment
Step 3: Create shipment       → Compensation: Cancel shipment
Step 4: Send confirmation     → Compensation: Send cancellation

Circuit Breaker Pattern

States:

CLOSED ──[N failures in window]──→ OPEN ──[timeout]──→ HALF-OPEN
  ↑                                                         │
  └─────────────[success]───────────────────────────────────┘

Configuration defaults for enterprise:

failureThreshold: 5 failures in 60 seconds
openDuration: 30 seconds
halfOpenMaxCalls: 3
successThreshold: 2 consecutive successes

C4 Model — Diagram Levels

Use C4 model for all architecture documentation:

LevelAudienceShows
L1: System ContextNon-technical stakeholdersSystem + external actors
L2: ContainerTechnical stakeholdersApplications, databases, services
L3: ComponentDevelopersMajor components within a container
L4: CodeImplementersClasses, functions (generated from code)

Minimum required: L1 and L2 for every system. L3 for critical services.


ADR Archive Template

Maintain ADRs in docs/adr/ directory:

docs/
└── adr/
    ├── ADR-001-modular-monolith.md
    ├── ADR-002-postgresql-as-primary-db.md
    ├── ADR-003-event-sourcing-for-audit.md
    └── ADR-NNN-[decision-slug].md

Numbering: Sequential integers, never reused. Deprecated ADRs are marked Status: Superseded by ADR-NNN, not deleted.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.