Skip to content

Commit 4860fc4

Browse files
authored
Merge pull request #32 from ts-graphviz/improve-architecture-and-design-principles
Improve architecture and design principles
2 parents 6fb3149 + b09a573 commit 4860fc4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+858
-412
lines changed

docs/ts-graphviz/04-intermediate-topics/01-rendering-graphs-to-images.md renamed to docs/ts-graphviz/03-guides/01-rendering-graphs-to-images.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Ensure that [Graphviz](https://graphviz.org/download/) is installed on your syst
2626
### Converting DOT to an Image Stream
2727

2828
```typescript
29-
import { toStream } from '@ts-graphviz/adapter';
29+
import { toStream } from 'ts-graphviz/adapter';
3030

3131
const dot = `
3232
digraph example {
@@ -46,7 +46,7 @@ await stream.pipeTo(Deno.stdout.writable);
4646
### Writing DOT to an Image File
4747

4848
```typescript
49-
import { toFile } from '@ts-graphviz/adapter';
49+
import { toFile } from 'ts-graphviz/adapter';
5050

5151
const dot = `
5252
digraph example {
@@ -63,7 +63,7 @@ await toFile(dot, './result.svg', { format: 'svg' });
6363
- **Output Formats**: Specify the desired output format (e.g., `svg`, `png`) through the options.
6464
- **Runtime Compatibility**: Designed to work seamlessly in both Node.js and Deno environments.
6565

66-
## When to Use `@ts-graphviz/adapter`
66+
## When to Use `ts-graphviz/adapter` module
6767

6868
- When you need to render your graphs into image files for visualization.
6969
- If you want to generate images dynamically within your application.

docs/ts-graphviz/11-advanced-usage/02-extending-ts-graphviz.md renamed to docs/ts-graphviz/03-guides/03-extending-ts-graphviz.md

+57-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
description: How to extend ts-graphviz with custom classes.
2+
description: How to extend ts-graphviz for advanced use cases.
33
---
44
# Extending ts-graphviz
55

6-
`ts-graphviz` is designed to be extensible, allowing advanced users to customize and enhance the library's functionality to meet specific needs. This section covers how to extend the type system and create custom implementations.
6+
`ts-graphviz` is designed to be extensible, allowing intermediate users to customize and enhance the library's functionality to meet specific needs. This section covers how to extend the type system and create custom implementations.
77

88
## Creating Custom Classes
99

@@ -172,3 +172,58 @@ console.log(
172172
),
173173
);
174174
```
175+
176+
---
177+
178+
179+
## Internal Package Overview
180+
181+
For users interested in extending or customizing `ts-graphviz`, understanding the internal packages can be valuable. Below is an overview of the internal packages and how they can be used in advanced scenarios.
182+
183+
184+
### `@ts-graphviz/adapter`
185+
186+
**Purpose**: Provides interfaces to execute Graphviz commands and convert DOT language strings into various output formats.
187+
188+
**Usage**:
189+
190+
- Convert DOT strings to streams or files.
191+
- Use in environments where you need to render graphs to images or other formats.
192+
193+
:::note
194+
You can use either `@ts-graphviz/adapter` or `ts-graphviz/adapter` imports. The latter is maintained for backward compatibility.
195+
:::
196+
197+
198+
### `@ts-graphviz/ast`
199+
200+
**Purpose**: Allows manipulation of the DOT language at the Abstract Syntax Tree (AST) level.
201+
202+
**Usage**:
203+
204+
- Parse DOT strings into AST nodes.
205+
- Manipulate and transform the AST programmatically.
206+
- Useful for advanced analysis or transformations of existing DOT code.
207+
208+
:::note
209+
You can use either `@ts-graphviz/ast` or `ts-graphviz/ast` imports. The latter is maintained for backward compatibility.
210+
:::
211+
212+
### `@ts-graphviz/common`
213+
214+
**Purpose**: Centralizes Graphviz domain knowledge, providing type definitions, constants, and utilities. It is designed to handle use cases such as extending types.
215+
216+
**Usage**:
217+
218+
- Extend or customize types and attributes.
219+
- Ensure type safety when working with custom attributes.
220+
- Aggregate domain knowledge of Graphviz for consistent usage across packages.
221+
222+
### `@ts-graphviz/core`
223+
224+
**Purpose**: Contains the core implementations of the models and functions provided to users.
225+
226+
**Usage**:
227+
228+
- Use object-oriented APIs for fine-grained control over graph elements.
229+
- Extend classes for custom behaviors or attributes.

docs/ts-graphviz/11-advanced-usage/03-using-ast.md renamed to docs/ts-graphviz/03-guides/04-using-ast.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ description: Manipulate DOT graphs at the AST level with @ts-graphviz/ast.
33
---
44
# Using Abstract Syntax Tree (AST)
55

6-
For advanced use cases, `@ts-graphviz/ast` provides an API to handle Abstract Syntax Trees (ASTs) of DOT language graphs.
6+
For advanced use cases, `ts-graphviz/ast` module provides an API to handle Abstract Syntax Trees (ASTs) of DOT language graphs.
77

88
## Available Functions
99

10-
1110
The following functions are provided:
1211

1312
- `fromModel`: Converts a **Model** to an **AST**.
@@ -27,7 +26,7 @@ The `toDot` function provided by the `ts-graphviz` package is a composition of `
2726

2827

2928
```typescript
30-
import { parse } from '@ts-graphviz/ast';
29+
import { parse } from 'ts-graphviz/ast';
3130

3231
const ast = parse(`
3332
digraph example {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "Guides",
3+
"link": {
4+
"type": "generated-index",
5+
"description": "Guides to help you understand ts-graphviz."
6+
}
7+
}

docs/ts-graphviz/04-intermediate-topics/_category_.json

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
description: Design principles of ts-graphviz.
3+
---
4+
# Design Principles
5+
6+
**ts-graphviz** is built around several key concepts that make it modular, extensible, and easy to use:
7+
8+
1. **TypeScript-First Design & Type Definitions**
9+
10+
**ts-graphviz** is designed primarily with TypeScript in mind, offering strong typing and seamless integration with TypeScript projects. Comprehensive type definitions for DOT language elements enable type-safe interactions, enhancing development efficiency and reducing errors.
11+
12+
1. **Object-Oriented API**
13+
14+
The library provides an object-oriented API for creating and manipulating graph elements such as graphs, nodes, and edges. This approach makes working with complex graph structures intuitive and efficient, leveraging familiar programming paradigms.
15+
16+
1. **Modular Design**
17+
18+
**ts-graphviz** adopts a modular architecture, split into multiple packages, each serving a specific purpose. This modularity allows users to include only the functionality they need, improving maintainability, flexibility, and reducing unnecessary dependencies.
19+
20+
1. **AST Support**
21+
22+
The library includes support for Abstract Syntax Trees (AST) for processing the DOT language. This enables parsing and generating DOT language while preserving its structure, facilitating programmatic manipulation and transformation of graphs.
23+
24+
1. **Runtime Adapter**
25+
26+
To ensure compatibility across different runtime environments, **ts-graphviz** provides adapter functions for environments like Node.js and Deno. These adapters serve as a wrapper, enabling seamless execution of Graphviz commands regardless of the underlying platform.
27+
28+
1. **Extensibility**
29+
30+
Designed with extensibility in mind, **ts-graphviz** allows users to extend its functionality with custom implementations for specific use cases. This flexibility supports a wide range of applications and integration scenarios.
31+
32+
1. **Multi-Paradigm Support**
33+
34+
The library accommodates various programming paradigms, including Object-Oriented Programming and Declarative Programming. Users can choose the style that best suits their needs, making the library versatile and adaptable.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
description: Package architecture of ts-graphviz.
3+
---
4+
# Package Architecture
5+
6+
**ts-graphviz** consists of several packages, each with a specific role:
7+
8+
- **`ts-graphviz`** (Main Package): Provides high-level APIs for creating and manipulating graphs, suitable for most users.
9+
10+
- **`@ts-graphviz/core`**: Contains core implementations of models and functions, used internally and available for advanced use.
11+
12+
- **`@ts-graphviz/common`**: Aggregates Graphviz domain knowledge, providing type definitions, constants, and utilities. Supports use cases like extending custom types and attributes.
13+
14+
- **`@ts-graphviz/ast`**: Offers tools for parsing, manipulating, and generating DOT language graphs at the AST level.
15+
16+
- **`@ts-graphviz/adapter`**: Executes Graphviz commands in various runtime environments (Node.js, Deno) and converts DOT strings to images.
17+
18+
- **`@ts-graphviz/react`**: Allows defining graphs using React's declarative UI paradigm, expressing DOT language models with JSX.
19+
20+
## Exposing Internal Modules as Submodules
21+
22+
**ts-graphviz** publishes some of its internal modules as submodules within the main package. Specifically, the following import paths are available to access these internal modules:
23+
24+
- **`ts-graphviz/ast`** or **`@ts-graphviz/ast`**
25+
- **`ts-graphviz/adapter`** or **`@ts-graphviz/adapter`**
26+
27+
This allows users to choose the module import style that best fits their project's needs. By using the `ts-graphviz/<module-name>` style, you can limit your dependencies to the `ts-graphviz` library itself, with internal packages (e.g., `@ts-graphviz/adapter`, `@ts-graphviz/ast`) being managed centrally by the `ts-graphviz` package. On the other hand, using the `@ts-graphviz/<module-name>` style enables you to manage dependencies on a per-module basis, allowing you to selectively install specific modules as needed.
28+
29+
:::tip Managing Dependencies When Choosing Import Paths
30+
31+
When using package managers that enforce strict dependency management (e.g., pnpm), the choice of import path can significantly impact how dependencies are handled. Consider the following points:
32+
33+
- **Using `ts-graphviz/<module-name>` Style**:
34+
- **Advantages**: Limits dependencies to the `ts-graphviz` library itself, with internal packages (e.g., `@ts-graphviz/adapter`, `@ts-graphviz/ast`) being managed centrally by the `ts-graphviz` package. This prevents dependency conflicts and ensures that stable versions recommended by the library are used.
35+
- **Recommended Scenarios**: When you want to minimize dependencies or when the internal packages managed by `ts-graphviz` do not have specific version requirements.
36+
37+
- **Using `@ts-graphviz/<module-name>` Style**:
38+
- **Advantages**: Allows you to manage dependencies on a per-module basis, installing only the specific modules you need, which can help keep your application lightweight.
39+
- **Caveats**: Requires you to manage internal dependencies (e.g., `@ts-graphviz/adapter`, `@ts-graphviz/ast`) separately within your package manager. This can complicate version management.
40+
- **Recommended Scenarios**: When you need to use specific modules only or require detailed control over your dependencies.
41+
42+
**Summary**:
43+
- If you prefer **simple dependency management**, use the `ts-graphviz/<module-name>` style.
44+
- If you require **fine-grained control over dependencies** or only need specific modules, opt for the `@ts-graphviz/<module-name>` style.
45+
46+
This approach allows you to manage dependencies in a way that best suits your project's requirements.
47+
:::
48+
49+
50+
The relationships between packages can be visualized as follows:
51+
52+
![Package dependency graph showing relationships between ts-graphviz packages and their dependencies](./img/dependency-graph.svg)
53+
54+
This modular architecture ensures:
55+
56+
- **Maintainability**: Individual packages can be maintained and updated without affecting others.
57+
58+
- **Flexibility**: Users can select only the packages needed for their specific use cases.
59+
60+
- **Extensibility**: Facilitates the addition of new features or packages as the library evolves.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
description: Versioning policy for ts-graphviz.
3+
---
4+
# Versioning Policy
5+
6+
## Overview
7+
8+
**ts-graphviz** follows [**Semantic Versioning 2.0**](https://semver.org/) to ensure consistency and predictability. This policy clarifies how we manage breaking changes, especially those related to runtime support, and what users can expect when using **ts-graphviz**.
9+
10+
## Semantic Versioning
11+
12+
Version numbers are formatted as **MAJOR.MINOR.PATCH**, with changes classified as follows:
13+
14+
- **MAJOR**: Introduces backward-incompatible changes.
15+
- **MINOR**: Adds functionality in a backward-compatible manner.
16+
- **PATCH**: Fixes bugs in a backward-compatible manner.
17+
18+
---
19+
20+
## Exceptions: TypeScript Version Updates
21+
22+
There are scenarios where **ts-graphviz** may deviate from strict Semantic Versioning:
23+
24+
- **TypeScript Definitions**: Breaking changes to TypeScript type definitions may occur between minor versions due to:
25+
- TypeScript introducing breaking changes in its own minor updates.
26+
- Adopting features available only in newer TypeScript versions, which may raise the minimum required TypeScript version.
27+
28+
:::tip
29+
For TypeScript projects, we recommend pinning the **ts-graphviz** minor version to control upgrade timing and compatibility testing.
30+
:::
31+
32+
---
33+
34+
## Information Sharing
35+
36+
We are committed to transparent communication regarding our versioning and support policies:
37+
38+
- **Documentation and Release Notes**: All changes to the versioning policy and support levels will be documented in our official documentation and detailed in release notes.
39+
- **Community Engagement**: Users are encouraged to subscribe to updates or follow our repositories to stay informed about the latest developments.
40+
41+
---
42+
43+
## Migration Support
44+
45+
To assist users in transitioning between versions, especially when breaking changes occur:
46+
47+
- **Migration Guides**: We provide comprehensive migration guides outlining steps to upgrade to new major versions.
48+
- **Code Examples**: Examples are included to demonstrate how to adapt code to accommodate changes.
49+
- **Support Channels**: Users can seek assistance through community forums, issue trackers, or other support channels if they encounter difficulties during migration.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
description: Supported environments for ts-graphviz.
3+
draft: true
4+
---
5+
# Supported Environments
6+
7+
To provide clarity on the environments in which **ts-graphviz** operates, we have categorized support levels:
8+
9+
## Support Levels
10+
11+
### Tier 1: Full Support
12+
13+
- **Definition**: Environments that are fully supported, with comprehensive automated testing and maintenance.
14+
- **Environments**:
15+
- **Node.js**: All active Long-Term Support (LTS) versions.
16+
- **Details**:
17+
- We run automated tests on all LTS versions of Node.js.
18+
- Full compatibility and performance are ensured.
19+
- Critical issues are prioritized for fixes.
20+
21+
### Tier 2: Active Support
22+
23+
- **Definition**: Environments that receive active support with limited automated testing.
24+
- **Environments**:
25+
- **Deno**: Latest stable version.
26+
- **Node.js Current Release**: The latest Node.js release outside the LTS schedule.
27+
- **Details**:
28+
- Automated tests are conducted on the latest version of Deno to confirm functionality.
29+
- Compatibility is maintained, and issues are addressed.
30+
31+
### Tier 3: Community Support
32+
33+
- **Definition**: Environments that are not officially tested but are supported on a best-effort basis.
34+
- **Environments**:
35+
- **Modern Browsers**: Latest versions of major browsers, including:
36+
- Google Chrome
37+
- Mozilla Firefox
38+
- Microsoft Edge
39+
- Apple Safari
40+
- **Details**:
41+
- Installation methods are provided.
42+
- No automated testing is performed.
43+
- Issues reported by users will be addressed.
44+
- Targeting the latest versions ensures compatibility with modern web standards.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
description: Security policies for ts-graphviz.
3+
---
4+
# Security Policies
5+
6+
## Purpose and Importance
7+
8+
In today's software development landscape, **Open Source Software (OSS)** plays an indispensable role in building applications. According to the **Open Source Security Foundation (OpenSSF)**, **70% to 90%** of modern applications consist of OSS components[^1], and the complexity of their dependencies is increasing daily.
9+
10+
[^1]: Behlendorf, B. (2022, May 11). *Brian Behlendorf Testifies to Congress on Open Source Software Security* (original in English). The Linux Foundation. Retrieved from [https://www.linuxfoundation.org/blog/blog/lf/brian-behlendorf-testifies-open-source-software-security](https://www.linuxfoundation.org/blog/blog/lf/brian-behlendorf-testifies-open-source-software-security)
11+
12+
### The Impact and Responsibility of ts-graphviz
13+
14+
**ts-graphviz** is a widely used library with over 2 million downloads per month, impacting a broad range of applications. Even users who do not directly interact with ts-graphviz are affected through software that depends on it.
15+
16+
> ![Dependency](https://imgs.xkcd.com/comics/dependency.png)
17+
>
18+
> *An illustration of software dependencies (Source: [xkcd.com/2347](https://xkcd.com/2347/))*
19+
20+
This illustration highlights how modern software relies on numerous underlying components.
21+
22+
**Ensuring the security of ts-graphviz is crucial because vulnerabilities can cascade through dependencies, potentially affecting countless applications.**
23+
24+
## Commitment to Security
25+
26+
ts-graphviz is committed to more than just providing secure source code. We implement **comprehensive security measures** that consider the **entire software supply chain**. This dedication ensures that users can confidently adopt ts-graphviz, knowing it contributes to building secure and reliable applications.
27+
28+
## Software Supply Chain Security
29+
30+
Recognizing that modern applications are heavily dependent on open-source software, we implement practices that safeguard against vulnerabilities throughout the dependency chain.
31+
32+
## Reporting Vulnerabilities
33+
34+
We encourage users and security researchers to report any vulnerabilities or security concerns. Prompt reporting allows us to address issues swiftly, maintaining the integrity and security of the library.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
2-
"label": "Advanced Usage",
2+
"label": "Advanced Topics",
33
"link": {
44
"type": "generated-index",
55
"description": "Advanced topics to help you understand the inner workings of ts-graphviz."
66
}
77
}
8-

0 commit comments

Comments
 (0)