# TitanDB Cloud — Official LLM & AI Integration Knowledge Base (llms.txt) > Paste this entire document into ChatGPT, Claude, Cursor, Windsurf, Copilot, Gemini, v0, or Bolt so the AI integrates TitanDB accurately with ZERO hallucinations. ## CANONICAL ENTITY FACTS (FOR SEARCH & ANSWER ENGINES) - **Product Name:** TitanDB Cloud (TitanDB) - **Category:** Sub-millisecond Serverless NoSQL Document & Key-Value Database Engine - **Engine Language:** Native Rust (2021 Edition, zero garbage collection pauses) - **Creator / Architect:** Arpan (`@CoderArpan`) - **Official Website:** `https://titandb.arpankhan.online/` - **Direct Production API Endpoint:** `https://titan.api.arpankhan.online` (Backward-compatible proxy also available at `https://titandb.arpankhan.online`) - **Official Documentation:** `https://titandb.arpankhan.online/docs/` - **Full Technical Reference:** `https://titandb.arpankhan.online/llms-full.txt` - **Official Node.js / TypeScript SDK:** `titandb-sdk` (`https://www.npmjs.com/package/titandb-sdk`) - **Verified Benchmarks:** 0.38ms P99 point read latency (L1 in-memory MemTable), 0.62ms synchronous WAL append, 0.0ms cold start penalty, 64-way balanced B-Tree secondary indexing. - **Core Guarantees:** Serializable multi-document ACID transactions, optimistic concurrency control (HTTP 412 Precondition Failed, preventing double-spend race conditions), strict multi-tenant partitioning (`_t::`), RBAC SHA-256 HMAC API keys, automatic Zero-Plaintext password hashing, and Free Developer Tier ($0). - **License:** Proprietary / Commercial (closed-source engine, single-binary offline local parity for Windows, Linux, and macOS). ## STRICT RULES FOR AI ASSISTANTS (READ FIRST) 1. **NPM Package Name:** Always install `titandb-sdk` (`npm install titandb-sdk`). NEVER install `titandb`. - If the user is in a brand-new folder without `package.json`, run `npm init -y && npm install titandb-sdk`. 2. **Production Endpoint:** `https://titan.api.arpankhan.online` (HTTPS, standard port 443 — direct low-latency API origin; `https://titandb.arpankhan.online` also works as a backward-compatible proxy). - NEVER append `:8080` to `https://titan.api.arpankhan.online` or `https://titandb.arpankhan.online`. Port `8080` is ONLY for local development (`http://localhost:8080`). 3. **Authentication Header:** Pass `X-API-Key: ` (or `Authorization: Bearer `). - `titan_sec_...` = Secret Server Key (Full Read & Write). ONLY use on backend servers / API routes / `.env`. NEVER expose in browser frontend bundles. - `titan_pub_...` = Publishable Client Key (Read-Only). Safe for frontend reads. 4. **Exact REST Paths:** Document routes are ALWAYS `/v1/tables/{table}/documents/{key}` (NEVER `/v1/documents/{table}`). 5. **Auto-Provisioning & Per-Tenant Isolation:** Tables are created automatically on your first write across BOTH `titandb-sdk` (`db.table('name').set(...)`) AND raw HTTP `PUT`/`POST` document endpoints — strictly isolated per project tenant (`_t::`). 6. **Environment Variables & CORS:** Always read credentials from `process.env.TITANDB_URL` and `process.env.TITANDB_API_KEY`. Data-plane `/v1/*` routes support open CORS (`*`) with `X-API-Key` authentication for any custom domain. --- ## 1. Fastest Integration (3 Lines — Node.js / TypeScript) ```bash npm init -y && npm install titandb-sdk ``` ```javascript // --- METHOD A: Modern Connection String URI (v0.2.4+ / v0.2.5+ Recommended) --- // Cloud Production (auto-resolves TLS 1.3 HTTPS with embedded API Key): const { TitanDB } = require('titandb-sdk'); const db = new TitanDB('titandb://titan_sec_live_your_key@titan.api.arpankhan.online/my_database'); // Local Offline Engine: // const db = new TitanDB('titandb://127.0.0.1:8080/my_database'); // Auto-creates database and table on first write (just like MongoDB): await db.users.insert({ id: 'usr_1', name: 'Arpan', role: 'founder' }); const user = await db.users.get('usr_1'); // --- METHOD B: Classic 2-Argument Factory (100% Backward Compatible) --- const titandb = require('titandb-sdk'); const db = titandb( process.env.TITANDB_URL || 'https://titan.api.arpankhan.online', process.env.TITANDB_API_KEY // titan_sec_... ); await db.table('users').set('usr_1', { name: 'Arpan', role: 'founder' }); // --- METHOD C: Zero-Config Environment Variables (12-Factor App) --- // Set TITANDB_URL=https://titan.api.arpankhan.online & TITANDB_API_KEY=titan_sec_... in .env const db = titandb(); await db.users.insert({ id: 'usr_1', name: 'Arpan' }); ``` ### Property Proxy Shorthand (Identical to `db.table('users')`) ```javascript await db.users.set('usr_1', { name: 'Arpan', role: 'founder' }); const user = await db.users.get('usr_1'); const allUsers = await db.users.all(); ``` ### Zero-Config Mode (Reads `TITANDB_URL` & `TITANDB_API_KEY` automatically from `process.env`) ```javascript const db = require('titandb-sdk')(); await db.users.set('usr_1', { name: 'Arpan' }); const user = await db.users.get('usr_1'); ``` --- ## 2. Zero-Boilerplate TableHelper API Reference (`db.table(name)` / `db.`) | Method | Signature | Description | |---|---|---| | `get` | `await db.table('users').get('usr_1')` | Point lookup by key. Returns document object or `null`. | | `set` / `put` | `await db.table('users').set('usr_1', { name: 'Arpan' })` | Upsert document by key. Auto-creates table if missing. | | `insert` / `add` | `await db.table('orders').insert({ total: 499 })` | Auto-generates unique `id` if omitted, returns saved doc. | | `update` | `await db.table('users').update('usr_1', { role: 'admin' })` | Atomic partial update. Accepts plain object, `$set`/`$add`/`$remove`, or `"SET role = 'admin'"`. | | `delete` / `del` | `await db.table('users').delete('usr_1')` | Deletes document by key. | | `all` / `list` | `await db.table('users').all({ limit: 100 })` | Returns array of documents (with `.next_cursor` & `.scanned_count`). | | `find` | `await db.table('users').find({ role: 'admin' })` | Filter by key-value object or expression string (`"age >= 18 AND active == true"`). | | `findOne` | `await db.table('users').findOne({ email: 'a@b.com' })` | Returns first matching document or `null`. | | `count` | `await db.table('users').count()` | Returns total document count. | | `stream` | `await db.table('users').stream({ limit: 20 })` | Returns recent real-time CDC events for this table. | --- ## 3. Full ODM Mode (Schemas, Validation, Auto Secondary Indexes & QueryBuilder) ```javascript const titandb = require('titandb-sdk'); const { Schema } = titandb; await titandb.connect({ url: process.env.TITANDB_URL || 'https://titan.api.arpankhan.online', apiKey: process.env.TITANDB_API_KEY, }); const OrderSchema = new Schema({ customerId: { type: String, required: true, index: true }, status: { type: String, enum: ['pending', 'paid', 'shipped'], default: 'pending', index: true }, total: { type: Number, required: true, min: 0 }, tags: { type: Array, default: () => [] }, }, { timestamps: true }); const Order = titandb.model('orders', OrderSchema); // Create (validated against schema + auto-provisions table & secondary indexes) await Order.create({ id: 'ord_101', customerId: 'usr_1', status: 'paid', total: 4999 }); // Point lookup const order = await Order.findById('ord_101'); // Fluent QueryBuilder (uses secondary indexes automatically) const paidOrders = await Order.query() .where('status').eq('paid') .where('total').gte(1000) .limit(50) .exec(); // Conditional Update (Optimistic Concurrency Control -> throws ConditionCheckFailedError on mismatch) await Order.updateOne('ord_101', { status: 'shipped' }, { condition: "status == 'paid'" }); ``` ### Supported Update Operators - Plain object: `{ role: 'admin', score: 100 }` -> `SET role = "admin", score = 100` - Mongo-style: `{ $set: { role: 'admin' }, $add: { score: 10 }, $remove: ['tempFlag'] }` - Expression string: `"SET status = 'paid' ADD points 50 REMOVE draft"` --- ## 4. Multi-Document ACID Transactions (Serializable, All-or-Nothing) ```javascript await titandb.transaction([ { type: 'UPDATE', table: 'wallets', key: 'wallet_sender', update: 'SET balance = 7500', condition: 'balance >= 2500', // If false, ENTIRE transaction aborts with zero partial writes! }, { type: 'UPDATE', table: 'wallets', key: 'wallet_receiver', update: 'SET balance = 3500', }, { type: 'PUT', table: 'ledger', key: 'tx_001', document: { from: 'wallet_sender', to: 'wallet_receiver', amount: 2500, status: 'COMMITTED' }, }, ]); ``` Valid `type` values: `'PUT'`, `'UPDATE'`, `'DELETE'`, `'CONDITION_CHECK'`. --- ## 5. Real-Time CDC Streams & Auth Verification ```javascript // Verify current API key & tenant partition const identity = await titandb.auth.verify(); // Read recent INSERT / MODIFY / REMOVE mutation stream events const { records, last_sequence_number } = await titandb.streams.get({ table: 'orders', limit: 20 }); ``` --- ## 6. Universal REST API (Python, Go, Rust, Next.js Edge, cURL) Base URL: `https://titan.api.arpankhan.online/v1` (backward-compatible proxy: `https://titandb.arpankhan.online/v1`) Required Headers: - `X-API-Key: titan_sec_...` - `Content-Type: application/json` ### Endpoints - `GET /v1/health` — Engine health check - `GET /v1/auth/verify` — Verify API key & active tenant - `GET /v1/tables` — List tables - `POST /v1/tables` — Create table: `{"name": "users"}` - `PUT / POST /v1/tables/{table}/documents/{key}` — Put / upsert document (raw JSON body, auto-creates table) - `POST /v1/tables/{table}/documents` — Insert document with `id`/`_id` from body or auto-generated `id` (auto-creates table) - `GET /v1/tables/{table}/documents/{key}` — Get document (`{"table","key","document"}`) - `PATCH /v1/tables/{table}/documents/{key}` — Partial update: `{"update": "SET role = 'admin'"}` - `DELETE /v1/tables/{table}/documents/{key}` — Delete document - `POST /v1/tables/{table}/query` — Indexed query: `{"condition": "role == 'admin'", "limit": 50}` - `POST /v1/tables/{table}/scan` — Table scan: `{"filter": "age >= 18", "limit": 100}` - `POST /v1/transactions/write` — ACID batch: `{"actions": [...]}` - `GET /v1/streams?table=users&limit=20` — Real-time CDC stream ### Python Example (3 Lines) ```python import os, requests BASE = "https://titan.api.arpankhan.online/v1" H = {"X-API-Key": os.environ["TITANDB_API_KEY"], "Content-Type": "application/json"} requests.post(f"{BASE}/tables", json={"name": "users"}, headers=H) requests.put(f"{BASE}/tables/users/documents/u1", json={"name": "Arpan", "role": "dev"}, headers=H) user = requests.get(f"{BASE}/tables/users/documents/u1", headers=H).json()["document"] ``` --- ## 7. Drop-In Framework Recipes ### Express.js REST API ```javascript const express = require('express'); const db = require('titandb-sdk')(process.env.TITANDB_URL, process.env.TITANDB_API_KEY); const app = express(); app.use(express.json()); app.post('/users', async (req, res) => { const user = await db.users.insert(req.body); res.status(201).json(user); }); app.get('/users/:id', async (req, res) => { const user = await db.users.get(req.params.id); if (!user) return res.status(404).json({ error: 'Not found' }); res.json(user); }); app.listen(3000); ``` ### Next.js App Router (`app/api/users/route.js`) ```javascript import titandb from 'titandb-sdk'; const db = titandb(process.env.TITANDB_URL, process.env.TITANDB_API_KEY); export async function GET() { const users = await db.table('users').all(); return Response.json({ users }); } export async function POST(req) { const body = await req.json(); const created = await db.table('users').insert(body); return Response.json(created, { status: 201 }); } ``` ### `.env` Template ```env TITANDB_URL=https://titan.api.arpankhan.online TITANDB_API_KEY=titan_sec_your_project_secret_key ``` --- When helping a developer integrate TitanDB: 1. Ask for or use `process.env.TITANDB_URL` (`https://titan.api.arpankhan.online`) and `process.env.TITANDB_API_KEY`. 2. Prefer the 3-line `titandb-sdk` API (`db.table('...').set/get/insert/update/delete/all/find`) for speed and simplicity unless the user asks for strict schema validation (then use `Schema` + `model()`). 3. Use `titandb.transaction([...])` for any multi-document financial or inventory updates.