bhooai-nexus 0.1.2 → 0.1.4

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 (127) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +240 -135
  3. package/apps/admin/package.json +3 -5
  4. package/apps/admin/postcss.config.js +5 -6
  5. package/docs/ARCHITECTURE.md +154 -0
  6. package/docs/IMPROVEMENTS.md +105 -0
  7. package/docs/api/admin.html +651 -0
  8. package/docs/api/ads.html +314 -0
  9. package/docs/api/ai-client.html +336 -0
  10. package/docs/api/auth.html +697 -0
  11. package/docs/api/cache.html +331 -0
  12. package/docs/api/cli.html +612 -0
  13. package/docs/api/cluster.html +489 -0
  14. package/docs/api/core.html +796 -0
  15. package/docs/api/crypto.html +310 -0
  16. package/docs/api/data.html +811 -0
  17. package/docs/api/email.html +345 -0
  18. package/docs/api/graphql.html +697 -0
  19. package/docs/api/http-endpoints.html +221 -0
  20. package/docs/api/node-agent.html +155 -0
  21. package/docs/api/payments.html +558 -0
  22. package/docs/api/plugins.html +522 -0
  23. package/docs/api/postcss.html +241 -0
  24. package/docs/api/realtime.html +324 -0
  25. package/docs/api/safe-goto.html +215 -0
  26. package/docs/api/supervisor.html +312 -0
  27. package/docs/api/telemetry.html +264 -0
  28. package/docs/api/websockets.html +163 -0
  29. package/docs/architecture.html +211 -0
  30. package/docs/assets/bhooai-nexus-cluster-link.postman_collection.json +185 -0
  31. package/docs/assets/bhooai-nexus-local.postman_environment.json +47 -0
  32. package/docs/assets/bhooai-nexus-logo.png +0 -0
  33. package/docs/assets/bhooai-nexus-logo.svg +135 -0
  34. package/docs/assets/docs.js +368 -0
  35. package/docs/assets/favicon.ico +0 -0
  36. package/docs/assets/favicon.zip +0 -0
  37. package/docs/assets/nav.js +91 -0
  38. package/docs/assets/playground.js +283 -0
  39. package/docs/assets/screenshots/01-collection.png +0 -0
  40. package/docs/assets/screenshots/02-step1-csrf.png +0 -0
  41. package/docs/assets/screenshots/03-step2-login.png +0 -0
  42. package/docs/assets/screenshots/04-step3-link.png +0 -0
  43. package/docs/assets/screenshots/05-error-fetch-failed.png +0 -0
  44. package/docs/assets/screenshots/06-error-agent-401.png +0 -0
  45. package/docs/assets/screenshots/07-error-401-csrf.png +0 -0
  46. package/docs/assets/screenshots/08-env-runner.png +0 -0
  47. package/docs/assets/screenshots/visual-flow.png +0 -0
  48. package/docs/assets/style.css +1140 -0
  49. package/docs/examples.html +248 -0
  50. package/docs/favicon.ico +0 -0
  51. package/docs/getting-started.html +155 -0
  52. package/docs/guides/guide-ai-chat.html +202 -0
  53. package/docs/guides/guide-auth.html +328 -0
  54. package/docs/guides/guide-cluster.html +325 -0
  55. package/docs/guides/guide-email.html +234 -0
  56. package/docs/guides/guide-empty-project.html +279 -0
  57. package/docs/guides/guide-frontend-styling.html +235 -0
  58. package/docs/guides/guide-graphql.html +214 -0
  59. package/docs/guides/guide-mongodb.html +220 -0
  60. package/docs/guides/guide-payments.html +321 -0
  61. package/docs/guides/guide-uploads.html +170 -0
  62. package/docs/guides/guide-websocket.html +263 -0
  63. package/docs/improvements.html +146 -0
  64. package/docs/index.html +101 -0
  65. package/docs/learn/01-foundation.html +129 -0
  66. package/docs/learn/02-security.html +104 -0
  67. package/docs/learn/03-data.html +99 -0
  68. package/docs/learn/04-graphql.html +86 -0
  69. package/docs/learn/05-realtime.html +76 -0
  70. package/docs/learn/06-payments-email-crypto.html +93 -0
  71. package/docs/learn/07-cache-ads.html +85 -0
  72. package/docs/learn/08-ai.html +93 -0
  73. package/docs/learn/09-plugins.html +81 -0
  74. package/docs/learn/10-cluster.html +83 -0
  75. package/docs/learn/11-cli.html +183 -0
  76. package/docs/learn/12-apps.html +123 -0
  77. package/docs/learn/13-tests.html +79 -0
  78. package/docs/learn/14-postman-testing.html +580 -0
  79. package/docs/learn/PLAN.md +59 -0
  80. package/docs/learn/index.html +87 -0
  81. package/docs/screenshots/README.md +23 -0
  82. package/docs/screenshots/ai-agents-playground.png +0 -0
  83. package/docs/screenshots/ai-agents-providers.png +0 -0
  84. package/docs/screenshots/ai-agents.png +0 -0
  85. package/docs/screenshots/appearance.png +0 -0
  86. package/docs/screenshots/cluster-master.png +0 -0
  87. package/docs/screenshots/cluster-nodes.png +0 -0
  88. package/docs/screenshots/cluster-slave.png +0 -0
  89. package/docs/screenshots/login.png +0 -0
  90. package/docs/screenshots/logs-ai-summary.png +0 -0
  91. package/docs/screenshots/monitoring.png +0 -0
  92. package/docs/screenshots/nexus-dev.png +0 -0
  93. package/docs/screenshots/nexus-init.png +0 -0
  94. package/docs/screenshots/notification.png +0 -0
  95. package/docs/screenshots/overview.png +0 -0
  96. package/docs/screenshots/search-bar.png +0 -0
  97. package/docs/screenshots/settings.png +0 -0
  98. package/docs/screenshots/themes.png +0 -0
  99. package/docs/troubleshooting.html +400 -0
  100. package/package.json +9 -2
  101. package/packages/nexus-admin/package.json +1 -1
  102. package/packages/nexus-ads/package.json +4 -2
  103. package/packages/nexus-ai-client/package.json +4 -2
  104. package/packages/nexus-auth/package.json +4 -2
  105. package/packages/nexus-cache/package.json +4 -2
  106. package/packages/nexus-cli/package.json +4 -2
  107. package/packages/nexus-cli/templates/apps/admin/package.json +1 -3
  108. package/packages/nexus-cli/templates/apps/admin/postcss.config.js +3 -6
  109. package/packages/nexus-cli/templates/apps/frontend/package.json +1 -0
  110. package/packages/nexus-cli/templates/apps/frontend/postcss.config.js +3 -0
  111. package/packages/nexus-cli/templates/apps/frontend/src/index.css +44 -0
  112. package/packages/nexus-cli/templates/apps/frontend/src/main.tsx +1 -0
  113. package/packages/nexus-cli/templates/apps/frontend/tailwind.config.js +9 -0
  114. package/packages/nexus-core/package.json +4 -2
  115. package/packages/nexus-crypto/package.json +4 -2
  116. package/packages/nexus-data/package.json +4 -2
  117. package/packages/nexus-email/package.json +4 -2
  118. package/packages/nexus-graphql/package.json +4 -2
  119. package/packages/nexus-payments/package.json +4 -2
  120. package/packages/nexus-plugins/package.json +4 -2
  121. package/packages/nexus-postcss/package.json +34 -0
  122. package/packages/nexus-postcss/src/index.js +1 -0
  123. package/packages/nexus-postcss/src/plugins.js +46 -0
  124. package/packages/nexus-postcss/src/theme.css +64 -0
  125. package/packages/nexus-postcss/src/types.ts +12 -0
  126. package/packages/nexus-realtime/package.json +4 -2
  127. package/packages/nexus-telemetry/package.json +4 -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,289 @@
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
17
+ - Tailwind CSS + `@bhooai/nexus-postcss` preset with PostCSS pipeline, design tokens, and dark theme baseline for every scaffolded frontend
12
18
 
13
- ## Layout
19
+ ## Requirements
14
20
 
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
21
+ - Node.js `>=20.10`
22
+ - npm, included with Node.js
23
+ - MongoDB 7 or newer, running locally or reachable through `MONGODB_URI`
24
+ - Redis 7 or newer, running locally or reachable through `REDIS_URL`
25
+ - Python 3.10 or newer for the optional AI server
26
+ - A virtual environment is recommended for Python dependencies
27
27
 
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
- ```
28
+ 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
29
 
35
- ## Use as an npm package
30
+ 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
31
 
37
- Publish the public workspace packages together from the framework repository:
32
+ ## Install
38
33
 
39
34
  ```bash
40
- npm publish
35
+ npm install bhooai-nexus
36
+ npx nexus init my-app
37
+ cd my-app
38
+ npm run doctor
39
+ npm run dev
41
40
  ```
42
41
 
43
- Then a new app can be created without copying the framework repository:
42
+ Initialize the current directory with `npx nexus init .`. Use `npx nexus init . --skip-install` to defer dependency installation.
43
+
44
+ ## Quick Start
44
45
 
45
46
  ```bash
46
- mkdir my-app
47
+ npm install bhooai-nexus
48
+ npx nexus init my-app
47
49
  cd my-app
48
- npm init -y
49
- npm install C:\server\BhooAI\BhooAI-Nexus\BhooAI-Nexus\bhooai-nexus
50
- npx nexus init .
51
50
  npm run doctor
52
51
  npm run dev
53
52
  ```
54
53
 
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.
54
+ Default development services:
55
+
56
+ | Service | Default port |
57
+ | --- | ---: |
58
+ | Backend API | `4000` |
59
+ | Frontend | `3000` |
60
+ | Admin console | `3300` |
61
+ | Python AI server | `8000` |
62
+ | Cluster load balancer | `8080` |
63
+ | Node agent | `7575` |
64
+
65
+ `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.
66
+
67
+ ## Screenshots
68
+
69
+ ### Admin login
70
+
71
+ ![BhooAI Nexus admin login](docs/screenshots/login.png)
72
+
73
+ ### Overview dashboard
74
+
75
+ ![BhooAI Nexus overview dashboard](docs/screenshots/overview.png)
76
+
77
+ ### Master cluster management
78
+
79
+ ![BhooAI Nexus master cluster management](docs/screenshots/cluster-master.png)
80
+
81
+ ### Slave node agent and roles
82
+
83
+ ![BhooAI Nexus slave node agent](docs/screenshots/cluster-slave.png)
84
+
85
+ ### Connected cluster nodes
86
+
87
+ ![Connected cluster nodes](docs/screenshots/cluster-nodes.png)
88
+
89
+ ### AI agents
90
+
91
+ ![AI agents](docs/screenshots/ai-agents.png)
92
+
93
+ ### AI providers
94
+
95
+ ![AI agent providers](docs/screenshots/ai-agents-providers.png)
96
+
97
+ ### AI playground
98
+
99
+ ![AI playground](docs/screenshots/ai-agents-playground.png)
100
+
101
+ ### Monitoring
102
+
103
+ ![Monitoring dashboard](docs/screenshots/monitoring.png)
104
+
105
+ ### Settings
106
+
107
+ ![Settings](docs/screenshots/settings.png)
108
+
109
+ ### Themes
110
+
111
+ ![Theme selection](docs/screenshots/themes.png)
112
+
113
+ ### Appearance
114
+
115
+ ![Appearance settings](docs/screenshots/appearance.png)
116
+
117
+ ### Search
118
+
119
+ ![Admin search](docs/screenshots/search-bar.png)
120
+
121
+ ### Notifications
122
+
123
+ ![Notifications](docs/screenshots/notification.png)
124
+
125
+ ### AI log summary
126
+
127
+ ![AI log summary](docs/screenshots/logs-ai-summary.png)
128
+
129
+ ### Nexus development services
130
+
131
+ ![Nexus development services](docs/screenshots/nexus-dev.png)
132
+
133
+ ### Nexus initialization
134
+
135
+ ![Nexus initialization](docs/screenshots/nexus-init.png)
59
136
 
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.
137
+ ## Cluster Mesh
62
138
 
63
- ## Scaffold a new project
139
+ BhooAI Nexus supports a central master and one or more slave nodes.
140
+
141
+ Initialize a master:
64
142
 
65
143
  ```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
144
+ npx nexus init master --as=root
145
+ ```
146
+
147
+ Initialize a slave with a built-in role:
148
+
149
+ ```bash
150
+ npx nexus init slave-1 --as=node --role=backend --port=7575
151
+ npx nexus init slave-2 --as=node --role=files --port=7576
70
152
  ```
71
153
 
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>`.
154
+ Supported node roles are `backend`, `files`, `database`, and `ai`.
155
+
156
+ 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.
157
+
158
+ The master load balancer listens on port `8080` and distributes traffic across ready backend nodes. Authentication routes are pinned to the master:
159
+
160
+ - `/auth/*`
161
+ - `/csrf-token`
162
+
163
+ Use the same `NEXUS_AUTH_JWT_SECRET` on all nodes so slaves can verify master-issued access tokens.
164
+
165
+ ### Upload path allocation
166
+
167
+ The master admin console includes **Cluster → Path routing**. Pin URL prefixes to specific nodes:
168
+
169
+ ```text
170
+ /uploads/images -> slave-1
171
+ /uploads/files -> slave-2
172
+ ```
173
+
174
+ 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.
175
+
176
+ 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.
177
+
178
+ 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.
179
+
180
+ ## Admin Console
181
+
182
+ 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.
183
+
184
+ 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
185
 
78
186
  ## Configuration
79
187
 
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).
188
+ Edit `nexus.config.ts`. Configuration precedence is:
117
189
 
118
- ## Documentation
190
+ ```text
191
+ code defaults < nexus.config.ts < nexus.runtime.json < NEXUS_* environment variables < CLI flags
192
+ ```
119
193
 
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.
194
+ Admin changes are written to the gitignored `nexus.runtime.json` file. Store secrets in the project `.env` file:
126
195
 
127
- ## Status — complete (12/12 phases)
196
+ ```env
197
+ MONGODB_URI=mongodb://localhost:27017/my-app
198
+ REDIS_URL=redis://localhost:6379
199
+ NEXUS_AUTH_JWT_SECRET=replace-with-a-long-random-secret
200
+ ```
128
201
 
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)
202
+ Common port overrides include `NEXUS_SERVER_PORT`, `NEXUS_FRONTEND_PORT`, `NEXUS_ADMIN_PORT`, `NEXUS_CLUSTER_LBPORT`, `NEXUS_CLUSTER_NODEAGENTPORT`, and `AI_PORT`.
142
203
 
143
- ## Dependency policy
204
+ ## Uninstall
144
205
 
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.
206
+ Preview changes:
149
207
 
208
+ ```bash
209
+ npx nexus uninstall --dry-run
210
+ ```
150
211
 
151
- ## Docker Windows
212
+ Remove the project database and registration while keeping files:
152
213
 
153
- In project directory, open PowerShell and run:
154
214
  ```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
215
+ npx nexus uninstall
161
216
  ```
162
217
 
163
- Or from cmd:
218
+ Remove the database, registration, and project directory:
219
+
164
220
  ```bash
165
- `docker.bat build`
166
- `docker.bat run`
221
+ npx nexus uninstall --purge
167
222
  ```
168
223
 
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
224
+ Skip confirmations or keep the database:
225
+
226
+ ```bash
227
+ npx nexus uninstall --purge --force
228
+ npx nexus uninstall --keep-db
229
+ ```
230
+
231
+ Uninstall does not remove the framework package, MongoDB's `nexus_projects` database, or other projects.
232
+
233
+ ## Project Layout
234
+
235
+ ```text
236
+ packages/ Framework packages (@bhooai/nexus-*)
237
+ apps/backend/ Node.js backend
238
+ apps/frontend/ React + Vite frontend
239
+ apps/admin/ React + Vite admin host
240
+ apps/ai-server/ Python FastAPI AI service
241
+ bin/ CLI entry point
242
+ contracts/ Node-to-Python API contracts
243
+ plugins/ Project plugins
244
+ tests/ Cross-service tests
245
+ docs/ Architecture, improvements, and screenshots
246
+ ```
247
+
248
+ ## Testing
249
+
250
+ ```bash
251
+ npx vitest run
252
+ cd apps/ai-server
253
+ python -m pip install -r requirements.txt
254
+ pytest
176
255
  ```
177
256
 
178
- ## Docker Linux
257
+ Run Playwright end-to-end tests from the framework root:
179
258
 
180
259
  ```bash
181
- cd project-directory
182
- ./docker.sh build
183
- ./docker.sh run
260
+ npx playwright test --config=playwright.config.ts
184
261
  ```
262
+
263
+ ## Docker
264
+
265
+ ```powershell
266
+ .\docker.ps1 build
267
+ .\docker.ps1 run
268
+ .\docker.ps1 logs
269
+ .\docker.ps1 stop
270
+ ```
271
+
272
+ Development endpoints are frontend `http://localhost:3000`, admin `http://localhost:3300`, and backend `http://localhost:4000/health`.
273
+
274
+ ## Documentation
275
+
276
+ - [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) — architecture and data flow
277
+ - [`docs/IMPROVEMENTS.md`](docs/IMPROVEMENTS.md) — improvement history
278
+ - [`docs/troubleshooting.html`](docs/troubleshooting.html) — common errors and fixes
279
+ - [`docs/screenshots/README.md`](docs/screenshots/README.md) — screenshot catalog
280
+ - [`apps/ai-server/README.md`](apps/ai-server/README.md) — Python AI service
281
+ - Package documentation under `packages/nexus-*/README.md`
282
+
283
+ ## Design Principles
284
+
285
+ 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.
286
+
287
+ ## License
288
+
289
+ BhooAI Nexus is released under the [MIT License](LICENSE).
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhooai/admin-host",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -13,13 +13,11 @@
13
13
  "react-dom": "^18.3.1"
14
14
  },
15
15
  "devDependencies": {
16
+ "@bhooai/nexus-postcss": "*",
16
17
  "@types/react": "^18.3.0",
17
18
  "@types/react-dom": "^18.3.0",
18
19
  "@vitejs/plugin-react": "^4.3.0",
19
- "autoprefixer": "^10.4.20",
20
- "postcss": "^8.4.47",
21
- "tailwindcss": "^3.4.13",
22
20
  "typescript": "^5.6.2",
23
21
  "vite": "^5.4.0"
24
22
  }
25
- }
23
+ }
@@ -1,6 +1,5 @@
1
- export default {
2
- plugins: {
3
- tailwindcss: {},
4
- autoprefixer: {},
5
- },
6
- };
1
+ import { createPreset } from '@bhooai/nexus-postcss';
2
+
3
+ export default createPreset({
4
+ extraContent: ['../../packages/nexus-admin/src/**/*.{ts,tsx}'],
5
+ });
@@ -0,0 +1,154 @@
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-postcss opinionated PostCSS preset (Tailwind, nesting, preset-env, autoprefixer, cssnano) + theme.css design tokens
31
+ │ └── nexus-cli init, dev (supervisor), build, test, doctor
32
+ ├── apps/
33
+ │ ├── backend/ user backend built on @bhooai/nexus-* (modules + plugins)
34
+ │ ├── frontend/ React+Vite+TS+Tailwind user-facing app
35
+ │ └── ai-server/ Python FastAPI: OpenAI + Ollama
36
+ ├── apps/admin/ admin app (React+Vite+TS) — grouped key/value config + env editors (themed, responsive), database/process control, plugins, users, monitoring
37
+ ├── plugins/ user plugins (self-contained dirs with plugin.json)
38
+ └── tests/ cross-service Playwright e2e
39
+ ```
40
+
41
+ ### Frontend CSS pipeline
42
+
43
+ Both `apps/frontend` and `apps/admin` use Tailwind CSS via the framework-owned
44
+ `@bhooai/nexus-postcss` preset. The preset (`packages/nexus-postcss/src/plugins.js`)
45
+ loads six PostCSS plugins in order: `postcss-import` → `postcss-nested` → `tailwindcss`
46
+ → `postcss-preset-env` (stage 2) → `autoprefixer` → `cssnano` (production only). A
47
+ `theme.css` stylesheet (`packages/nexus-postcss/src/theme.css`) defines 22 CSS custom
48
+ properties (`--nexus-bg`, `--nexus-ink`, `--nexus-surface`, `--nexus-accent`, etc.) on
49
+ `:root`, plus 15 `--admin-*` aliases for backwards compatibility. Scaffolded projects
50
+ import the tokens with `@import '@bhooai/nexus-postcss/theme.css'` at the top of their
51
+ `index.css`.
52
+
53
+ Run workspace commands from `bhooai-nexus/`. The parent directory only groups
54
+ the package and related local projects.
55
+
56
+ ## Four terminals = one supervisor + control API
57
+
58
+ `bin/nexus.js dev` runs a custom supervisor (not `concurrently`/`pm2`) that owns the four child processes:
59
+
60
+ 1. `apps/backend` (tsx watch) — :4000
61
+ 2. `apps/frontend` (vite) — :3000
62
+ 3. `apps/ai-server` (uvicorn --reload) — :8000
63
+ 4. `apps/admin/` (vite) — :3001
64
+
65
+ 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.
66
+
67
+ ## Config precedence
68
+
69
+ Low → high: **code defaults < framework config < user `nexus.config.ts` < `nexus.runtime.json` (admin, gitignored) < `.env` / env vars < CLI flags.**
70
+
71
+ `@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.
72
+
73
+ ## Request lifecycle (backend)
74
+
75
+ ```
76
+ HTTP request
77
+ → NexusServer (node:http) securityHeaders → cors → static /uploads → bodyParser → csrf → rateLimit → router
78
+ → Router (trie: params/wildcard/405) per-route middleware: [authToken, requireRole, ...] then handler
79
+ → handler(ctx) ctx.body (JSON/urlencoded/multipart), ctx.state.user, ctx.json/ctx.res
80
+ → Server sends 404 if !ctx.res.writableEnded
81
+ ```
82
+
83
+ `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.
84
+
85
+ ### File uploads
86
+
87
+ `bodyParser` buffers multipart requests and exposes `ctx.state.files`. The backend registers
88
+ `registerUploadRoutes` at `POST /uploads`; files are validated, renamed with generated UUID-based names,
89
+ and written below the configured project-local `uploads.dir`. `serveStatic` mounts that directory read-only
90
+ under `uploads.path`. The default request envelope is 12 MiB, the per-file limit is 10 MiB, and CSRF remains
91
+ enforced by the normal middleware pipeline. Projects should set `uploads.allowedTypes` and authentication
92
+ middleware for their own security requirements.
93
+
94
+ ## Security (nexus-auth — one cohesive unit)
95
+
96
+ - **CORS**: preflight short-circuit, credentials, `Vary: Origin`.
97
+ - **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.
98
+ - **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.
99
+ - **Rate limiting**: fixed-window; in-memory now, Redis-backed in production.
100
+
101
+ ## GraphQL (no Apollo)
102
+
103
+ `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`.
104
+
105
+ ```
106
+ defineSubgraph (SDL+resolvers, auto-wires _service/_entities, @key parse)
107
+ → createGateway
108
+ ├─ in-process: execute() against the built PUBLIC schema (federation directives stripped)
109
+ └─ federated: composeSupergraph → queryPlanner → executeFederated (FetchNode DAG, @key joins, @provides/@requires)
110
+ → graphqlHttpHandler (POST/GET, introspection toggle) + SubscriptionServer (graphql-transport-ws over ws)
111
+ ```
112
+
113
+ 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.
114
+
115
+ ## Data (custom ODM, no mongoose)
116
+
117
+ `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.
118
+
119
+ ## Realtime + WebRTC (nexus-realtime)
120
+
121
+ - **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.
122
+ - **WebRTC signaling relay** over WS (offer/answer/candidate — direct if same-instance, else published to `conn:<to>`).
123
+ - **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.
124
+
125
+ ## Plugins (nexus-plugins)
126
+
127
+ 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).
128
+
129
+ ```
130
+ PluginManifest { name, version, entry, mode, capabilities[], configSchema, hooks[], dependencies[] }
131
+ PluginHost: load(dir) → topoSort by deps (cycle detection) → runLifecycle(install→init→start→stop, stop reverses)
132
+ PluginContext: http/graphql/data/auth/realtime/scheduler/events/admin registrars (capability-gated in sandbox)
133
+ capabilityPolicy: METHOD_CAPABILITY map + fs path-allowlist + net host-allowlist + authorize()
134
+ AdminExtensions: registerPage/registerSlot → grouped pages + ordered slots
135
+ ```
136
+
137
+ 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.
138
+
139
+ ## Payments (nexus-payments)
140
+
141
+ `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.
142
+
143
+ ## Cross-service contract (contracts/)
144
+
145
+ `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`.
146
+
147
+ ## Telemetry (nexus-telemetry)
148
+
149
+ 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.
150
+
151
+ ## Testing
152
+
153
+ - **Vitest** per Node package (real MongoDB via `.env` — no embedded Mongo) + **pytest** for the AI server + **Playwright** for cross-service e2e.
154
+ - Each phase ships runnable + tested. See `docs/IMPROVEMENTS.md` for honest seams and next steps.