Skip to content

Comments

feat: add architecture-colocate-contexts rule#121

Open
nouamanecodes wants to merge 1 commit intovercel-labs:mainfrom
nouamanecodes:main
Open

feat: add architecture-colocate-contexts rule#121
nouamanecodes wants to merge 1 commit intovercel-labs:mainfrom
nouamanecodes:main

Conversation

@nouamanecodes
Copy link

Problem

The existing rules cover component composition and performance optimization well, but there's no guidance on where context files should live in a codebase. This leads to a common antipattern: dumping all contexts into a top-level src/contexts/ folder regardless of scope.

When contexts are scattered away from the components that use them:

  • Debugging requires jumping between distant directories
  • Moving a feature means updating imports across the codebase
  • It's unclear which contexts are feature-scoped vs app-wide

Solution

This adds a new architecture-colocate-contexts rule that recommends placing context definitions adjacent to the components that consume them.

The rule covers:

  • File structure pattern (types.ts, provider.tsx, index.ts)
  • When to co-locate vs when to use a shared location
  • Integration with the existing { state, actions, meta } context interface pattern

Example

Instead of:

src/contexts/ComposerContext.ts
src/components/Composer/Input.tsx

Co-locate:

src/components/Composer/context/types.ts
src/components/Composer/context/provider.tsx
src/components/Composer/context/index.ts
src/components/Composer/Input.tsx

This complements the composition-patterns skill by providing the structural container for those patterns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant