threadforge 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +152 -0
  3. package/bin/forge.js +1050 -0
  4. package/bin/host-commands.js +344 -0
  5. package/bin/platform-commands.js +570 -0
  6. package/package.json +71 -0
  7. package/shared/auth.js +475 -0
  8. package/src/core/DirectMessageBus.js +364 -0
  9. package/src/core/EndpointResolver.js +247 -0
  10. package/src/core/ForgeContext.js +2227 -0
  11. package/src/core/ForgeHost.js +122 -0
  12. package/src/core/ForgePlatform.js +145 -0
  13. package/src/core/Ingress.js +768 -0
  14. package/src/core/Interceptors.js +420 -0
  15. package/src/core/MessageBus.js +310 -0
  16. package/src/core/Prometheus.js +305 -0
  17. package/src/core/RequestContext.js +413 -0
  18. package/src/core/RoutingStrategy.js +316 -0
  19. package/src/core/Supervisor.js +1306 -0
  20. package/src/core/ThreadAllocator.js +196 -0
  21. package/src/core/WorkerChannelManager.js +879 -0
  22. package/src/core/config.js +624 -0
  23. package/src/core/host-config.js +311 -0
  24. package/src/core/network-utils.js +166 -0
  25. package/src/core/platform-config.js +308 -0
  26. package/src/decorators/ServiceProxy.js +899 -0
  27. package/src/decorators/index.js +571 -0
  28. package/src/deploy/NginxGenerator.js +865 -0
  29. package/src/deploy/PlatformManifestGenerator.js +96 -0
  30. package/src/deploy/RouteManifestGenerator.js +112 -0
  31. package/src/deploy/index.js +984 -0
  32. package/src/frontend/FrontendDevLifecycle.js +65 -0
  33. package/src/frontend/FrontendPluginOrchestrator.js +187 -0
  34. package/src/frontend/SiteResolver.js +63 -0
  35. package/src/frontend/StaticMountRegistry.js +90 -0
  36. package/src/frontend/index.js +5 -0
  37. package/src/frontend/plugins/index.js +2 -0
  38. package/src/frontend/plugins/viteFrontend.js +79 -0
  39. package/src/frontend/types.js +35 -0
  40. package/src/index.js +56 -0
  41. package/src/internals.js +31 -0
  42. package/src/plugins/PluginManager.js +537 -0
  43. package/src/plugins/ScopedPostgres.js +192 -0
  44. package/src/plugins/ScopedRedis.js +142 -0
  45. package/src/plugins/index.js +1729 -0
  46. package/src/registry/ServiceRegistry.js +796 -0
  47. package/src/scaling/ScaleAdvisor.js +442 -0
  48. package/src/services/Service.js +195 -0
  49. package/src/services/worker-bootstrap.js +676 -0
  50. package/src/templates/auth-service.js +65 -0
  51. package/src/templates/identity-service.js +75 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 ThreadForge Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # ThreadForge
2
+
3
+ A multi-threaded Node.js service runtime framework. Deploy multiple services on the same machine, intelligently distributed across available CPU cores, with built-in IPC messaging, metrics, and lifecycle management.
4
+
5
+ ## Why ThreadForge?
6
+
7
+ Node.js runs on a single thread. Modern servers have 16, 32, 64+ cores. ThreadForge bridges that gap by giving you a declarative way to run multiple services across all available cores — with zero-overhead inter-service communication via IPC instead of HTTP.
8
+
9
+ **Key features:**
10
+
11
+ - **Declarative service config** — define services, ports, thread allocation, and topology in one file
12
+ - **Smart thread allocation** — auto-distributes cores by weight, or set fixed counts
13
+ - **3-tier IPC resolution** — colocated (direct call) → Unix Domain Socket → HTTP fallback
14
+ - **Colocation groups** — pack lightweight services into a shared process for zero-overhead calls
15
+ - **TC39 decorators** — `@Route`, `@Expose`, `@Emit`, `@On`, `@Validate` and more
16
+ - **Plugin system** — Redis, PostgreSQL, S3, CORS, Cron, Realtime — with custom plugin support
17
+ - **Auto-restart** — crashed workers are automatically replaced
18
+ - **Runtime scaling** — scale services up/down without restarting
19
+ - **RequestContext propagation** — correlation IDs, auth, deadlines, and baggage across services
20
+ - **Built-in metrics** — Prometheus-compatible endpoint out of the box
21
+ - **Multi-machine deployment** — grow from one machine to a full cluster with `forge.deploy.js`
22
+
23
+ ## Quick Start
24
+
25
+ > **Note:** ThreadForge is not yet published to npm. See installation options below.
26
+
27
+ ### Option 1: Local Development (Recommended)
28
+
29
+ ```bash
30
+ # Clone and link ThreadForge locally
31
+ git clone https://github.com/ChrisBland/threadforge.git
32
+ cd threadforge
33
+ npm install
34
+ npm link
35
+
36
+ # Create your project
37
+ mkdir my-app && cd my-app
38
+ npm link threadforge
39
+ forge init . --source local
40
+ npm install
41
+
42
+ # Start
43
+ npm run dev
44
+ ```
45
+
46
+ ### Option 2: Install from GitHub
47
+
48
+ ```bash
49
+ # Scaffold a new project
50
+ npx github:ChrisBland/threadforge init my-app
51
+ cd my-app
52
+ npm install
53
+
54
+ # Start in development mode (hot reload)
55
+ npm run dev
56
+
57
+ # Start in production mode
58
+ npm run start
59
+ ```
60
+
61
+ If `npx github:ChrisBland/threadforge ...` fails with npm cache permission errors (`EPERM` on `~/.npm/_cacache`), use a writable cache directory for the command:
62
+
63
+ ```bash
64
+ NPM_CONFIG_CACHE=/tmp/threadforge-npm-cache npx github:ChrisBland/threadforge init my-app
65
+ ```
66
+
67
+ Create `forge.config.js`:
68
+
69
+ ```javascript
70
+ import { defineServices } from 'threadforge';
71
+
72
+ export default defineServices({
73
+ api: {
74
+ entry: './services/api.js',
75
+ type: 'edge',
76
+ port: 3000,
77
+ threads: 'auto',
78
+ connects: ['users'],
79
+ },
80
+
81
+ users: {
82
+ entry: './services/users.js',
83
+ type: 'internal',
84
+ },
85
+ });
86
+ ```
87
+
88
+ Create `services/api.js`:
89
+
90
+ ```javascript
91
+ import { Service } from 'threadforge';
92
+
93
+ export default class ApiService extends Service {
94
+ static contract = {
95
+ routes: [
96
+ { method: 'GET', path: '/users/:id', handler: 'getUser' },
97
+ ],
98
+ };
99
+
100
+ async getUser(body, params) {
101
+ return await this.users.getUser(params.id);
102
+ }
103
+ }
104
+ ```
105
+
106
+ Create `services/users.js`:
107
+
108
+ ```javascript
109
+ import { Service } from 'threadforge';
110
+
111
+ export default class UsersService extends Service {
112
+ static contract = {
113
+ expose: ['getUser'],
114
+ };
115
+
116
+ async onStart(ctx) {
117
+ this.store = new Map([['1', { id: '1', name: 'Alice' }]]);
118
+ }
119
+
120
+ async getUser(id) {
121
+ return this.store.get(String(id));
122
+ }
123
+ }
124
+ ```
125
+
126
+ ```bash
127
+ forge start
128
+ # curl http://localhost:3000/users/1
129
+ # → { "id": "1", "name": "Alice" }
130
+ ```
131
+
132
+ ## Documentation
133
+
134
+ Full documentation is in the [`docs/`](./docs/) directory:
135
+
136
+ - [**Getting Started**](./docs/getting-started.md) — Install, create your first service, and run it
137
+ - [**Architecture**](./docs/architecture.md) — Process model, communication layers, request lifecycle
138
+ - **Guides:**
139
+ - [Services](./docs/guides/services.md) — Types, lifecycle, colocation, plain JS fallback
140
+ - [IPC & Communication](./docs/guides/ipc.md) — Proxy clients, events, interceptors
141
+ - [Plugins](./docs/guides/plugins.md) — Redis, PostgreSQL, S3, CORS, Cron, Realtime
142
+ - [Deployment](./docs/guides/deployment.md) — Single machine to multi-machine scaling
143
+ - **Reference:**
144
+ - [Configuration](./docs/reference/configuration.md) — All `forge.config.js` options
145
+ - [Decorators](./docs/reference/decorators.md) — Full decorator API
146
+ - [CLI](./docs/reference/cli.md) — Commands, options, metrics endpoints
147
+ - [API](./docs/reference/api.md) — All public exports
148
+ - [**ForgeProxy**](./docs/FORGEPROXY_ARCHITECTURE.js) — Rust gateway design and performance
149
+
150
+ ## License
151
+
152
+ MIT