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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@canxjs/blocks

v1.0.0

Published

Modular architecture support for CanxJS applications

Readme

@canxjs/blocks


✨ Features

  • 📦 Modular Structure - Organize code into self-contained modules
  • 🔄 Auto-Discovery - Automatically scan and load modules
  • ⚙️ Module Configuration - Enable/disable modules via JSON config
  • 🎯 Ordered Loading - Control module boot order
  • 🧩 Reusable Components - Share modules across projects

📦 Installation

npm install @canxjs/blocks
# or
bun add @canxjs/blocks

🚀 Quick Start

1. Register the Service Provider

// src/providers.ts
import { BlocksServiceProvider } from "@canxjs/blocks";

export const providers = [
  // ... other providers
  BlocksServiceProvider,
];

2. Create Your First Module

node canx make:module Blog

This creates the following structure:

/modules
  /Blog
    module.json
    /src
      BlogServiceProvider.ts
      /controllers
      /models
    /routes
      api.ts
      web.ts

📖 Usage

Module Configuration

Each module must have a module.json file:

{
  "name": "Blog",
  "description": "Blog module for managing posts and comments",
  "enabled": true,
  "order": 1
}

| Field | Type | Description | | ------------- | ------- | ---------------------------- | | name | string | Module identifier | | description | string | Human-readable description | | enabled | boolean | Whether to load this module | | order | number | Boot order (lower = earlier) |

Module Service Provider

// modules/Blog/src/BlogServiceProvider.ts
import { ServiceProvider } from "canxjs";

export class BlogServiceProvider extends ServiceProvider {
  register(): void {
    // Register bindings
  }

  async boot(): Promise<void> {
    // Bootstrap module (register routes, etc.)
  }
}

Module Routes

// modules/Blog/routes/api.ts
import { router } from "canxjs";
import { PostController } from "../src/controllers/PostController";

router.group({ prefix: "/api/blog" }, () => {
  router.get("/posts", [PostController, "index"]);
  router.post("/posts", [PostController, "store"]);
  router.get("/posts/:id", [PostController, "show"]);
});

Module Controllers

// modules/Blog/src/controllers/PostController.ts
import { BaseController, Controller } from "canxjs";
import { Post } from "../models/Post";

@Controller("/posts")
export class PostController extends BaseController {
  async index() {
    return await Post.all();
  }

  async store() {
    const data = this.request.body;
    return await Post.create(data);
  }
}

🔧 How It Works

Module Discovery

When your application boots:

  1. ModuleManager scans the /modules directory
  2. Each folder with a valid module.json is registered
  3. Modules are sorted by their order property
  4. Only enabled: true modules are booted
import { ModuleManager } from "@canxjs/blocks";

const manager = new ModuleManager();

// Scan and load all modules
manager.scan();

// Boot all enabled modules
await manager.boot();

// Get all modules
const modules = manager.all();

// Find a specific module
const blogModule = manager.find("Blog");

Module Class

Each discovered module is represented by a Module instance:

class Module {
  name: string; // Module name
  path: string; // Absolute path to module
  description: string; // From module.json
  enabled: boolean; // Whether active
  order: number; // Boot priority

  getPath(file?: string): string; // Get path within module
  async boot(): Promise<void>; // Boot the module
}

Folder Structure Best Practice

/modules
  /Blog
    module.json
    /src
      BlogServiceProvider.ts
      /controllers
        PostController.ts
        CommentController.ts
      /models
        Post.ts
        Comment.ts
      /services
        PostService.ts
    /routes
      api.ts
      web.ts
    /resources
      /views
        index.tsx
        show.tsx
    /tests
      PostController.test.ts

  /Shop
    module.json
    /src
      ...

📚 API Reference

ModuleManager

| Method | Description | | ------------ | ---------------------------------------------- | | scan() | Scan /modules directory and register modules | | all() | Get all registered modules (sorted by order) | | find(name) | Get a specific module by name | | boot() | Boot all enabled modules |

Module

| Property | Type | Description | | ------------- | ------- | ------------------ | | name | string | Module identifier | | path | string | Absolute file path | | description | string | Module description | | enabled | boolean | Is module active | | order | number | Boot priority |

| Method | Description | | ---------------- | ----------------------------------- | | getPath(file?) | Get absolute path to file in module | | boot() | Boot this module |


💡 Benefits

1. Separation of Concerns

Keep related features together. All blog-related code lives in /modules/Blog.

2. Reusability

Copy a module folder to another project. With minimal configuration, it's ready to use.

3. Team Scalability

Different teams can work on different modules without conflicts.

4. Easy Testing

Test modules in isolation. Each module can have its own test suite.

5. Feature Flags

Disable modules in production by setting enabled: false.


📄 License

MIT © CanxJS Team