# compsys

> Provides a lifecycle and dependency system

Latest version **0.0.2** (published 2019-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install compsys
pnpm add compsys
yarn add compsys
bun add compsys
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2019-09-28 |
| First published | 2019-09-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 33.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Donald Ball |
| Maintainers | donaldball |
| Keywords | system, component, dependency, lifecycle, architecture |

## Links

- npm: https://www.npmjs.com/package/compsys
- Repository: https://github.com/dball/compsys
- Homepage: https://github.com/dball/compsys#readme
- Issues: https://github.com/dball/compsys/issues
- npm.io page: https://npm.io/package/compsys

## Dependencies (1)

- [dependency-graph](https://npm.io/package/dependency-graph.md) ^0.8.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2019-09-28
- 0.0.1 — 2019-09-28

## README

# Compsys

Compsys is a Typescript system architecture framework library. It is heavily
inspired by [Stuart Sierra's component library for Clojure](https://github.com/stuartsierra/component).

## Components

A System is a javascript object constructed from a blueprint declaring and
describing the named component roles, instances, and their dependencies.
Components may be of any type.

Components may have dependencies. Dependencies are declared on roles and are
injected when the system is started. These components must have a property for
the module's `inject` symbol whose value is a function accepting the role and
instance for each dependency. Component injection occurs at system start.

Components may have lifecycles. These are started when the system starts, in the
order required by the dependency graph, and stopped with the system stops, in
reverse order. Injected components with lifecycles are always injected after
being started. Components with lifecycles are replaced by their promised started
or stopped values, allowing for immutable components. Components with lifecycles
must have properties for the module's `start` and `stop` symbols, whose values
are async functions of no arguments which must return the component in its new
state.

## Motivation

Most of the Javascript applications I've seen seem to suffer from a lack of
architecture. The applications lack any encapsulation of and separation between
phases of the application's existence, which leads to confused code paths,
redundant code, ill-specified behaviors, bugs, etc.

Moreover, side effects tend occur all over the place, both internal and
external, which complicates testing, reduces the possibility of code reuse, and
impedes analysis.

Most applications can profitably be characterized by the following phases:

1. Constructing configuration data from various sources, including the
   filesystem, envirionment variables, command-line arguments, inspecting the
   environment, calling services, etc.
2. Validating the syntax of the configuration - not does the password work, but
   is it a non-empty string
3. Constructing a system of components that have well-defined interfaces behind
   which all side effects occur
4. Starting the system, at which point expensive resources are allocated,
   network connections are established, ports are bound for listening, etc.
5. Stopping the system, affording components the explicit opportunity to finish
   work and clean up resources

This library intends to faciliate clarifying and correctly implementing the last
three steps.

## Design Goals

* Provide a principled approach to system architecture
* Facilitate encapsulating side effects within coherent substitutable components
* Separate and simplify the stages of an application's lifecycle
* Allow, but not mandate, immutable components
* Components play named roles, and depend on any number of other named roles
* Components may or may not have lifecycles
* Components may or may not have dependencies
* Use of the library should be able to write idiomatic Javascript using normal
  mutable objects and method signatures
* The library should have as few dependencies as possible

## License

MIT

## Copyright

Copyright Donald A. Ball Jr. 2019

---
_Source: https://npm.io/package/compsys · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
