MO

modular-code

Provides best practices and rules for splitting large files into maintainable, modular components.

Install

mkdir -p .claude/skills/modular-code && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1142" && unzip -o skill.zip -d .claude/skills/modular-code && rm skill.zip

Installs to .claude/skills/modular-code

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Modular Code Organization
25 charsno explicit “when” trigger
Intermediate

Key capabilities

  • Decompose monolithic files into domain modules
  • Apply file size guidelines for maintainability
  • Organize feature-based directory structures
  • Isolate pure functions from side effects

How it works

It provides structural patterns and size thresholds to guide the refactoring of large files into focused, logical modules.

Inputs & outputs

You give it
Large monolithic file or codebase structure
You get back
Refactored modular file structure

When to use modular-code

  • Refactor large files into modules
  • Improve AI code generation context
  • Organize feature-based directory structures
  • Define clean boundaries for implementation

About this skill

Modular Code Organization

Write modular Python code with files sized for maintainability and AI-assisted development.

File Size Guidelines

LinesStatusAction
150-500OptimalSweet spot for AI code editors and human comprehension
500-1000LargeLook for natural split points
1000-2000Too largeRefactor into focused modules
2000+CriticalMust split - causes tooling issues and cognitive overload

When to Split

Split when ANY of these apply:

  • File exceeds 500 lines
  • Multiple unrelated concerns in same file
  • Scroll fatigue finding functions
  • Tests for the file are hard to organize
  • AI tools truncate or miss context

How to Split

Natural Split Points

  1. By domain concept: auth.pyauth/login.py, auth/tokens.py, auth/permissions.py
  2. By abstraction layer: Separate interface from implementation
  3. By data type: Group operations on related data structures
  4. By I/O boundary: Isolate database, API, file operations

Package Structure

feature/
├── __init__.py      # Keep minimal, just exports
├── core.py          # Main logic (under 500 lines)
├── models.py        # Data structures
├── handlers.py      # I/O and side effects
└── utils.py         # Pure helper functions

DO

  • Use meaningful module names (data_storage.py not utils2.py)
  • Keep __init__.py files minimal or empty
  • Group related functions together
  • Isolate pure functions from side effects
  • Use snake_case for module names

DON'T

  • Split files arbitrarily by line count alone
  • Create single-function modules
  • Over-modularize into "package hell"
  • Use dots or special characters in module names
  • Hide dependencies with "magic" imports

Refactoring Large Files

When splitting an existing large file:

  1. Identify clusters: Find groups of related functions
  2. Extract incrementally: Move one cluster at a time
  3. Update imports: Fix all import statements
  4. Run tests: Verify nothing broke after each move
  5. Document: Update any references to old locations

Current Codebase Candidates

Files over 2000 lines that need attention:

  • Math compute modules (scipy, mpmath, numpy) - domain-specific, may be acceptable
  • patterns.py - consider splitting by pattern type
  • memory_backfill.py - consider splitting by operation type

Sources

When not to use it

  • Over-modularizing small scripts
  • Creating single-function modules

Prerequisites

Python codebase

Limitations

  • Requires manual refactoring effort
  • Does not automate code movement

How it compares

It focuses on AI-assisted maintainability by enforcing file size limits that prevent context truncation in AI tools.

Compared to similar skills

modular-code side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
modular-code (this skill)47moNo flagsIntermediate
python-design-patterns192moNo flagsIntermediate
tldr-code17moReviewAdvanced
tapps-refactor01moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry