bhooai-nexus 0.1.2 → 0.1.3

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 (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +238 -135
  3. package/docs/ARCHITECTURE.md +141 -0
  4. package/docs/IMPROVEMENTS.md +100 -0
  5. package/docs/api/admin.html +651 -0
  6. package/docs/api/ads.html +314 -0
  7. package/docs/api/ai-client.html +336 -0
  8. package/docs/api/auth.html +697 -0
  9. package/docs/api/cache.html +331 -0
  10. package/docs/api/cli.html +612 -0
  11. package/docs/api/cluster.html +489 -0
  12. package/docs/api/core.html +796 -0
  13. package/docs/api/crypto.html +310 -0
  14. package/docs/api/data.html +811 -0
  15. package/docs/api/email.html +345 -0
  16. package/docs/api/graphql.html +697 -0
  17. package/docs/api/http-endpoints.html +221 -0
  18. package/docs/api/node-agent.html +155 -0
  19. package/docs/api/payments.html +558 -0
  20. package/docs/api/plugins.html +522 -0
  21. package/docs/api/realtime.html +324 -0
  22. package/docs/api/safe-goto.html +215 -0
  23. package/docs/api/supervisor.html +312 -0
  24. package/docs/api/telemetry.html +264 -0
  25. package/docs/api/websockets.html +163 -0
  26. package/docs/architecture.html +211 -0
  27. package/docs/assets/bhooai-nexus-cluster-link.postman_collection.json +185 -0
  28. package/docs/assets/bhooai-nexus-local.postman_environment.json +47 -0
  29. package/docs/assets/bhooai-nexus-logo.png +0 -0
  30. package/docs/assets/bhooai-nexus-logo.svg +135 -0
  31. package/docs/assets/docs.js +368 -0
  32. package/docs/assets/favicon.ico +0 -0
  33. package/docs/assets/favicon.zip +0 -0
  34. package/docs/assets/nav.js +88 -0
  35. package/docs/assets/playground.js +283 -0
  36. package/docs/assets/screenshots/01-collection.png +0 -0
  37. package/docs/assets/screenshots/02-step1-csrf.png +0 -0
  38. package/docs/assets/screenshots/03-step2-login.png +0 -0
  39. package/docs/assets/screenshots/04-step3-link.png +0 -0
  40. package/docs/assets/screenshots/05-error-fetch-failed.png +0 -0
  41. package/docs/assets/screenshots/06-error-agent-401.png +0 -0
  42. package/docs/assets/screenshots/07-error-401-csrf.png +0 -0
  43. package/docs/assets/screenshots/08-env-runner.png +0 -0
  44. package/docs/assets/screenshots/visual-flow.png +0 -0
  45. package/docs/assets/style.css +1140 -0
  46. package/docs/examples.html +248 -0
  47. package/docs/favicon.ico +0 -0
  48. package/docs/getting-started.html +138 -0
  49. package/docs/guides/guide-ai-chat.html +202 -0
  50. package/docs/guides/guide-auth.html +328 -0
  51. package/docs/guides/guide-cluster.html +325 -0
  52. package/docs/guides/guide-email.html +234 -0
  53. package/docs/guides/guide-empty-project.html +279 -0
  54. package/docs/guides/guide-graphql.html +214 -0
  55. package/docs/guides/guide-mongodb.html +220 -0
  56. package/docs/guides/guide-payments.html +321 -0
  57. package/docs/guides/guide-uploads.html +170 -0
  58. package/docs/guides/guide-websocket.html +263 -0
  59. package/docs/improvements.html +146 -0
  60. package/docs/index.html +101 -0
  61. package/docs/learn/01-foundation.html +129 -0
  62. package/docs/learn/02-security.html +104 -0
  63. package/docs/learn/03-data.html +99 -0
  64. package/docs/learn/04-graphql.html +86 -0
  65. package/docs/learn/05-realtime.html +76 -0
  66. package/docs/learn/06-payments-email-crypto.html +93 -0
  67. package/docs/learn/07-cache-ads.html +85 -0
  68. package/docs/learn/08-ai.html +93 -0
  69. package/docs/learn/09-plugins.html +81 -0
  70. package/docs/learn/10-cluster.html +83 -0
  71. package/docs/learn/11-cli.html +183 -0
  72. package/docs/learn/12-apps.html +105 -0
  73. package/docs/learn/13-tests.html +79 -0
  74. package/docs/learn/14-postman-testing.html +580 -0
  75. package/docs/learn/PLAN.md +59 -0
  76. package/docs/learn/index.html +87 -0
  77. package/docs/screenshots/README.md +23 -0
  78. package/docs/screenshots/ai-agents-playground.png +0 -0
  79. package/docs/screenshots/ai-agents-providers.png +0 -0
  80. package/docs/screenshots/ai-agents.png +0 -0
  81. package/docs/screenshots/appearance.png +0 -0
  82. package/docs/screenshots/cluster-master.png +0 -0
  83. package/docs/screenshots/cluster-nodes.png +0 -0
  84. package/docs/screenshots/cluster-slave.png +0 -0
  85. package/docs/screenshots/login.png +0 -0
  86. package/docs/screenshots/logs-ai-summary.png +0 -0
  87. package/docs/screenshots/monitoring.png +0 -0
  88. package/docs/screenshots/nexus-dev.png +0 -0
  89. package/docs/screenshots/nexus-init.png +0 -0
  90. package/docs/screenshots/notification.png +0 -0
  91. package/docs/screenshots/overview.png +0 -0
  92. package/docs/screenshots/search-bar.png +0 -0
  93. package/docs/screenshots/settings.png +0 -0
  94. package/docs/screenshots/themes.png +0 -0
  95. package/package.json +5 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BhooAI
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 CHANGED
@@ -1,184 +1,287 @@
1
1
  # BhooAI Nexus
2
2
 
3
- A Node-based full-stack framework: websockets, GraphQL federation (no Apollo), inbuilt CSRF/CORS, a from-scratch ODM on the MongoDB driver, Google/Facebook OAuth, five payment gateways, email, public/private certificate generation, Redis cache, Google Ads, WebRTC live streaming, a Python AI server (OpenAI + Ollama), an admin project, and a plugin system — all driven by a single `nexus.config.ts` and a `/bin` CLI.
3
+ Build full-stack Node.js applications with one CLI and one configuration file. BhooAI Nexus includes an HTTP server, WebSockets, GraphQL federation, MongoDB data access, authentication, CSRF/CORS protection, payments, email, WebRTC, Python AI services, plugins, an admin console, and master/slave cluster orchestration.
4
4
 
5
- This directory is the package and workspace root. Its `package.json` and
6
- `package-lock.json` live here; the parent `BhooAI-Nexus/` directory is only a
7
- container and is not an npm project.
5
+ ## Features
8
6
 
9
- The `apps/admin/` panel is built into this package and shared by every project created
10
- with `nexus init`. Generated projects only contain a launcher; the common panel
11
- source remains owned by this package.
7
+ - Node.js HTTP server with trie routing, middleware, uploads, static files, security headers, CORS, CSRF, and rate limiting
8
+ - MongoDB ODM with schemas, hooks, indexes, populate, and transactions
9
+ - JWT access tokens, refresh tokens, sessions, Google OAuth, Facebook OAuth, and role-based access control
10
+ - WebSockets, Redis adapters, WebRTC signaling, and mediasoup SFU integration
11
+ - GraphQL subscriptions, federation composition, entity joins, `@provides`, and `@requires`
12
+ - Razorpay, PayPal, PayU, Skrill, and Payoneer integrations
13
+ - Email, certificate generation, Redis cache, Google Ads, and plugin extensions
14
+ - Python FastAPI AI server with OpenAI-compatible chat, embeddings, Ollama, and SSE streaming
15
+ - Admin console with configuration, environment, process, monitoring, database, AI, and cluster management
16
+ - Master/slave cluster mesh with load balancing, node agents, request allocation, health checks, and upload path pinning
12
17
 
13
- ## Layout
18
+ ## Requirements
14
19
 
15
- ```
16
- packages/ scoped framework packages (@bhooai/nexus-*)
17
- apps/ backend (Node), frontend (React+Vite+Tailwind), ai-server (Python FastAPI)
18
- apps/admin/ admin project (React+Vite+TS) — manages config, plugins, the user project
19
- bin/ CLI entry — `node bin/nexus.js <command>`
20
- contracts/ Node↔Python contract (single source of truth)
21
- plugins/ user-created plugins
22
- tests/ cross-service e2e (Playwright) driving the real backend
23
- logs/ certs/ generated at runtime (gitignored)
24
- ```
25
-
26
- ## Quick start
20
+ - Node.js `>=20.10`
21
+ - npm, included with Node.js
22
+ - MongoDB 7 or newer, running locally or reachable through `MONGODB_URI`
23
+ - Redis 7 or newer, running locally or reachable through `REDIS_URL`
24
+ - Python 3.10 or newer for the optional AI server
25
+ - A virtual environment is recommended for Python dependencies
27
26
 
28
- ```bash
29
- npm install # install workspaces
30
- npm run doctor # verify node/python/mongo/redis
31
- npm run dev # start the four terminals under the supervisor
32
- npm test # vitest (Node) + pytest (Python)
33
- ```
27
+ The Python service dependencies are listed in [`apps/ai-server/requirements.txt`](apps/ai-server/requirements.txt): FastAPI, Uvicorn, HTTPX, pytest, and pytest-asyncio.
34
28
 
35
- ## Use as an npm package
29
+ MongoDB and Redis can be started with Docker, system services, or managed cloud providers. The AI server is optional when AI features are not used.
36
30
 
37
- Publish the public workspace packages together from the framework repository:
31
+ ## Install
38
32
 
39
33
  ```bash
40
- npm publish
34
+ npm install bhooai-nexus
35
+ npx nexus init my-app
36
+ cd my-app
37
+ npm run doctor
38
+ npm run dev
41
39
  ```
42
40
 
43
- Then a new app can be created without copying the framework repository:
41
+ Initialize the current directory with `npx nexus init .`. Use `npx nexus init . --skip-install` to defer dependency installation.
42
+
43
+ ## Quick Start
44
44
 
45
45
  ```bash
46
- mkdir my-app
46
+ npm install bhooai-nexus
47
+ npx nexus init my-app
47
48
  cd my-app
48
- npm init -y
49
- npm install C:\server\BhooAI\BhooAI-Nexus\BhooAI-Nexus\bhooai-nexus
50
- npx nexus init .
51
49
  npm run doctor
52
50
  npm run dev
53
51
  ```
54
52
 
55
- `bhooai-nexus` installs the `nexus` executable. `nexus init` copies the backend, frontend, AI,
56
- admin, config, and `uploads/` scaffold into the current directory, then automatically runs
57
- `npm install` for React, Vite, the admin workspace, and framework packages. Use
58
- `nexus init . --skip-install` when dependency installation should be deferred.
53
+ Default development services:
54
+
55
+ | Service | Default port |
56
+ | --- | ---: |
57
+ | Backend API | `4000` |
58
+ | Frontend | `3000` |
59
+ | Admin console | `3300` |
60
+ | Python AI server | `8000` |
61
+ | Cluster load balancer | `8080` |
62
+ | Node agent | `7575` |
63
+
64
+ `nexus dev` automatically moves a configured port to the next available port, allowing master and slave projects to run side by side on one machine.
65
+
66
+ ## Screenshots
67
+
68
+ ### Admin login
69
+
70
+ ![BhooAI Nexus admin login](docs/screenshots/login.png)
71
+
72
+ ### Overview dashboard
73
+
74
+ ![BhooAI Nexus overview dashboard](docs/screenshots/overview.png)
75
+
76
+ ### Master cluster management
77
+
78
+ ![BhooAI Nexus master cluster management](docs/screenshots/cluster-master.png)
79
+
80
+ ### Slave node agent and roles
81
+
82
+ ![BhooAI Nexus slave node agent](docs/screenshots/cluster-slave.png)
83
+
84
+ ### Connected cluster nodes
85
+
86
+ ![Connected cluster nodes](docs/screenshots/cluster-nodes.png)
87
+
88
+ ### AI agents
89
+
90
+ ![AI agents](docs/screenshots/ai-agents.png)
91
+
92
+ ### AI providers
93
+
94
+ ![AI agent providers](docs/screenshots/ai-agents-providers.png)
95
+
96
+ ### AI playground
97
+
98
+ ![AI playground](docs/screenshots/ai-agents-playground.png)
99
+
100
+ ### Monitoring
101
+
102
+ ![Monitoring dashboard](docs/screenshots/monitoring.png)
103
+
104
+ ### Settings
105
+
106
+ ![Settings](docs/screenshots/settings.png)
107
+
108
+ ### Themes
109
+
110
+ ![Theme selection](docs/screenshots/themes.png)
111
+
112
+ ### Appearance
113
+
114
+ ![Appearance settings](docs/screenshots/appearance.png)
115
+
116
+ ### Search
117
+
118
+ ![Admin search](docs/screenshots/search-bar.png)
119
+
120
+ ### Notifications
121
+
122
+ ![Notifications](docs/screenshots/notification.png)
123
+
124
+ ### AI log summary
125
+
126
+ ![AI log summary](docs/screenshots/logs-ai-summary.png)
127
+
128
+ ### Nexus development services
129
+
130
+ ![Nexus development services](docs/screenshots/nexus-dev.png)
131
+
132
+ ### Nexus initialization
133
+
134
+ ![Nexus initialization](docs/screenshots/nexus-init.png)
59
135
 
60
- Four terminals boot under one supervisor: backend (`:4000`), frontend (`:3000`),
61
- admin (`:3001`), and the Python AI server (`:8000`). Each is also runnable standalone.
136
+ ## Cluster Mesh
62
137
 
63
- ## Scaffold a new project
138
+ BhooAI Nexus supports a central master and one or more slave nodes.
139
+
140
+ Initialize a master:
64
141
 
65
142
  ```bash
66
- node bin/nexus.js init ./my-app
67
- cd my-app
68
- npm run doctor # check the environment
69
- npm run dev # start all four terminals
143
+ npx nexus init master --as=root
144
+ ```
145
+
146
+ Initialize a slave with a built-in role:
147
+
148
+ ```bash
149
+ npx nexus init slave-1 --as=node --role=backend --port=7575
150
+ npx nexus init slave-2 --as=node --role=files --port=7576
70
151
  ```
71
152
 
72
- `init` copies a real, runnable project tree from `packages/nexus-cli/templates/`
73
- — the generated backend boots a Nexus HTTP server with the full security stack
74
- (CSRF/CORS/security headers) and serves `/health`, `/csrf-token`, `/echo`, and the CSRF-protected
75
- multipart upload endpoint `/uploads`. Uploaded files are stored below the project-local `uploads/`
76
- directory and served at `/uploads/<generated-name>`.
153
+ Supported node roles are `backend`, `files`, `database`, and `ai`.
154
+
155
+ After `npm run dev`, a node project automatically starts its node agent. The agent exposes the control API and advertises the node's development backend without starting a duplicate backend process.
156
+
157
+ The master load balancer listens on port `8080` and distributes traffic across ready backend nodes. Authentication routes are pinned to the master:
158
+
159
+ - `/auth/*`
160
+ - `/csrf-token`
161
+
162
+ Use the same `NEXUS_AUTH_JWT_SECRET` on all nodes so slaves can verify master-issued access tokens.
163
+
164
+ ### Upload path allocation
165
+
166
+ The master admin console includes **Cluster → Path routing**. Pin URL prefixes to specific nodes:
167
+
168
+ ```text
169
+ /uploads/images -> slave-1
170
+ /uploads/files -> slave-2
171
+ ```
172
+
173
+ Path pins use longest-prefix matching. A pinned request is sent only to its configured node. If the pinned node is unavailable, the load balancer returns `503 pinned_node_down` instead of silently sending the request to another node.
174
+
175
+ When no slave nodes are linked, the load balancer fails open to the master's own backend if `cluster.failOpenSingleNode` is enabled. This keeps a cluster-enabled master usable as a single-node installation.
176
+
177
+ Upload endpoints accept both `/uploads` and sub-paths such as `/uploads/images`. The upload directory is created automatically on the node that handles the request.
178
+
179
+ ## Admin Console
180
+
181
+ Open the admin console at `http://localhost:3300` during development. The console provides overview, processes, logs, configuration, environment, plugins, users, monitoring, payments, databases, schema, AI, and cluster management.
182
+
183
+ The Cluster tab includes connected-node cards with request allocation percentage, CPU, memory, freshness, service health, test, enable, restart, and unlink controls. Slave mode includes role selection, node-agent status, pairing tokens, node IDs, and copyable serve/link commands. Master mode includes path-prefix routing for uploads and other services.
77
184
 
78
185
  ## Configuration
79
186
 
80
- Edit `nexus.config.ts`. Precedence (low → high): code defaults < `nexus.config.ts`
81
- < `nexus.runtime.json` (admin write-back, gitignored) < env vars < CLI flags.
82
- Put secrets directly in a project-root `.env` (no `.env.example` — the framework
83
- loads `.env` itself). Admin overrides write only to
84
- `nexus.runtime.json` so the human config file stays clean.
85
-
86
- ## Admin console
87
-
88
- The admin app (`apps/admin/`, Vite on `:3001`, backend-adjacent) is an `admin`-role
89
- login gate plus a glass dashboard. Overview, Processes, Configuration, Environment,
90
- Plugins, Users, Monitoring, Payments, Databases, and AI Schema.
91
-
92
- - **Theme & mode** — three themes (Aurora, Midnight, Violet) and three interface
93
- modes (Workspace, Compact, Focus), persisted in browser local storage and applied
94
- to the login screen too. Desktop shell is a fixed 80% of the actual screen width;
95
- responsive down to a full-width mobile drawer.
96
- - **Configuration** — grouped key/value editor (add-key box on top, autoloads the
97
- current config) writing to `nexus.runtime.json`, plus an effective merged view
98
- and a raw source editor for `nexus.config.ts`.
99
- - **Environment** — masked grouped key/value editor for `.env`; secrets stay on
100
- disk and are never returned to the browser.
101
- - **Safety** — custom restart-required dialog after config/env saves and a
102
- confirmation dialog for destructive database/collection drops; writes are
103
- schema-validated with atomic file replacement.
104
-
105
- See [`apps/admin/README.md`](apps/admin/README.md) for full details and routes.
106
-
107
- ## Testing & CI
108
-
109
- - **Unit/integration:** `npx vitest run` across all workspace packages (real MongoDB
110
- via `.env`; Redis optional). Frontend client tests run under `apps/frontend`.
111
- - **Python:** `pytest` in `apps/ai-server` (FastAPI contract tests).
112
- - **E2E:** `npx playwright test --config=playwright.config.ts` boots the real backend
113
- on a throwaway port + DB and drives auth → CSRF → GraphQL → payments end to end.
114
- - **CI:** `workflows/ci.yml` runs a **Linux** job (full suite with Mongo + Redis
115
- service containers, pytest, Playwright e2e) and a **Windows** job (build, the
116
- Mongo/Redis-free unit suites, frontend tests, and `nexus init`/`doctor` verification).
187
+ Edit `nexus.config.ts`. Configuration precedence is:
117
188
 
118
- ## Documentation
189
+ ```text
190
+ code defaults < nexus.config.ts < nexus.runtime.json < NEXUS_* environment variables < CLI flags
191
+ ```
119
192
 
120
- - [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) — full architecture, data flow, and
121
- component deep-dives (federation, ODM, plugins).
122
- - [`docs/IMPROVEMENTS.md`](docs/IMPROVEMENTS.md) — improvements made during the build,
123
- 28 suggested next steps, and an honest seams table.
124
- - Per-package READMEs under `packages/nexus-*/README.md`.
125
- - [`apps/admin/README.md`](apps/admin/README.md) — admin console UI, theme, and config/env editing.
193
+ Admin changes are written to the gitignored `nexus.runtime.json` file. Store secrets in the project `.env` file:
126
194
 
127
- ## Status — complete (12/12 phases)
195
+ ```env
196
+ MONGODB_URI=mongodb://localhost:27017/my-app
197
+ REDIS_URL=redis://localhost:6379
198
+ NEXUS_AUTH_JWT_SECRET=replace-with-a-long-random-secret
199
+ ```
128
200
 
129
- - ✅ Phase 0 — Foundations (config loader + precedence, DI, telemetry, CLI doctor/init, supervisor)
130
- - ✅ Phase 1 — HTTP + Security (custom `node:http` server, trie router, CSRF/CORS/headers/rate-limit)
131
- - ✅ Phase 2 — Data layer (custom ODM on the `mongodb` driver — schemas, hooks, populate, transactions, indexes)
132
- - ✅ Phase 3 — Auth (local JWT+refresh+sessions, Google + Facebook OAuth2, CSRF on auth + WS upgrade)
133
- - ✅ Phase 4 — Realtime + WebRTC signaling (WS rooms, Redis adapter, WS auth, mediasoup SFU)
134
- - ✅ Phase 5 — GraphQL (single subgraph, `_service`/`_entities`, subscriptions over WS)
135
- - ✅ Phase 6 — Federation (composition, supergraph SDL, query planner, entity joins, `@provides`/`@requires`)
136
- - ✅ Phase 7 — Payments (Razorpay + PayPal full, PayU/Skrill/Payoneer happy-path) + Email + Crypto (keypair/X.509/CSR) + Cache + Ads
137
- - ✅ Phase 8 — Plugins (trusted in-process + sandboxed worker_threads, capability policy, admin extensions)
138
- - ✅ Phase 9 — Python AI server (FastAPI, OpenAI + Ollama, SSE) + Node AI client
139
- - ✅ Phase 10 — Admin + supervisor (process control API, config editor → runtime.json, plugins, users, monitoring)
140
- - ✅ Phase 11 — Frontend (React + Vite + Tailwind; auth UI, non-Apollo graphql client, WS client, checkout, live-stream viewer)
141
- - ✅ Phase 12 — Hardening, docs, e2e, release (Playwright e2e, Win+Linux CI, `nexus init` upgrade, docs)
201
+ Common port overrides include `NEXUS_SERVER_PORT`, `NEXUS_FRONTEND_PORT`, `NEXUS_ADMIN_PORT`, `NEXUS_CLUSTER_LBPORT`, `NEXUS_CLUSTER_NODEAGENTPORT`, and `AI_PORT`.
142
202
 
143
- ## Dependency policy
203
+ ## Uninstall
144
204
 
145
- Built from scratch where it matters: **no Apollo**, **no mongoose**, **no express**.
146
- Allowed: `graphql` (graphql-js core), `mongodb`, `ws`, `nodemailer`, `node-redis`,
147
- `bcrypt`, `jose`, `mediasoup`/`mediasoup-client`, `google-ads-api`. The federation
148
- layer, ODM, HTTP server, and plugin sandbox are all hand-rolled.
205
+ Preview changes:
149
206
 
207
+ ```bash
208
+ npx nexus uninstall --dry-run
209
+ ```
150
210
 
151
- ## Docker Windows
211
+ Remove the project database and registration while keeping files:
152
212
 
153
- In project directory, open PowerShell and run:
154
213
  ```bash
155
- `.\docker.ps1 run` # start the container
156
- `.\docker.ps1 build` # build the image first
157
- `.\docker.ps1 run -f` # start + follow logs
158
- `.\docker.ps1 logs` # tail logs
159
- `.\docker.ps1 stop` # stop container
160
- `.\docker.ps1 rm` # stop + remove
214
+ npx nexus uninstall
161
215
  ```
162
216
 
163
- Or from cmd:
217
+ Remove the database, registration, and project directory:
218
+
164
219
  ```bash
165
- `docker.bat build`
166
- `docker.bat run`
220
+ npx nexus uninstall --purge
167
221
  ```
168
222
 
169
- Note: if PowerShell blocks it, allow first with:
170
- Set-ExecutionPolicy -Scope Process Bypass
171
- After run, access:
172
- ```ps1
173
- frontend http://localhost:3000
174
- admin http://localhost:3001
175
- backend http://localhost:4000/health
223
+ Skip confirmations or keep the database:
224
+
225
+ ```bash
226
+ npx nexus uninstall --purge --force
227
+ npx nexus uninstall --keep-db
228
+ ```
229
+
230
+ Uninstall does not remove the framework package, MongoDB's `nexus_projects` database, or other projects.
231
+
232
+ ## Project Layout
233
+
234
+ ```text
235
+ packages/ Framework packages (@bhooai/nexus-*)
236
+ apps/backend/ Node.js backend
237
+ apps/frontend/ React + Vite frontend
238
+ apps/admin/ React + Vite admin host
239
+ apps/ai-server/ Python FastAPI AI service
240
+ bin/ CLI entry point
241
+ contracts/ Node-to-Python API contracts
242
+ plugins/ Project plugins
243
+ tests/ Cross-service tests
244
+ docs/ Architecture, improvements, and screenshots
245
+ ```
246
+
247
+ ## Testing
248
+
249
+ ```bash
250
+ npx vitest run
251
+ cd apps/ai-server
252
+ python -m pip install -r requirements.txt
253
+ pytest
176
254
  ```
177
255
 
178
- ## Docker Linux
256
+ Run Playwright end-to-end tests from the framework root:
179
257
 
180
258
  ```bash
181
- cd project-directory
182
- ./docker.sh build
183
- ./docker.sh run
259
+ npx playwright test --config=playwright.config.ts
184
260
  ```
261
+
262
+ ## Docker
263
+
264
+ ```powershell
265
+ .\docker.ps1 build
266
+ .\docker.ps1 run
267
+ .\docker.ps1 logs
268
+ .\docker.ps1 stop
269
+ ```
270
+
271
+ Development endpoints are frontend `http://localhost:3000`, admin `http://localhost:3300`, and backend `http://localhost:4000/health`.
272
+
273
+ ## Documentation
274
+
275
+ - [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) — architecture and data flow
276
+ - [`docs/IMPROVEMENTS.md`](docs/IMPROVEMENTS.md) — improvement history
277
+ - [`docs/screenshots/README.md`](docs/screenshots/README.md) — screenshot catalog
278
+ - [`apps/ai-server/README.md`](apps/ai-server/README.md) — Python AI service
279
+ - Package documentation under `packages/nexus-*/README.md`
280
+
281
+ ## Design Principles
282
+
283
+ BhooAI Nexus avoids Apollo, Express, and Mongoose where direct control is required. The HTTP server, trie router, ODM, federation layer, and plugin sandbox are implemented in the workspace. Established libraries are used for standards and infrastructure, including GraphQL.js, MongoDB, Redis, WebSockets, Nodemailer, Jose, and mediasoup.
284
+
285
+ ## License
286
+
287
+ BhooAI Nexus is released under the [MIT License](LICENSE).
@@ -0,0 +1,141 @@
1
+ # BhooAI Nexus — Architecture
2
+
3
+ BhooAI Nexus is a source-first full-stack framework. A typed config file (`nexus.config.ts`), a project-root `.env`, and the `/bin` CLI drive four services under one supervisor: a Node backend, a React+Vite frontend, a Python (FastAPI) AI server, and a React admin app.
4
+
5
+ ## Repository shape (npm workspaces)
6
+
7
+ ```
8
+ BhooAI-Nexus/ (container; no package.json)
9
+ └── bhooai-nexus/ package/workspace root
10
+ ├── package.json workspaces root: packages/*, apps/*, admin
11
+ ├── package-lock.json workspace lockfile
12
+ ├── bin/nexus.js CLI entry (loads @bhooai/nexus-cli via tsx, no build step)
13
+ ├── nexus.config.ts framework reference config
14
+ ├── nexus.runtime.json gitignored — admin write-back overrides
15
+ ├── contracts/ai-openapi.yaml Node↔Python AI contract (single source of truth)
16
+ ├── packages/ 14 scoped framework packages
17
+ │ ├── nexus-core http (node:http, no express), router, middleware, config, DI
18
+ │ ├── nexus-telemetry structured logger, metrics, request/trace IDs
19
+ │ ├── nexus-auth CORS, CSRF, security headers, rate limit, JWT, OAuth, RBAC
20
+ │ ├── nexus-data custom ODM on the mongodb driver (no mongoose)
21
+ │ ├── nexus-graphql graphql-js + custom federation/gateway (no Apollo)
22
+ │ ├── nexus-realtime WS server, rooms, Redis pub/sub, WebRTC signaling, mediasoup SFU
23
+ │ ├── nexus-payments PaymentProvider + Razorpay/PayPal/PayU/Skrill/Payoneer + webhooks
24
+ │ ├── nexus-email SMTP (nodemailer) + templates + queue
25
+ │ ├── nexus-crypto RSA/EC keypair, X.509 self-signed, CSR (hand-rolled DER)
26
+ │ ├── nexus-cache Redis wrapper + cache-aside + rate-limit backend
27
+ │ ├── nexus-ads Google Ads REST client (GAQL)
28
+ │ ├── nexus-ai-client Node client for the Python AI server (SSE, retries, timeout)
29
+ │ ├── nexus-plugins plugin runtime: manifest, host, sandbox, hooks
30
+ │ └── nexus-cli init, dev (supervisor), build, test, doctor
31
+ ├── apps/
32
+ │ ├── backend/ user backend built on @bhooai/nexus-* (modules + plugins)
33
+ │ ├── frontend/ React+Vite+TS+Tailwind user-facing app
34
+ │ └── ai-server/ Python FastAPI: OpenAI + Ollama
35
+ ├── apps/admin/ admin app (React+Vite+TS) — grouped key/value config + env editors (themed, responsive), database/process control, plugins, users, monitoring
36
+ ├── plugins/ user plugins (self-contained dirs with plugin.json)
37
+ └── tests/ cross-service Playwright e2e
38
+ ```
39
+
40
+ Run workspace commands from `bhooai-nexus/`. The parent directory only groups
41
+ the package and related local projects.
42
+
43
+ ## Four terminals = one supervisor + control API
44
+
45
+ `bin/nexus.js dev` runs a custom supervisor (not `concurrently`/`pm2`) that owns the four child processes:
46
+
47
+ 1. `apps/backend` (tsx watch) — :4000
48
+ 2. `apps/frontend` (vite) — :3000
49
+ 3. `apps/ai-server` (uvicorn --reload) — :8000
50
+ 4. `apps/admin/` (vite) — :3001
51
+
52
+ The supervisor streams prefixed colored logs, handles graceful Ctrl-C, and exposes a **localhost HTTP control API** on :7474 (`GET /status`, `POST /start?name=...`, `POST /restart?name=...`, `POST /stop?name=...`, `GET /logs?name=...`, CORS-enabled). On Windows, stop/restart terminates the complete child process tree. Each process is also runnable standalone.
53
+
54
+ ## Config precedence
55
+
56
+ Low → high: **code defaults < framework config < user `nexus.config.ts` < `nexus.runtime.json` (admin, gitignored) < `.env` / env vars < CLI flags.**
57
+
58
+ `@bhooai/nexus-core/config` loads the project `.env`, validates with zod, deep-merges, and exposes a typed object. The admin app writes **only `nexus.runtime.json`** so the human `nexus.config.ts` stays clean (no AST patching). Sections: server, uploads, db, redis, graphql, ws, auth, payments, email, certs, ads, webrtc, ai, plugins, logging.
59
+
60
+ ## Request lifecycle (backend)
61
+
62
+ ```
63
+ HTTP request
64
+ → NexusServer (node:http) securityHeaders → cors → static /uploads → bodyParser → csrf → rateLimit → router
65
+ → Router (trie: params/wildcard/405) per-route middleware: [authToken, requireRole, ...] then handler
66
+ → handler(ctx) ctx.body (JSON/urlencoded/multipart), ctx.state.user, ctx.json/ctx.res
67
+ → Server sends 404 if !ctx.res.writableEnded
68
+ ```
69
+
70
+ `ctx.res` is the raw `ServerResponse` (used directly for SSE streaming: `writeHead` + `write` + `end`). Raw body is retained on `ctx.state.__rawBody` for webhook signature verification.
71
+
72
+ ### File uploads
73
+
74
+ `bodyParser` buffers multipart requests and exposes `ctx.state.files`. The backend registers
75
+ `registerUploadRoutes` at `POST /uploads`; files are validated, renamed with generated UUID-based names,
76
+ and written below the configured project-local `uploads.dir`. `serveStatic` mounts that directory read-only
77
+ under `uploads.path`. The default request envelope is 12 MiB, the per-file limit is 10 MiB, and CSRF remains
78
+ enforced by the normal middleware pipeline. Projects should set `uploads.allowedTypes` and authentication
79
+ middleware for their own security requirements.
80
+
81
+ ## Security (nexus-auth — one cohesive unit)
82
+
83
+ - **CORS**: preflight short-circuit, credentials, `Vary: Origin`.
84
+ - **CSRF**: double-submit token (HttpOnly cookie `nexus_csrf` + `x-csrf-token` header); safe methods mint a fresh token, unsafe methods do `checkOrigin` (trustedOrigins non-empty → 401 on missing/untrusted Origin) + double-submit match. **CSRF is also enforced on the WS upgrade** (query/`Sec-WebSocket-Protocol`) since WS has no CORS preflight.
85
+ - **Auth**: local (bcryptjs, JWT access+refresh rotation, httpOnly session cookies, Redis session store with reuse detection), Google (PKCE) + Facebook OAuth2 (state, token exchange, account linking), RBAC (role inheritance). First registered user is bootstrapped as admin.
86
+ - **Rate limiting**: fixed-window; in-memory now, Redis-backed in production.
87
+
88
+ ## GraphQL (no Apollo)
89
+
90
+ `nexus-graphql` uses `graphql` (graphql-js) for parse/validate/execute. Composition, supergraph SDL, the query planner, and the gateway executor are ours — no `@apollo/*`, no `@graphql-tools/federation`.
91
+
92
+ ```
93
+ defineSubgraph (SDL+resolvers, auto-wires _service/_entities, @key parse)
94
+ → createGateway
95
+ ├─ in-process: execute() against the built PUBLIC schema (federation directives stripped)
96
+ └─ federated: composeSupergraph → queryPlanner → executeFederated (FetchNode DAG, @key joins, @provides/@requires)
97
+ → graphqlHttpHandler (POST/GET, introspection toggle) + SubscriptionServer (graphql-transport-ws over ws)
98
+ ```
99
+
100
+ Federation subset (v1): `@key` (single + composite), `@external`, `@requires`, `@provides`, `@extends`, `_entities`, `_service { sdl }`. The app ships single-subgraph by default; `nexus add subgraph` opts into federation.
101
+
102
+ ## Data (custom ODM, no mongoose)
103
+
104
+ `nexus-data` on the official `mongodb` driver. Self-contained validators (no zod). Connection/ConnectionManager, Schema (field opts incl. ref/refPath/select/immutable/expires/unique/index/transform), Model (find/findById/create/insertMany/update*/delete*/aggregate/bulkWrite/findOneAndUpdate), DocumentInstance (Proxy, save/remove/validate/populate, pre/post hooks, timestamps, strict, virtuals), chainable+thenable Query, batched multi-level populate, transactions (`withTransaction`). Auto-index creation at boot.
105
+
106
+ ## Realtime + WebRTC (nexus-realtime)
107
+
108
+ - **WS server** (`ws`, noServer upgrade) with connection registry, room membership, pub/sub adapter (Memory + Redis for cross-instance fanout), auth on upgrade via `?token=`/subprotocol + optional CSRF origin check.
109
+ - **WebRTC signaling relay** over WS (offer/answer/candidate — direct if same-instance, else published to `conn:<to>`).
110
+ - **mediasoup SFU adapter** (lazy import, one worker/router-per-room, send/recv transports, produce/consume). The browser uses `mediasoup-client`; the frontend `stream.ts` wraps it over the realtime `media` action channel.
111
+
112
+ ## Plugins (nexus-plugins)
113
+
114
+ Two modes: **trusted** (in-process, full Node API, dynamic-import entry) and **sandboxed** (`worker_threads` with capability-restricted RPC — real heap/event-loop isolation, crash can't take down the host).
115
+
116
+ ```
117
+ PluginManifest { name, version, entry, mode, capabilities[], configSchema, hooks[], dependencies[] }
118
+ PluginHost: load(dir) → topoSort by deps (cycle detection) → runLifecycle(install→init→start→stop, stop reverses)
119
+ PluginContext: http/graphql/data/auth/realtime/scheduler/events/admin registrars (capability-gated in sandbox)
120
+ capabilityPolicy: METHOD_CAPABILITY map + fs path-allowlist + net host-allowlist + authorize()
121
+ AdminExtensions: registerPage/registerSlot → grouped pages + ordered slots
122
+ ```
123
+
124
+ The sandbox bootstrap is plain `.mjs` (Node runs it directly in the worker, no TS loader). The host drives ALL lifecycle hooks including `install`. Documented v1 seams: sandboxed plugins can't add GraphQL subgraphs (resolvers aren't serializable); sandboxed middleware is a no-op.
125
+
126
+ ## Payments (nexus-payments)
127
+
128
+ `PaymentProvider` interface (createOrder/capture/refund/getOrderStatus/verifyWebhook) with an injectable `HttpTransport` (tests inject mocks — no live gateways). Razorpay + PayPal are full; PayU/Skrill/Payoneer are happy-path + sandbox tests. `WebhookRouter` dispatches by `:provider` param with per-provider signature verification. Browser-facing `/payments/order` routes are auth+CSRF guarded; webhooks stay separate.
129
+
130
+ ## Cross-service contract (contracts/)
131
+
132
+ `ai-openapi.yaml` (OpenAPI 3.1) is the single source of truth for the Node↔Python AI boundary. The Python FastAPI server and the Node `nexus-ai-client` both conform to it. The browser never talks to Python directly — Node proxies/re-emits SSE. Both OpenAI and Ollama speak the OpenAI-compatible API → one `OpenAICompatibleProvider` parameterised by `base_url`+`api_key`.
133
+
134
+ ## Telemetry (nexus-telemetry)
135
+
136
+ Structured JSON logger (stdout + rotating file, child loggers, redaction), metrics registry (counters/histograms, `/metrics`), request/trace-ID propagation across Node→WS→Python. Admin monitoring consumes this.
137
+
138
+ ## Testing
139
+
140
+ - **Vitest** per Node package (real MongoDB via `.env` — no embedded Mongo) + **pytest** for the AI server + **Playwright** for cross-service e2e.
141
+ - Each phase ships runnable + tested. See `docs/IMPROVEMENTS.md` for honest seams and next steps.