npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ts-boundaries-cli

v0.3.0

Published

A TypeScript architectural boundary enforcement tool that analyzes import statements to prevent unwanted dependencies between different parts of your codebase.

Readme

ts-boundaries-cli

A TypeScript architectural boundary enforcement tool that analyzes import statements to prevent unwanted dependencies between different parts of your codebase.

Installation

pnpm install ts-boundaries-cli

Or use directly with npx et al.:

pnpm dlx ts-boundaries-cli init
pnpm dpx ts-boundaries-cli check

Quick Start

  1. Initialize configuration:
ts-boundaries init

This creates a ts-boundaries.config.json file with an empty rules array.

  1. Add rules to your config:
{
  "$schema": "https://raw.githubusercontent.com/maxwihlborg/ts-boundaries-cli/refs/heads/main/schema.json",
  "rules": [
    {
      "from": ["./src/!(shared|server)/**"],
      "disallow": ["./src/server/**"],
      "message": "Client code cannot import from server code"
    },
    {
      "from": ["./src/shared/**"],
      "disallow": ["./src/!(shared)/**"],
      "message": "Shared code can only import shared code"
    },
    {
      "from": ["./src/server/**"],
      "disallow": ["./src/!(shared|server)/**"],
      "message": "Server code cannot import from client code"
    }
  ]
}
  1. Check your codebase:
ts-boundaries check

Configuration

Basic Rules

Rules define which imports are forbidden from specific locations:

{
  "rules": [
    {
      "from": ["./src/components/**"],
      "disallow": ["./src/utils/internal/**"],
      "message": "Components should not import internal utilities"
    }
  ]
}

Path Aliases

Configure path aliases for import resolution:

{
  "resolve": {
    "alias": {
      "~": "./src",
      "@components": "./src/components",
      "@utils": "./src/utils"
    }
  }
}

This allows the tool to properly resolve imports like ~/components/Button to ./src/components/Button.

Ignoring Specific Imports

You can opt-out of boundary checking for specific imports using the // ts-boundaries-ignore comment:

// ts-boundaries-ignore
import { ServerAPI } from "../server/api"; // This import will be ignored

import { ClientUtils } from "../client/utils"; // This import will still be checked

// ts-boundaries-ignore
const serverModule = await import("../server/auth"); // Dynamic import ignored too

The comment must appear directly before the import statement and works with both static imports and dynamic import() calls.

Commands

ts-boundaries init

Creates a new configuration file with an empty rules array.

ts-boundaries check

Analyzes your TypeScript files and reports boundary violations.

Options:

  • --vimgrep: Output errors in vimgrep format

Output Formats

Default Format

Human-readable output with detailed error information:

./src/client/app.ts:5:10
  Client code cannot import from server code
  Import: src/server/api

[ERROR] Found 1 fence violation(s)

Vimgrep Format

Machine-readable format compatible with vim quickfix and other tools:

ts-boundaries check --vimgrep

Output:

/Users/user/projects/package/src/client/app.ts:5:10: Client code cannot import from server code

Use Cases

Layered Architecture

Enforce architectural layers (presentation, business, data):

{
  "rules": [
    {
      "from": ["./src/presentation/**"],
      "disallow": ["./src/data/**"],
      "message": "Presentation layer cannot directly access data layer"
    },
    {
      "from": ["./src/data/**"],
      "disallow": ["./src/presentation/**"],
      "message": "Data layer cannot depend on presentation layer"
    }
  ]
}

Feature-Based Boundaries

Prevent features from importing from each other:

{
  "rules": [
    {
      "from": ["./src/features/auth/**"],
      "disallow": ["./src/features/billing/**"],
      "message": "Auth feature cannot import from billing feature"
    },
    {
      "from": ["./src/features/billing/**"],
      "disallow": ["./src/features/auth/**"],
      "message": "Billing feature cannot import from auth feature"
    }
  ]
}

Integration

CI/CD

Add to your build process:

# GitHub Actions
- name: Check boundaries
  run: pnpm dlx ts-boundaries-cli check
# npm script
{
  "scripts": {
    "lint:boundaries": "ts-boundaries check"
  }
}

Vim/Neovim

Use vimgrep format for quickfix integration:

:cexpr system('pnpm dlx ts-boundaries-cli check --vimgrep')

License

MIT