axiodb 10.8.11 โ†’ 11.9.13

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 (74) hide show
  1. package/README.md +447 -315
  2. package/lib/Services/Auth/AuthEvents.service.d.ts +15 -0
  3. package/lib/Services/Auth/AuthEvents.service.js +17 -0
  4. package/lib/Services/Auth/AuthEvents.service.js.map +1 -0
  5. package/lib/Services/Auth/AuthService.service.js +4 -0
  6. package/lib/Services/Auth/AuthService.service.js.map +1 -1
  7. package/lib/Services/Auth/LoginRateLimiter.service.d.ts +35 -0
  8. package/lib/Services/Auth/LoginRateLimiter.service.js +89 -0
  9. package/lib/Services/Auth/LoginRateLimiter.service.js.map +1 -0
  10. package/lib/Services/Collection/collection.operation.d.ts +6 -0
  11. package/lib/Services/Collection/collection.operation.js +10 -0
  12. package/lib/Services/Collection/collection.operation.js.map +1 -1
  13. package/lib/Services/Index/Index.service.d.ts +20 -0
  14. package/lib/Services/Index/Index.service.js +25 -1
  15. package/lib/Services/Index/Index.service.js.map +1 -1
  16. package/lib/Services/Indexation.operation.d.ts +4 -0
  17. package/lib/Services/Indexation.operation.js +13 -4
  18. package/lib/Services/Indexation.operation.js.map +1 -1
  19. package/lib/client/AxioDBCloud.client.d.ts +20 -1
  20. package/lib/client/AxioDBCloud.client.js +54 -3
  21. package/lib/client/AxioDBCloud.client.js.map +1 -1
  22. package/lib/client/CollectionProxy.d.ts +4 -0
  23. package/lib/client/CollectionProxy.js +11 -0
  24. package/lib/client/CollectionProxy.js.map +1 -1
  25. package/lib/client/types/client.types.d.ts +8 -0
  26. package/lib/client/types/client.types.js.map +1 -1
  27. package/lib/config/Interfaces/Operation/Indexation.operation.interface.d.ts +2 -0
  28. package/lib/config/Keys/Permissions.d.ts +13 -0
  29. package/lib/config/Keys/Permissions.js +21 -1
  30. package/lib/config/Keys/Permissions.js.map +1 -1
  31. package/lib/server/config/keys.js +26 -0
  32. package/lib/server/config/keys.js.map +1 -1
  33. package/lib/server/controller/Auth/Auth.controller.js +9 -0
  34. package/lib/server/controller/Auth/Auth.controller.js.map +1 -1
  35. package/lib/server/controller/Index/Index.controller.d.ts +35 -0
  36. package/lib/server/controller/Index/Index.controller.js +148 -0
  37. package/lib/server/controller/Index/Index.controller.js.map +1 -0
  38. package/lib/server/router/Router.js +6 -0
  39. package/lib/server/router/Router.js.map +1 -1
  40. package/lib/server/router/Routers/Index.routes.d.ts +7 -0
  41. package/lib/server/router/Routers/Index.routes.js +38 -0
  42. package/lib/server/router/Routers/Index.routes.js.map +1 -0
  43. package/lib/tcp/config/keys.d.ts +8 -0
  44. package/lib/tcp/config/keys.js +8 -0
  45. package/lib/tcp/config/keys.js.map +1 -1
  46. package/lib/tcp/config/permissions.d.ts +16 -0
  47. package/lib/tcp/config/permissions.js +46 -0
  48. package/lib/tcp/config/permissions.js.map +1 -0
  49. package/lib/tcp/config/protocol.js +13 -0
  50. package/lib/tcp/config/protocol.js.map +1 -1
  51. package/lib/tcp/config/server.d.ts +1 -1
  52. package/lib/tcp/config/server.js +28 -6
  53. package/lib/tcp/config/server.js.map +1 -1
  54. package/lib/tcp/connection/ConnectionManager.d.ts +19 -0
  55. package/lib/tcp/connection/ConnectionManager.js +31 -0
  56. package/lib/tcp/connection/ConnectionManager.js.map +1 -1
  57. package/lib/tcp/connection/RequestContext.d.ts +4 -1
  58. package/lib/tcp/connection/RequestContext.js +4 -1
  59. package/lib/tcp/connection/RequestContext.js.map +1 -1
  60. package/lib/tcp/handler/CommandHandler.d.ts +5 -1
  61. package/lib/tcp/handler/CommandHandler.js +34 -4
  62. package/lib/tcp/handler/CommandHandler.js.map +1 -1
  63. package/lib/tcp/handler/handlers/Auth.handler.d.ts +16 -0
  64. package/lib/tcp/handler/handlers/Auth.handler.js +91 -0
  65. package/lib/tcp/handler/handlers/Auth.handler.js.map +1 -0
  66. package/lib/tcp/handler/handlers/Operation.handler.d.ts +4 -0
  67. package/lib/tcp/handler/handlers/Operation.handler.js +27 -0
  68. package/lib/tcp/handler/handlers/Operation.handler.js.map +1 -1
  69. package/lib/tcp/types/command.types.d.ts +2 -0
  70. package/lib/tcp/types/command.types.js +5 -0
  71. package/lib/tcp/types/command.types.js.map +1 -1
  72. package/lib/tcp/types/protocol.types.d.ts +2 -0
  73. package/lib/tcp/types/protocol.types.js.map +1 -1
  74. package/package.json +1 -1
package/README.md CHANGED
@@ -16,143 +16,207 @@
16
16
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.6-blue)](https://www.typescriptlang.org/)
17
17
  [![Zero Dependencies](https://img.shields.io/badge/dependencies-0%20native-success)](https://www.npmjs.com/package/axiodb)
18
18
 
19
- > **AxioDB** is an embedded NoSQL database for Node.js with MongoDB-style queries. Zero native dependencies, no compilation, no platform issues. Pure JavaScript from npm install to production. Think SQLite, but NoSQL with JavaScript queriesโ€”perfect for desktop apps, CLI tools, and embedded systems.
20
-
21
19
  ๐Ÿ‘‰ **[Official Documentation](https://axiodb.in/)**: Access full guides, examples, and API references.
22
20
 
23
21
  ---
24
22
 
25
- ## ๐ŸŽฏ Why AxioDB?
23
+ ## Table of Contents
24
+
25
+ - [What is AxioDB, and why does it exist?](#what-is-axiodb-and-why-does-it-exist)
26
+ - [Installation](#-installation)
27
+ - [Quick Start โ€” Local AxioDB](#-quick-start--local-axiodb)
28
+ - [Features](#-features)
29
+ - [AxioDBCloud โ€” Connecting Remotely](#-axiodbcloud--connecting-remotely)
30
+ - [Simple: connect without authentication](#simple-connect-without-authentication)
31
+ - [Advanced: TCP authentication](#advanced-tcp-authentication)
32
+ - [Troubleshooting](#-troubleshooting)
33
+ - [Docker Deployment](#-docker-deployment)
34
+ - [Simple: run the container](#simple-run-the-container)
35
+ - [Advanced: env vars, volumes, Compose](#advanced-env-vars-volumes-compose)
36
+ - [Built-in Web GUI & Authentication (RBAC)](#-built-in-web-gui--authentication-rbac)
37
+ - [Detailed Usage](#-detailed-usage)
38
+ - [API Reference](#-api-reference)
39
+ - [Best Practices](#-best-practices)
40
+ - [Architecture & Internal Mechanisms](#-architecture--internal-mechanisms)
41
+ - [Comparisons](#-comparisons)
42
+ - [Limitations & Honest Positioning](#-limitations--honest-positioning)
43
+ - [FAQ](#-faq)
44
+ - [Contributing, License & Support](#-contributing-license--support)
45
+
46
+ ---
47
+
48
+ ## What is AxioDB, and why does it exist?
26
49
 
27
- **SQLite requires native C bindings that cause deployment headaches. JSON files have no querying or caching. MongoDB needs a separate server. AxioDB combines the best of all: embedded like SQLite, NoSQL queries like MongoDB, intelligent caching built-in.**
50
+ **AxioDB is an embedded NoSQL database for Node.js, with MongoDB-style queries, zero native dependencies, and a built-in web GUI.** Think SQLite, but NoSQL โ€” install it with npm, and you have a working database with no server, no compilation step, and no platform-specific binaries.
28
51
 
29
- ### The Problem with SQLite
52
+ ### The problem
30
53
 
31
- SQLite is great, but it requires native bindings that break in Electron and cross-platform deployments:
54
+ SQLite is great, but its native C bindings cause real deployment pain in JavaScript projects:
32
55
 
33
56
  - โŒ `electron-rebuild` on every Electron update
34
- - โŒ Platform-specific builds (Windows .node files โ‰  Mac .node files)
57
+ - โŒ Platform-specific builds (Windows `.node` files โ‰  Mac `.node` files)
35
58
  - โŒ SQL strings instead of JavaScript objects
36
59
  - โŒ Schema migrations when your data model changes
37
60
  - โŒ `node-gyp` compilation headaches
38
61
 
39
- ### AxioDB Solution
62
+ Meanwhile, plain JSON files have no querying, no caching, and no indexing โ€” they just don't scale past a few thousand records. And MongoDB solves the query/caching problem, but needs a separate server process, which is overkill for a desktop app, CLI tool, or embedded system.
40
63
 
41
- - โœ… Works everywhere Node.js runsโ€”no rebuild, no native dependencies
42
- - โœ… MongoDB-style queries: `{age: {$gt: 25}}`
43
- - โœ… Schema-less JSON documentsโ€”no migrations
44
- - โœ… Built-in InMemoryCache with automatic invalidation
64
+ ### The solution
65
+
66
+ AxioDB combines the parts of each that actually matter for an embedded use case:
67
+
68
+ - โœ… Works everywhere Node.js runs โ€” no rebuild, no native dependencies
69
+ - โœ… MongoDB-style queries: `{ age: { $gt: 25 } }`
70
+ - โœ… Schema-less JSON documents โ€” no migrations
71
+ - โœ… Built-in `InMemoryCache` with automatic invalidation
45
72
  - โœ… Multi-core parallelism with Worker Threads
46
73
  - โœ… Built-in web GUI at `localhost:27018`
47
- - โœ… **NEW:** AxioDBCloud - TCP remote access for Docker/Cloud deployments
74
+ - โœ… AxioDBCloud โ€” optional TCP remote access for Docker/cloud deployments
75
+
76
+ ### Is it a fit for you?
77
+
78
+ **Great fit for:**
79
+ - ๐Ÿ–ฅ๏ธ Desktop apps (Electron, Tauri)
80
+ - ๐Ÿ› ๏ธ CLI tools
81
+ - ๐Ÿ“ฆ Embedded systems
82
+ - ๐Ÿš€ Rapid prototyping
83
+ - ๐Ÿ  Local-first applications
84
+ - ๐Ÿ’ป Node.js apps requiring local storage
85
+
86
+ **Sweet spot:** 10Kโ€“500K documents with intelligent caching.
87
+
88
+ **Not a fit for:**
89
+ - 10M+ documents, or datasets that need to scale far beyond a single node โ†’ use PostgreSQL, MongoDB, or SQLite
90
+ - Multi-user web applications with hundreds of concurrent connections โ†’ AxioDB is single-instance, not a client-server database
91
+ - Relational data with JOINs and foreign-key constraints โ†’ AxioDB is document-based NoSQL
92
+ - Distributed systems needing replication, sharding, or clustering โ†’ AxioDB is single-node only
93
+ - Cross-collection ACID transactions โ†’ AxioDB's transactions are scoped to a single collection
94
+
95
+ **AxioDB isn't competing with PostgreSQL or MongoDB.** It's for when you need a database *embedded in your app* โ€” no server setup, no native dependencies. When you outgrow it, migrating to PostgreSQL or MongoDB is the right call, and expected.
48
96
 
49
97
  ---
50
98
 
51
- ## ๐Ÿš€ Key Features
52
-
53
- - **Intelligent Caching:** Advanced `InMemoryCache` system with automatic eviction policies, random TTL (5-15 min), and smart data persistence
54
- - **Production Security:** Enterprise-grade AES-256 encryption for sensitive cached data and secure access controls
55
- - **Frontend Integration:** Seamless integration with React, Vue, Angular, and all modern frontend frameworks
56
- - **Chainable Query Methods:** Fluent API for real-time data retrieval and filtering (`.query()`, `.Sort()`, `.Limit()`, `.Skip()`)
57
- - **Aggregation Pipelines:** MongoDB-compatible aggregation operations (`$match`, `$group`, `$sort`, `$project`, etc.)
58
- - **Bulk Operations:** High-performance bulk insert, update, and delete operations (`insertMany`, `UpdateMany`, `DeleteMany`)
59
- - **Tree-like Structure:** Hierarchical data storage for efficient retrieval and organization
60
- - **Auto Indexing:** Optimized indexes on document IDs for lightning-fast queries
61
- - **Index Cache with TTL:** In-memory index cache with automatic expiration (5-15 min random TTL) and disk persistence
62
- - **Selective Cache Invalidation:** Smart cache invalidation that only clears affected entries on updates/deletes
63
- - **Transaction Support:** ACID-compliant transactions with savepoints, rollback, and Write-Ahead Logging (WAL)
64
- - **Single Instance Architecture:** Unified management for unlimited databases, collections, and documents
65
- - **Web-Based GUI Dashboard:** Visual database administration, query execution, and real-time monitoring at `localhost:27018`
66
- - **Role-Based Access Control:** Built-in login for the Control Server with Super Admin/Admin/View roles and per-permission enforcement
67
- - **AxioDBCloud Remote Access:** TCP-based client for connecting to AxioDB from anywhereโ€”Docker, Cloud, or local network
68
- - **Zero-Configuration Setup:** Serverless architectureโ€”install and start building instantly
69
- - **Custom Database Path:** Flexible storage locations for better project organization
99
+ ## ๐Ÿ“ฆ Installation
100
+
101
+ ```bash
102
+ npm install axiodb@latest --save
103
+ ```
104
+
105
+ **Requirements:** Node.js โ‰ฅ20.0.0, npm โ‰ฅ6.0.0 (yarn โ‰ฅ1.0.0 optional). AxioDB runs on Node.js servers only โ€” it requires the filesystem, so it does not run in a browser.
106
+
107
+ ---
108
+
109
+ ## ๐Ÿ› ๏ธ Quick Start โ€” Local AxioDB
110
+
111
+ ```javascript
112
+ const { AxioDB } = require('axiodb');
113
+
114
+ // Create AxioDB instance with the built-in GUI enabled
115
+ const db = new AxioDB({ GUI: true }); // GUI available at http://localhost:27018
116
+
117
+ // Create a database and a collection
118
+ const myDB = await db.createDB('HelloWorldDB');
119
+ const collection = await myDB.createCollection('greetings');
120
+
121
+ // Insert and query โ€” Hello World! ๐Ÿ‘‹
122
+ await collection.insert({ message: 'Hello, Developer! ๐Ÿ‘‹' });
123
+ const result = await collection.query({}).exec();
124
+ console.log(result.data.documents[0].message); // Hello, Developer! ๐Ÿ‘‹
125
+ ```
126
+
127
+ > **Only one `AxioDB` instance per application.** It's a singleton by design โ€” create it once, then create as many databases and collections as you need under it.
70
128
 
71
129
  ---
72
130
 
73
- ## ๐Ÿ†• Recent Enhancements (v5.33+)
131
+ ## ๐Ÿš€ Features
132
+
133
+ ### Querying
134
+ - **Chainable Query API:** `.query()`, `.Sort()`, `.Limit()`, `.Skip()`, `.setCount()`, `.setProject()`, `.exec()` / `.findOne()`
135
+ - **MongoDB-style Query Operators:** `$gt`, `$gte`, `$lt`, `$lte`, `$ne`, `$in`, `$nin`, `$exists`, `$regex`, `$or`, `$and`
136
+ - **Aggregation Pipelines:** MongoDB-compatible (`$match`, `$group`, `$sort`, `$project`, `$limit`, `$skip`, `$unwind`, `$addFields`, ...)
137
+ - **Bulk Operations:** high-performance `insertMany`, `UpdateMany`, `deleteMany`
74
138
 
75
- ### Transaction Support
76
- Full ACID-compliant transaction support with:
77
- - **Savepoints:** Create intermediate checkpoints within transactions
78
- - **Rollback:** Revert to previous state on errors
79
- - **Write-Ahead Logging (WAL):** Crash recovery and data durability
80
- - **Session Management:** Scoped transactions with timeout support
139
+ ### Indexing
140
+ - **Auto Indexing:** every collection gets an automatic `documentId` index for O(1) lookups
141
+ - **Custom Field Indexes:** `newIndex(...fieldNames)` to add fast lookups on any field, `dropIndex(indexName)` to remove one, `getIndexes()` to list what's registered
142
+ - **Index Cache with TTL:** in-memory index cache with random 5โ€“15 min TTL (prevents cache stampede) and disk persistence for cold-start recovery
143
+ - **Automatic Document Removal:** documents are automatically removed from indexes when deleted
144
+ - **Dual-Write Pattern:** indexes persist to both memory (speed) and disk (durability)
145
+
146
+ ### Transactions
147
+ - **ACID-compliant, single-collection transactions** with savepoints, rollback, and Write-Ahead Logging (WAL) for crash recovery
148
+ - **Session Management:** scoped transactions with timeout support
81
149
 
82
150
  ```javascript
83
- // Transaction example
84
151
  const session = collection.startSession();
85
152
  await session.withTransaction(async (tx) => {
86
153
  await tx.insert({ name: 'Alice', balance: 1000 });
87
154
  await tx.update({ name: 'Bob' }, { $inc: { balance: -100 } });
88
- // Auto-commits on success, auto-rollbacks on error
155
+ // Auto-commits on success, auto-rolls-back on error
89
156
  });
90
157
  ```
91
158
 
92
- ### Enhanced Index System
93
- - **Index Cache with TTL:** Random 5-15 minute TTL prevents cache stampede
94
- - **Automatic Document Removal:** Documents are automatically removed from indexes when deleted
95
- - **Dual-Write Pattern:** Indexes persist to both memory (speed) and disk (durability)
96
- - **Cold Start Recovery:** Indexes reload from disk automatically on server restart
97
-
98
- ### Intelligent Cache System
99
- - **Selective Invalidation:** Only affected cache entries are cleared on update/delete
100
- - **Random TTL:** 5-15 minute random expiration prevents thundering herd
101
- - **Async Operations:** Non-blocking cache updates for faster response times
102
- - **Collection-Scoped Keys:** Cache keys include collection path to prevent collisions
159
+ ### Caching
160
+ - **`InMemoryCache`:** automatic eviction policies, random TTL (5โ€“15 min) to avoid thundering-herd cache expiry
161
+ - **Selective Invalidation:** only the affected cache entries are cleared on update/delete โ€” not the whole cache
162
+ - **Async, Non-blocking Updates:** cache writes don't block the response path
163
+ - **Collection-Scoped Keys:** cache keys include the collection path, so there's no cross-collection collision
164
+
165
+ ### Encryption & Security
166
+ - **AES-256 Encryption:** optional per collection, with an auto-generated or custom key
167
+ - **File-level Isolation:** each document lives in its own `.axiodb` file with locking
168
+ - See [Built-in Web GUI & Authentication](#-built-in-web-gui--authentication-rbac) for RBAC/login and [Security Best Practices](#-best-practices) below
169
+
170
+ ### Architecture
171
+ - **Tree-like Storage:** hierarchical, file-per-document layout for efficient retrieval, selective loading, and easy backup
172
+ - **Worker Threads:** non-blocking I/O and multi-core utilization, especially for reads
173
+ - **Single Instance Architecture:** one `AxioDB` instance manages unlimited databases and collections, with strong consistency
174
+ - **Zero-Configuration Setup:** serverless โ€” install and start building instantly
175
+ - **Custom Database Path:** flexible storage location via `CustomPath`
176
+
177
+ ### GUI & Remote Access
178
+ - **Web-based GUI Dashboard:** visual database browser, query execution, real-time monitoring at `localhost:27018`
179
+ - **Role-Based Access Control:** Super Admin / Admin / View roles, shared between the GUI and AxioDBCloud
180
+ - **AxioDBCloud:** TCP-based remote access โ€” connect to a running AxioDB instance from anywhere with the exact same API as embedded mode
103
181
 
104
182
  ---
105
183
 
106
- ## โ˜๏ธ AxioDBCloud - Remote Database Access (NEW!)
184
+ ## โ˜๏ธ AxioDBCloud โ€” Connecting Remotely
107
185
 
108
- **Host AxioDB in Docker, connect from anywhere!** AxioDBCloud provides TCP-based remote access to your AxioDB instance with the exact same API as local embedded mode.
186
+ **Host AxioDB in Docker or on a server, connect from anywhere** โ€” AxioDBCloud is a TCP client that mirrors the embedded API exactly, so switching from local to remote is a one-line change (`new AxioDB()` โ†’ `new AxioDBCloud()`).
109
187
 
110
- ### ๐ŸŒŸ Why AxioDBCloud?
188
+ - **๐Ÿ”„ Zero Code Changes:** same `createDB`/`createCollection`/`insert`/`query` API as embedded AxioDB
189
+ - **โšก Fast Binary Protocol:** length-prefixed JSON framing, with automatic reconnection
190
+ - **๐Ÿ” Optional Authentication:** shared RBAC with the GUI, per-IP rate limiting (see [Advanced](#advanced-tcp-authentication) below)
191
+ - **๐Ÿ“ฆ 35+ Commands:** full CRUD, aggregation, and indexing over the wire
192
+ - **๐Ÿ” Auto-Reconnect:** exponential backoff, up to 10 retry attempts
193
+ - **๐Ÿ’“ Heartbeat Monitoring:** `PING`/`PONG` every 30 seconds
194
+ - **๐Ÿ†” Request Correlation:** UUID-based request/response matching
195
+ - **๐Ÿงต Connection Pooling:** supports 1,000+ concurrent connections
196
+ - **๐Ÿ“ TypeScript Support:** full type definitions included
111
197
 
112
- - **๐Ÿš€ Deploy Once, Connect Everywhere:** Host AxioDB in Docker/Cloud, connect from multiple clients
113
- - **๐Ÿ”„ Zero Code Changes:** Same API as embedded AxioDB - just change the client class!
114
- - **โšก TCP Protocol:** Fast binary protocol with automatic reconnection
115
- - **๐Ÿ” Production Ready:** Connection pooling, heartbeat monitoring, error recovery
116
- - **๐Ÿ“ฆ Docker Support:** One-command deployment with included Dockerfile
198
+ **Use cases:** microservices sharing one AxioDB instance, Electron apps connecting to a local or remote database, teams sharing a development database, container/cloud deployments (AWS, Azure, GCP, DigitalOcean).
117
199
 
118
- ### Quick Start - Server (Docker)
200
+ ### Simple: connect without authentication
119
201
 
120
- ```bash
121
- # Pull and run the AxioDB Docker container
122
- docker run -d \
123
- --name axiodb-server \
124
- -p 27018:27018 \
125
- -p 27019:27019 \
126
- -v axiodb-data:/app \
127
- theankansaha/axiodb
128
-
129
- # Ports:
130
- # 27018 - HTTP GUI Dashboard
131
- # 27019 - TCP Remote Access (AxioDBCloud)
132
- # Volume: /app is the main data directory
133
- ```
134
-
135
- **Or run locally with Node.js:**
202
+ By default, TCP connections are unauthenticated โ€” anyone who can reach the port can run any command. This is fine for local development or a fully trusted private network.
136
203
 
204
+ **Server:**
137
205
  ```javascript
138
206
  const { AxioDB } = require('axiodb');
139
- const db = new AxioDB({ GUI: false, RootName: 'MyDB', CustomPath: '.', TCP: true }); // Enable TCP on port 27019
207
+ const db = new AxioDB({ GUI: false, RootName: 'MyDB', CustomPath: '.', TCP: true }); // TCP on port 27019
140
208
  ```
141
209
 
142
- ### Quick Start - Client
143
-
210
+ **Client:**
144
211
  ```javascript
145
212
  const { AxioDBCloud } = require('axiodb');
146
213
 
147
- // Connect to remote AxioDB (same API as embedded!)
148
214
  const client = new AxioDBCloud("axiodb://localhost:27019");
149
215
  await client.connect();
150
216
 
151
- // Use exactly like embedded AxioDB
152
217
  const db = await client.createDB("ProductionDB");
153
218
  const users = await db.createCollection("Users");
154
219
 
155
- // All operations work identically
156
220
  await users.insert({ name: "Alice", role: "admin" });
157
221
  const results = await users.query({ role: "admin" })
158
222
  .Limit(10)
@@ -162,191 +226,211 @@ const results = await users.query({ role: "admin" })
162
226
  await client.disconnect();
163
227
  ```
164
228
 
165
- ### Features
166
-
167
- โœ… **35+ Commands** - Full CRUD, aggregation, indexing
168
- โœ… **Auto-Reconnect** - Exponential backoff with up to 10 retry attempts
169
- โœ… **Heartbeat Monitoring** - PING/PONG every 30 seconds
170
- โœ… **Request Correlation** - UUID-based request/response matching
171
- โœ… **Connection Pooling** - Supports 1000+ concurrent connections
172
- โœ… **TypeScript Support** - Full type definitions included
173
- โœ… **Zero Breaking Changes** - Existing AxioDB code works unchanged
229
+ ### Advanced: TCP authentication
174
230
 
175
- ### Use Cases
231
+ Opt in with `TCPAuth: true` to require a username/password on every connection. This reuses the **exact same accounts and roles** as the GUI's RBAC system (see [Built-in Web GUI & Authentication](#-built-in-web-gui--authentication-rbac)) โ€” one set of credentials for both.
176
232
 
177
- - **Microservices:** Share one AxioDB instance across multiple services
178
- - **Desktop Apps:** Electron apps connecting to local/remote database
179
- - **Development:** Team members sharing a development database
180
- - **Docker Deployments:** Container-based production deployments
181
- - **Cloud Hosting:** Deploy to AWS, Azure, Google Cloud, DigitalOcean
182
-
183
- ๐Ÿ‘‰ **[Full AxioDBCloud Documentation](https://axiodb.in/cloud)** - Setup guides, API reference, Docker examples
184
-
185
- ---
233
+ **Server:**
234
+ ```javascript
235
+ const db = new AxioDB({ TCP: true, TCPAuth: true, RootName: 'MyDB', CustomPath: '.' });
236
+ ```
186
237
 
187
- ## ๐Ÿ† Performance Comparison
238
+ **Client โ€” credentials in the constructor** (recommended; `connect()` authenticates automatically):
239
+ ```javascript
240
+ const client = new AxioDBCloud("axiodb://localhost:27019", {
241
+ username: 'admin',
242
+ password: 'admin',
243
+ });
244
+ await client.connect();
188
245
 
189
- ### AxioDB vs SQLite
246
+ console.log(client.authenticatedUser); // { username, role, mustChangePassword }
247
+ ```
190
248
 
191
- | Feature | SQLite | AxioDB |
192
- | ------- | ------ | ------ |
193
- | **Native Dependencies** | โŒ Yes (C bindings) | โœ… Pure JavaScript |
194
- | **Query Language** | SQL Strings | JavaScript Objects |
195
- | **Schema Migrations** | โŒ Required (ALTER TABLE) | โœ… Schema-less (optional) |
196
- | **Built-in Caching** | โš ๏ธ Manual | โœ… InMemoryCache |
197
- | **Multi-core Processing** | โŒ Single-threaded | โœ… Worker Threads |
198
- | **Built-in GUI** | โŒ External tools only | โœ… Web interface included |
199
- | **Best For** | 10M+ records, relational data | 10K-500K documents, embedded apps |
249
+ **Client โ€” authenticate after connecting** (e.g. credentials supplied at runtime):
250
+ ```javascript
251
+ const client = new AxioDBCloud("axiodb://localhost:27019");
252
+ await client.connect();
253
+ await client.login('admin', 'admin');
254
+ ```
200
255
 
201
- ### AxioDB vs Traditional JSON Files
256
+ **What's enforced:**
257
+ - Every command except `PING`/`DISCONNECT`/`AUTHENTICATE` requires a prior successful login on that connection.
258
+ - The same role permissions as the GUI apply per command (e.g. a `View`-role user gets `403` on `CREATE_DB`).
259
+ - **Shared per-IP login rate limiter with the GUI:** 5 failed attempts within a trailing 15-minute window locks that IP out for 15 minutes (`429 Too Many Requests`) โ€” counted across both TCP and GUI login attempts from that IP.
260
+ - **Accounts that still need their forced password change are rejected outright (`403`)**, not allowed through with a warning โ€” there's no TCP command to change a password today, so log into the GUI (`http://localhost:27018`) to complete it first, or authenticate with an account that already has.
261
+ - If a Super Admin resets a user's password, changes their role, or deletes them via the GUI while that user has an open TCP connection, the TCP connection is immediately forced to re-authenticate on its next command.
202
262
 
203
- | Feature | Traditional JSON Files | AxioDB |
204
- | ------- | --------------------- | ------ |
205
- | **Storage** | Single JSON file | File-per-document |
206
- | **Caching** | None | InMemoryCache |
207
- | **Indexing** | None | Auto documentId |
208
- | **Query Speed** | Linear O(n) | Sub-millisecond O(1) |
209
- | **Scalability** | Poor | Excellent |
210
- | **Built-in Query Operators** | None | $gt, $lt, $regex, $in |
263
+ **Known limitations:** the TCP protocol itself is unencrypted (no TLS) โ€” deploy behind a private network, VPN, or your own TLS termination if connecting over an untrusted network. There's currently no TCP command to change a password; that must go through the GUI.
211
264
 
212
- **Benchmark:** AxioDB's documentId search with InMemoryCache provides **instant retrieval** compared to traditional JSON files that require full-file parsing (tested with 1M+ documents).
265
+ ๐Ÿ‘‰ **[Full AxioDBCloud Documentation](https://axiodb.in/cloud)** โ€” setup guides, API reference, Docker examples
213
266
 
214
267
  ---
215
268
 
216
- ## ๐Ÿ›ก๏ธ Security
269
+ ## ๐Ÿ”ง Troubleshooting
217
270
 
218
- - **AES-256 Encryption:** Optional for collections, with auto-generated or custom keys
219
- - **Secure Storage:** Data stored in `.axiodb` files with file-level isolation and locking
220
- - **InMemoryCache:** Minimizes disk reads and exposure of sensitive data
221
- - **Configurable Access Controls:** Protects against unauthorized access
222
- - **Automatic Cache Invalidation:** Ensures stale data is never served
271
+ ### "Not connected to server" right after calling `connect()`
223
272
 
224
- **Best Practices:**
273
+ `client.connect()` is asynchronous and must be `await`ed before you use the connection โ€” it resolves only once the TCP handshake (and, if `TCPAuth` is on, the `AUTHENTICATE` round-trip) has completed.
225
274
 
226
- - Use strong, unique encryption keys
227
- - Never hardcode keysโ€”use environment variables or secure key management
228
- - Implement proper access controls and regular backups
275
+ ```javascript
276
+ // โŒ Wrong โ€” races ahead before the connection (and login) finish
277
+ client.connect();
278
+ console.log(client.authenticatedUser); // undefined
279
+ await client.createDB("MyDB"); // "Not connected to server"
229
280
 
230
- For vulnerabilities, see [SECURITY.md](SECURITY.md).
281
+ // โœ… Right
282
+ await client.connect();
283
+ console.log(client.authenticatedUser); // populated
284
+ await client.createDB("MyDB"); // works
285
+ ```
231
286
 
232
- ---
287
+ ### `401` โ€” "Authentication required..."
233
288
 
234
- ## ๐ŸŽจ Built-in Web GUI
289
+ You're running with `TCPAuth: true` and sent a command before a successful `AUTHENTICATE`. Either pass `{ username, password }` in the `AxioDBCloud` constructor (auto-authenticates on `connect()`), or call `await client.login(username, password)` yourself before any other command.
235
290
 
236
- AxioDB includes a built-in web-based GUI for database visualization and managementโ€”perfect for Electron apps and development environments.
291
+ ### `403` โ€” "This account must change its password before it can be used over TCP..."
237
292
 
238
- ### Enabling the GUI
293
+ Your credentials are correct, but that account is still flagged for a forced password change (true for the default `admin`/`admin` account, and for any newly created user). Log into the GUI at `http://localhost:27018`, sign in, and complete the password change there โ€” there's no TCP command for this yet. Then reconnect with the new password, or use a different account that has already completed its change.
239
294
 
240
- ```javascript
241
- // Enable GUI when creating AxioDB instance
242
- const db = new AxioDB({ GUI: true }); // GUI available at localhost:27018
295
+ ### `429` โ€” "Too many failed login attempts..."
243
296
 
244
- // With custom database path
245
- const db = new AxioDB({ GUI: true, RootName: "MyDB", CustomPath: "./custom/path" });
246
- ```
297
+ Five failed logins from your IP within 15 minutes trigger a 15-minute lockout, shared between TCP and the GUI. Double check the credentials you're sending, wait out the cooldown, or fix the underlying typo/config issue causing repeated failures โ€” there's no way to clear the lockout early.
247
298
 
248
- ### GUI Features
299
+ ### `403` โ€” "This is a reserved system database"
249
300
 
250
- - ๐Ÿ“Š Visual database and collection browser
251
- - ๐Ÿ” Real-time data inspection
252
- - ๐Ÿ“ Query execution interface
253
- - ๐Ÿ“ˆ Performance monitoring
254
- - ๐ŸŽฏ No external dependencies required
301
+ You (or a client) tried to read/write a database literally named `config` โ€” that name is reserved for AxioDB's own RBAC storage (`users`/`roles`/`permissions`) and is blocked on both the GUI and TCP, authenticated or not. Use a different database name.
255
302
 
256
- Access the GUI at `http://localhost:27018` when enabled.
303
+ ### Connection refused / timeout connecting to `axiodb://host:27019`
257
304
 
258
- ### Authentication & Access Control (v9.8+)
305
+ - Confirm the server was started with `TCP: true` (or, in Docker, `AXIODB_TCP=true`, the default).
306
+ - Confirm the port is published: `-p 27019:27019` on `docker run`, or that nothing else on the host is bound to 27019.
307
+ - If you're getting a protocol error mentioning "Message exceeds maximum size" or "Received HTTP data on TCP port," you're likely pointed at the GUI port (27018) instead of the TCP port (27019) โ€” check your connection string.
259
308
 
260
- The Control Server ships with built-in login and role-based access control (RBAC). On first start with `GUI: true`, AxioDB seeds a reserved `config` database (hidden from the regular database list) containing three collectionsโ€”`users`, `roles`, `permissions`โ€”and a default account:
309
+ ### Docker container issues (won't start, port conflicts, data not persisting)
261
310
 
262
- ```
263
- Username: admin
264
- Password: admin
265
- ```
311
+ See the [Docker Deployment](#-docker-deployment) section below, and `Docker/README.md` in the repository for a fuller Docker-specific troubleshooting guide (`docker logs`, port-conflict remapping, volume-mounting checklist).
266
312
 
267
- You'll be forced to change this password on first login (this applies to every account, not just the default one). Three predefined roles are seeded automatically:
313
+ ---
268
314
 
269
- | Role | Access |
270
- |------|--------|
271
- | **Super Admin** | Full access, including creating users/roles |
272
- | **Admin** | Full database/collection/document access, no user or role management |
273
- | **View** | Read-only access to databases, collections, and documents |
315
+ ## ๐Ÿณ Docker Deployment
274
316
 
275
- A Super Admin can create additional roles from the predefined permission catalogue and create new users with any role. Sessions are held only in server memory (never persisted to disk) and are tied to an httpOnly cookie, so restarting the server logs everyone out.
317
+ ### Simple: run the container
276
318
 
277
- > **Security note:** RBAC protects the Control Server's HTTP API; it is still intended for trusted local/network access, not public internet exposure.
319
+ ```bash
320
+ docker run -d \
321
+ --name axiodb-server \
322
+ -p 27018:27018 \
323
+ -p 27019:27019 \
324
+ -e AXIODB_TCP_AUTH=true \
325
+ -v axiodb-data:/app \
326
+ theankansaha/axiodb
278
327
 
279
- ---
328
+ # Ports:
329
+ # 27018 - HTTP GUI Dashboard
330
+ # 27019 - TCP Remote Access (AxioDBCloud)
331
+ # Volume: /app is the main data directory
332
+ ```
280
333
 
281
- ## โš™๏ธ Architecture & Internal Mechanisms
334
+ TCP authentication is on by default in the image. Log into the GUI at `http://localhost:27018` as `admin`/`admin` to complete the forced password change before connecting over TCP (see [Troubleshooting](#-troubleshooting) if you skip this step).
282
335
 
283
- ### Tree Structure for Fast Data Retrieval
336
+ ### Advanced: env vars, volumes, Compose
284
337
 
285
- Hierarchical storage enables O(1) document lookups, logarithmic query time, and efficient indexing. Each document is isolated in its own file, supporting selective loading and easy backup.
338
+ Every option below has a default matching the image's previous fixed behavior โ€” override any of them with `-e VAR=value` at `docker run` time, no rebuild required:
286
339
 
287
- ### Worker Threads for Parallel Processing
340
+ | Variable | Default | Description |
341
+ | --- | --- | --- |
342
+ | `AXIODB_GUI` | `true` | Enable the HTTP Control Server / web GUI on port 27018 |
343
+ | `AXIODB_TCP` | `true` | Enable the AxioDBCloud TCP server on port 27019 |
344
+ | `AXIODB_TCP_AUTH` | `true` | Require username/password authentication on TCP connections (same RBAC accounts as the GUI) |
345
+ | `AXIODB_ROOT_NAME` | `AxioDB` | Name of the root database folder created under the data volume |
346
+ | `AXIODB_CUSTOM_PATH` | *(container's working directory)* | Custom path for database storage inside the container |
288
347
 
289
- Leverages Node.js Worker Threads for non-blocking I/O, multi-core utilization, and scalable performanceโ€”especially for read operations.
348
+ > Ports themselves (27018/27019) aren't configurable via environment variable โ€” remap them at the Docker layer with `-p <host-port>:27018` / `-p <host-port>:27019`.
290
349
 
291
- ### Two-Pointer Searching Algorithm
350
+ **Disabling TCP authentication** (only on a trusted private network โ€” the wire is unencrypted; see [Known limitations](#advanced-tcp-authentication)):
351
+ ```bash
352
+ docker run -d \
353
+ --name axiodb-server \
354
+ -p 27018:27018 \
355
+ -p 27019:27019 \
356
+ -e AXIODB_TCP_AUTH=false \
357
+ -v axiodb-data:/app \
358
+ theankansaha/axiodb
359
+ ```
292
360
 
293
- Optimized for range queries and filtered searches, minimizing memory usage and computational overhead.
361
+ **Docker Compose:**
362
+ ```yaml
363
+ version: "3.8"
364
+
365
+ services:
366
+ axiodb:
367
+ image: theankansaha/axiodb
368
+ container_name: axiodb-server
369
+ ports:
370
+ - "27018:27018"
371
+ - "27019:27019"
372
+ environment:
373
+ - AXIODB_GUI=true
374
+ - AXIODB_TCP=true
375
+ - AXIODB_TCP_AUTH=true
376
+ - AXIODB_ROOT_NAME=AxioDB
377
+ volumes:
378
+ - axiodb-data:/app
379
+ restart: unless-stopped
380
+
381
+ volumes:
382
+ axiodb-data:
383
+ ```
294
384
 
295
- ### InMemoryCache System
385
+ **Building the image from source, and a fuller Docker troubleshooting guide** (container won't start, port-in-use, data-persistence checks) live in [`Docker/README.md`](Docker/README.md) โ€” the canonical Docker doc, not duplicated here in full.
296
386
 
297
- Built-in intelligent caching with automatic eviction policies, TTL support, and memory optimization. Delivers sub-millisecond response times for frequently accessed data.
387
+ ---
298
388
 
299
- ### Query Processing Pipeline
389
+ ## ๐ŸŽจ Built-in Web GUI & Authentication (RBAC)
300
390
 
301
- Intelligent caching, parallelized processing, lazy evaluation, and just-in-time query optimization for maximum throughput.
391
+ AxioDB includes a built-in web-based GUI for database visualization and management โ€” perfect for Electron apps and development environments.
302
392
 
303
- ### Single Instance Architecture
393
+ ### Enabling the GUI
304
394
 
305
- Ensures ACID compliance, strong data consistency, and simplified deployment. One AxioDB instance manages all databases and collections.
395
+ ```javascript
396
+ // Enable GUI when creating the AxioDB instance
397
+ const db = new AxioDB({ GUI: true }); // GUI available at localhost:27018
306
398
 
307
- ### Designed for Node.js Developers
399
+ // With a custom database path
400
+ const db = new AxioDB({ GUI: true, RootName: "MyDB", CustomPath: "./custom/path" });
401
+ ```
308
402
 
309
- Native JavaScript API, promise-based interface, lightweight dependency, and simple learning curve.
403
+ **GUI Features:** visual database and collection browser, real-time data inspection, query execution interface, performance monitoring, no external dependencies required. Access at `http://localhost:27018` when enabled.
310
404
 
311
- ---
405
+ ### Authentication & Access Control
312
406
 
313
- ## ๐Ÿ“ฆ Installation
407
+ The Control Server ships with built-in login and role-based access control (RBAC) โ€” the same system TCP's [`TCPAuth`](#advanced-tcp-authentication) reuses. On first start with `GUI: true` (or `TCP: true, TCPAuth: true`), AxioDB seeds a reserved `config` database (hidden from the regular database list) containing three collections โ€” `users`, `roles`, `permissions` โ€” and a default account:
314
408
 
315
- ```bash
316
- npm install axiodb@latest --save
409
+ ```
410
+ Username: admin
411
+ Password: admin
317
412
  ```
318
413
 
319
- ---
320
-
321
- ## ๐Ÿ› ๏ธ Quick Start
322
-
323
- ### Hello World in 30 Seconds
414
+ You'll be forced to change this password on first login (this applies to every account, not just the default one โ€” there's currently no way around it other than completing the change via the GUI). Three predefined roles are seeded automatically:
324
415
 
325
- ```javascript
326
- // npm install axiodb
327
- const { AxioDB } = require('axiodb');
416
+ | Role | Access |
417
+ |------|--------|
418
+ | **Super Admin** | Full access, including creating users/roles |
419
+ | **Admin** | Full database/collection/document access, no user or role management |
420
+ | **View** | Read-only access to databases, collections, documents, and indexes |
328
421
 
329
- // Create AxioDB instance with built-in GUI
330
- const db = new AxioDB({ GUI: true }); // Enable GUI at localhost:27018
422
+ A Super Admin can create additional roles from the predefined permission catalogue and create new users with any role. Sessions are held only in server memory (never persisted to disk) and are tied to an httpOnly cookie, so restarting the server logs everyone out.
331
423
 
332
- // Create database and collection
333
- const myDB = await db.createDB('HelloWorldDB');
334
- const collection = await myDB.createCollection('greetings', false);
424
+ **Login rate limiting:** after 5 failed login attempts from the same IP within a trailing 15-minute window, that IP is locked out for 15 minutes (`429 Too Many Requests`) โ€” regardless of username. This limiter is shared with [TCP `AUTHENTICATE` attempts](#advanced-tcp-authentication) (see [Troubleshooting](#-troubleshooting) for what the error looks like).
335
425
 
336
- // Insert and retrieve data - Hello World! ๐Ÿ‘‹
337
- await collection.insert({ message: 'Hello, Developer! ๐Ÿ‘‹' });
338
- const result = await collection.findAll();
339
- console.log(result[0].message); // Hello, Developer! ๐Ÿ‘‹
340
- ```
426
+ **Index management:** the Control Server also exposes `GET /api/index/list`, `POST /api/index/create`, and `DELETE /api/index/delete`, gated by the same `index:view` / `index:create` / `index:delete` permissions (View role gets view-only, Admin and Super Admin get all three).
341
427
 
342
- **Node.js Required:** AxioDB runs on Node.js servers (v20.0.0+), not in browsers.
428
+ > **Security note:** RBAC protects the Control Server's HTTP API and TCP server; both are still intended for trusted local/network access, not public internet exposure. See [Troubleshooting](#-troubleshooting) for the TLS caveat on TCP.
343
429
 
344
430
  ---
345
431
 
346
432
  ## ๐Ÿ› ๏ธ Detailed Usage
347
433
 
348
- > **Important:** Only one AxioDB instance should be initialized per application for consistency and security.
349
-
350
434
  ### Collection Creation Options
351
435
 
352
436
  ```javascript
@@ -365,10 +449,10 @@ const db = new AxioDB();
365
449
 
366
450
  const userDB = await db.createDB("MyDB");
367
451
 
368
- // Create basic collection
452
+ // Create a basic collection
369
453
  const userCollection = await userDB.createCollection("Users");
370
454
 
371
- // Create encrypted collection with custom key
455
+ // Create an encrypted collection with a custom key
372
456
  const secureCollection = await userDB.createCollection(
373
457
  "SecureUsers",
374
458
  true,
@@ -386,24 +470,59 @@ const results = await userCollection
386
470
  .Limit(10)
387
471
  .Sort({ age: 1 })
388
472
  .exec();
389
- console.log(results);
473
+ console.log(results.data.documents);
474
+ ```
475
+
476
+ ### Worked example: e-commerce product catalog
477
+
478
+ ```javascript
479
+ const { AxioDB } = require('axiodb');
480
+ const db = new AxioDB();
481
+
482
+ const shopDB = await db.createDB('ecommerce');
483
+ const products = await shopDB.createCollection('products');
484
+
485
+ await products.insert({
486
+ name: 'Laptop',
487
+ price: 999.99,
488
+ category: 'Electronics',
489
+ inStock: true,
490
+ });
491
+
492
+ // Sorted, filtered query
493
+ const electronics = await products
494
+ .query({ category: 'Electronics', inStock: true })
495
+ .Sort({ price: 1 })
496
+ .exec();
497
+ ```
498
+
499
+ ### Worked example: encrypted user records
500
+
501
+ ```javascript
502
+ const users = await db.createCollection(
503
+ 'users',
504
+ true, // encrypted
505
+ process.env.USER_ENCRYPTION_KEY, // custom key from env โ€” see Best Practices below
506
+ );
507
+
508
+ await users.insert({
509
+ username: 'johndoe',
510
+ email: 'john@example.com',
511
+ passwordHash: hashedPassword,
512
+ createdAt: new Date(),
513
+ });
514
+
515
+ const user = await users.query({ username: 'johndoe' }).exec();
390
516
  ```
391
517
 
392
518
  ---
393
519
 
394
520
  ## ๐ŸŒŸ Advanced Features
395
521
 
396
- - **Multiple Databases:** Architect scalable apps with multiple databases and collections with flexible security
397
- - **Aggregation Pipelines:** Complex data processing with MongoDB-like syntax
398
- - **Encryption:** Military-grade AES-256 encryption for collections
399
- - **Bulk Operations:** Efficient batch insert, update, and delete
400
- - **Flexible Collection Types:** Basic or encrypted
401
- - **Custom Query Operators:** `$gt`, `$lt`, `$in`, `$regex`, `$gte`, `$lte`, `$ne`, `$nin`, `$exists`, `$or`, `$and`
402
- - **Schema-less Design:** Store any JSON structure without predefined schemas
403
- - **Performance Optimization:** Fast lookups, pagination, and intelligent caching with random TTL
404
- - **ACID Transactions:** Single-collection transactions with savepoints, rollback, and WAL recovery
405
- - **Index Management:** Create custom indexes, automatic document-to-index sync on CRUD operations
406
- - **Enterprise Data Management:** Bulk operations, conditional updates, atomic transactions
522
+ - **Multiple Databases:** architect scalable apps with multiple databases and collections, each with independent security settings
523
+ - **Custom Query Processing:** the full operator set (`$gt`, `$lt`, `$in`, `$regex`, `$gte`, `$lte`, `$ne`, `$nin`, `$exists`, `$or`, `$and`) plus aggregation pipelines
524
+ - **Enterprise Data Management:** bulk operations, conditional updates, atomic transactions
525
+ - **Performance Optimization:** fast lookups, pagination, and intelligent caching with random TTL
407
526
 
408
527
  ---
409
528
 
@@ -411,7 +530,7 @@ console.log(results);
411
530
 
412
531
  ### AxioDB
413
532
 
414
- - `createDB(dbName: string, schemaValidation: boolean = true): Promise<Database>`
533
+ - `createDB(dbName: string): Promise<Database>`
415
534
  - `deleteDatabase(dbName: string): Promise<SuccessInterface | ErrorInterface>`
416
535
 
417
536
  ### Database
@@ -429,8 +548,9 @@ console.log(results);
429
548
  - `delete(query: object): Deleter`
430
549
  - `aggregate(pipeline: object[]): Aggregation`
431
550
  - `startSession(options?: SessionOptions): Session`
432
- - `createIndex(fieldName: string): Promise<SuccessInterface>`
551
+ - `newIndex(...fieldNames: string[]): Promise<SuccessInterface>`
433
552
  - `dropIndex(indexName: string): Promise<SuccessInterface | ErrorInterface>`
553
+ - `getIndexes(): Promise<SuccessInterface | ErrorInterface>` โ€” lists all indexes registered on the collection
434
554
 
435
555
  ### Reader
436
556
 
@@ -457,45 +577,95 @@ console.log(results);
457
577
 
458
578
  ---
459
579
 
460
- ## ๐ŸŽฏ When to Use AxioDB
580
+ ## โœ… Best Practices
461
581
 
462
- **Perfect For:**
463
- - ๐Ÿ–ฅ๏ธ Desktop apps (Electron, Tauri)
464
- - ๐Ÿ› ๏ธ CLI tools
465
- - ๐Ÿ“ฆ Embedded systems
466
- - ๐Ÿš€ Rapid prototyping
467
- - ๐Ÿ  Local-first applications
468
- - ๐Ÿ’ป Node.js apps requiring local storage
582
+ **Use environment variables for encryption keys and TCP credentials โ€” never hardcode them:**
469
583
 
470
- **Sweet Spot:** 10K-500K documents with intelligent caching
584
+ ```javascript
585
+ // โŒ Bad
586
+ const collection = await db.createCollection('data', true, 'myKey123');
471
587
 
472
- ---
588
+ // โœ… Good
589
+ const collection = await db.createCollection(
590
+ 'data',
591
+ true,
592
+ process.env.AXIODB_ENCRYPTION_KEY,
593
+ );
594
+ ```
595
+
596
+ **Use `documentId` for the fastest possible lookups** โ€” it's the one field that's always indexed automatically, backed by `InMemoryCache`:
597
+
598
+ ```javascript
599
+ const user = await collection.query({ documentId: 'ABC123' }).exec();
600
+ ```
601
+
602
+ **Handle errors explicitly** โ€” AxioDB operations reject/return error responses rather than throwing silently:
603
+
604
+ ```javascript
605
+ try {
606
+ await collection.insert({ name: 'User' });
607
+ } catch (error) {
608
+ console.error('Insert failed:', error);
609
+ }
610
+ ```
473
611
 
474
- ## ๐Ÿ’ญ Honest Positioning
612
+ **Clean up resources you no longer need:**
613
+
614
+ ```javascript
615
+ await database.deleteCollection('tempCollection');
616
+ await db.deleteDatabase('tempDB');
617
+ ```
475
618
 
476
- **AxioDB is not competing with PostgreSQL or MongoDB.** It's for when you need a database embedded in your appโ€”no server setup, no native dependencies. Think SQLite-scale with MongoDB-style queries and built-in caching.
619
+ **Encryption & access control:**
620
+ - Use strong, unique encryption keys
621
+ - Never hardcode keys โ€” use environment variables or a secrets manager
622
+ - Implement proper access controls and take regular backups
623
+ - For AxioDBCloud/GUI, rotate the default `admin` password immediately (see [Authentication & Access Control](#-built-in-web-gui--authentication-rbac))
477
624
 
478
- When you outgrow AxioDB (1M+ documents, distributed systems), migrate to PostgreSQL or MongoDB. That's the right choice, and we support it.
625
+ For vulnerability reporting, see [SECURITY.md](SECURITY.md).
479
626
 
480
627
  ---
481
628
 
482
- ## โš ๏ธ Limitations & Scale Considerations
629
+ ## โš™๏ธ Architecture & Internal Mechanisms
483
630
 
484
- ### Scale & Performance Boundaries
631
+ - **Tree Structure for Fast Data Retrieval:** hierarchical storage enables O(1) document lookups and efficient indexing. Each document is isolated in its own file, supporting selective loading and easy backup.
632
+ - **Worker Threads for Parallel Processing:** leverages Node.js Worker Threads for non-blocking I/O, multi-core utilization, and scalable performance โ€” especially for read operations.
633
+ - **Two-Pointer Searching Algorithm:** optimized for range queries and filtered searches, minimizing memory usage and computational overhead.
634
+ - **`InMemoryCache` System:** automatic eviction policies, TTL support, and memory optimization, delivering sub-millisecond response times for frequently accessed data.
635
+ - **Query Processing Pipeline:** intelligent caching, parallelized processing, lazy evaluation, and just-in-time query optimization.
636
+ - **Single Instance Architecture:** ensures ACID compliance, strong data consistency, and simplified deployment โ€” one `AxioDB` instance manages all databases and collections.
637
+ - **Designed for Node.js Developers:** native JavaScript API, promise-based interface, lightweight dependency footprint, simple learning curve.
485
638
 
486
- - **Dataset Size:** Optimized for 10K-500K documents. For 10M+ documents, use PostgreSQL, MongoDB, or SQLite which are designed for massive scale.
639
+ ---
487
640
 
488
- - **Concurrency:** Single-instance architecture. For multi-user web applications with hundreds of concurrent connections, use traditional client-server databases.
641
+ ## ๐Ÿ† Comparisons
489
642
 
490
- - **Relational Data:** Document-based NoSQL architecture. No JOIN operations. For complex relational data with foreign keys and constraints, use SQL databases.
643
+ ### AxioDB vs SQLite
491
644
 
492
- - **Distributed Systems:** Single-node only. No replication, no sharding, no clustering. For distributed systems, use MongoDB or CouchDB.
645
+ | Feature | SQLite | AxioDB |
646
+ | ------- | ------ | ------ |
647
+ | **Native Dependencies** | โŒ Yes (C bindings) | โœ… Pure JavaScript |
648
+ | **Query Language** | SQL Strings | JavaScript Objects |
649
+ | **Schema Migrations** | โŒ Required (ALTER TABLE) | โœ… Schema-less |
650
+ | **Built-in Caching** | โš ๏ธ Manual | โœ… InMemoryCache |
651
+ | **Multi-core Processing** | โŒ Single-threaded | โœ… Worker Threads |
652
+ | **Built-in GUI** | โŒ External tools only | โœ… Web interface included |
653
+ | **Best For** | 10M+ records, relational data | 10Kโ€“500K documents, embedded apps |
493
654
 
494
- - **Transactions:** Single-collection ACID transactions supported. Cross-collection transactions are not supported. For multi-collection transaction requirements, use PostgreSQL or MongoDB.
655
+ ### AxioDB vs Traditional JSON Files
495
656
 
496
- ---
657
+ | Feature | Traditional JSON Files | AxioDB |
658
+ | ------- | --------------------- | ------ |
659
+ | **Storage** | Single JSON file | File-per-document |
660
+ | **Caching** | None | InMemoryCache |
661
+ | **Indexing** | None | Auto `documentId` + custom fields |
662
+ | **Query Speed** | Linear O(n) | Sub-millisecond O(1) |
663
+ | **Scalability** | Poor | Excellent (up to sweet spot) |
664
+ | **Built-in Query Operators** | None | `$gt`, `$lt`, `$regex`, `$in`, ... |
665
+
666
+ **Benchmark:** AxioDB's `documentId` search with `InMemoryCache` provides instant retrieval compared to traditional JSON files, which require full-file parsing (tested with 1M+ documents).
497
667
 
498
- ## โš–๏ธ AxioDB vs lowdb, nedb, better-sqlite3
668
+ ### AxioDB vs lowdb, nedb, better-sqlite3
499
669
 
500
670
  | Feature | lowdb | nedb | better-sqlite3 | AxioDB |
501
671
  |---------|-------|------|---------------|--------|
@@ -515,109 +685,71 @@ When you outgrow AxioDB (1M+ documents, distributed systems), migrate to Postgre
515
685
 
516
686
  ---
517
687
 
688
+ ## โš ๏ธ Limitations & Honest Positioning
689
+
690
+ - **Dataset Size:** optimized for 10Kโ€“500K documents. For 10M+, use PostgreSQL, MongoDB, or SQLite.
691
+ - **Concurrency:** single-instance architecture. For multi-user web apps with hundreds of concurrent connections, use a traditional client-server database.
692
+ - **Relational Data:** document-based NoSQL, no JOIN operations. For complex relational data with foreign keys, use a SQL database.
693
+ - **Distributed Systems:** single-node only โ€” no replication, sharding, or clustering. Use MongoDB or CouchDB for that.
694
+ - **Transactions:** single-collection ACID transactions only. For cross-collection transaction requirements, use PostgreSQL or MongoDB.
695
+
696
+ None of this is a shortcoming to apologize for โ€” AxioDB is deliberately scoped to the embedded/local-first niche. When you outgrow it, that's a sign to migrate, not a bug to file.
697
+
698
+ ---
699
+
518
700
  ## โ“ FAQ
519
701
 
520
702
  **Q: What is AxioDB?**
521
- An embedded NoSQL database for Node.js. Pure JavaScript, zero native dependencies. `npm install axiodb` and you have a database โ€” no server, no node-gyp, no electron-rebuild.
703
+ An embedded NoSQL database for Node.js. Pure JavaScript, zero native dependencies. `npm install axiodb` and you have a database โ€” no server, no `node-gyp`, no `electron-rebuild`.
522
704
 
523
705
  **Q: Is AxioDB a replacement for MongoDB?**
524
- No. AxioDB is embedded (runs inside your app). MongoDB is a client-server database for multi-user systems. Use AxioDB for desktop apps, CLI tools, and local-first apps up to 500K documents. Use MongoDB when you need a shared networked database.
706
+ No. AxioDB is embedded (runs inside your app); MongoDB is a client-server database for multi-user systems. Use AxioDB for desktop apps, CLI tools, and local-first apps up to ~500K documents; use MongoDB when you need a shared networked database.
525
707
 
526
708
  **Q: Does AxioDB work with Electron?**
527
709
  Yes โ€” this is the primary use case it was built for. Zero native dependencies means no `electron-rebuild`, no platform-specific `.node` files, no compilation step.
528
710
 
529
- **Q: What is the difference between AxioDB and better-sqlite3?**
530
- `better-sqlite3` uses C native bindings and requires `node-gyp` compilation. AxioDB is pure JavaScript โ€” no compilation, works across all platforms including Electron without a rebuild step. AxioDB also uses MongoDB-style JSON queries instead of SQL strings.
531
-
532
- **Q: What is the difference between AxioDB and lowdb?**
533
- `lowdb` stores everything in a single JSON file โ€” it gets slow above 1,000โ€“5,000 records because every read parses the entire file. AxioDB uses file-per-document storage, InMemoryCache, Worker Threads, and auto-indexing โ€” optimized for 10Kโ€“500K documents with O(1) lookups by documentId.
534
-
535
- **Q: What is the difference between AxioDB and nedb?**
536
- NeDB is abandoned since 2016. AxioDB is actively maintained with TypeScript, ACID transactions, Worker Threads, AES-256 encryption, custom field indexing, built-in GUI, and AxioDBCloud remote access.
711
+ **Q: How does AxioDB compare to better-sqlite3 / lowdb / nedb?**
712
+ See the [Comparisons](#-comparisons) tables above for the full breakdown โ€” in short: no native bindings (unlike better-sqlite3), no single-file bottleneck (unlike lowdb), and actively maintained with TypeScript/transactions/encryption (unlike the abandoned nedb).
537
713
 
538
714
  **Q: How many documents can AxioDB handle?**
539
- Optimized for 10,000โ€“500,000 documents. For 1M+, use PostgreSQL or MongoDB. documentId lookups take ~1ms on 10K documents with InMemoryCache.
715
+ Optimized for 10,000โ€“500,000 documents. For 1M+, use PostgreSQL or MongoDB. `documentId` lookups take ~1ms on 10K documents with `InMemoryCache`.
540
716
 
541
717
  **Q: Does AxioDB support TypeScript?**
542
718
  Yes. Full type definitions are included โ€” no separate `@types` package needed.
543
719
 
544
720
  **Q: Does AxioDB work in the browser?**
545
- No. AxioDB requires Node.js (v20+) and the filesystem. Server-side and desktop only.
721
+ No. AxioDB requires Node.js (v20+) and the filesystem โ€” server-side and desktop only.
546
722
 
547
723
  **Q: What is AxioDBCloud?**
548
- TCP-based remote access for AxioDB. Deploy AxioDB in Docker, connect from multiple clients with the exact same API. Supports 1,000+ concurrent connections with auto-reconnect.
549
-
550
- ---
551
-
552
- ## ๐Ÿ”ฎ Future Roadmap
553
-
554
- - **Data Export & Import:** Seamless data migration with support for JSON, CSV, and native AxioDB formats
555
- - **Enhanced Web GUI:** Advanced web interface with real-time analytics, visual query builder, and performance monitoring
556
- - **Comprehensive Documentation:** Extensive tutorials, interactive examples, and complete API references for all skill levels
557
- - **Performance Optimizations:** Continued improvements to query performance and caching strategies
558
-
559
- ---
560
-
561
- ## ๐Ÿค Contributing
562
-
563
- We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
564
-
565
- ---
566
-
567
- ## ๐Ÿ“œ License
568
-
569
- MIT License. See [LICENSE](LICENSE).
570
-
571
- ---
572
-
573
- ## ๐Ÿ™Œ Acknowledgments
574
-
575
- Special thanks to all contributors and supporters of AxioDB. Your feedback and contributions make this project better!
724
+ TCP-based remote access for AxioDB. Deploy AxioDB in Docker, connect from multiple clients with the exact same API. Supports 1,000+ concurrent connections with auto-reconnect. Optional username/password authentication (`TCPAuth: true`) reuses the same RBAC accounts as the GUI โ€” see [AxioDBCloud](#-axiodbcloud--connecting-remotely) above.
576
725
 
577
726
  ---
578
727
 
579
- ## ๐Ÿ“‹ Requirements
580
-
581
- - **Node.js:** >=20.0.0
582
- - **npm:** >=6.0.0
583
- - **yarn:** >=1.0.0 (optional)
584
-
585
- ---
728
+ ## ๐Ÿค Contributing, License & Support
586
729
 
587
- ## ๐ŸŒ Documentation Website
730
+ **Contributing:** we welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
588
731
 
589
- The AxioDB documentation is built with:
590
- - **React 18** with TypeScript
591
- - **Vite** for fast development and building
592
- - **TailwindCSS** for styling
593
- - **Lucide React** for icons
732
+ **License:** MIT. See [LICENSE](LICENSE).
594
733
 
595
- To run the documentation locally:
734
+ **Requirements:** Node.js โ‰ฅ20.0.0, npm โ‰ฅ6.0.0, yarn โ‰ฅ1.0.0 (optional).
596
735
 
736
+ **Documentation website:** built with React 18 + TypeScript, Vite, TailwindCSS, and Lucide React. To run it locally:
597
737
  ```bash
598
738
  cd Document
599
739
  npm install
600
740
  npm run dev
601
741
  ```
742
+ Available at `http://localhost:5173`.
602
743
 
603
- The documentation site will be available at `http://localhost:5173`
744
+ **Author:** Ankan Saha
604
745
 
605
- ---
606
-
607
- ## ๐Ÿ“ Author
746
+ **Support the project:**
747
+ - โญ Star the repository
748
+ - ๐Ÿ› Report issues
749
+ - ๐Ÿ’ก Suggest features
750
+ - ๐Ÿค Contribute code
751
+ - ๐Ÿ’ฐ [Sponsor the project](https://github.com/sponsors/AnkanSaha)
608
752
 
609
- **Ankan Saha**
753
+ **Acknowledgments:** special thanks to all contributors and supporters of AxioDB โ€” your feedback and contributions make this project better.
610
754
 
611
755
  ---
612
-
613
- ## ๐Ÿ’– Support
614
-
615
- If you find AxioDB helpful, consider:
616
- - โญ Starring the repository
617
- - ๐Ÿ› Reporting issues
618
- - ๐Ÿ’ก Suggesting features
619
- - ๐Ÿค Contributing code
620
- - ๐Ÿ’ฐ [Sponsoring the project](https://github.com/sponsors/AnkanSaha)
621
-
622
- ---
623
-