MCPInstall

component-flattening-analysis

Detects misplaced classes and fixes component hierarchy problems — finds code that should belong inside a component but sits at the root level. Use when asking "clean up component structure", "find orphaned classes", "fix module hierarchy", "flatten nested components", or analyzing why namespaces have misplaced code. Do NOT use for dependency analysis (use coupling-analysis) or domain grouping (use domain-identification-grouping).

Installs
212
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/tech-leads-club/agent-skills --skill component-flattening-analysis
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads component-flattening-analysis automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

Component Flattening Analysis

This skill identifies component hierarchy issues and ensures components exist only as leaf nodes in directory/namespace structures, removing orphaned classes from root namespaces.

How to Use

Quick Start

Request analysis of your codebase:

  • "Find orphaned classes in root namespaces"
  • "Flatten component hierarchies"
  • "Identify components that need flattening"
  • "Analyze component structure for hierarchy issues"

Usage Examples

Example 1: Find Orphaned Classes

User: "Find orphaned classes in root namespaces"

The skill will:
1. Scan component namespaces for hierarchy issues
2. Identify orphaned classes in root namespaces
3. Detect components built on top of other components
4. Suggest flattening strategies
5. Create refactoring plan

Example 2: Flatten Components

User: "Flatten component hierarchies in this codebase"

The skill will:
1. Identify components with hierarchy issues
2. Analyze orphaned classes
3. Suggest consolidation or splitting strategies
4. Create refactoring plan
5. Estimate effort

Example 3: Component Structure Analysis

User: "Analyze component structure for hierarchy issues"

The skill will:
1. Map component namespace structure
2. Identify root namespaces with code
3. Find components built on components
4. Flag hierarchy violations
5. Provide recommendations

Step-by-Step Process

  1. Scan Structure: Map component namespace hierarchies
  2. Identify Issues: Find orphaned classes and component nesting
  3. Analyze Options: Determine flattening strategy (consolidate vs split)
  4. Create Plan: Generate refactoring plan with steps
  5. Execute: Refactor components to remove hierarchy

When to Use

Apply this skill when:

  • After gathering common domain components (Pattern 2)
  • Before determining component dependencies (Pattern 4)
  • When components have nested structures
  • Finding orphaned classes in root namespaces
  • Preparing for domain grouping
  • Cleaning up component structure
  • Ensuring components are leaf nodes only

Core Concepts

Component Definition

A component is identified by a leaf node in directory/namespace structure:

  • Leaf Node: The deepest directory containing source files
  • Component: Source code files in leaf node namespace
  • Subdomain: Parent namespace that has been extended

Key Rule: Components exist only as leaf nodes. If a namespace is extended, the parent becomes a subdomain, not a component.

Root Namespace

A root namespace is a namespace node that has been extended:

  • Extended: Another namespace node added below it
  • Example: ss.survey extended to ss.survey.templates
  • Result: ss.survey becomes a root namespace (subdomain)

Orphaned Classes

Orphaned classes are source files in root namespaces:

  • Location: Root namespace (non-leaf node)
  • Problem: No definable component associated with them
  • Solution: Move to leaf node namespace (component)

Example:

ss.survey/              ← Root namespace (extended by .templates)
├── Survey.js           ← Orphaned class (in root namespace)
└── templates/          ← Component (leaf node)
    └── Template.js

Flattening Strategies

Strategy 1: Consolidate Down

  • Move code from leaf nodes into root namespace
  • Makes root namespace the component
  • Example: Move ss.survey.templates → ss.survey

Strategy 2: Split Up

  • Move code from root namespace into new leaf nodes
  • Creates new components from root namespace
  • Example: Split ss.survey → ss.survey.create + ss.survey.process

Strategy 3: Move Shared Code

  • Move shared code to dedicated component
  • Creates .shared component
  • Example: ss.survey shared code → ss.survey.shared

Analysis Process

Phase 1: Map Component Structure

Scan directory/namespace structure to identify hierarchy:

  1. Map Namespace Tree

    • Build tree of all namespaces
    • Identify parent-child relationships
    • Mark leaf nodes (components)
  2. Identify Root Namespaces

    • Find namespaces that have been extended
    • Mark as root namespaces (subdomains)
    • Note which namespaces extend them
  3. Locate Source Files

    • Find all source files in each namespace
    • Map files to their namespace location
    • Identify files in root namespaces

Example Structure Mapping:

## Component Structure Map

ss.survey/ ← Root namespace (extended) ├── Survey.js ← Orphaned class ├── SurveyProcessor.js ← Orphaned class └── templates/ ← Component (leaf node) ├── EmailTemplate.js └── SMSTemplate.js

ss.ticket/ ← Root namespace (extended) ├── Ticket.js ← Orphaned class ├── assign/ ← Component (leaf node) │ └── TicketAssign.js └── route/ ← Component (leaf node) └── TicketRoute.js

Phase 2: Identify Orphaned Classes

Find source files in root namespaces:

  1. Scan Root Namespaces

    • Check each root namespace for source files
    • Identify files that are orphaned
    • Count orphaned files per root namespace
  2. Classify Orphaned Classes

    • Shared Code: Common utilities, interfaces, abstract classes
    • Domain Code: Business logic that should be in component
    • Mixed: Combination of shared and domain code
  3. Assess Impact

    • How many files are orphaned?
    • What functionality do they contain?
    • What components depend on them?

Example Orphaned Class Detection:

## Orphaned Classes Found

### Root Namespace: ss.survey

**Orphaned Files** (5 files):

- Survey.js (domain code - survey creation)
- SurveyProcessor.js (domain code - survey processing)
- SurveyValidator.js (shared code - validation)
- SurveyFormatter.js (shared code - formatting)
- SurveyConstants.js (shared code - constants)

**Classification**:

- Domain Code: 2 files (should be in components)
- Shared Code: 3 files (should be in .shared component)

**Dependencies**: Used by ss.survey.templates component

Phase 3: Analyze Flattening Options

Determine best flattening strategy for each root namespace:

  1. Option 1: Consolidate Down

    • Move leaf node code into root namespace
    • Makes root namespace the component
    • Use when: Leaf nodes are small, related functionality
  2. Option 2: Split Up

    • Move root namespace code into new leaf nodes
    • Creates multiple components from root
    • Use when: Root namespace has distinct functional areas
  3. Option 3: Move Shared Code

    • Extract shared code to .shared component
    • Keep domain code in root or split
    • Use when: Root namespace has shared utilities

Example Flattening Analysis:

## Flattening Options Analysis

### Root Namespace: ss.survey

**Current State**:

- Root namespace: 5 orphaned files
- Leaf component: ss.survey.templates (7 files)

**Option 1: Consolidate Down** ✅ Recommended

- Move templates code into ss.survey
- Result: Single component ss.survey
- Effort: Low (7 files to move)
- Rationale: Templates are small, related to survey functionality

**Option 2: Split Up**

- Create ss.survey.create (2 files)
- Create ss.survey.process (1 file)
- Create ss.survey.shared (3 files)
- Keep ss.survey.templates (7 files)
- Effort: High (multiple components to create)
- Rationale: More granular, but may be over-engineering

**Option 3: Move Shared Code**

- Create ss.survey.shared (3 shared files)
- Keep domain code in root (2 files)
- Keep ss.survey.templates (7 files)
- Effort: Medium
- Rationale: Separates shared from domain, but still has hierarchy

Phase 4: Create Flattening Plan

Generate refactoring plan for each root namespace:

  1. Select Strategy

    • Choose best flattening option
    • Consider effort, complexity, maintainability
  2. Plan Refactoring Steps

    • List files to move
    • Identify target namespaces
    • Note dependencies to update
  3. Estimate Effort

    • Time to refactor
    • Risk assessment
    • Testing requirements

Example Flattening Plan:

## Flattening Plan

### Priority: High

**Root Namespace: ss.survey**

**Strategy**: Consolidate Down

**Steps**:

1. Move files from ss.survey.templates/ to ss.survey/
   - EmailTemplate.js
   - SMSTemplate.js
   - [5 more files]

2. Update imports in dependent components
   - Update references from ss.survey.templates._ to ss.survey._

3. Remove ss.survey.templates/ directory

4. Update namespace declarations
   - Change namespace from ss.survey.templates to ss.survey

5. Run tests to verify changes

**Effort**: 2-3 days
**Risk**: Low (templates are self-contained)
**Dependencies**: None

Phase 5: Execute Flattening

Perform the refactoring:

  1. Move Files

    • Move source files to target namespace
    • Update file paths and imports
  2. Update References

    • Update imports in dependent components
    • Update namespace declarations
    • Update directory structure
  3. Verify Changes

    • Run tests
    • Check for broken references
    • Validate component structure

Output Format

Orphaned Classes Report

## Orphaned Classes Analysis

### Root Namespace: ss.survey

**Status**: ⚠️ Has Orphaned Classes

**Orphaned Files** (5 files):

- Survey.js (domain code)
- SurveyProcessor.js (domain code)
- SurveyValidator.js (shared code)
- SurveyFormatter.js (shared code)
- SurveyConstants.js (shared code)

**Leaf Components**:

- ss.survey.templates (7 files)

**Issue**: Root namespace contains code but is extended by leaf component

**Recommendation**: Consolidate templates into root namespace

Component Hierarchy Issues

## Component Hierarchy Issues

| Root Namespace | Orphaned Files | Leaf Components                 | Issue                | Recommendation   |
| -------------- | -------------- | ------------------------------- | -------------------- | ---------------- |
| ss.survey      | 5              | 1 (templates)                   | Has orphaned classes | Consolidate down |
| ss.ticket      | 45             | 2 (assign, route)               | Large orphaned code  | Split up         |
| ss.reporting   | 0              | 3 (tickets, experts, financial) | No issue             | ✅ OK            |

Flattening Plan

## Flattening Plan

### Priority: High

**ss.survey** → Consolidate Down

- Move 7 files from templates to root
- Effort: 2-3 days
- Risk: Low

### Priority: Medium

**ss.ticket** → Split Up

- Create ss.ticket.maintenance (30 files)
- Create ss.ticket.completion (10 files)
- Create ss.ticket.shared (5 files)
- Effort: 1 week
- Risk: Medium

Analysis Checklist

Structure Mapping:

  • Mapped all namespace hierarchies
  • Identified root namespaces
  • Located all source files
  • Marked leaf nodes (components)

Orphaned Class Detection:

  • Scanned root namespaces for source files
  • Identified orphaned classes
  • Classified orphaned classes (shared/domain/mixed)
  • Assessed impact and dependencies

Flattening Analysis:

  • Analyzed consolidation option
  • Analyzed splitting option
  • Analyzed shared code extraction option
  • Selected best strategy for each root namespace

Plan Creation:

  • Selected flattening strategy
  • Created refactoring steps
  • Estimated effort and risk
  • Prioritized work

Execution:

  • Moved files to target namespaces
  • Updated imports and references
  • Updated namespace declarations
  • Verified changes with tests

Implementation Notes

For Node.js/Express Applications

Components typically in services/ directory:

services/
├── survey/              ← Root namespace (extended)
│   ├── Survey.js       ← Orphaned class
│   └── templates/      ← Component (leaf node)
│       └── Template.js

Flattening:

  • Consolidate: Move templates/ files to survey/
  • Split: Create survey/create/ and survey/process/
  • Shared: Create survey/shared/ for utilities

For Java Applications

Components identified by package structure:

com.company.survey       ← Root package (extended)
├── Survey.java         ← Orphaned class
└── templates/          ← Component (leaf package)
    └── Template.java

Flattening:

  • Consolidate: Move templates classes to survey package
  • Split: Create survey.create and survey.process packages
  • Shared: Create survey.shared package

Detection Strategies

Find Root Namespaces with Code:

// Find root namespaces containing source files
function findRootNamespacesWithCode(namespaces, sourceFiles) {
  const rootNamespaces = namespaces.filter((ns) => {
    // Check if namespace has been extended
    const hasChildren = namespaces.some((n) => n.startsWith(ns + '.') || n.startsWith(ns + '/'))

    // Check if namespace contains source files
    const hasFiles = sourceFiles.some((f) => f.namespace === ns)

    return hasChildren && hasFiles
  })

  return rootNamespaces
}

Find Orphaned Classes:

// Find orphaned classes in root namespaces
function findOrphanedClasses(rootNamespaces, sourceFiles) {
  const orphaned = []

  rootNamespaces.forEach((rootNs) => {
    const files = sourceFiles.filter((f) => f.namespace === rootNs)
    orphaned.push({
      rootNamespace: rootNs,
      files: files,
      count: files.length,
    })
  })

  return orphaned
}

Fitness Functions

After flattening components, create automated checks:

No Source Code in Root Namespaces

// Alert if source code exists in root namespace
function checkRootNamespaceCode(namespaces, sourceFiles) {
  const violations = []

  namespaces.forEach((ns) => {
    // Check if namespace has been extended
    const hasChildren = namespaces.some((n) => n.startsWith(ns + '.') || n.startsWith(ns + '/'))

    if (hasChildren) {
      // Check if namespace contains source files
      const files = sourceFiles.filter((f) => f.namespace === ns)

      if (files.length > 0) {
        violations.push({
          namespace: ns,
          files: files.map((f) => f.name),
          issue: 'Root namespace contains source files (orphaned classes)',
        })
      }
    }
  })

  return violations
}

Components Only as Leaf Nodes

// Ensure components exist only as leaf nodes
function validateComponentStructure(namespaces, sourceFiles) {
  const violations = []

  // Find all leaf nodes (components)
  const leafNodes = namespaces.filter((ns) => {
    return !namespaces.some((n) => n.startsWith(ns + '.') || n.startsWith(ns + '/'))
  })

  // Check that all source files are in leaf nodes
  sourceFiles.forEach((file) => {
    if (!leafNodes.includes(file.namespace)) {
      violations.push({
        file: file.name,
        namespace: file.namespace,
        issue: 'Source file not in leaf node (component)',
      })
    }
  })

  return violations
}

Best Practices

Do's ✅

  • Ensure components exist only as leaf nodes
  • Remove orphaned classes from root namespaces
  • Choose flattening strategy based on functionality
  • Consolidate when functionality is related
  • Split when functionality is distinct
  • Extract shared code to .shared components
  • Update all references after flattening
  • Verify changes with tests

Don'ts ❌

  • Don't leave orphaned classes in root namespaces
  • Don't create components on top of other components
  • Don't skip updating imports after moving files
  • Don't flatten without analyzing impact
  • Don't mix flattening strategies inconsistently
  • Don't ignore shared code when flattening
  • Don't skip testing after refactoring

Common Patterns

Pattern 1: Simple Consolidation

Before:

ss.survey/
├── Survey.js           ← Orphaned
└── templates/          ← Component
    └── Template.js

After:

ss.survey/              ← Component (leaf node)
├── Survey.js
└── Template.js

Pattern 2: Functional Split

Before:

ss.ticket/              ← Root namespace
├── Ticket.js           ← Orphaned (45 files)
├── assign/             ← Component
└── route/              ← Component

After:

ss.ticket/              ← Subdomain
├── maintenance/        ← Component
│   └── Ticket.js
├── completion/        ← Component
│   └── TicketCompletion.js
├── assign/             ← Component
└── route/              ← Component

Pattern 3: Shared Code Extraction

Before:

ss.survey/              ← Root namespace
├── Survey.js           ← Domain code
├── SurveyValidator.js  ← Shared code
└── templates/          ← Component

After:

ss.survey/              ← Component
├── Survey.js
└── shared/             ← Component
    └── SurveyValidator.js

Next Steps

After flattening components:

  1. Apply Determine Component Dependencies Pattern - Analyze coupling
  2. Create Component Domains - Group components into domains
  3. Create Domain Services - Extract domains to services

Notes

  • Components must exist only as leaf nodes
  • Root namespaces with code are problematic
  • Flattening improves component clarity
  • Choose flattening strategy based on functionality
  • Shared code should be in dedicated components
  • Always update references after moving files
  • Test thoroughly after flattening

FAQ

What does the component-flattening-analysis skill do?

Detects misplaced classes and fixes component hierarchy problems — finds code that should belong inside a component but sits at the root level. Use when asking "clean up component structure", "find orphaned classes", "fix module hierarchy", "flatten nested components", or analyzing why namespaces have misplaced code. Do NOT use for dependency analysis (use coupling-analysis) or domain grouping (use domain-identification-grouping).

How do I install component-flattening-analysis?

Run npx skills add https://github.com/tech-leads-club/agent-skills --skill component-flattening-analysis in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/component-flattening-analysis/ (personal) or .claude/skills/component-flattening-analysis/ (project).

Which AI agents can use component-flattening-analysis?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is component-flattening-analysis safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains component-flattening-analysis?

It is published by tech-leads-club in tech-leads-club/agent-skills. It has 212 recorded installs.

More from tech-leads-club/agent-skills

View all →

tlc-spec-driven

tech-leads-club/agent-skills

Feature planning and implementation with 4 adaptive phases (Specify, Design, Tasks, Execute). Auto-sizes depth by complexity. Asks every product decision before the spec is approved, writes testable requirements in EARS notation, atomic tasks with a gate and a commit each, and one check per criterion with the test that proves it. Captures that come with the request bind, and each screen is judged against them. Ships deterministic Python scripts so the gates are enforced by code, not memory; the proofs run once at the end, and an independent Verifier (author != verifier) spends its time on mutations and judgement. Use when (1) planning features, (2) implementing with verification and atomic commits, (3) validating an implementation against a spec. Triggers on "specify feature", "discuss feature", "design", "tasks", "implement", "validate", "verify work", "UAT", "record decision", "pause work", "resume work". Do NOT use for pure architecture decomposition analysis or standalone technical

subagent-creator

tech-leads-club/agent-skills

Guide for creating AI subagents with isolated context for complex multi-step workflows. Use when users want to create a subagent, specialized agent, verifier, debugger, or orchestrator that requires isolated context and deep specialization. Works with any agent that supports subagent delegation. Triggers on "create subagent", "new agent", "specialized assistant", "create verifier". Do NOT use for Cursor-specific subagents (use cursor-subagent-creator instead).

AI & Agents911 installs

technical-design-doc-creator

tech-leads-club/agent-skills

Creates comprehensive Technical Design Documents (TDD) with mandatory and optional sections through interactive discovery. Use when user asks to "write a design doc", "create a TDD", "technical spec", "architecture document", "RFC", "design proposal", or needs to document a technical decision before implementation. Do NOT use for README files, API docs, or general documentation (use docs-writer instead).

Docs & Writing609 installs

security-best-practices

tech-leads-club/agent-skills

Perform language and framework specific security best-practice reviews and suggest improvements. Use when the user explicitly requests security best practices guidance, a security review or report, or secure-by-default coding help. Supports Python, JavaScript/TypeScript, and Go. Do NOT use for general code review, debugging, threat modeling (use security-threat-model), or non-security tasks.

domain-analysis

tech-leads-club/agent-skills

Maps business domains and suggests service boundaries in any codebase using DDD Strategic Design. Use when asking "what are the domains in this codebase?", "where should I draw service boundaries?", "identify bounded contexts", "classify subdomains", "DDD analysis", or analyzing domain cohesion. Do NOT use for grouping existing components into domains (use domain-identification-grouping) or dependency analysis (use coupling-analysis).

nestjs-modular-monolith

tech-leads-club/agent-skills

Open the skill to read its SKILL.md instructions.

AI & Agents331 installs

Popular frontend & design skills

View category →

setup-matt-pocock-skills

mattpocock/skills

Configure this repo for the engineering skills: set up its issue tracker, triage label vocabulary, and domain doc layout. Run once before first use of the other engineering skills.

Frontend & Design1.1M installs

frontend-design

anthropics/skills

Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.

OfficialFrontend & Design1M installs

hyperframes-animation

heygen-com/hyperframes

All animation knowledge for HyperFrames — atomic motion rules, multi-phase scene blueprints, scene transitions, broader motion-design techniques, AND the seven runtime adapters (GSAP default, plus Lottie, Three.js, Anime.js, CSS keyframes, Web Animations API, TypeGPU). Use for any motion or animation task: pick 2-4 rules and compose, or load a blueprint, or look up runtime-specific API (e.g. GSAP eases / Lottie player / Three.js mixer). Also covers auditing an existing composition's choreography (animation map) and 24 named text-animation effects. HyperFrames-native: single paused timeline, seek-safe, deterministic.

prototype

mattpocock/skills

Build a throwaway prototype to answer a design question. Use when the user wants to sanity-check whether a state model or logic feels right, or explore what a UI should look like.

Frontend & Design999.2K installs

hyperframes-core

heygen-com/hyperframes

The HyperFrames composition contract — build one renderable project. Use for composition structure, the data- timing attributes, class="clip", tracks, sub-compositions, variables, framework-owned media playback, deterministic-render rules, and validation. Read before writing composition HTML.

Frontend & Design930.5K installs

vercel-react-best-practices

vercel-labs/agent-skills

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

OfficialFrontend & Design843.1K installs