agentleFS
DrakaniiaDrakaniia/skills/skills/folder-architecture/SKILL.md

folder-architecture

Skill7 starsChanged 5 months agoMITView on GitHub

Define and enforce best-practice folder architecture whenever creating or modifying files. Use whenever the AI adds or edits code to prevent structural clutter, directory bloat, misplaced files, naming inconsistencies, and deep nesting.

The file

Show its rules and text

We split this skill into the rules it gives an agent

18 rules. About 0 are common, 13 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈13

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill to act as a Structure Guardian — proactively enforcing clean folder organization and best-practice file placement before …

    line 22
  2. Distinctive:

    Language-agnostic: Every check applies to any language.

    line 26
  3. Distinctive:

    Prevention over cleanup: Check structure BEFORE creating or modifying files — not after.

    line 27
  4. Distinctive:

    Follow existing conventions: When the project already has a pattern (even if imperfect), match it for new files.

    line 28
  5. Very specific:

    Respect framework defaults: Don't fight established conventions (Rails MVC, Django apps, Next.js App Router, Go's internal/).

    line 29
  6. Distinctive:

    Feature-first by default: Prefer grouping by domain/feature over technical layering.

    line 30
  7. Distinctive:

    Before the AI creates or modifies any file, run through this step-by-step checklist in order:

    line 62
  8. Distinctive:

    Naming convention: Check nearby files for kebab-case, snake_case, camelCase, PascalCase

    line 68
  9. Very specific:

    If detection is ambiguous — mixed signals, blank project, or borderline size (40-60 files, 400-600 files, or unclear business domains) — …

    line 77
  10. Distinctive:

    Before placing a new file in a directory:

    line 94
  11. Distinctive:

    When modifying an existing file:

    line 127
  12. Distinctive:

    When deciding how to organize a project's folders, choose the appropriate pattern:

    line 135
  13. Very specific:

    Check root-level packages/ or apps/ directories for bloat (each should contain ≤30 subdirectories)

    line 197
  14. Distinctive:

    Prefer duplication over wrong abstraction: If only 1-2 features use the code, keep it local.

    line 208
  15. Distinctive:

    If no barrel file exists and only 1-2 files are in the directory, do not create one.

    line 221
  16. Very specific:

    When to use audit-codebase: If during development you notice pervasive structural issues (multiple oversized files, many bloated …

    line 255
  17. Very specific:

    When to use code-design: After placing a file with this skill, use code-design to ensure every function inside that file follows clean …

    line 268
  18. Distinctive:

    Before creating or modifying any file, verify every applicable item:

    line 272

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill 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
SKILL.md

Folder Architecture

Use this skill to act as a Structure Guardian — proactively enforcing clean folder organization and best-practice file placement before every file creation or modification. This skill prevents structural decay at the point of change.

Core Principles

  • Language-agnostic: Every check applies to any language. Language-specific details are in references/ORGANIZATION-PATTERNS.md.
  • Prevention over cleanup: Check structure BEFORE creating or modifying files — not after.
  • Follow existing conventions: When the project already has a pattern (even if imperfect), match it for new files. Only proactively restructure when clear rules are violated.
  • Respect framework defaults: Don't fight established conventions (Rails MVC, Django apps, Next.js App Router, Go's internal/).
  • Feature-first by default: Prefer grouping by domain/feature over technical layering. Let the AI choose the best architecture pattern based on project size and complexity.
  • Self-contained: See references/ORGANIZATION-PATTERNS.md for language-specific patterns and references/SPLITTING-GUIDE.md for file-splitting mechanics.

When This Skill Activates

This skill activates every time the AI adds or edits code:

  • Creating a new file
  • Modifying an existing file
  • Creating a new directory
  • Adding new imports/exports
  • Restructuring existing code (moving files, renaming)

Thresholds (Hard Defaults)

#CheckThresholdSeverityAction
1Directory file count>30 files per directory🔴 BlockerCreate subdirectory before placing file
2File line count (growth)File will cross >400 lines after edits🔴 BlockerWarn and suggest splitting
3Nesting depth>4 levels deep🔴 BlockerHARD BLOCK: Do not create deeper than 4 levels. Place the file at a shallower level or flatten the target tree first.
4Root-level source codeAny source file in project root🔴 BlockerPlace in appropriate subdirectory
5Config-in-sourceConfig files mixed with source code🟡 WarningMove to config/
6Naming consistencyNew file doesn't match existing convention🟡 WarningRename to match project pattern
7Misplaced fileFile type doesn't match parent directory🟡 WarningMove to appropriate directory
8Dumping groundAdding to utils/, helpers/, shared/🟡 WarningCheck if feature-local placement is better
9Barrel file staleNew file added without updating barrel🟡 WarningAuto-update barrel (index.ts, init.py, etc.)
10Circular import riskNew import may create a cycle🟢 SuggestionCheck import chain

Adjusting thresholds: For small projects (<50 files), use stricter limits (≤15 files/dir, ≤200 lines/file). For large projects (>500 files), relax to ≤50 files/dir, ≤600 lines/file.

Workflow: Before Every File Operation

Before the AI creates or modifies any file, run through this step-by-step checklist in order:

Step 1: Detect Project Convention

Scan the project to detect:

  • Naming convention: Check nearby files for kebab-case, snake_case, camelCase, PascalCase
  • Architecture pattern: Is it feature-first, layered, or mixed?
  • Framework defaults: Does the framework prescribe a structure (Rails, Django, Next.js)?
  • Existing barrel files: Are there index.ts, __init__.py, mod.rs files?

Implementation tip: Read 3-5 existing files from the target directory to detect patterns. If the directory is empty, check sibling directories.

Step 1a: Confirm Architecture Pattern (ask_user checkpoint)

If detection is ambiguous — mixed signals, blank project, or borderline size (40-60 files, 400-600 files, or unclear business domains) — MUST use ask_user tool before placing files:

ask_user(
  question: "Architecture pattern is ambiguous. Which should I enforce?",
  options:
    a) Feature-Based (Recommended for 50-500 files / clear domains) — e.g., src/users/, src/billing/
    b) Layered (Recommended for <50 files / simple CRUD) — e.g., src/controllers/, src/services/
    c) Hybrid (Layered-by-Feature, for >500 files / scaling) — e.g., src/features/users/application/
    d) Keep existing mixed pattern — don't restructure, just match current placement
)

When to skip ask_user: Pattern is clear (e.g., src/features/ exists → feature-first; src/controllers/ + src/services/ with <30 files → layered; framework mandates structure like Next.js App Router). When to require ask_user: Transition zone per shared/references/ORGANIZATION-PATTERNS.md Glossary & Decision Tree and Core Concepts above — never silently auto-migrate between Layered ↔ Feature-Based without user confirmation.

Step 2: Check Target Directory Health

Before placing a new file in a directory:

  • File count check: Count files in the target directory. If >30 files, create a subdirectory before adding the file.
  • Nesting depth check: Is the directory >4 levels from the project root? If so, do not create deeper. Suggest flattening or placing the file where nesting is shallower.
  • Dumping ground check: Is the directory named utils/, helpers/, shared/, common/, misc/? If so, verify the new file truly belongs there (must be used by 3+ features). Otherwise, suggest a feature-local location.
  • Directory theme check: Does the directory name match the file type? (e.g., don't put a .py file in images/, don't put a config file in components/)

Step 3: Check File Placement

  • Root check: If the file would go in the project root, move it to src/, lib/, or an appropriate subdirectory. Root is only for: README.md, LICENSE, CI config, dependency manifests (package.json, Cargo.toml, etc.), and build config.
  • Config check: If the file is a config file (.yml, .json, .toml, .ini), does it belong in a config/ directory? Flag if mixed with source code.
  • Test mirroring: For test files, ensure the test path mirrors the source path. E.g., src/features/users/user.service.ts → tests/features/users/user.service.test.ts.
  • Feature proximity: Check if there's an existing feature folder related to the new file. Prefer placing the file within that feature's directory tree.

Step 4: Check Naming

  • Detect convention: What naming style do nearby files use? (kebab-case, snake_case, camelCase, PascalCase)
  • Match convention: Name the new file using the detected convention
  • Component naming: If the file exports a React/Vue/Svelte component, use PascalCase for the filename (e.g., UserProfile.tsx)
  • Test naming: Match the source file naming convention (e.g., user.service.ts → user.service.test.ts or test_user_service.py)

Step 5: Check Import Hygiene

  • Import ordering: Organize imports in this order with blank-line separators:
    1. Standard library / built-in modules
    2. Third-party packages / frameworks
    3. Local / project imports
    4. Relative imports (if used, prefer absolute)
  • Barrel file update: If the directory has a barrel file (index.ts, __init__.py, mod.rs), add a re-export line for the new file.
  • Circular dependency check: If adding a new import, verify it does not create a direct A→B→A cycle. Trace the immediate import chain of the imported module.

Step 6: Check for Oversized Files (Modifications)

When modifying an existing file:

  • Current size check: Read the file's current line count. If it's already >350 lines and the edit will push it near or over 400, warn and suggest splitting.
  • Growth tracking: If the file has grown by 100+ lines since the last change, consider whether the new code belongs in a separate file.
  • Split recommendation: If splitting is needed, use the audit-codebase skill to generate a detailed split plan, or follow the language-specific mechanics in references/SPLITTING-GUIDE.md.

Architecture Pattern Reference

When deciding how to organize a project's folders, choose the appropriate pattern:

1. Feature-First (Domain-Driven) — Best for medium-to-large projects

src/
  ├── users/           (everything related to users)
  │   ├── handlers/
  │   ├── models/
  │   ├── tests/
  │   └── index.ts
  ├── billing/         (everything related to billing)
  │   ├── handlers/
  │   ├── models/
  │   ├── tests/
  │   └── index.ts
  └── shared/          (truly cross-cutting, 3+ consumers)
      └── middleware/

2. Technical Layered — Good for small/simple projects

src/
  ├── controllers/
  ├── services/
  ├── repositories/
  ├── models/
  └── middleware/

3. Hybrid (Layered-by-Feature) — Best for scaling projects

src/
  └── features/
      ├── users/
      │   ├── application/      (DTOs, handlers)
      │   ├── domain/           (business entities)
      │   ├── infrastructure/   (database, external APIs)
      │   └── presentation/     (UI components, controllers)
      └── billing/

4. Ports & Adapters (Hexagonal) — For complex business domains

src/
  ├── domain/          (pure business logic, no frameworks)
  ├── application/     (use cases / application services)
  ├── ports/           (interfaces/contracts)
  └── adapters/        (implementations: database, web, API)

Decision guide: For small projects (<50 files), prefer technical layered. For medium projects (50-500 files), prefer feature-first. For large/complex projects (>500 files), prefer hybrid or hexagonal.

Monorepo Handling

For monorepos with multiple packages/modules:

  • Apply checks per-package, not globally
  • Each package is treated as its own project with its own thresholds
  • Check root-level packages/ or apps/ directories for bloat (each should contain ≤30 subdirectories)
  • Shared packages (e.g., @shared/ui, common/) should follow stricter rules: max 15 files per directory
  • Each package should have a consistent architecture pattern (don't mix feature-first and layered across packages)

Shared / Cross-Cutting Code Policy

The shared/, common/, or lib/ directory is permitted but strictly limited:

  • Entry requirement: A function/module must be used by 3+ features before it qualifies for shared/placement
  • Size limit: Shared/ directory must not exceed 30 files total. If exceeded, split into shared/ui/, shared/utils/, shared/types/, etc.
  • No business logic: Shared/ is for technical cross-cutting concerns only (formatting, types, HTTP clients, logging). Business logic must remain in feature folders.
  • Prefer duplication over wrong abstraction: If only 1-2 features use the code, keep it local. Extract to shared/ only when the 3rd consumer appears.

Barrel File Policy

Whenever adding a new file that exports symbols, check if the enclosing directory has a barrel file:

LanguageBarrel fileUpdate action
Python__init__.pyAdd from .new_module import ExportedSymbol
JS/TSindex.ts or index.jsAdd export { X } from './new-module'
Rustmod.rsAdd pub mod new_module; and re-export
GoN/A (package-level visibility)No barrel needed — same package is auto-visible

If no barrel file exists and only 1-2 files are in the directory, do not create one. Barrel files are only needed when a directory has 3+ public modules.

Language-Specific Patterns

For language-specific folder conventions, naming styles, and module mechanics, see:

  • ORGANIZATION-PATTERNS.md — How to organize code per language (Python, JS/TS, Go, Rust, Java, C#, Ruby, PHP)
  • SPLITTING-GUIDE.md — How to split oversized files per language (import changes, module boundaries, before/after examples)

Edge Cases

SituationHandling
Empty projectCreate a standard structure: src/ or lib/ based on language
No clear conventionDefault to kebab-case for JS/TS, snake_case for Python/Rust/Go, PascalCase for components/classes
Generated codeSkip checks for files in generated/, dist/, build/ — they follow their own rules
Third-party/vendorSkip checks for node_modules/, vendor/, .venv/
Hidden filesSkip .-prefixed files except config files
SymlinksFollow symlinks but avoid creating new ones
Test-only projectIf the project is exclusively tests, use the test framework's convention (__tests__/, spec/)
User explicitly requests locationIf the user says "put it in [path]", follow their instruction but flag any structural issues

Interaction with audit-codebase Skill

This skill (folder-architecture) and audit-codebase are complementary:

Aspectfolder-architecture (this)audit-codebase
WhenBefore/during file operationsAfter-the-fact review
PurposePrevent clutter proactivelyDetect existing issues
ScopeSingle file/directory at a timeFull codebase scan
ActionPlace correctly, warn, split if neededGenerate report with fix plan
Split depthBasic split warning + contextFull split plan with diagrams

When to use audit-codebase: If during development you notice pervasive structural issues (multiple oversized files, many bloated directories, inconsistent patterns), switch to audit-codebase for a comprehensive review.

code-design

This skill (folder-architecture) handles where files go. The code-design skill handles how code is written inside those files — it's the function-level counterpart:

Aspectfolder-architecture (this)code-design
ScopeFile/directory placementFunction-level code design
ChecksDir count, nesting depth, naming, etc.Pure functions, SRP, guard clauses
WhenBefore creating/modifying filesBefore/during writing functions
ActionPlace correctly or warnRefactor impure/nested/mixed code

When to use code-design: After placing a file with this skill, use code-design to ensure every function inside that file follows clean design principles — guard clauses, single responsibility, side-effect management, and top-to-bottom readability.

Execution Checklist

Before creating or modifying any file, verify every applicable item:

Pre-File Creation

  • Step 1: Detected project convention (naming, architecture pattern)
  • Step 2: Target directory is healthy (<30 files, ≤4 levels deep)
  • Step 2: Not adding to a dumping ground (utils/shared verified)
  • Step 3: File is not in project root
  • Step 3: Config files go in config/ directory
  • Step 3: Tests mirror source structure
  • Step 4: File naming matches project convention
  • Step 5: Imports are correctly ordered
  • Step 5: Barrel file is updated (if exists)
  • Step 5: No circular import created

Pre-File Modification

  • Step 6: Existing file is not near the 400-line threshold
  • Steps 1-5: All applicable creation checks re-verified if adding new exports

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.