diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770459207_110a91bf.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770459207_110a91bf.png new file mode 100644 index 0000000..da60d6d Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770459207_110a91bf.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770460480_20a5f779.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770460480_20a5f779.png new file mode 100644 index 0000000..b25431c Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770460480_20a5f779.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770461195_23d6d22d.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770461195_23d6d22d.png new file mode 100644 index 0000000..ec7d5df Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770461195_23d6d22d.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770888462_aeb61f9c.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770888462_aeb61f9c.png new file mode 100644 index 0000000..2a7a73e Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770888462_aeb61f9c.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770889468_a3690f3b.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770889468_a3690f3b.png new file mode 100644 index 0000000..2f2b3e6 Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770889468_a3690f3b.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770890028_2ebff761.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770890028_2ebff761.png new file mode 100644 index 0000000..1aca6db Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770890028_2ebff761.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770973306_ac691f74.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770973306_ac691f74.png new file mode 100644 index 0000000..0c987fc Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770973306_ac691f74.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770973783_4403b520.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770973783_4403b520.png new file mode 100644 index 0000000..bb09e9e Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792770973783_4403b520.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771509037_62171046.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771509037_62171046.png new file mode 100644 index 0000000..2a7a73e Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771509037_62171046.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771510155_23d73c5b.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771510155_23d73c5b.png new file mode 100644 index 0000000..8a6b3f3 Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771510155_23d73c5b.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771510658_edd91084.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771510658_edd91084.png new file mode 100644 index 0000000..c4a1faf Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771510658_edd91084.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771511113_2d3b9e5f.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771511113_2d3b9e5f.png new file mode 100644 index 0000000..01adfa9 Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771511113_2d3b9e5f.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771660960_0ec121d1.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771660960_0ec121d1.png new file mode 100644 index 0000000..6ae09bd Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771660960_0ec121d1.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771661633_7238bf23.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771661633_7238bf23.png new file mode 100644 index 0000000..908c102 Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771661633_7238bf23.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771940535_38aba1b1.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771940535_38aba1b1.png new file mode 100644 index 0000000..6ae09bd Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771940535_38aba1b1.png differ diff --git a/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771941196_c77bc55d.png b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771941196_c77bc55d.png new file mode 100644 index 0000000..908c102 Binary files /dev/null and b/.aistudio/artifacts/brain/6b4b967a-c8f6-4313-a509-fb928631106a/.tempmediaStorage/media_1792771941196_c77bc55d.png differ diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..7a550fe --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +# GEMINI_API_KEY: Required for Gemini AI API calls. +# AI Studio automatically injects this at runtime from user secrets. +# Users configure this via the Secrets panel in the AI Studio UI. +GEMINI_API_KEY="MY_GEMINI_API_KEY" + +# APP_URL: The URL where this applet is hosted. +# AI Studio automatically injects this at runtime with the Cloud Run service URL. +# Used for self-referential links, OAuth callbacks, and API endpoints. +APP_URL="MY_APP_URL" diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..15b1ed9 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "next" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..71b810c --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +node_modules/ +.next/ +coverage/ +.DS_Store +*.log +.env* +!.env.example diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..125f1a0 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,23 @@ +# AGENTS.md — Component-Only Architecture Rules & System Directives + +## 1. Single Source of Truth Components +- All UI design styles are designed once as reusable components in `components/ui/` and `components/layout/`. +- Pages must never implement isolated, inline styles or custom ad-hoc styling blocks. +- Spacing, colors, fonts, borders, buttons, cards, modals, and tables are defined centrally. Any design token alteration automatically cascades across all pages. + +## 2. Decoupled Runtime Split +- **Port 3000**: Next.js App Router (Frontend UI, `/vcon/*` admin console, streaming CSV export `/api/export`). +- **Port 4000**: Express.js + Socket.IO process (WebSocket handshake, JWT verification, real-time ingestion). +- **Socket.IO Rule**: Socket.IO must never reside inside Next.js serverless route handlers. + +## 3. Data Storage Rules +- **Collected Realtime Data**: Strictly stored in rotated CSV files at `/storage/data/{clientId}/{YYYY-MM-DD}.csv`. +- **Zero Database Inserts**: Per-row DB inserts are prohibited for collected data streams. +- **File Rotation**: Rotates daily or upon reaching 100MB (`-part2.csv`). +- **Redis / In-Memory Buffer**: Aggregates batches (500 events or 2000ms timer) before flushing to disk. +- **PostgreSQL / Prisma**: Exclusively dedicated to metadata, SDK registrations, and admin settings. + +## 4. Design & Typography Tokens +- **Font Stack**: `"Segoe UI", "Segoe UI Web", system-ui, -apple-system, "Helvetica Neue", sans-serif`. +- **Border Radius**: `--radius: 0rem` strictly across all shadcn and custom UI components. +- **Shadows**: None. Clean, soft, compact flat design with subtle 1px borders. diff --git a/README.md b/README.md index 2241000..324c0a0 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,42 @@ -
+# DataStack — Self-Hosted Universal Realtime Data Collection Platform -GHBanner +DataStack is a high-throughput, self-hosted data collection platform designed for high-frequency event ingestion over WebSockets with buffered batch persistence to CSV. -

Built with AI Studio

+## Architecture -

The fastest path from prompt to production with Gemini.

+| Process | Port | Role | +| :--- | :--- | :--- | +| **Next.js App Router** | 3000 | Frontend UI, `/vcon/*` admin console, streaming CSV export `/api/export` | +| **Express + Socket.IO** | 4000 | WebSocket handshake, JWT client auth, event intake | +| **CSV Writer Worker** | — | In-memory buffer flush to CSV (`500 rows / 2s`) | - Start building +## Data Persistence +- **CSV Storage Path**: `/storage/data/{clientId}/{YYYY-MM-DD}.csv` +- **Schema**: `clientId, eventId, timestamp(ISO), payload(JSON)` +- **Rotation Rule**: Per-day OR 100MB threshold (whichever triggers first). +- **PostgreSQL**: Used strictly for SDK client registration and admin settings. Zero collected data is inserted into the database. -
+## Python SDK +Install the client: +```bash +pip install ./sdk-python +``` + +Usage: +```python +from datastack_sdk import DataStackClient + +client = DataStackClient(server_url="http://localhost:4000", token="JWT_TOKEN") +if client.connect(): + client.sync({"metric": "load", "value": 42}) + client.disconnect() +``` + +## Running the Platform +```bash +# Terminal 1: Web Interface & Admin Console +npm run dev + +# Terminal 2: Express Socket.IO Ingestion Engine +npm run server +``` diff --git a/app/api/clients/[id]/route.ts b/app/api/clients/[id]/route.ts new file mode 100644 index 0000000..04363b5 --- /dev/null +++ b/app/api/clients/[id]/route.ts @@ -0,0 +1,54 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { SDKManager } from '@/core/sdk/sdkManager'; + +export async function GET( + _req: NextRequest, + { params }: { params: Promise<{ id: string }> } +) { + const { id } = await params; + const client = SDKManager.getClient(id); + if (!client) { + return NextResponse.json({ error: 'Client not found' }, { status: 404 }); + } + return NextResponse.json({ client }); +} + +export async function PATCH( + req: NextRequest, + { params }: { params: Promise<{ id: string }> } +) { + const { id } = await params; + try { + const body = await req.json(); + + // Special action: regenerate token + if (body.action === 'regenerate_token') { + const refreshed = SDKManager.regenerateToken(id); + if (!refreshed) { + return NextResponse.json({ error: 'Client not found' }, { status: 404 }); + } + return NextResponse.json({ client: refreshed }); + } + + const updated = SDKManager.updateClient(id, body); + if (!updated) { + return NextResponse.json({ error: 'Client not found' }, { status: 404 }); + } + return NextResponse.json({ client: updated }); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Update failed'; + return NextResponse.json({ error: message }, { status: 500 }); + } +} + +export async function DELETE( + _req: NextRequest, + { params }: { params: Promise<{ id: string }> } +) { + const { id } = await params; + const deleted = SDKManager.deleteClient(id); + if (!deleted) { + return NextResponse.json({ error: 'Client not found' }, { status: 404 }); + } + return NextResponse.json({ success: true, message: `Client ${id} deleted` }); +} diff --git a/app/api/clients/route.ts b/app/api/clients/route.ts new file mode 100644 index 0000000..1c19af8 --- /dev/null +++ b/app/api/clients/route.ts @@ -0,0 +1,45 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { SDKManager } from '@/core/sdk/sdkManager'; + +export async function GET() { + try { + const clients = SDKManager.listClients(); + return NextResponse.json({ clients, count: clients.length }); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Failed to list clients'; + return NextResponse.json({ error: message }, { status: 500 }); + } +} + +export async function POST(req: NextRequest) { + try { + const body = await req.json(); + const { clientId, name, rateLimit } = body; + + if (!clientId || !name) { + return NextResponse.json( + { error: 'clientId and name are required' }, + { status: 400 } + ); + } + + const existing = SDKManager.getClient(clientId); + if (existing) { + return NextResponse.json( + { error: `Client '${clientId}' already exists` }, + { status: 409 } + ); + } + + const newClient = SDKManager.registerClient({ + clientId, + name, + rateLimit: rateLimit ? Number(rateLimit) : 100, + }); + + return NextResponse.json({ client: newClient }, { status: 201 }); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Client creation failed'; + return NextResponse.json({ error: message }, { status: 500 }); + } +} diff --git a/app/api/events/route.ts b/app/api/events/route.ts new file mode 100644 index 0000000..f6bf8e2 --- /dev/null +++ b/app/api/events/route.ts @@ -0,0 +1,49 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { DataBufferEngine } from '@/core/data/buffer'; +import { SDKManager } from '@/core/sdk/sdkManager'; +import { SecurityEngine } from '@/core/Security/security'; + +export async function GET(req: NextRequest) { + try { + const { searchParams } = new URL(req.url); + const clientId = searchParams.get('clientId') || undefined; + const limit = Number(searchParams.get('limit')) || 50; + + const events = DataBufferEngine.getRecentEvents(limit, clientId); + return NextResponse.json({ events, count: events.length }); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Events retrieval failed'; + return NextResponse.json({ error: message }, { status: 500 }); + } +} + +export async function POST(req: NextRequest) { + try { + const body = await req.json(); + const clientId = body.clientId || 'py_telemetry_agent_01'; + const eventId = body.eventId || `evt_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`; + const timestamp = body.timestamp || new Date().toISOString(); + const data = body.data || { sample: 'Realtime event via DataStack API', rand: Math.random() }; + + // Validate security + const val = SecurityEngine.validateEvent(clientId, eventId, data, 200); + if (!val.allowed) { + return NextResponse.json({ error: val.reason }, { status: 429 }); + } + + const event = { + clientId, + eventId, + timestamp, + payload: typeof data === 'string' ? data : JSON.stringify(data), + }; + + DataBufferEngine.push(event); + SDKManager.incrementEventCount(clientId, 1); + + return NextResponse.json({ success: true, event }); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Event simulation failed'; + return NextResponse.json({ error: message }, { status: 500 }); + } +} diff --git a/app/api/export/route.ts b/app/api/export/route.ts new file mode 100644 index 0000000..63fa57f --- /dev/null +++ b/app/api/export/route.ts @@ -0,0 +1,76 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { CSVStorageManager } from '@/core/Storage/csvStorage'; +import fs from 'fs'; +import path from 'path'; + +export async function GET(req: NextRequest) { + try { + const { searchParams } = new URL(req.url); + const clientId = searchParams.get('clientId'); + const filename = searchParams.get('filename'); + + // Single specific file export + if (clientId && filename) { + const content = CSVStorageManager.getFileContent(clientId, filename); + if (!content) { + return NextResponse.json({ error: 'CSV file not found' }, { status: 404 }); + } + + return new NextResponse(content, { + status: 200, + headers: { + 'Content-Type': 'text/csv; charset=utf-8', + 'Content-Disposition': `attachment; filename="${filename}"`, + }, + }); + } + + // Stream aggregate or list files + const allFiles = CSVStorageManager.listAllFiles(); + const filtered = clientId && clientId !== 'all' + ? allFiles.filter((f) => f.clientId === clientId) + : allFiles; + + if (filtered.length === 0) { + const emptyCsv = 'clientId,eventId,timestamp,payload\n'; + return new NextResponse(emptyCsv, { + status: 200, + headers: { + 'Content-Type': 'text/csv; charset=utf-8', + 'Content-Disposition': `attachment; filename="datastack_export_${Date.now()}.csv"`, + }, + }); + } + + // Combine matching files with a single header + let combined = 'clientId,eventId,timestamp,payload\n'; + for (const f of filtered) { + try { + const raw = fs.readFileSync(f.filePath, 'utf8'); + const lines = raw.split('\n'); + // skip header on subsequent lines + const dataLines = lines.slice(1).filter((l) => l.trim().length > 0); + if (dataLines.length > 0) { + combined += dataLines.join('\n') + '\n'; + } + } catch { + // continue + } + } + + const exportFileName = clientId && clientId !== 'all' + ? `${clientId}_export_${new Date().toISOString().split('T')[0]}.csv` + : `datastack_universal_export_${new Date().toISOString().split('T')[0]}.csv`; + + return new NextResponse(combined, { + status: 200, + headers: { + 'Content-Type': 'text/csv; charset=utf-8', + 'Content-Disposition': `attachment; filename="${exportFileName}"`, + }, + }); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Export failed'; + return NextResponse.json({ error: message }, { status: 500 }); + } +} diff --git a/app/api/metrics/route.ts b/app/api/metrics/route.ts new file mode 100644 index 0000000..b6d4fd8 --- /dev/null +++ b/app/api/metrics/route.ts @@ -0,0 +1,12 @@ +import { NextResponse } from 'next/server'; +import { ApiEngine } from '@/core/apiEngine/apiService'; + +export async function GET() { + try { + const metrics = await ApiEngine.getDashboardMetrics(); + return NextResponse.json(metrics); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Metrics calculation failed'; + return NextResponse.json({ error: message }, { status: 500 }); + } +} diff --git a/app/api/settings/route.ts b/app/api/settings/route.ts new file mode 100644 index 0000000..a1c2e05 --- /dev/null +++ b/app/api/settings/route.ts @@ -0,0 +1,23 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { SettingsManager } from '@/core/adminSettings/settingsManager'; + +export async function GET() { + try { + const settings = SettingsManager.getSettings(); + return NextResponse.json({ settings }); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Settings read failed'; + return NextResponse.json({ error: message }, { status: 500 }); + } +} + +export async function POST(req: NextRequest) { + try { + const body = await req.json(); + const updated = SettingsManager.updateSettings(body); + return NextResponse.json({ settings: updated, success: true }); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Settings update failed'; + return NextResponse.json({ error: message }, { status: 500 }); + } +} diff --git a/app/api/storage/route.ts b/app/api/storage/route.ts new file mode 100644 index 0000000..4a7a20e --- /dev/null +++ b/app/api/storage/route.ts @@ -0,0 +1,37 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { CSVStorageManager } from '@/core/Storage/csvStorage'; +import { DataBufferEngine } from '@/core/data/buffer'; + +export async function GET(req: NextRequest) { + try { + const { searchParams } = new URL(req.url); + const clientId = searchParams.get('clientId') || undefined; + + const stats = CSVStorageManager.getStorageStats(); + let files = CSVStorageManager.listAllFiles(); + + if (clientId && clientId !== 'all') { + files = files.filter((f) => f.clientId === clientId); + } + + return NextResponse.json({ stats, files }); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Storage stats failed'; + return NextResponse.json({ error: message }, { status: 500 }); + } +} + +export async function POST(_req: NextRequest) { + try { + // Manual flush buffer to disk + const res = await DataBufferEngine.flush(); + return NextResponse.json({ + success: true, + flushedCount: res.count, + filesUpdated: res.files, + }); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Manual flush failed'; + return NextResponse.json({ error: message }, { status: 500 }); + } +} diff --git a/app/globals.css b/app/globals.css new file mode 100644 index 0000000..c8c0348 --- /dev/null +++ b/app/globals.css @@ -0,0 +1,117 @@ +@import "tailwindcss"; + +:root { + --radius: 0rem; + --font-sans: "Segoe UI", "Segoe UI Web", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif; + --font-mono: ui-monospace, "SF Mono", "Liberation Mono", Menlo, Consolas, monospace; + + /* Theme tokens - Dark Mode (Sleek Graphite Workbench) */ + --bg-main: #0c0e12; + --bg-sidebar: #0f1117; + --bg-activity: #131720; + --bg-elevated: #161b24; + --bg-hover: #1c2230; + --bg-active: #242c3d; + --border: #212836; + --border-strong: #2e374a; + --text: #e6ebf2; + --text-muted: #8c96a8; + --text-dim: #5c6577; + --accent: #3b82f6; + --accent-soft: rgba(59, 130, 246, 0.08); + --accent-hover: #60a5fa; + --text-on-accent: #ffffff; + --success: #10b981; + --success-soft: rgba(16, 185, 129, 0.08); + --warning: #f59e0b; + --warning-soft: rgba(245, 158, 11, 0.08); + --danger: #ef4444; + --danger-soft: rgba(239, 68, 68, 0.08); +} + +html.light, body.light { + /* Theme tokens - Light Mode (Clean, soft contrast) */ + --bg-main: #ffffff; + --bg-sidebar: #f8fafc; + --bg-activity: #f1f5f9; + --bg-elevated: #ffffff; + --bg-hover: #f1f5f9; + --bg-active: #e2e8f0; + --border: #e2e8f0; + --border-strong: #cbd5e1; + --text: #0f172a; + --text-muted: #475569; + --text-dim: #94a3b8; + --accent: #2563eb; + --accent-soft: rgba(37, 99, 235, 0.06); + --accent-hover: #1d4ed8; + --text-on-accent: #ffffff; + --success: #059669; + --success-soft: rgba(5, 150, 105, 0.08); + --warning: #d97706; + --warning-soft: rgba(217, 119, 6, 0.08); + --danger: #dc2626; + --danger-soft: rgba(220, 38, 38, 0.08); +} + +* { + box-sizing: border-box; + margin: 0; + padding: 0; + border-radius: 0 !important; + box-shadow: none !important; + text-shadow: none !important; +} + +html, body { + font-family: var(--font-sans) !important; + background-color: var(--bg-main); + color: var(--text); + font-size: 12px; + line-height: 1.4; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +button, input, select, textarea, table, th, td, div, p, span { + font-family: inherit; +} + +/* Headings font weight & line-height */ +h1, h2, h3, h4, h5, h6 { + font-family: var(--font-sans) !important; + font-weight: 500; + color: var(--text); + letter-spacing: -0.01em; +} + +/* Code & pre font */ +pre, code, kbd, samp { + font-family: var(--font-mono) !important; +} + +/* Scrollbar clean styling */ +::-webkit-scrollbar { + width: 5px; + height: 5px; +} +::-webkit-scrollbar-track { + background: transparent; +} +::-webkit-scrollbar-thumb { + background: var(--border-strong); +} +::-webkit-scrollbar-thumb:hover { + background: var(--text-dim); +} + +/* Interactive focus */ +button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { + outline: 1px solid var(--accent); + outline-offset: 1px; +} + +/* Hide floating dev badges */ +nextjs-portal, [data-nextjs-toast], #__next-build-watcher { + display: none !important; +} diff --git a/app/layout.tsx b/app/layout.tsx new file mode 100644 index 0000000..a9e162c --- /dev/null +++ b/app/layout.tsx @@ -0,0 +1,33 @@ +import type { Metadata } from 'next'; +import './globals.css'; +import { ToastProvider } from '@/components/ui/Toast'; + +export const metadata: Metadata = { + title: 'DataStack - Realtime Data Collection Platform', + description: 'Self-hosted universal realtime data collection engine with Socket.IO ingestion, Redis buffer, JWT client auth, CSV batch rotation, and /vcon/ admin panel.', + manifest: '/manifest.json', + openGraph: { + title: 'DataStack - Realtime Data Collection Platform', + description: 'Self-hosted universal realtime data collection engine with Socket.IO ingestion, Redis buffer, and CSV batch storage.', + type: 'website', + }, + twitter: { + card: 'summary_large_image', + title: 'DataStack - Realtime Data Collection Platform', + description: 'Self-hosted universal realtime data collection engine with Socket.IO ingestion.', + }, +}; + +export default function RootLayout({ children }: { children: React.ReactNode }) { + return ( + + + + + + + {children} + + + ); +} diff --git a/app/not-found.tsx b/app/not-found.tsx new file mode 100644 index 0000000..d705385 --- /dev/null +++ b/app/not-found.tsx @@ -0,0 +1,29 @@ +import React from 'react'; +import Link from 'next/link'; +import { MainLayout } from '@/components/layout/MainLayout'; +import { Button } from '@/components/ui/Button'; + +export default function NotFound() { + return ( + +
+

404

+

+ The requested page or route does not exist on DataStack. +

+
+ + + + + + +
+
+
+ ); +} diff --git a/app/page.tsx b/app/page.tsx new file mode 100644 index 0000000..d04ab0d --- /dev/null +++ b/app/page.tsx @@ -0,0 +1,17 @@ +import React from 'react'; +import { MainLayout } from '@/components/layout/MainLayout'; +import { Hero } from '@/components/sections/Hero'; +import { Features } from '@/components/sections/Features'; +import { Architecture } from '@/components/sections/Architecture'; + +export default function RootHomePage() { + return ( + +
+ + + +
+
+ ); +} diff --git a/app/vcon/clients/page.tsx b/app/vcon/clients/page.tsx new file mode 100644 index 0000000..37f0c11 --- /dev/null +++ b/app/vcon/clients/page.tsx @@ -0,0 +1,393 @@ +'use client'; + +import React, { useState, useEffect, useCallback } from 'react'; +import { Card } from '@/components/ui/Card'; +import { Button } from '@/components/ui/Button'; +import { Input } from '@/components/ui/Input'; +import { Modal } from '@/components/ui/Modal'; +import { Icon } from '@/components/ui/Icon'; +import { + TableWrap, + Table, + TableHeader, + TableBody, + TableRow, + TableHead, + TableCell, + TableEmpty, +} from '@/components/ui/Table'; +import { useToast } from '@/components/ui/Toast'; + +interface ClientItem { + clientId: string; + name: string; + secret: string; + token: string; + rateLimit: number; + status: 'active' | 'revoked'; + totalEvents: number; + lastActive?: string; + createdAt: string; +} + +export default function ClientsPage() { + const { success, error, warning } = useToast(); + const [clients, setClients] = useState([]); + const [loading, setLoading] = useState(true); + + // Modals + const [createModalOpen, setCreateModalOpen] = useState(false); + const [tokenModalOpen, setTokenModalOpen] = useState(false); + const [selectedClient, setSelectedClient] = useState(null); + + // Form State + const [newClientId, setNewClientId] = useState(''); + const [newClientName, setNewClientName] = useState(''); + const [newRateLimit, setNewRateLimit] = useState('100'); + const [submitting, setSubmitting] = useState(false); + + const fetchClients = useCallback(async () => { + try { + const res = await fetch('/api/clients'); + if (res.ok) { + const data = await res.json(); + setClients(data.clients || []); + } + } catch { + // ignore + } finally { + setLoading(false); + } + }, []); + + useEffect(() => { + fetchClients(); + }, [fetchClients]); + + const handleCreateClient = async (e: React.FormEvent) => { + e.preventDefault(); + if (!newClientId.trim() || !newClientName.trim()) { + error('Validation Error', 'Client ID and Client Name are required'); + return; + } + + setSubmitting(true); + try { + const res = await fetch('/api/clients', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + clientId: newClientId.trim(), + name: newClientName.trim(), + rateLimit: Number(newRateLimit) || 100, + }), + }); + + if (res.ok) { + const data = await res.json(); + success('Client Registered', `Client ${data.client.clientId} created successfully`); + setCreateModalOpen(false); + setNewClientId(''); + setNewClientName(''); + setNewRateLimit('100'); + fetchClients(); + // Open token modal immediately + setSelectedClient(data.client); + setTokenModalOpen(true); + } else { + const errData = await res.json(); + error('Registration Failed', errData.error || 'Unknown error'); + } + } catch (err: any) { + error('Error', err.message); + } finally { + setSubmitting(false); + } + }; + + const handleToggleStatus = async (client: ClientItem) => { + const newStatus = client.status === 'active' ? 'revoked' : 'active'; + try { + const res = await fetch(`/api/clients/${client.clientId}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ status: newStatus }), + }); + if (res.ok) { + warning( + `Status Changed`, + `Client ${client.clientId} is now ${newStatus.toUpperCase()}` + ); + fetchClients(); + } + } catch (err: any) { + error('Update Failed', err.message); + } + }; + + const handleRegenerateToken = async (client: ClientItem) => { + try { + const res = await fetch(`/api/clients/${client.clientId}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ action: 'regenerate_token' }), + }); + if (res.ok) { + const data = await res.json(); + success('Token Regenerated', `New JWT issued for ${client.clientId}`); + setSelectedClient(data.client); + setTokenModalOpen(true); + fetchClients(); + } + } catch (err: any) { + error('Regeneration Failed', err.message); + } + }; + + const handleDeleteClient = async (client: ClientItem) => { + if (!confirm(`Are you sure you want to delete client '${client.clientId}'?`)) return; + + try { + const res = await fetch(`/api/clients/${client.clientId}`, { + method: 'DELETE', + }); + if (res.ok) { + success('Client Removed', `Client ${client.clientId} deleted`); + fetchClients(); + } + } catch (err: any) { + error('Deletion Failed', err.message); + } + }; + + const copyToClipboard = (text: string, label: string) => { + navigator.clipboard.writeText(text); + success('Copied to Clipboard', `${label} copied`); + }; + + return ( +
+ {/* Header */} +
+

+ Client SDKs +

+ +
+ + {/* Clients Table */} + + + + + Client ID + Client Name + Status + Rate Limit + Total Ingested + Created + Actions + + + + {clients.length === 0 ? ( + + ) : ( + clients.map((client) => ( + + + {client.clientId} + + + {client.name} + + + + {client.status.toUpperCase()} + + + + {client.rateLimit} req/s + + + {client.totalEvents.toLocaleString()} + + + {new Date(client.createdAt).toLocaleDateString()} + + +
+ + +
+
+
+ )) + )} +
+
+
+ + {/* Register Client Modal */} + setCreateModalOpen(false)} + title="Register Client SDK" + footer={ + <> + + + + } + > +
+ setNewClientId(e.target.value)} + required + /> + setNewClientName(e.target.value)} + required + /> + setNewRateLimit(e.target.value)} + /> +
+
+ + {/* View Token & Credentials Modal */} + setTokenModalOpen(false)} + title={`Credentials: ${selectedClient?.clientId}`} + footer={ + + } + > + {selectedClient && ( +
+
+ + Client ID + +
+ {selectedClient.clientId} +
+
+ +
+ + Client Secret Key + +
+ {selectedClient.secret} +
+
+ +
+
+ + JWT Handshake Bearer Token + + +
+