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.zipInstalls 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 OrganizationKey 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
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
| Lines | Status | Action |
|---|---|---|
| 150-500 | Optimal | Sweet spot for AI code editors and human comprehension |
| 500-1000 | Large | Look for natural split points |
| 1000-2000 | Too large | Refactor into focused modules |
| 2000+ | Critical | Must 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
- By domain concept:
auth.py→auth/login.py,auth/tokens.py,auth/permissions.py - By abstraction layer: Separate interface from implementation
- By data type: Group operations on related data structures
- 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.pynotutils2.py) - Keep
__init__.pyfiles 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:
- Identify clusters: Find groups of related functions
- Extract incrementally: Move one cluster at a time
- Update imports: Fix all import statements
- Run tests: Verify nothing broke after each move
- 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
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.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| modular-code (this skill) | 4 | 7mo | No flags | Intermediate |
| python-design-patterns | 19 | 2mo | No flags | Intermediate |
| tldr-code | 1 | 7mo | Review | Advanced |
| tapps-refactor | 0 | 1mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by parcadei
View all by parcadei →You might also like
python-design-patterns
wshobson
Python design patterns including KISS, Separation of Concerns, Single Responsibility, and composition over inheritance. Use when making architecture decisions, refactoring code structure, or evaluating when abstractions are appropriate.
tldr-code
parcadei
Token-efficient code analysis via 5-layer stack (AST, Call Graph, CFG, DFG, PDG). 95% token savings.
tapps-refactor
wtthornton
>-
deepwiki-rs
sopaco
AI-powered Rust documentation generation engine for comprehensive codebase analysis, C4 architecture diagrams, and automated technical documentation. Use when Claude needs to analyze source code, understand software architecture, generate technical specs, or create professional documentation from any programming language.
python-patterns
affaan-m
Pythonic 惯用法、PEP 8 标准、类型提示以及构建健壮、高效、可维护的 Python 应用程序的最佳实践。
ast-grep-find
parcadei
AST-based code search and refactoring via ast-grep MCP