Where to Create a Component: Packages vs Templates
Monorepo Structure
Our internal-libs-monorepo
is organized as follows:
/packages
- Contains our packages available on npm/apps
- Contains our application templates
When to create in packages (/packages
)
Use packages when:
- The component needs to be reused across multiple applications
- The component should be available via npm for distribution
- The component is independent and has no specific project dependencies
- The component represents generic functionality that can be leveraged by different contexts
Example use cases for Packages
Generic UI components, shared utilities, reusable hooks, validation libraries, etc.
When to create in apps (template) (/apps
)
Use templates when:
- The component depends on some project-specific aspect
- The component is coupled to the application's business logic
- The component uses application-specific configurations or contexts
- Placing it in packages would be inadequate due to coupling
Example use cases for Templates
Feature-specific components, project-specific API integrations.
Decision on where to create
The choice of where to create a new component should be based on the level of coupling and the need for reusability:
- Low coupling + High reusability = Create in Package
- High coupling + Low reusability = Create in Template