decomposition

A set of rules for deciding when a source-code file is too large or mixes unrelated responsibilities, and how to split it into a package safely.

In plain words
What is it for?
Use it to set file-size limits, identify natural split points, and plan small changes that preserve the names other code already uses.
Why use it?
It prevents files from becoming difficult to navigate and helps avoid breaking existing imports when code is reorganised.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/yerdaulet-damir/vibe-coding-rules/decomposition
Clone the repo
git clone --depth 1 https://github.com/yerdaulet-damir/vibe-coding-rules

Made for: Cursor.

Per session 1,408 This file is loaded in full into every session.
When invoked 1,408 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01408 $0.01408
Opus 5 $0.00704 $0.00704
Sonnet 5 $0.00282 $0.00282
Haiku 4.5 $0.00141 $0.00141

Measured 2d ago against content hash 5fa0f6aa26ba, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

decomposition scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/decomposition.mdc · 184 lines

How it starts

The opening of the file, as written. The whole thing — 184 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Decomposition Rules

Files grow. Without a rule, they grow until grep is the only navigation tool. These rules tell you exactly when to split, and how to split safely.

File Size Limits

LOC range State Action required
0–400 Green None.
400–600 Yellow Plan a split. Add # TODO(decompose): A1 — split by ... header.
600+ Red Block the merge. Decompose first.

CI runs python scripts/check_loc.py app/ and fails on any file > 600 LOC.

When to Convert a File into a Package

Convert <file>.py into <file>/ when any is true:

  • Crosses 400 LOC and the next change would push it past 500.
  • Contains 2+ disjoint sub-domains (image vs video, user vs admin).
  • Mixes HTTP handlers with worker handlers.
  • Mixes Pydantic schemas + auth deps + route handlers.
  • Has 2+ callers each importing only one symbol — the split lines are obvious.

How to Split Safely (Atomic PR Pattern)

  1. Create the package. <file>/__init__.py is empty for now.

  2. Move disjoint pieces to sub-files (a.py, b.py, c.py).

  3. Re-export old public names from __init__.py:

    # services/wallet/__init__.py
    from .user import WalletUserService
    from .admin import WalletAdminService
    
    # backwards-compat alias for old imports
    WalletService = WalletUserService
    
    __all__ = ["WalletUserService", "WalletAdminService", "WalletService"]
    
  4. Run tests — they must pass without changes.

  5. Open a follow-up PR to migrate callers off the legacy alias. Once it lands, delete the alias.

Static Data Separation

Static data goes in app/data/ (project-wide) or <domain>/registry.py (domain-local). Never inline:

# ❌ BAD — pricing constants tangled into service file
class AIService:
    PRICING = {
        "gpt-4o":     Decimal("0.005"),
        "claude-3-5": Decimal("0.003"),
        # ... 80 more lines ...
    }
    async def generate(self, ...): ...

Read the full file on GitHub · 184 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 184 lines · 1,408 tokens per session scan A 5fa0f6aa26ba

Subscribe to this mod's changes

decomposition is a cursor rule published in the GitHub repository yerdaulet-damir/vibe-coding-rules (10 stars, last pushed 3mo ago), licensed MIT. It adds 1,408 tokens to every session, about $0.0070 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.