mcpField
C
cohesion

cohesion

github.com/tossDevelopment2.0k52 installsUpdated 33w ago
Repository

About cohesion

A code organization skill for frontend developers that groups code changed together. It presents domain-based file layout and centralized constants, while noting when sharing should be avoided.

Key features

  1. 01Group related files by feature domain
  2. 02Extract repeated magic numbers into shared constants
  3. 03Keep type definitions near their use
  4. 04Shorten relative paths between files
  5. 05Identify cases where code should not be shared

Use cases

  1. 01Organize feature code spread across directories
  2. 02Unify numeric constants used in multiple places
  3. 03Keep types close to their implementation

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/toss/frontend-fundamentals --skill cohesion

After installing, type/cohesionin Claude Code to confirm it loaded.

Details

From the project README

응집도

함께 수정되는 코드는 함께 있어야 한다.

핵심 패턴

함께 수정되는 파일을 같은 디렉토리에 두기

❌ 종류별 분리 (의존 관계 파악 어려움):

src/
├── components/UserForm.tsx
├── hooks/useUserValidation.ts
├── types/userTypes.ts
└── api/userApi.ts

✅ 도메인별 배치:

src/
├── components/   # 전역 공유
└── domains/User/ # User 관련 코드 모음
    ├── UserForm.tsx
    ├── useUserValidation.ts
    ├── types.ts
    └── api.ts
매직 넘버 제거

같은 숫자가 여러 곳에 있으면 한쪽만 수정되어 버그 발생.

❌ 분산:

// Pagination.tsx
const pages = Math.ceil(total / 20);
// useItems.ts
const offset = (page - 1) * 20;

✅ 상수로 통합:

export const PAGE_SIZE = 20;
import { PAGE_SIZE } from './constants';

빠른 참조

코드 냄새개선 방법
같은 매직 넘버 3곳 이상공유 상수로 추출
기능이 components/, hooks/, types/ 모두 수정domains/featureName/으로 배치
긴 상대 경로 ../../..파일들을 가까이 배치
타입 정의가 사용처와 멀리 떨어짐사용하는 코드와 함께 배치

예외: 중복이 나은 경우

  • 두 기능이 다르게 발전할 가능성이 높을 때
  • 공유 시 원치 않는 의존성이 생길 때
  • 공유 코드가 5줄 미만으로 단순할 때

참고: https://frontend-fundamentals.com/code-quality/cohesive/

Comments

Markdown supported