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

diagram-as-code

v1.0.0

Published

This library allows you to easily create diagrams of your infrastructure in code.

Readme

Diagram as code

This library allows you to easily create diagrams of your infrastructure in code. The library aims to make creating a new diagram and changing an existing one extremely easy, requiring only a text editor.

An example of a diagram that can be created with this library:

Example diagram

To generate this diagram, we use the following code as specified in example.html:

const client = new Client();
const loadbalancer = new Elb();
const webserver = new Ec2Cluster();
const databases = new RdsCluster();

client.getsDataFrom(loadbalancer);
loadbalancer.getsDataFrom(webserver);
webserver.getsDataFrom(databases);

diagram.render();

Getting started

Follow these steps to get started:

  • Download the file example.html.
  • Change the body to reflect your infrastructure. See the reference below for a list of what's possible.
  • Open it in your browser.

Reference

Adding nodes to a diagram

To create a new node, create a new instance of the class you want:

const customer = new Client('Customer');

The node will automatically be added to the diagram. All node types can be supplied with a label as the first argument of the constructor.

Linking nodes together

There are three ways to specify flow between nodes. An example for the nodes customer and server:

customer.exchangesDataWith(server);
customer.getsDataFrom(server);
customer.sendsDataTo(server);

You can call any function that ends either in with, from or to. For example you could instead do:

customer.requestsLoginPageFrom(server);

Rendering the diagram

To render the diagram:

diagram.render();

You can also send some settings via the render function:

diagram.render({
    leftToRight: false,
    container: document.body
});

The values shown are the defaults.

Customizing positioning

In most cases, the way the nodes are layed out will make sense. If it doesn't, you can customize the layers of the nodes. Add the layer as the second parameter to any node:

const layerNumber = 3;
const customer = new Client('Customer', layerNumber);

Important: You'll have to specify the layer for all nodes in your diagram to make this work.

Available node types

The following node types are currently available:

Client, Server, ServerCluster, Database, DatabaseCluster, Mysql, MysqlCluster, Oracle, OracleCluster, PostgreSql, PostgreSqlCluster, Elasticsearch, ElasticsearchCluster, Ec2, Ec2Cluster, Rds, RdsCluster, Elb, S3, DynamoDb, Redshift, Cloudwatch, Elasticache, Iam, SimpleDb, Swf, Cloudfront, Sqs, Sns, Route53, StorageGateway, CloudFormation, CloudSearch, Glacier, ElasticBeanstalk, Ebs, Lambda, ApiGateway

Each of these will get a nice icon when you use them. If you want to add something that is not in this list, you can use the Custom type:

const instanceCount = 17;
const layerNumber = 3;
const customNode = new Custom(
    'Custom label',
    'https://custom.icon.website.org/icon.png',
    layerNumber,
    instanceCount
);