Back to list
tennashi

design-structure

by tennashi

0🍴 0📅 Jan 13, 2026

SKILL.md


name: design-structure description: Design directory structure from layer structure. Derives structure through iterative separation decisions. Use before code generation.

Directory Structure Designer

Overview

Designs directory structure by iteratively deciding how to separate code. Each separation decision involves two choices:

  • Axis: Layer or Feature (direction of separation)
  • Stage: How far to separate (granularity)

Definitions

Layer

Horizontal axis. Partitions by technical responsibility with defined dependency direction.

Types:

  • Feature-bound: Has Code Units per Feature. Example: Entity, InterfaceAdapter
  • Cross-feature: Independent of Features. Example: Framework, Config, Middleware

Feature

Vertical axis. Partitions by domain/business concern. Orthogonal to Layer. Example: Task, Project, User, Order

Component

Technical subdivision within a Layer. No dependency direction between Components (parallel). Example: Handler, Repository, Gateway (all within InterfaceAdapter Layer)

Code Unit

Intersection of Layer (or Component) × Feature. The actual code to be organized. Example: TaskEntity, TaskHandler, TaskRepository

Feature-bound Layers:
                          |  Task  | Project | Comment |
--------------------------|--------|---------|---------|
Entity                    |   ●    |    ●    |    ●    |
InterfaceAdapter/Handler  |   ●    |    ●    |    ●    |
InterfaceAdapter/Repository|  ●    |    ●    |    ●    |

Cross-feature Layers:
                          |   DB   |  HTTP   |  Logger |
--------------------------|--------|---------|---------|
Framework                 |   ●    |    ●    |    ●    |

Note:

  • Handler and Repository are Components within InterfaceAdapter Layer
  • Cross-feature Layers have their own subdivision (not Features)

Axis

Direction of separation: by-layer or by-feature.

  • By Layer: Group by technical responsibility (entity.{ext}, handler.{ext}, ...)
  • By Feature: Group by domain concept (user.{ext}, project.{ext}, ...)

Stage

Granularity of separation:

StageDescriptionExample
inlineNo separationall in main.{ext}
functionsSplit into functionsnewUser(), saveUser()
filesSplit into filesuser.{ext}, handler.{ext}
packagesSplit into directoriesuser/, handler/
servicesSplit into servicesuser-service/

Reference:

Workflow

  1. Read Layer Structure

    • Parse CLAUDE.md for ## Layer Structure section
    • Count Layers, Components (horizontal) and Features (vertical)
    • Identify the (Layer/Component) × Feature matrix
  2. Analyze Git History (for existing codebases)

    • Read Git log for scale metrics (total lines, commits/month, contributors)
    • Use metrics to inform Stage selection
  3. Derive Separation Decisions

    • For each separation point, decide Axis and Stage
    • Based on Code Unit count, Git metrics, and estimated complexity
    • Do NOT consider current directory structure (derive from requirements only)
    • Do NOT pre-consider language-specific constraints (e.g., circular dependencies)
      • If implementation fails due to constraints, adjust then
  4. Write to CLAUDE.md

    • Write designed directory structure to project's CLAUDE.md
    • If differs from current structure, note as proposed change

Separation Flow

Each separation decision = Axis (direction) × Stage (granularity)

The (Layer/Component) × Feature matrix is sliced along one axis, then optionally subdivided along the other.

Note: When counting for Axis selection, Components count as separate rows (like Layers).

Step 0: Single File

Everything starts in one file (Stage: inline).

main.{ext}   // all Code Units in one file

Step 1: Initial Separation

Choose Axis based on matrix shape:

ConditionAxis
Feature count > (Layer + Component) countFeature (slice columns)
Feature count ≤ (Layer + Component) countLayer (slice rows)

Choose Stage based on Code Unit count (see Decision Criteria for details):

Code UnitsStage
≤ 30files (default)
31+packages

Example: Feature axis + files stage (slice by columns)

task.{ext}        // Entity×Task, Handler×Task, Repository×Task
project.{ext}     // Entity×Project, Handler×Project, Repository×Project
comment.{ext}     // ...

Example: Layer axis + files stage (slice by rows)

entity.{ext}      // Entity×Task, Entity×Project, Entity×Comment, ...
handler.{ext}     // Handler×Task, Handler×Project, ...
repository.{ext}  // Repository×Task, Repository×Project, ...

Example: Layer axis + packages stage

entity/
interface_adapter/
  handler/
  repository/

(Internal structure decided in Step 2)

Step 2: Internal Separation

After initial separation, each unit may need further separation using the other Axis.

CRITICAL: Step 2 Stage must be LOWER than Step 1 Stage.

Step 1 StageStep 2 Options
servicespackages, files, functions, inline
packagesfiles, functions, inline
filesfunctions, inline
functionsinline
inline(none)

Example of INVALID derivation:

  • Step 1: files stage
  • Step 2: files stage ← WRONG (must be functions or inline)
  • Result: packages ← WRONG (contradicts Step 1)

See references/stages/ for examples of each stage.

Step 3: Extract Cross-feature Layers

Cross-feature Layers are separated independently from Feature-bound Layers.

Layer classification:

Feature-bound:              Cross-feature:
- Entity                    - Framework
- InterfaceAdapter
  • Feature-bound Layers share Features → can group by Feature
  • Cross-feature Layers have their own subdivision → extracted independently

Result:

task/                      // Feature-bound, grouped by Feature
  entity.{ext}
  handler.{ext}
  repository.{ext}
project/
  ...
framework/                 // Cross-feature, separated independently
  db.{ext}
  http.{ext}

Grouping Rules

Grouping is the inverse of separation.

Can group?

ConditionCan Group?
Feature-bound Layers/ComponentsYes (by Feature)
Cross-feature LayersNo (separate independently)

Should group?

ConditionAction
Feature changes > Layer changesGroup by Feature
Team ownership by FeatureGroup by Feature
Feature count growingGroup by Feature
Need to see Layer across FeaturesGroup by Layer

Decision Criteria

Axis Selection

ConditionAxis
Feature count > (Layer + Component) countFeature first (slice columns)
Feature count ≤ (Layer + Component) countLayer first (slice rows)
Team owns featuresFeature
Team owns layersLayer

Stage Selection

By Code Unit count:

Code UnitsStage
1-3inline or functions
4-10files
11-30files (consider packages if complex)
31+packages

By estimated lines per Code Unit:

Lines/UnitStage
< 50files (combine in single file per axis)
50-150files (separate files)
150+packages

Principle: Start minimal, grow as needed.

  • Default to files stage
  • Only use packages when files become unwieldy

Git-based Scale Analysis

For existing codebases (skip for new projects):

MetricThresholdImplication
Total lines< 1000files stage sufficient
Total lines1000-5000files or packages
Total lines5000+packages likely needed
Commits/month< 10Low churn, files sufficient
Commits/month10+Higher churn, consider packages
Contributors1-2files sufficient
Contributors3+packages for parallel work

When to Separate Further

SignalAction
File > ~300 linesConsider next stage
Multiple Code Units in one fileSeparate by other axis
Cross-feature Layer existsExtract independently
Layer has multiple ComponentsSeparate Components within Layer

Output Format

Output must be faithful to the analysis results.

  • If Step 1 selected files stage, output must be files (not packages)
  • Do NOT contradict the derived Stage in the final structure

Write to project's CLAUDE.md:

## Directory Structure

{directory or file tree based on separation decisions}

Score

Total Score

45/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

0/5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon