• This repository has been archived on 06/Apr/2021
  • Stars
    star
    981
  • Rank 46,671 (Top 1.0 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 13 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple yet powerful plugin system for large-scale node applications

Architect

Architect is a simple but powerful structure for Node.js applications. Using Architect, you set up a simple configuration and tell Architect which plugins you want to load. Each plugin registers itself with Architect, so other plugins can use its functions. Plugins can be maintained as NPM packages so they can be dropped in to other Architect apps.

Plugin Interface

// auth.js

/* All plugins must export this public signature.
 * @options is the hash of options the user passes in when creating an instance
 * of the plugin.
 * @imports is a hash of all services this plugin consumes.
 * @register is the callback to be called when the plugin is done initializing.
 */
module.exports = function setup(options, imports, register) {

  // "database" was a service this plugin consumes
  var db = imports.database;

  register(null, {
    // "auth" is a service this plugin provides
    auth: {
      users: function (callback) {
        db.keys(callback);
      },
      authenticate: function (username, password, callback) {
        db.get(username, function (user) {
          if (!(user && user.password === password)) {
            return callback();
          }
          callback(user);
        });
      }
    }
  });
};

Each plugin is a node module complete with a package.json file. It need not actually be in npm, it can be a simple folder in the code tree.

{
    "name": "auth",
    "version": "0.0.1",
    "main": "auth.js",
    "private": true,
    "plugin": {
        "consumes": ["database"],
        "provides": ["auth"]
    }
}

Config Format

The loadConfig function below can read an architect config file. This file can be either JSON or JS (or anything that node's require can read).

The sample calculator app has a config like this:

module.exports = [
  { packagePath: "architect-http", port: 8080 },
  { packagePath: "architect-http-static", root: "www" },
  "./plugins/calculator",
  "./plugins/db",
  "./plugins/auth"
]

Notice that the config is a list of plugin config options. If the only option in the config is packagePath, then a string can be used in place of the object. If you want to pass other options to the plugin when it's being created, you can put arbitrary properties here.

The plugin section in each plugin's package.json is also merged in as a prototype to the main config. This is where provides and consumes properties are usually set.

Architect main API

The architect module exposes two functions as it's main API.

createApp(config, [callback])

This function starts an architect config. The return value is an Architect instance. The optional callback will listen for both "error" and "ready" on the app object and report on which one happens first.

loadConfig(configPath)

This is a sync function that loads a config file and parses all the plugins into a proper config object for use with createApp. While this uses sync I/O all steps along the way are memoized and I/O only occurs on the first invocation. It's safe to call this in an event loop provided a small set of configPaths are used.

Class: Architect

Inherits from EventEmitter.

The createApp function returns an instance of Architect.

Event: "service" (name, service)

When a new service is registered, this event is emitted on the app. Name is the short name for the service, and service is the actual object with functions.

Event: "plugin" (plugin)

When a plugin registers, this event is emitted.

Event: "ready" (app)

When all plugins are done, the "ready" event is emitted. The value is the Architect instance itself.

More Repositories

1

core

Cloud9 Core - Part of the Cloud9 SDK for Plugin Development https://c9.github.io/core/ https://c9.io
JavaScript
2,564
star
2

install

Cloud9 SSH installer
Shell
180
star
3

vfs

A http friendly stream based vfs system for node.js
JavaScript
111
star
4

docs.c9.io

The documentation. For Cloud9 IDE.
HTML
90
star
5

smith

Smith is an RPC agent system for Node.JS used in vfs.
JavaScript
82
star
6

smith.io

JavaScript
74
star
7

vfs-local

A VFS implementation for the local file-system.
JavaScript
32
star
8

node-gnu-tools

GNU tools installer for npm
C
27
star
9

vfs-http-adapter

A Restful front-end to a vfs instance
JavaScript
26
star
10

node-bitbucket

node.js library to access the Bitbucket API
JavaScript
26
star
11

c9.ide.language.python

The repository for c9.ide.language.python, a Cloud9 core plugin
JavaScript
23
star
12

templates

Cloud9 Templates
Shell
22
star
13

c9.ide.collab

The repository for c9.ide.collab, a Cloud9 core plugin
JavaScript
15
star
14

node-http-error

Expose HTTP error codes as Error objects
JavaScript
14
star
15

connect-architect

build a connect server using architect plugins
JavaScript
14
star
16

c9.ide.run.debug

The repository for c9.ide.run.debug, a Cloud9 core plugin
JavaScript
13
star
17

c9.ide.run.debug.xdebug

Cloud9 debugger plugin for Xdebug
JavaScript
12
star
18

open-in-c9-extension

JavaScript
12
star
19

vfs-socket

A wrapper to use vfs instances remotely over a socket-like transport.
JavaScript
12
star
20

node-netutil

utils to find free ports in a range, checking if a port is open, etc
JavaScript
12
star
21

c9.ide.run

The repository for c9.ide.run, a Cloud9 core plugin
JavaScript
11
star
22

c9.ide.language.codeintel

The repository for c9.ide.language.codeintel, a Cloud9 core plugin
JavaScript
10
star
23

c9.ide.language.go

The repository for c9.ide.language.go, a Cloud9 core plugin
JavaScript
9
star
24

c9.ide.installer

The repository for c9.ide.installer, a Cloud9 core plugin
JavaScript
7
star
25

google.cloud

Cloud9 + Google Cloud Platform custom integration
JavaScript
7
star
26

vfs-architect

Architect plugins for VFS
JavaScript
7
star
27

c9.ide.ace.repl

The repository for c9.ide.ace.repl, a Cloud9 core plugin
JavaScript
6
star
28

c9.ide.format

The repository for c9.ide.format, a Cloud9 core plugin
JavaScript
6
star
29

c9.ide.language.javascript.tern

The repository for c9.ide.language.javascript.tern, a Cloud9 core plugin
JavaScript
5
star
30

c9.ide.run.build

The repository for c9.ide.run.build, a Cloud9 core plugin
JavaScript
5
star
31

vfs-ftp

A FTP client for vfs
JavaScript
5
star
32

architect-build

A simple utility to package architect apps
JavaScript
5
star
33

c9.ide.language

The repository for c9.ide.language, a Cloud9 core plugin
JavaScript
4
star
34

c9.ide.mount

The repository for c9.ide.mount, a Cloud9 core plugin
JavaScript
4
star
35

c9.ide.language.javascript

The repository for c9.ide.language.javascript, a Cloud9 core plugin
JavaScript
4
star
36

grav

Cloud9 plugin for the grav CMS
JavaScript
4
star
37

c9.ide.preview.browser

The repository for c9.ide.preview.browser, a Cloud9 core plugin
JavaScript
4
star
38

c9.ide.preview.markdown

The repository for c9.ide.preview.markdown, a Cloud9 core plugin
HTML
4
star
39

c9.ide.example

JavaScript
4
star
40

c9.ide.imgeditor

The repository for c9.ide.imgeditor, a Cloud9 core plugin
JavaScript
4
star
41

vfs-nodefs-adapter

A node-style api wrapper around vfs for quick migration of code.
JavaScript
3
star
42

c9.ide.remote

The repository for c9.ide.remote, a Cloud9 core plugin
JavaScript
3
star
43

c9.ide.ace.keymaps

The repository for c9.ide.ace.keymaps, a Cloud9 core plugin
JavaScript
3
star
44

c9.ide.scm

The repository for c9.ide.scm, a Cloud9 core plugin
JavaScript
3
star
45

c9.ide.language.core

The repository for c9.ide.language.core, a Cloud9 core plugin
JavaScript
3
star
46

c9.ide.find

The repository for c9.ide.find, a Cloud9 core plugin
JavaScript
3
star
47

c9.ide.language.javascript.infer

The repository for c9.ide.language.javascript.infer, a Cloud9 core plugin
JavaScript
3
star
48

c9.ide.local

The repository for c9.ide.local, a Cloud9 core plugin
JavaScript
3
star
49

c9.ide.test

The repository for c9.ide.test, a Cloud9 core plugin
JavaScript
3
star
50

c9.ide.preview

The repository for c9.ide.preview, a Cloud9 core plugin
JavaScript
3
star
51

c9.ide.language.html

The repository for c9.ide.language.html, a Cloud9 core plugin
JavaScript
3
star
52

c9.ide.navigate

The repository for c9.ide.navigate, a Cloud9 core plugin
JavaScript
3
star
53

c9.ide.language.javascript.immediate

The repository for c9.ide.language.javascript.immediate, a Cloud9 core plugin
JavaScript
3
star
54

c9.ide.find.infiles

The repository for c9.ide.find.infiles, a Cloud9 core plugin
JavaScript
3
star
55

c9.ide.immediate

The repository for c9.ide.immediate, a Cloud9 core plugin
JavaScript
3
star
56

c9.ide.pubsub

The repository for c9.ide.pubsub, a Cloud9 core plugin
JavaScript
3
star
57

c9.ide.ace.emmet

The repository for c9.ide.ace.emmet, a Cloud9 core plugin
JavaScript
3
star
58

c9.ide.language.html.diff

The repository for c9.ide.language.html.diff, a Cloud9 core plugin
JavaScript
3
star
59

c9.ide.language.css

The repository for c9.ide.language.css, a Cloud9 core plugin
JavaScript
3
star
60

c9.ide.ace.gotoline

The repository for c9.ide.ace.gotoline, a Cloud9 core plugin
JavaScript
2
star
61

c9.ide.ace.statusbar

The repository for c9.ide.ace.statusbar, a Cloud9 core plugin
JavaScript
2
star
62

c9.ide.welcome

The repository for c9.ide.welcome, a Cloud9 core plugin
JavaScript
2
star
63

c9.ide.save

The repository for c9.ide.save, a Cloud9 core plugin
JavaScript
2
star
64

c9.ide.fontawesome

The repository for c9.ide.fontawesome, a Cloud9 core plugin
JavaScript
2
star
65

c9.ide.ace.split

The repository for c9.ide.ace.split, a Cloud9 core plugin
JavaScript
2
star
66

c9.ide.readonly

The repository for c9.ide.readonly, a Cloud9 core plugin
JavaScript
2
star
67

c9.ide.find.replace

The repository for c9.ide.find.replace, a Cloud9 core plugin
JavaScript
2
star
68

c9.ide.recentfiles

The repository for c9.ide.recentfiles, a Cloud9 core plugin
JavaScript
2
star
69

c9.ide.closeconfirmation

The repository for c9.ide.closeconfirmation, a Cloud9 core plugin
JavaScript
2
star
70

c9.ide.openfiles

The repository for c9.ide.openfiles, a Cloud9 core plugin
JavaScript
2
star
71

c9.ide.language.javascript.eslint

The repository for c9.ide.language.javascript.eslint, a Cloud9 core plugin
JavaScript
2
star
72

c9.ide.guide

JavaScript
2
star
73

c9.ide.configuration

The repository for c9.ide.configuration, a Cloud9 core plugin
JavaScript
2
star
74

c9.ide.language.generic

The repository for c9.ide.language.generic, a Cloud9 core plugin
JavaScript
2
star
75

vfs-lint

A simple API lint wrapper for vfs instances.
JavaScript
2
star
76

c9.ide.processlist

The repository for c9.ide.processlist, a Cloud9 core plugin
JavaScript
2
star
77

c9.ide.behaviors

The repository for c9.ide.behaviors, a Cloud9 core plugin
JavaScript
2
star
78

c9.ide.dialog.wizard

The repository for c9.ide.dialog.wizard, a Cloud9 core plugin
JavaScript
2
star
79

c9.automate

The repository for c9.automate, a Cloud9 core plugin
JavaScript
2
star
80

c9.ide.terminal.monitor

The repository for c9.ide.terminal.monitor, a Cloud9 core plugin
JavaScript
2
star
81

c9.ide.ace.stripws

The repository for c9.ide.ace.stripws, a Cloud9 core plugin
JavaScript
2
star
82

c9.ide.undo

The repository for c9.ide.undo, a Cloud9 core plugin
JavaScript
2
star
83

vfs-shell-interop

This module is an extension to VFS which allows shell scripts to talk to VFS agents.
JavaScript
2
star
84

c9.ide.newresource

The repository for c9.ide.newresource, a Cloud9 core plugin
JavaScript
2
star
85

c9.ide.theme.flat

The repository for c9.ide.theme.flat, a Cloud9 core plugin
JavaScript
2
star
86

c9.ide.help.support

The repository for c9.ide.help.support, a Cloud9 core plugin
JavaScript
2
star
87

c9.ide.test.mocha

The repository for c9.ide.test.mocha, a Cloud9 core plugin
JavaScript
2
star
88

open-bitbucket-in-cloud9

Extension to open a BitBucket repository in Cloud9
2
star
89

c9.ide.upload

The repository for c9.ide.upload, a Cloud9 core plugin
JavaScript
2
star
90

c9.ide.language.jsonalyzer

The repository for c9.ide.language.jsonalyzer, a Cloud9 core plugin
JavaScript
2
star
91

c9.ide.threewaymerge

The repository for c9.ide.threewaymerge, a Cloud9 core plugin
JavaScript
2
star