Overview
JS Boundaries is a project that provides a set of tools to help you enforce architectural boundaries in your JavaScript and TypeScript projects.
"Software architecture is the art of drawing lines that I call boundaries. Those boundaries separate software elements from one another, and restrict those on one side from knowing about those on the other."
Clean Architecture: A Craftsman's Guide to Software Structure and Design
At the moment, it consists of an ESLint plugin: eslint-plugin-boundaries: It ensures that your architectural boundaries are respected by the elements in your project by checking the folder and file structure and the dependencies between them.
By default, it analyzes import statements, but it can also evaluate require, exports and dynamic imports (import()). You can further customize it to inspect any other AST node that creates a dependency, such as jest.mock(). See the configuration guide for more details.
1. Define your Element Types
const elementDescriptors = [
{ type: "controllers", pattern: "controllers/*" },
{ type: "models", pattern: "models/*" },
{ type: "views", pattern: "views/*" }
];
2. Define your Rules
const dependencyRules = [
{
from: "controllers",
allow: ["models", "views"]
},
{
from: "views",
allow: ["models"]
},
{
from: "models",
disallow: ["*"]
}
];
3. Get Instant Feedback
When a file violates a dependencies rule, ESLint will report an error:
// In src/models/model-a.js
import View from '../views/view-a'; /* ❌ Error: Importing elements of type
'views' is not allowed in elements of type 'models'. Disallowed in rule 3 */
Scope
This plugin focuses on enforcing architectural boundaries by analyzing the relationships between abstract elements. It does not inspect import syntax or enforce coding standards unrelated to module dependencies.
This plugin is not a replacement for eslint-plugin-import. In fact, using both together is recommended.
Quick Start
Read the Quick Start Guide for step-by-step instructions on setting up the plugin in your project.