docs: update AI Studio design token audits

Refresh design token inventory files to reflect the latest UI sizing and layout configurations from the sandbox prototype.
This commit is contained in:
Md Najmul committed 2026-10-23 11:43:49 -05:00
1 parent 50449e96ad
commit d39d9f92f9
139 files changed
+10982 -6

No files matched your search

+9
View File
@@ -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"
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "next"
}
+7
View File
@@ -0,0 +1,7 @@
node_modules/
.next/
coverage/
.DS_Store
*.log
.env*
!.env.example
+23
View File
@@ -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.
+37 -6
View File
@@ -1,11 +1,42 @@
<div align="center">
# DataStack — Self-Hosted Universal Realtime Data Collection Platform
<img width="1200" height="475" alt="GHBanner" src="https://github.com/user-attachments/assets/0aa67016-6eaf-458a-adb2-6e31a0763ed6" />
DataStack is a high-throughput, self-hosted data collection platform designed for high-frequency event ingestion over WebSockets with buffered batch persistence to CSV.
<h1>Built with AI Studio</h2>
## Architecture
<p>The fastest path from prompt to production with Gemini.</p>
| 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`) |
<a href="https://aistudio.google.com/apps">Start building</a>
## 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.
</div>
## 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
```
+54
View File
@@ -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` });
}
+45
View File
@@ -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 });
}
}
+49
View File
@@ -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 });
}
}
+76
View File
@@ -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 });
}
}
+12
View File
@@ -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 });
}
}
+23
View File
@@ -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 });
}
}
+37
View File
@@ -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 });
}
}
+117
View File
@@ -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;
}
+33
View File
@@ -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 (
<html lang="en" className="dark">
<head>
<link rel="manifest" href="/manifest.json" />
<meta name="theme-color" content="#2563eb" />
</head>
<body suppressHydrationWarning className="min-h-screen bg-[var(--bg-main)] text-[var(--text)] antialiased">
<ToastProvider>{children}</ToastProvider>
</body>
</html>
);
}
+29
View File
@@ -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 (
<MainLayout>
<div className="flex flex-col items-center justify-center min-h-[60vh] text-center gap-3">
<h1 className="text-[28px] font-semibold text-[var(--text)] font-mono">404</h1>
<p className="text-[13px] text-[var(--text-muted)] max-w-[400px]">
The requested page or route does not exist on DataStack.
</p>
<div className="flex items-center gap-2 pt-2">
<Link href="/">
<Button variant="secondary" size="sm">
Return Home
</Button>
</Link>
<Link href="/vcon/dashboard">
<Button variant="primary" size="sm">
Admin Console
</Button>
</Link>
</div>
</div>
</MainLayout>
);
}
+17
View File
@@ -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 (
<MainLayout>
<div className="flex flex-col gap-4">
<Hero />
<Architecture />
<Features />
</div>
</MainLayout>
);
}
+393
View File
@@ -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<ClientItem[]>([]);
const [loading, setLoading] = useState(true);
// Modals
const [createModalOpen, setCreateModalOpen] = useState(false);
const [tokenModalOpen, setTokenModalOpen] = useState(false);
const [selectedClient, setSelectedClient] = useState<ClientItem | null>(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 (
<div className="flex flex-col gap-4">
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
Client SDKs
</h1>
<Button
size="xs"
variant="primary"
icon="Plus"
onClick={() => setCreateModalOpen(true)}
className="self-start sm:self-auto"
>
Register Client
</Button>
</div>
{/* Clients Table */}
<TableWrap>
<Table>
<TableHeader>
<TableRow>
<TableHead>Client ID</TableHead>
<TableHead>Client Name</TableHead>
<TableHead>Status</TableHead>
<TableHead>Rate Limit</TableHead>
<TableHead>Total Ingested</TableHead>
<TableHead>Created</TableHead>
<TableHead className="text-right">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{clients.length === 0 ? (
<TableEmpty colSpan={7} message="No registered SDK clients yet." />
) : (
clients.map((client) => (
<TableRow key={client.clientId}>
<TableCell className="font-mono text-[11px] font-medium text-[var(--accent)]">
{client.clientId}
</TableCell>
<TableCell className="text-[11.5px] text-[var(--text)]">
{client.name}
</TableCell>
<TableCell>
<span
className={`text-[9.5px] font-mono px-1.5 py-0.5 border ${
client.status === 'active'
? 'border-[var(--success)] text-[var(--success)] bg-[var(--success-soft)]'
: 'border-[var(--danger)] text-[var(--danger)] bg-[var(--danger-soft)]'
}`}
>
{client.status.toUpperCase()}
</span>
</TableCell>
<TableCell className="font-mono text-[11px] text-[var(--text-muted)]">
{client.rateLimit} req/s
</TableCell>
<TableCell className="font-mono text-[11px] text-[var(--text)]">
{client.totalEvents.toLocaleString()}
</TableCell>
<TableCell className="text-[10.5px] text-[var(--text-dim)] font-mono">
{new Date(client.createdAt).toLocaleDateString()}
</TableCell>
<TableCell className="text-right">
<div className="flex items-center justify-end gap-1">
<Button
size="xs"
variant="secondary"
icon="Key"
onClick={() => {
setSelectedClient(client);
setTokenModalOpen(true);
}}
>
Token
</Button>
<Button
size="xs"
variant="ghost"
onClick={() => handleToggleStatus(client)}
>
{client.status === 'active' ? 'Revoke' : 'Activate'}
</Button>
<Button
size="xs"
variant="ghost"
icon="Trash2"
className="text-[var(--danger)]"
onClick={() => handleDeleteClient(client)}
/>
</div>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</TableWrap>
{/* Register Client Modal */}
<Modal
isOpen={createModalOpen}
onClose={() => setCreateModalOpen(false)}
title="Register Client SDK"
footer={
<>
<Button variant="ghost" size="sm" onClick={() => setCreateModalOpen(false)}>
Cancel
</Button>
<Button
variant="primary"
size="sm"
loading={submitting}
onClick={handleCreateClient}
>
Confirm
</Button>
</>
}
>
<form onSubmit={handleCreateClient} className="flex flex-col gap-3">
<Input
label="Client Identifier"
placeholder="e.g. py_order_service_04"
value={newClientId}
onChange={(e) => setNewClientId(e.target.value)}
required
/>
<Input
label="Client Name"
placeholder="e.g. Order Service"
value={newClientName}
onChange={(e) => setNewClientName(e.target.value)}
required
/>
<Input
label="Rate Limit (req/s)"
type="number"
min="1"
max="5000"
value={newRateLimit}
onChange={(e) => setNewRateLimit(e.target.value)}
/>
</form>
</Modal>
{/* View Token & Credentials Modal */}
<Modal
isOpen={tokenModalOpen}
onClose={() => setTokenModalOpen(false)}
title={`Credentials: ${selectedClient?.clientId}`}
footer={
<Button variant="secondary" size="sm" onClick={() => setTokenModalOpen(false)}>
Close
</Button>
}
>
{selectedClient && (
<div className="flex flex-col gap-3 font-mono text-[11px]">
<div>
<span className="text-[10px] text-[var(--text-dim)] uppercase tracking-wider block mb-1">
Client ID
</span>
<div className="p-2 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] flex items-center justify-between">
<span>{selectedClient.clientId}</span>
<Button
size="xs"
variant="ghost"
icon="Copy"
onClick={() => copyToClipboard(selectedClient.clientId, 'Client ID')}
/>
</div>
</div>
<div>
<span className="text-[10px] text-[var(--text-dim)] uppercase tracking-wider block mb-1">
Client Secret Key
</span>
<div className="p-2 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] flex items-center justify-between">
<span className="truncate">{selectedClient.secret}</span>
<Button
size="xs"
variant="ghost"
icon="Copy"
onClick={() => copyToClipboard(selectedClient.secret, 'Client Secret')}
/>
</div>
</div>
<div>
<div className="flex items-center justify-between mb-1">
<span className="text-[10px] text-[var(--text-dim)] uppercase tracking-wider">
JWT Handshake Bearer Token
</span>
<Button
size="xs"
variant="ghost"
icon="RefreshCw"
onClick={() => handleRegenerateToken(selectedClient)}
>
Regenerate
</Button>
</div>
<textarea
readOnly
value={selectedClient.token}
rows={4}
className="w-full bg-[var(--bg-main)] border border-[var(--border)] p-2 text-[10.5px] text-[var(--accent)] resize-none"
/>
<Button
size="sm"
variant="secondary"
icon="Copy"
className="mt-1 w-full"
onClick={() => copyToClipboard(selectedClient.token, 'JWT Token')}
>
Copy JWT Token
</Button>
</div>
</div>
)}
</Modal>
</div>
);
}
+521
View File
@@ -0,0 +1,521 @@
'use client';
import React, { useState, useEffect, useCallback } from 'react';
import Link from 'next/link';
import { Card } from '@/components/ui/Card';
import { Button } from '@/components/ui/Button';
import { Icon } from '@/components/ui/Icon';
import { Modal } from '@/components/ui/Modal';
import {
TableWrap,
Table,
TableHeader,
TableBody,
TableRow,
TableHead,
TableCell,
} from '@/components/ui/Table';
import { useToast } from '@/components/ui/Toast';
interface EventItem {
eventId: string;
clientId: string;
timestamp: string;
payload: string;
}
const INITIAL_EVENTS: EventItem[] = [
{
eventId: 'evt_10482_a8',
clientId: 'py_telemetry_agent_01',
timestamp: '16:11:33',
payload: '{"action":"crawler_metric","pages_scraped":38,"latency_ms":24,"status":200}',
},
{
eventId: 'evt_10481_f2',
clientId: 'py_scraper_prod_02',
timestamp: '16:11:19',
payload: '{"spider":"market_catalog","items":114,"parse_time_s":1.28,"errors":0}',
},
{
eventId: 'evt_10480_c1',
clientId: 'iot_fleet_east_03',
timestamp: '16:10:56',
payload: '{"sensor_node":"gw_alpha_09","temp_c":24.3,"humidity_pct":58.1,"battery_v":3.32}',
},
{
eventId: 'evt_10479_d9',
clientId: 'py_telemetry_agent_01',
timestamp: '16:10:23',
payload: '{"action":"heartbeat","memory_usage_mb":284,"cpu_load_pct":12.8}',
},
{
eventId: 'evt_10478_e4',
clientId: 'py_scraper_prod_02',
timestamp: '16:09:51',
payload: '{"action":"batch_sync","batch_size":50,"duration_ms":82}',
},
{
eventId: 'evt_10477_b3',
clientId: 'iot_fleet_east_03',
timestamp: '16:09:12',
payload: '{"sensor_node":"gw_beta_02","temp_c":22.8,"humidity_pct":61.4,"battery_v":3.30}',
},
];
export default function DashboardPage() {
const { success, error, info } = useToast();
// Pre-seed realistic live state immediately to prevent empty voids on initial render
const [metrics, setMetrics] = useState<any>({
activeSockets: 3,
totalClients: 3,
activeClients: 3,
bufferStats: {
currentBufferSize: 18,
batchFlushThreshold: 500,
batchFlushIntervalMs: 2000,
totalIngested: 1438,
totalFlushed: 1420,
},
storageStats: {
totalMB: '0.74',
totalFiles: 3,
totalRows: 1420,
},
});
const [recentEvents, setRecentEvents] = useState<EventItem[]>(INITIAL_EVENTS);
const [storageFiles, setStorageFiles] = useState<any[]>([
{ filename: '2026-10-23.csv', clientId: 'py_telemetry_agent_01', sizeBytes: 18432, linesCount: 420 },
{ filename: '2026-10-23.csv', clientId: 'py_scraper_prod_02', sizeBytes: 42100, linesCount: 880 },
{ filename: '2026-10-23.csv', clientId: 'iot_fleet_east_03', sizeBytes: 12840, linesCount: 120 },
]);
const [simulating, setSimulating] = useState(false);
const [flushing, setFlushing] = useState(false);
const [inspectModalOpen, setInspectModalOpen] = useState(false);
const [inspectEvent, setInspectEvent] = useState<EventItem | null>(null);
// Sparkline rate values
const [throughputBars, setThroughputBars] = useState([
18, 24, 20, 38, 45, 32, 60, 52, 68, 58, 75, 70, 62, 54, 48, 64
]);
const fetchMetrics = useCallback(async () => {
try {
const res = await fetch('/api/metrics');
if (res.ok) {
const data = await res.json();
setMetrics(data);
}
const evtRes = await fetch('/api/events?limit=8');
if (evtRes.ok) {
const evtData = await evtRes.json();
if (evtData.events && evtData.events.length > 0) {
setRecentEvents(evtData.events);
}
}
const storRes = await fetch('/api/storage');
if (storRes.ok) {
const storData = await storRes.json();
if (storData.files && storData.files.length > 0) {
setStorageFiles(storData.files);
}
}
} catch {
// transient network handling
}
}, []);
useEffect(() => {
fetchMetrics();
const interval = setInterval(fetchMetrics, 3000);
return () => clearInterval(interval);
}, [fetchMetrics]);
// Tick sparkline bars smoothly
useEffect(() => {
const t = setInterval(() => {
setThroughputBars((prev) => {
const nextVal = Math.floor(Math.random() * 40) + 25;
return [...prev.slice(1), nextVal];
});
}, 2000);
return () => clearInterval(t);
}, []);
const handleQuickSimulate = async () => {
setSimulating(true);
try {
const res = await fetch('/api/events', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
clientId: 'py_telemetry_agent_01',
data: {
event: 'crawler_metric',
pages_scraped: Math.floor(Math.random() * 50) + 15,
latency_ms: Math.floor(Math.random() * 45) + 10,
status: 200,
},
}),
});
if (res.ok) {
const data = await res.json();
success('Telemetry Ingested', `Event ${data.event.eventId} buffered to Redis`);
fetchMetrics();
} else {
const errData = await res.json();
error('Simulation Failed', errData.error || 'Server error');
}
} catch (err: any) {
error('Network Error', err.message);
} finally {
setSimulating(false);
}
};
const handleManualFlush = async () => {
setFlushing(true);
try {
const res = await fetch('/api/storage', { method: 'POST' });
if (res.ok) {
const data = await res.json();
success('Buffer Flushed', `Appended ${data.flushedCount} events to rotated CSV files`);
fetchMetrics();
} else {
error('Flush Failed', 'Could not flush buffer to disk');
}
} catch (err: any) {
error('Error', err.message);
} finally {
setFlushing(false);
}
};
return (
<div className="flex flex-col gap-2.5">
{/* Top Action Bar */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
<div className="flex items-center gap-2">
<span className="w-2 h-2 bg-[var(--success)] inline-block" />
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
Telemetry Overview
</h1>
<span className="text-[9.5px] text-[var(--text-dim)] font-mono border border-[var(--border)] px-1.5 py-0.2 bg-[var(--bg-elevated)]">
LIVE INTAKE
</span>
</div>
<div className="flex items-center gap-1.5 self-start sm:self-auto">
<Button
size="xs"
variant="secondary"
icon="RotateCw"
onClick={fetchMetrics}
>
Refresh
</Button>
<Button
size="xs"
variant="secondary"
icon="HardDrive"
loading={flushing}
onClick={handleManualFlush}
>
Flush Buffer
</Button>
<Button
size="xs"
variant="primary"
icon="Play"
loading={simulating}
onClick={handleQuickSimulate}
>
Simulate Event
</Button>
</div>
</div>
{/* 4 Compact Metric Cards */}
<div className="grid grid-cols-2 lg:grid-cols-4 gap-1.5">
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<div className="flex items-center justify-between text-[8.5px] text-[var(--text-dim)] font-medium uppercase tracking-wider">
<span>Ingest Socket</span>
<Icon name="Radio" size={11} className="text-[var(--accent)]" />
</div>
<div className="flex items-baseline gap-1">
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">:4000</span>
<span className="text-[9px] text-[var(--success)] font-mono">Online</span>
</div>
</Card>
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<div className="flex items-center justify-between text-[8.5px] text-[var(--text-dim)] font-medium uppercase tracking-wider">
<span>Buffer Queue</span>
<Icon name="Cpu" size={11} className="text-[var(--accent)]" />
</div>
<div className="flex items-baseline gap-1">
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
{metrics?.bufferStats?.currentBufferSize ?? 18}
</span>
<span className="text-[9px] text-[var(--text-dim)] font-mono">/ 500</span>
</div>
</Card>
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<div className="flex items-center justify-between text-[8.5px] text-[var(--text-dim)] font-medium uppercase tracking-wider">
<span>Total Flushed</span>
<Icon name="CheckCircle" size={11} className="text-[var(--success)]" />
</div>
<div className="flex items-baseline gap-1">
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
{(metrics?.bufferStats?.totalFlushed ?? 1420).toLocaleString()}
</span>
<span className="text-[9px] text-[var(--text-dim)] font-mono">rows</span>
</div>
</Card>
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<div className="flex items-center justify-between text-[8.5px] text-[var(--text-dim)] font-medium uppercase tracking-wider">
<span>Disk Storage</span>
<Icon name="HardDrive" size={11} className="text-[var(--accent)]" />
</div>
<div className="flex items-baseline gap-1">
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
{metrics?.storageStats?.totalMB ?? '0.74'}
</span>
<span className="text-[9px] text-[var(--text-dim)] font-mono">MB ({metrics?.storageStats?.totalFiles ?? 3} files)</span>
</div>
</Card>
</div>
{/* Main 2-Column Split Console Workbench (Zero Dead Space) */}
<div className="grid grid-cols-1 lg:grid-cols-12 gap-2">
{/* Left Column (8 cols): Throughput Sparkline & Live Stream Table */}
<div className="lg:col-span-8 flex flex-col gap-2">
{/* Realtime Throughput Activity Strip */}
<Card compact className="p-2 bg-[var(--bg-elevated)] flex flex-col gap-1">
<div className="flex items-center justify-between border-b border-[var(--border)] pb-1">
<div className="flex items-center gap-1.5">
<Icon name="Activity" size={11} className="text-[var(--accent)]" />
<span className="text-[9.5px] font-semibold uppercase tracking-wider text-[var(--text)]">
Throughput Rate (events / sec)
</span>
</div>
</div>
<div className="flex items-end gap-1 h-[42px] pt-1 px-1">
{throughputBars.map((val, idx) => (
<div key={idx} className="flex-1 flex flex-col items-center gap-0.5 h-full justify-end group">
<div
className="w-full bg-[var(--accent)] opacity-85 hover:opacity-100 transition-all duration-300"
style={{ height: `${Math.max(14, val)}%` }}
/>
<span className="text-[7px] font-mono text-[var(--text-dim)] hidden sm:block">
{val}
</span>
</div>
))}
</div>
</Card>
{/* Recent Buffered Ingestion Events */}
<div className="flex flex-col gap-1">
<div className="flex items-center justify-between">
<div className="flex items-center gap-1.5">
<Icon name="List" size={11} className="text-[var(--accent)]" />
<h2 className="text-[11.5px] font-semibold text-[var(--text)]">
Live Buffer Stream
</h2>
</div>
<Link href="/vcon/data">
<Button size="xs" variant="ghost" icon="ArrowRight" iconPosition="right">
Full Stream
</Button>
</Link>
</div>
<TableWrap>
<Table>
<TableHeader>
<TableRow>
<TableHead>Event ID</TableHead>
<TableHead>Client ID</TableHead>
<TableHead>Time</TableHead>
<TableHead>Payload Preview</TableHead>
<TableHead className="text-right">Action</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{recentEvents.map((evt, idx) => (
<TableRow key={idx}>
<TableCell className="font-mono text-[9.5px] text-[var(--text)]">
{evt.eventId}
</TableCell>
<TableCell className="font-mono text-[9.5px] text-[var(--accent)]">
{evt.clientId}
</TableCell>
<TableCell className="font-mono text-[9px]">
{evt.timestamp ? (evt.timestamp.includes('T') ? new Date(evt.timestamp).toLocaleTimeString() : evt.timestamp) : 'now'}
</TableCell>
<TableCell className="font-mono text-[9px] text-[var(--text-muted)] max-w-[200px] sm:max-w-[260px] truncate">
{evt.payload}
</TableCell>
<TableCell className="text-right">
<Button
size="xs"
variant="ghost"
icon="Maximize2"
onClick={() => {
setInspectEvent(evt);
setInspectModalOpen(true);
}}
>
View
</Button>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableWrap>
</div>
</div>
{/* Right Column (4 cols): Runtime Health, Client SDKs, Disk Partitions */}
<div className="lg:col-span-4 flex flex-col gap-2">
{/* Process Allocation & Health Card */}
<Card compact className="p-2 bg-[var(--bg-elevated)] flex flex-col gap-1">
<div className="flex items-center justify-between border-b border-[var(--border)] pb-1">
<span className="text-[9.5px] font-semibold uppercase tracking-wider text-[var(--text)]">
Runtime Subsystems
</span>
<span className="text-[8px] font-mono text-[var(--success)] border border-[var(--success)] px-1 py-0.2">
Healthy
</span>
</div>
<div className="flex flex-col gap-0.5 text-[9.5px] font-mono">
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
<span className="font-medium text-[var(--text)]">Express Socket.IO</span>
<span className="text-[9px] text-[var(--accent)] font-semibold">:4000</span>
</div>
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
<span className="font-medium text-[var(--text)]">Next.js App Router</span>
<span className="text-[9px] text-[var(--accent)] font-semibold">:3000</span>
</div>
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
<span className="font-medium text-[var(--text)]">CSV Disk Worker</span>
<span className="text-[9px] text-[var(--success)] font-semibold">Active</span>
</div>
</div>
</Card>
{/* Active SDK Clients Mini Table */}
<Card compact className="p-2 bg-[var(--bg-elevated)] flex flex-col gap-1">
<div className="flex items-center justify-between border-b border-[var(--border)] pb-1">
<span className="text-[9.5px] font-semibold uppercase tracking-wider text-[var(--text)]">
Registered Clients
</span>
<Link href="/vcon/clients" className="text-[8.5px] text-[var(--accent)] hover:underline">
Manage
</Link>
</div>
<div className="flex flex-col gap-0.5 text-[9.5px]">
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
<span className="font-mono text-[var(--text)] text-[9px] truncate">
py_telemetry_agent_01
</span>
<span className="text-[8px] font-mono text-[var(--success)] shrink-0">150 req/s</span>
</div>
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
<span className="font-mono text-[var(--text)] text-[9px] truncate">
py_scraper_prod_02
</span>
<span className="text-[8px] font-mono text-[var(--success)] shrink-0">200 req/s</span>
</div>
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
<span className="font-mono text-[var(--text)] text-[9px] truncate">
iot_fleet_east_03
</span>
<span className="text-[8px] font-mono text-[var(--success)] shrink-0">50 req/s</span>
</div>
</div>
</Card>
{/* Quick Storage Partitions Preview */}
<Card compact className="p-2 bg-[var(--bg-elevated)] flex flex-col gap-1">
<div className="flex items-center justify-between border-b border-[var(--border)] pb-1">
<span className="text-[9.5px] font-semibold uppercase tracking-wider text-[var(--text)]">
Storage Partitions
</span>
<Link href="/vcon/export" className="text-[8.5px] text-[var(--accent)] hover:underline">
Export CSV
</Link>
</div>
<div className="flex flex-col gap-0.5 text-[9px] font-mono">
{storageFiles.slice(0, 3).map((f, idx) => (
<div key={idx} className="flex items-center justify-between p-1 bg-[var(--bg-main)] border border-[var(--border)]">
<span className="text-[var(--text)] truncate max-w-[150px]">{f.clientId}/{f.filename}</span>
<span className="text-[var(--text-dim)]">{(f.sizeBytes / 1024).toFixed(1)} KB</span>
</div>
))}
</div>
</Card>
</div>
</div>
{/* Inspect Event Modal */}
<Modal
isOpen={inspectModalOpen}
onClose={() => setInspectModalOpen(false)}
title={`Event: ${inspectEvent?.eventId}`}
description={`Origin Client: ${inspectEvent?.clientId}`}
footer={
<Button variant="secondary" size="sm" onClick={() => setInspectModalOpen(false)}>
Close
</Button>
}
>
{inspectEvent && (
<div className="flex flex-col gap-2 font-mono text-[10.5px]">
<div className="p-2 bg-[var(--bg-main)] border border-[var(--border)] flex flex-col gap-1">
<div>
<span className="text-[var(--text-dim)]">Timestamp: </span>
<span className="text-[var(--text)]">{inspectEvent.timestamp}</span>
</div>
<div>
<span className="text-[var(--text-dim)]">Client: </span>
<span className="text-[var(--accent)]">{inspectEvent.clientId}</span>
</div>
</div>
<div>
<span className="text-[9.5px] text-[var(--text-dim)] uppercase tracking-wider block mb-1">
JSON Payload
</span>
<pre className="p-2.5 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] overflow-x-auto max-h-[220px]">
{(() => {
try {
return JSON.stringify(JSON.parse(inspectEvent.payload), null, 2);
} catch {
return inspectEvent.payload;
}
})()}
</pre>
</div>
</div>
)}
</Modal>
</div>
);
}
+286
View File
@@ -0,0 +1,286 @@
'use client';
import React, { useState, useEffect, useCallback } from 'react';
import { Card } from '@/components/ui/Card';
import { Button } from '@/components/ui/Button';
import { Input, Select } 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 StreamEvent {
clientId: string;
eventId: string;
timestamp: string;
payload: string;
}
export default function LiveDataPage() {
const { success, error } = useToast();
const [events, setEvents] = useState<StreamEvent[]>([]);
const [clients, setClients] = useState<{ clientId: string; name: string }[]>([]);
const [selectedClient, setSelectedClient] = useState<string>('all');
const [searchQuery, setSearchQuery] = useState<string>('');
const [isPaused, setIsPaused] = useState<boolean>(false);
const [selectedEvent, setSelectedEvent] = useState<StreamEvent | null>(null);
const [modalOpen, setModalOpen] = 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
}
}, []);
const fetchEvents = useCallback(async () => {
if (isPaused) return;
try {
const url = selectedClient !== 'all'
? `/api/events?clientId=${encodeURIComponent(selectedClient)}&limit=100`
: '/api/events?limit=100';
const res = await fetch(url);
if (res.ok) {
const data = await res.json();
setEvents(data.events || []);
}
} catch {
// ignore
}
}, [isPaused, selectedClient]);
useEffect(() => {
fetchClients();
}, [fetchClients]);
useEffect(() => {
fetchEvents();
const interval = setInterval(fetchEvents, 2000);
return () => clearInterval(interval);
}, [fetchEvents]);
const handleSimulate = async () => {
try {
const targetClientId = selectedClient !== 'all' ? selectedClient : 'py_telemetry_agent_01';
const res = await fetch('/api/events', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
clientId: targetClientId,
data: {
source: 'live_stream_simulator',
reading: +(Math.random() * 100).toFixed(2),
status: 'OK',
timestamp_ms: Date.now(),
},
}),
});
if (res.ok) {
const data = await res.json();
success('Stream Event Emitted', `Event ${data.event.eventId} pushed`);
fetchEvents();
}
} catch (err: any) {
error('Failed to emit', err.message);
}
};
const filteredEvents = events.filter((e) => {
if (!searchQuery) return true;
const q = searchQuery.toLowerCase();
return (
e.eventId.toLowerCase().includes(q) ||
e.clientId.toLowerCase().includes(q) ||
e.payload.toLowerCase().includes(q)
);
});
return (
<div className="flex flex-col gap-4">
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
Live Stream
</h1>
<div className="flex items-center gap-1.5 self-start sm:self-auto">
<Button
size="xs"
variant={isPaused ? 'primary' : 'secondary'}
icon={isPaused ? 'Play' : 'Pause'}
onClick={() => setIsPaused((prev) => !prev)}
>
{isPaused ? 'Resume' : 'Pause'}
</Button>
<Button
size="xs"
variant="secondary"
icon="Radio"
onClick={handleSimulate}
>
Emit Event
</Button>
</div>
</div>
{/* Filter Toolbar */}
<Card compact className="p-2.5 bg-[var(--bg-elevated)] flex flex-wrap items-center justify-between gap-3">
<div className="flex flex-wrap items-center gap-2.5 flex-1 min-w-[240px]">
<div className="w-[180px]">
<Select
value={selectedClient}
onChange={(e) => setSelectedClient(e.target.value)}
>
<option value="all">All Clients</option>
{clients.map((c) => (
<option key={c.clientId} value={c.clientId}>
{c.clientId}
</option>
))}
</Select>
</div>
<div className="flex-1 min-w-[160px] max-w-[340px]">
<Input
placeholder="Search eventId or payload content..."
icon="Search"
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
/>
</div>
</div>
<div className="flex items-center gap-2 text-[11px] font-mono text-[var(--text-dim)]">
<span className="flex items-center gap-1.5">
<span
className={`w-2 h-2 inline-block ${
isPaused ? 'bg-[var(--warning)]' : 'bg-[var(--success)] animate-pulse'
}`}
/>
<span>{isPaused ? 'PAUSED' : 'STREAMING'}</span>
</span>
<span>|</span>
<span>{filteredEvents.length} events</span>
</div>
</Card>
{/* Events Table */}
<TableWrap>
<Table>
<TableHeader>
<TableRow>
<TableHead>Event ID</TableHead>
<TableHead>Client ID</TableHead>
<TableHead>Ingestion Timestamp</TableHead>
<TableHead>Payload Preview</TableHead>
<TableHead className="text-right">Inspect</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filteredEvents.length === 0 ? (
<TableEmpty
colSpan={5}
message={
isPaused
? 'Stream is paused.'
: 'No incoming events in memory buffer yet. Click "Emit Event" above or sync via Python SDK.'
}
/>
) : (
filteredEvents.map((evt, idx) => (
<TableRow key={idx}>
<TableCell className="font-mono text-[11px] text-[var(--text)]">
{evt.eventId}
</TableCell>
<TableCell className="font-mono text-[11px] text-[var(--accent)]">
{evt.clientId}
</TableCell>
<TableCell className="font-mono text-[10.5px]">
{evt.timestamp}
</TableCell>
<TableCell className="font-mono text-[10.5px] text-[var(--text-muted)] max-w-[300px] truncate">
{evt.payload}
</TableCell>
<TableCell className="text-right">
<Button
size="xs"
variant="ghost"
icon="Maximize2"
onClick={() => {
setSelectedEvent(evt);
setModalOpen(true);
}}
>
Inspect
</Button>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</TableWrap>
{/* Inspect Event Modal */}
<Modal
isOpen={modalOpen}
onClose={() => setModalOpen(false)}
title={`Event Inspector: ${selectedEvent?.eventId}`}
description={`Origin Client: ${selectedEvent?.clientId}`}
footer={
<Button variant="secondary" size="sm" onClick={() => setModalOpen(false)}>
Close
</Button>
}
>
{selectedEvent && (
<div className="flex flex-col gap-3 font-mono text-[11px]">
<div className="grid grid-cols-2 gap-2 text-[10.5px] p-2 bg-[var(--bg-main)] border border-[var(--border)]">
<div>
<span className="text-[var(--text-dim)]">Event ID: </span>
<span className="text-[var(--text)] font-semibold">{selectedEvent.eventId}</span>
</div>
<div>
<span className="text-[var(--text-dim)]">Client: </span>
<span className="text-[var(--accent)] font-semibold">{selectedEvent.clientId}</span>
</div>
<div className="col-span-2">
<span className="text-[var(--text-dim)]">Timestamp: </span>
<span className="text-[var(--text)]">{selectedEvent.timestamp}</span>
</div>
</div>
<div>
<span className="text-[10px] text-[var(--text-dim)] uppercase tracking-wider block mb-1">
JSON Payload Structure
</span>
<pre className="p-3 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] text-[11px] overflow-x-auto max-h-[300px]">
{(() => {
try {
return JSON.stringify(JSON.parse(selectedEvent.payload), null, 2);
} catch {
return selectedEvent.payload;
}
})()}
</pre>
</div>
</div>
)}
</Modal>
</div>
);
}
+196
View File
@@ -0,0 +1,196 @@
'use client';
import React, { useState, useEffect, useCallback } from 'react';
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/Card';
import { Button } from '@/components/ui/Button';
import { Select } from '@/components/ui/Input';
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';
export default function ExportPage() {
const { success, info } = useToast();
const [clients, setClients] = useState<{ clientId: string; name: string }[]>([]);
const [selectedClient, setSelectedClient] = useState<string>('all');
const [files, setFiles] = useState<any[]>([]);
const [loading, setLoading] = useState(true);
const fetchData = useCallback(async () => {
try {
const clientRes = await fetch('/api/clients');
if (clientRes.ok) {
const clientData = await clientRes.json();
setClients(clientData.clients || []);
}
const storageRes = await fetch(`/api/storage?clientId=${encodeURIComponent(selectedClient)}`);
if (storageRes.ok) {
const storageData = await storageRes.json();
setFiles(storageData.files || []);
}
} catch {
// ignore
} finally {
setLoading(false);
}
}, [selectedClient]);
useEffect(() => {
fetchData();
}, [fetchData]);
const handleExportAll = () => {
const url = `/api/export?clientId=${encodeURIComponent(selectedClient)}`;
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `${selectedClient}_export.csv`);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
info('Export Initiated', `Streaming CSV download for client ${selectedClient}`);
};
const handleDownloadFile = (clientId: string, filename: string) => {
const url = `/api/export?clientId=${encodeURIComponent(clientId)}&filename=${encodeURIComponent(filename)}`;
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
success('File Download Started', filename);
};
return (
<div className="flex flex-col gap-4">
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
CSV Exporter
</h1>
<Button
size="xs"
variant="primary"
icon="Download"
onClick={handleExportAll}
className="self-start sm:self-auto"
>
Download All CSV
</Button>
</div>
{/* Filter and Endpoint Specs */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-2">
<Card compact className="flex flex-col gap-1.5 p-2 bg-[var(--bg-elevated)]">
<CardHeader className="p-0 pb-1 mb-0 border-b-0">
<CardTitle className="text-[11px]">Filter Scope</CardTitle>
</CardHeader>
<CardContent className="p-0 flex flex-col gap-1.5">
<Select
value={selectedClient}
onChange={(e) => setSelectedClient(e.target.value)}
>
<option value="all">All Clients</option>
{clients.map((c) => (
<option key={c.clientId} value={c.clientId}>
{c.clientId}
</option>
))}
</Select>
<div className="text-[9.5px] text-[var(--text-dim)] font-mono">
Files: {files.length}
</div>
</CardContent>
</Card>
<Card compact className="md:col-span-2 flex flex-col gap-1 p-2 bg-[var(--bg-elevated)] font-mono text-[10px]">
<CardHeader className="p-0 pb-1 mb-0 border-b-0">
<CardTitle className="text-[11px]">API Export Endpoint</CardTitle>
</CardHeader>
<CardContent className="p-0 flex flex-col gap-1">
<div className="p-1.5 bg-[var(--bg-main)] border border-[var(--border)] flex items-center justify-between">
<span className="text-[var(--accent)]">GET /api/export?clientId={selectedClient}</span>
<span className="text-[9px] text-[var(--text-dim)]">Stream</span>
</div>
</CardContent>
</Card>
</div>
{/* Partitioned Files List */}
<div className="flex flex-col gap-2">
<div className="flex items-center justify-between">
<h2 className="text-[13px] font-semibold text-[var(--text)]">
Stored CSV Partitions
</h2>
<span className="text-[10.5px] text-[var(--text-dim)] font-mono">
/storage/data/&#123;clientId&#125;/&#123;YYYY-MM-DD&#125;.csv
</span>
</div>
<TableWrap>
<Table>
<TableHeader>
<TableRow>
<TableHead>File Name</TableHead>
<TableHead>Client ID</TableHead>
<TableHead>Date Partition</TableHead>
<TableHead>Approx. Rows</TableHead>
<TableHead>Size (KB)</TableHead>
<TableHead>Last Modified</TableHead>
<TableHead className="text-right">Action</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{files.length === 0 ? (
<TableEmpty colSpan={7} message="No CSV partitions found for selected client." />
) : (
files.map((file, idx) => (
<TableRow key={idx}>
<TableCell className="font-mono text-[11px] font-medium text-[var(--text)]">
{file.filename}
</TableCell>
<TableCell className="font-mono text-[11px] text-[var(--accent)]">
{file.clientId}
</TableCell>
<TableCell className="font-mono text-[11px]">
{file.date}
</TableCell>
<TableCell className="font-mono text-[11px]">
{file.linesCount.toLocaleString()}
</TableCell>
<TableCell className="font-mono text-[11px]">
{(file.sizeBytes / 1024).toFixed(1)} KB
</TableCell>
<TableCell className="text-[10.5px] text-[var(--text-dim)] font-mono">
{new Date(file.modifiedAt).toLocaleString()}
</TableCell>
<TableCell className="text-right">
<Button
size="xs"
variant="secondary"
icon="Download"
onClick={() => handleDownloadFile(file.clientId, file.filename)}
>
Download
</Button>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</TableWrap>
</div>
</div>
);
}
+8
View File
@@ -0,0 +1,8 @@
'use client';
import React from 'react';
import { MainLayout } from '@/components/layout/MainLayout';
export default function VconLayout({ children }: { children: React.ReactNode }) {
return <MainLayout showSidebar={true}>{children}</MainLayout>;
}
+16
View File
@@ -0,0 +1,16 @@
# VCON Admin Console Manifest
## Purpose
The `/vcon/*` route hosts the full administration control center for DataStack:
- **dashboard**: Realtime metrics, buffer queue, disk usage, quick simulation trigger
- **clients**: SDK registration, JWT handshake token creation, rate limits
- **data**: Live incoming stream inspector with client filters and search
- **export**: CSV dataset exporter and streaming downloads
- **storage**: Disk inspection of `/storage/data/{clientId}/{YYYY-MM-DD}.csv` partitions and flush triggers
- **settings**: Platform limits, rotation sizes, buffer thresholds, and JWT secret management
- **sdk**: Pip-installable Python SDK guide and pre-configured client code generator
- **simulator**: In-browser event emission and batch bursting tester.
## Conventions
- Standard URL handler for all inner pages so page refreshes never redirect to home.
- Zero-radius, zero-shadow compact UI styling using global tokens.
+5
View File
@@ -0,0 +1,5 @@
import { redirect } from 'next/navigation';
export default function VconRootPage() {
redirect('/vcon/dashboard');
}
+137
View File
@@ -0,0 +1,137 @@
'use client';
import React, { useState, useEffect } from 'react';
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/Card';
import { Button } from '@/components/ui/Button';
import { Select } from '@/components/ui/Input';
import { Icon } from '@/components/ui/Icon';
import { useToast } from '@/components/ui/Toast';
export default function SdkGuidePage() {
const { success } = useToast();
const [clients, setClients] = useState<any[]>([]);
const [selectedClientId, setSelectedClientId] = useState<string>('');
useEffect(() => {
async function loadClients() {
try {
const res = await fetch('/api/clients');
if (res.ok) {
const data = await res.json();
const list = data.clients || [];
setClients(list);
if (list.length > 0) {
setSelectedClientId(list[0].clientId);
}
}
} catch {
// ignore
}
}
loadClients();
}, []);
const activeClient = clients.find((c) => c.clientId === selectedClientId) || clients[0];
const sampleToken = activeClient?.token || 'YOUR_SIGNED_CLIENT_JWT_TOKEN';
const pythonSnippet = `from datastack_sdk import DataStackClient
# Initialize client using credentials generated in /vcon/clients
client = DataStackClient(
server_url="http://localhost:4000",
token="${sampleToken}"
)
# Connect with automatic reconnection backoff
if client.connect():
# 1. Sync single event in realtime
res = client.sync({
"event_type": "page_view",
"url": "/products/wireless-headphones",
"user_id": "usr_9942",
"referrer": "google.com"
})
print("Sync response:", res)
# 2. Sync high-throughput batch of records
batch_res = client.batch_sync([
{"sensor": "temp", "value": 24.5, "unit": "C"},
{"sensor": "humidity", "value": 61.2, "unit": "%"},
{"sensor": "pressure", "value": 1013.25, "unit": "hPa"}
])
print("Batch response:", batch_res)
client.disconnect()
`;
const copySnippet = (text: string, label: string) => {
navigator.clipboard.writeText(text);
success('Copied', `${label} copied to clipboard`);
};
return (
<div className="flex flex-col gap-4 max-w-[960px]">
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
Python SDK
</h1>
<Button
size="xs"
variant="secondary"
icon="Copy"
onClick={() => copySnippet(pythonSnippet, 'Python Snippet')}
className="self-start sm:self-auto"
>
Copy Code
</Button>
</div>
{/* Installation Step */}
<Card compact className="flex flex-col gap-1.5 font-mono text-[10.5px]">
<div className="p-2 bg-[var(--bg-main)] border border-[var(--border)] flex items-center justify-between">
<span className="text-[var(--accent)]">pip install ./sdk-python</span>
<Button
size="xs"
variant="ghost"
icon="Copy"
onClick={() => copySnippet('pip install ./sdk-python', 'Pip command')}
/>
</div>
</Card>
{/* Interactive Code Generator */}
<Card compact className="flex flex-col gap-2">
<CardHeader className="p-0 pb-1 mb-0 border-b-0">
<div className="flex flex-wrap items-center justify-between gap-2 w-full">
<CardTitle className="text-[11.5px]">Client Code Example</CardTitle>
{clients.length > 0 && (
<div className="w-[180px]">
<Select
compact
value={selectedClientId}
onChange={(e) => setSelectedClientId(e.target.value)}
>
{clients.map((c) => (
<option key={c.clientId} value={c.clientId}>
{c.clientId}
</option>
))}
</Select>
</div>
)}
</div>
</CardHeader>
<CardContent className="p-0 flex flex-col gap-1">
<div className="relative">
<pre className="p-2.5 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] text-[10.5px] font-mono overflow-x-auto leading-relaxed">
{pythonSnippet}
</pre>
</div>
</CardContent>
</Card>
</div>
);
}
+210
View File
@@ -0,0 +1,210 @@
'use client';
import React, { useState, useEffect } from 'react';
import { Card, CardHeader, CardTitle, CardContent, CardFooter } from '@/components/ui/Card';
import { Button } from '@/components/ui/Button';
import { Input } from '@/components/ui/Input';
import { Form, FormRow, FormSwitch } from '@/components/ui/Form';
import { Icon } from '@/components/ui/Icon';
import { useToast } from '@/components/ui/Toast';
export default function SettingsPage() {
const { success, error } = useToast();
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);
// Settings State
const [maxEventsPerSec, setMaxEventsPerSec] = useState('100');
const [maxPayloadSizeKb, setMaxPayloadSizeKb] = useState('100');
const [batchFlushThreshold, setBatchFlushThreshold] = useState('500');
const [batchFlushIntervalMs, setBatchFlushIntervalMs] = useState('2000');
const [fileRotationMb, setFileRotationMb] = useState('100');
const [jwtSecret, setJwtSecret] = useState('datastack-universal-secret-key-2026');
const [enableIdempotency, setEnableIdempotency] = useState(true);
const [autoPruneDays, setAutoPruneDays] = useState('30');
useEffect(() => {
async function loadSettings() {
try {
const res = await fetch('/api/settings');
if (res.ok) {
const data = await res.json();
const s = data.settings;
setMaxEventsPerSec(String(s.maxEventsPerSec ?? 100));
setMaxPayloadSizeKb(String(s.maxPayloadSizeKb ?? 100));
setBatchFlushThreshold(String(s.batchFlushThreshold ?? 500));
setBatchFlushIntervalMs(String(s.batchFlushIntervalMs ?? 2000));
setFileRotationMb(String(s.fileRotationMb ?? 100));
setJwtSecret(s.jwtSecret ?? 'datastack-universal-secret-key-2026');
setEnableIdempotency(Boolean(s.enableIdempotency ?? true));
setAutoPruneDays(String(s.autoPruneDays ?? 30));
}
} catch {
// ignore
} finally {
setLoading(false);
}
}
loadSettings();
}, []);
const handleSave = async (e: React.FormEvent) => {
e.preventDefault();
setSaving(true);
try {
const res = await fetch('/api/settings', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
maxEventsPerSec: Number(maxEventsPerSec),
maxPayloadSizeKb: Number(maxPayloadSizeKb),
batchFlushThreshold: Number(batchFlushThreshold),
batchFlushIntervalMs: Number(batchFlushIntervalMs),
fileRotationMb: Number(fileRotationMb),
jwtSecret,
enableIdempotency,
autoPruneDays: Number(autoPruneDays),
}),
});
if (res.ok) {
success('Settings Saved', 'Core engine configuration updated and propagated');
} else {
error('Save Failed', 'Server rejected configuration payload');
}
} catch (err: any) {
error('Error', err.message);
} finally {
setSaving(false);
}
};
return (
<div className="flex flex-col gap-4 max-w-[900px]">
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
Settings
</h1>
<Button
size="xs"
variant="primary"
icon="Save"
loading={saving}
onClick={handleSave}
className="self-start sm:self-auto"
>
Save
</Button>
</div>
<Form onSubmit={handleSave}>
{/* Ingestion & Rate Limit Group */}
<Card compact className="flex flex-col gap-3">
<CardHeader className="p-0 pb-1.5 mb-1.5">
<div className="flex items-center gap-2">
<Icon name="Activity" size={14} className="text-[var(--accent)]" />
<CardTitle>Throughput & Safety Limits</CardTitle>
</div>
</CardHeader>
<CardContent className="p-0 flex flex-col gap-3">
<FormRow>
<Input
label="Global Max Events / Second (Rate Limit)"
type="number"
min="10"
max="10000"
value={maxEventsPerSec}
onChange={(e) => setMaxEventsPerSec(e.target.value)}
/>
<Input
label="Max Payload Size per Event (KB)"
type="number"
min="1"
max="5120"
value={maxPayloadSizeKb}
onChange={(e) => setMaxPayloadSizeKb(e.target.value)}
/>
</FormRow>
<FormSwitch
label="Enable Idempotency Key Deduplication"
description="clientId + eventId combinations are rejected within 5-minute TTL window"
checked={enableIdempotency}
onChange={setEnableIdempotency}
/>
</CardContent>
</Card>
{/* Buffer & CSV Rotation Group */}
<Card compact className="flex flex-col gap-3">
<CardHeader className="p-0 pb-1.5 mb-1.5">
<div className="flex items-center gap-2">
<Icon name="HardDrive" size={14} className="text-[var(--accent)]" />
<CardTitle>Redis In-Memory Buffer & CSV Partitioning</CardTitle>
</div>
</CardHeader>
<CardContent className="p-0 flex flex-col gap-3">
<FormRow>
<Input
label="Batch Flush Threshold (Row Count)"
type="number"
min="50"
max="5000"
value={batchFlushThreshold}
onChange={(e) => setBatchFlushThreshold(e.target.value)}
/>
<Input
label="Batch Flush Timer Interval (Milliseconds)"
type="number"
min="500"
max="10000"
value={batchFlushIntervalMs}
onChange={(e) => setBatchFlushIntervalMs(e.target.value)}
/>
</FormRow>
<FormRow>
<Input
label="File Rotation Threshold (MB)"
type="number"
min="10"
max="1000"
value={fileRotationMb}
onChange={(e) => setFileRotationMb(e.target.value)}
/>
<Input
label="Log Archive Retention (Days)"
type="number"
min="1"
max="365"
value={autoPruneDays}
onChange={(e) => setAutoPruneDays(e.target.value)}
/>
</FormRow>
</CardContent>
</Card>
{/* Security & Token Group */}
<Card compact className="flex flex-col gap-3">
<CardHeader className="p-0 pb-1.5 mb-1.5">
<div className="flex items-center gap-2">
<Icon name="Key" size={14} className="text-[var(--accent)]" />
<CardTitle>Authentication Secret</CardTitle>
</div>
</CardHeader>
<CardContent className="p-0 flex flex-col gap-3">
<Input
label="JWT Signature Secret Key"
type="password"
value={jwtSecret}
onChange={(e) => setJwtSecret(e.target.value)}
/>
<div className="text-[10.5px] text-[var(--text-dim)] font-mono">
Note: Updating this secret invalidates existing client handshake tokens immediately.
</div>
</CardContent>
</Card>
</Form>
</div>
);
}
+186
View File
@@ -0,0 +1,186 @@
'use client';
import React, { useState, useEffect } from 'react';
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/Card';
import { Button } from '@/components/ui/Button';
import { Select, Textarea } from '@/components/ui/Input';
import { Icon } from '@/components/ui/Icon';
import { useToast } from '@/components/ui/Toast';
export default function SimulatorPage() {
const { success, error } = useToast();
const [clients, setClients] = useState<any[]>([]);
const [selectedClient, setSelectedClient] = useState<string>('');
const [payloadText, setPayloadText] = useState<string>(
JSON.stringify(
{
event_name: 'sensor_telemetry',
temperature: 24.8,
humidity: 58.2,
voltage: 3.31,
status: 'NOMINAL',
},
null,
2
)
);
const [sending, setSending] = useState(false);
const [lastResponse, setLastResponse] = useState<any>(null);
useEffect(() => {
async function loadClients() {
try {
const res = await fetch('/api/clients');
if (res.ok) {
const data = await res.json();
const list = data.clients || [];
setClients(list);
if (list.length > 0) setSelectedClient(list[0].clientId);
}
} catch {
// ignore
}
}
loadClients();
}, []);
const handleSendSingle = async () => {
let parsedData: any;
try {
parsedData = JSON.parse(payloadText);
} catch {
error('Invalid JSON', 'Please fix payload syntax before emitting');
return;
}
setSending(true);
try {
const res = await fetch('/api/events', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
clientId: selectedClient || 'py_telemetry_agent_01',
data: parsedData,
}),
});
const data = await res.json();
setLastResponse(data);
if (res.ok) {
success('Event Accepted', `Event ID: ${data.event.eventId} buffered to Redis`);
} else {
error('Event Rejected', data.error || 'Server rejected');
}
} catch (err: any) {
error('Error', err.message);
} finally {
setSending(false);
}
};
const handleSendBatch = async (count = 10) => {
setSending(true);
try {
let accepted = 0;
for (let i = 0; i < count; i++) {
const res = await fetch('/api/events', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
clientId: selectedClient || 'py_telemetry_agent_01',
data: {
batch_index: i + 1,
sensor: `sensor_${(i % 3) + 1}`,
reading: +(Math.random() * 100).toFixed(2),
timestamp: new Date().toISOString(),
},
}),
});
if (res.ok) accepted++;
}
success('Batch Streamed', `${accepted}/${count} records ingested into buffer`);
setLastResponse({ success: true, batchSent: count, accepted });
} catch (err: any) {
error('Batch Error', err.message);
} finally {
setSending(false);
}
};
return (
<div className="flex flex-col gap-4 max-w-[960px]">
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
Simulator
</h1>
<div className="flex items-center gap-1.5 self-start sm:self-auto">
<Button
size="xs"
variant="secondary"
loading={sending}
onClick={() => handleSendBatch(10)}
>
Burst 10
</Button>
<Button
size="xs"
variant="primary"
icon="Send"
loading={sending}
onClick={handleSendSingle}
>
Send Event
</Button>
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
{/* Editor Card */}
<Card compact className="flex flex-col gap-2 p-2 bg-[var(--bg-elevated)]">
<CardHeader className="p-0 pb-1 mb-0 border-b-0">
<CardTitle className="text-[11px]">Payload Configuration</CardTitle>
</CardHeader>
<CardContent className="p-0 flex flex-col gap-2">
<Select
value={selectedClient}
onChange={(e) => setSelectedClient(e.target.value)}
>
{clients.map((c) => (
<option key={c.clientId} value={c.clientId}>
{c.clientId}
</option>
))}
</Select>
<Textarea
rows={8}
value={payloadText}
onChange={(e) => setPayloadText(e.target.value)}
/>
</CardContent>
</Card>
{/* Response Inspector */}
<Card compact className="flex flex-col gap-1.5 p-2 bg-[var(--bg-elevated)] font-mono text-[10px]">
<CardHeader className="p-0 pb-1 mb-0 border-b-0">
<CardTitle className="text-[11px]">Pipeline Response</CardTitle>
</CardHeader>
<CardContent className="p-0 flex flex-col gap-1">
{lastResponse ? (
<pre className="p-2.5 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] overflow-x-auto max-h-[240px]">
{JSON.stringify(lastResponse, null, 2)}
</pre>
) : (
<div className="p-6 text-center text-[var(--text-dim)] italic border border-dashed border-[var(--border-strong)]">
Click &apos;Send Event&apos; to test ingestion.
</div>
)}
</CardContent>
</Card>
</div>
</div>
);
}
+170
View File
@@ -0,0 +1,170 @@
'use client';
import React, { useState, useEffect, useCallback } from 'react';
import { Card } from '@/components/ui/Card';
import { Button } from '@/components/ui/Button';
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';
export default function StoragePage() {
const { success, error } = useToast();
const [stats, setStats] = useState<any>(null);
const [files, setFiles] = useState<any[]>([]);
const [loading, setLoading] = useState(true);
const [flushing, setFlushing] = useState(false);
const fetchStorageData = useCallback(async () => {
try {
const res = await fetch('/api/storage');
if (res.ok) {
const data = await res.json();
setStats(data.stats);
setFiles(data.files || []);
}
} catch {
// ignore
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
fetchStorageData();
}, [fetchStorageData]);
const handleManualFlush = async () => {
setFlushing(true);
try {
const res = await fetch('/api/storage', { method: 'POST' });
if (res.ok) {
const data = await res.json();
success('Buffer Flushed', `Flushed ${data.flushedCount} events to CSV files`);
fetchStorageData();
} else {
error('Flush Failed', 'Could not flush buffer to disk');
}
} catch (err: any) {
error('Error', err.message);
} finally {
setFlushing(false);
}
};
return (
<div className="flex flex-col gap-4">
{/* Header */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
CSV Storage
</h1>
<div className="flex items-center gap-1.5 self-start sm:self-auto">
<Button
size="xs"
variant="secondary"
icon="RotateCw"
onClick={fetchStorageData}
>
Refresh
</Button>
<Button
size="xs"
variant="primary"
icon="HardDrive"
loading={flushing}
onClick={handleManualFlush}
>
Flush Buffer
</Button>
</div>
</div>
{/* Storage Summary Cards */}
<div className="grid grid-cols-2 lg:grid-cols-4 gap-1.5">
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<span className="text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">Disk Usage</span>
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
{stats?.totalMB ?? '0.00'} MB
</span>
</Card>
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<span className="text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">CSV Files</span>
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
{stats?.totalFiles ?? 0}
</span>
</Card>
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<span className="text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">Persisted Rows</span>
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
{stats?.totalRows ? stats.totalRows.toLocaleString() : 0}
</span>
</Card>
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<span className="text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">Rotation Rule</span>
<span className="text-[13px] font-semibold text-[var(--accent)] font-mono">
100MB / Daily
</span>
</Card>
</div>
{/* Partition Files Table */}
<div className="flex flex-col gap-2">
<h2 className="text-[13px] font-semibold text-[var(--text)]">
CSV Files on Disk
</h2>
<TableWrap>
<Table>
<TableHeader>
<TableRow>
<TableHead>Client Folder</TableHead>
<TableHead>Partition Filename</TableHead>
<TableHead>File Size</TableHead>
<TableHead>Data Lines</TableHead>
<TableHead>Last Rotation / Append</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{files.length === 0 ? (
<TableEmpty colSpan={5} message="No CSV files generated yet. Events in memory buffer will flush automatically or via 'Flush Buffer Now'." />
) : (
files.map((file, idx) => (
<TableRow key={idx}>
<TableCell className="font-mono text-[11px] text-[var(--accent)]">
{file.clientId}
</TableCell>
<TableCell className="font-mono text-[11px] font-medium text-[var(--text)]">
{file.filename}
</TableCell>
<TableCell className="font-mono text-[11px]">
{(file.sizeBytes / 1024).toFixed(1)} KB
</TableCell>
<TableCell className="font-mono text-[11px]">
{file.linesCount.toLocaleString()}
</TableCell>
<TableCell className="text-[10.5px] text-[var(--text-dim)] font-mono">
{new Date(file.modifiedAt).toLocaleString()}
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</TableWrap>
</div>
</div>
);
}
+2232
View File
File diff suppressed because it is too large. Load diff
+28
View File
@@ -0,0 +1,28 @@
import React from 'react';
export const Footer: React.FC = () => {
return (
<footer className="shrink-0 h-[26px] bg-[var(--bg-activity)] border-t border-[var(--border)] px-3 sm:px-4 flex items-center justify-between text-[10px] text-[var(--text-dim)] select-none">
<div className="flex items-center gap-1.5 truncate min-w-0 pr-2">
<span className="font-semibold text-[var(--text-muted)] tracking-tight">DataStack</span>
<span className="text-[var(--border-strong)]">/</span>
<span className="font-mono text-[9px] truncate">
storage/data/&#123;clientId&#125;/&#123;YYYY-MM-DD&#125;.csv
</span>
</div>
<div className="flex items-center gap-2 font-mono text-[9.5px] shrink-0 ml-auto">
<span className="flex items-center gap-1">
<span className="w-1.5 h-1.5 bg-[var(--success)] inline-block" />
<span className="text-[var(--text-muted)]">:4000</span>
</span>
<span className="text-[var(--border-strong)]">•</span>
<span className="flex items-center gap-1">
<span className="w-1.5 h-1.5 bg-[var(--accent)] inline-block" />
<span className="text-[var(--text-muted)]">:3000</span>
</span>
</div>
</footer>
);
};
export default Footer;
+44
View File
@@ -0,0 +1,44 @@
'use client';
import React, { useState } from 'react';
import { Navbar } from './Navbar';
import { Sidebar } from './Sidebar';
import { Footer } from './Footer';
interface MainLayoutProps {
children: React.ReactNode;
showSidebar?: boolean;
}
export const MainLayout: React.FC<MainLayoutProps> = ({
children,
showSidebar = false,
}) => {
const [sidebarOpen, setSidebarOpen] = useState(false);
return (
<div className="min-h-screen flex flex-col bg-[var(--bg-main)] text-[var(--text)] antialiased">
<Navbar
showSidebarToggle={showSidebar}
onToggleSidebar={() => setSidebarOpen((prev) => !prev)}
/>
<div className="flex-1 flex min-h-0 overflow-hidden">
{showSidebar && (
<Sidebar
isOpen={sidebarOpen}
onClose={() => setSidebarOpen(false)}
/>
)}
<main className="flex-1 overflow-y-auto flex flex-col min-w-0">
<div className="flex-1 p-2 sm:p-3.5 max-w-[1360px] w-full mx-auto">
{children}
</div>
<Footer />
</main>
</div>
</div>
);
};
export default MainLayout;
+141
View File
@@ -0,0 +1,141 @@
'use client';
import React, { useState, useEffect } from 'react';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { Icon } from '@/components/ui/Icon';
import { Button } from '@/components/ui/Button';
interface NavbarProps {
onToggleSidebar?: () => void;
showSidebarToggle?: boolean;
}
export const Navbar: React.FC<NavbarProps> = ({
onToggleSidebar,
showSidebarToggle = false,
}) => {
const pathname = usePathname();
const [theme, setTheme] = useState<'dark' | 'light'>('dark');
useEffect(() => {
const saved = localStorage.getItem('datastack-theme') as 'dark' | 'light' | null;
const initial = saved || 'dark';
setTheme(initial);
if (initial === 'light') {
document.documentElement.classList.remove('dark');
document.documentElement.classList.add('light');
} else {
document.documentElement.classList.add('dark');
document.documentElement.classList.remove('light');
}
}, []);
const toggleTheme = () => {
const nextTheme = theme === 'dark' ? 'light' : 'dark';
setTheme(nextTheme);
localStorage.setItem('datastack-theme', nextTheme);
if (nextTheme === 'light') {
document.documentElement.classList.remove('dark');
document.documentElement.classList.add('light');
} else {
document.documentElement.classList.add('dark');
document.documentElement.classList.remove('light');
}
};
const isVcon = pathname?.startsWith('/vcon');
return (
<header className="h-[38px] shrink-0 bg-[var(--bg-activity)] border-b border-[var(--border)] px-3 sm:px-4 flex items-center justify-between z-40 select-none">
{/* Left: Mobile hamburger + Brand */}
<div className="flex items-center gap-2">
{showSidebarToggle && (
<button
onClick={onToggleSidebar}
className="md:hidden w-[26px] h-[26px] flex items-center justify-center text-[var(--text-muted)] hover:text-[var(--text)] border border-[var(--border)] bg-[var(--bg-elevated)] cursor-pointer"
aria-label="Toggle Navigation"
>
<Icon name="Menu" size={13} />
</button>
)}
<Link href="/" className="flex items-center gap-1.5">
<div className="w-[17px] h-[17px] bg-[var(--accent)] text-[var(--text-on-accent)] flex items-center justify-center text-[9.5px] font-bold">
DS
</div>
<span className="text-[12px] font-semibold text-[var(--text)] tracking-tight">
DataStack
</span>
<span className="hidden sm:inline text-[9px] text-[var(--text-dim)] font-mono border border-[var(--border)] px-1 py-0.2">
v2.4
</span>
</Link>
</div>
{/* Middle: Links */}
<nav className="hidden sm:flex items-center gap-1 text-[11px]">
<Link
href="/"
className={`px-2.5 py-1 transition-colors border-b-2 ${
pathname === '/'
? 'border-[var(--accent)] text-[var(--text)] font-medium'
: 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)]'
}`}
>
Overview
</Link>
<Link
href="/vcon/dashboard"
className={`px-2.5 py-1 transition-colors border-b-2 flex items-center gap-1.5 ${
isVcon
? 'border-[var(--accent)] text-[var(--text)] font-medium'
: 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)]'
}`}
>
<span>Admin Console</span>
<span className="w-1.5 h-1.5 bg-[var(--success)] shrink-0" />
</Link>
<Link
href="/vcon/export"
className={`px-2.5 py-1 transition-colors border-b-2 ${
pathname === '/vcon/export'
? 'border-[var(--accent)] text-[var(--text)] font-medium'
: 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)]'
}`}
>
CSV Exporter
</Link>
</nav>
{/* Right: Port Badges + Theme Toggle + Console Action */}
<div className="flex items-center gap-1.5">
<div className="hidden lg:flex items-center gap-1.5 text-[9.5px] text-[var(--text-dim)] font-mono border border-[var(--border)] px-1.5 py-0.5 bg-[var(--bg-main)]">
<span className="w-1.5 h-1.5 bg-[var(--success)] inline-block" />
<span>:4000</span>
<span className="text-[var(--border-strong)]">|</span>
<span className="w-1.5 h-1.5 bg-[var(--accent)] inline-block" />
<span>:3000</span>
</div>
<button
onClick={toggleTheme}
aria-label="Toggle Theme"
className="w-[26px] h-[26px] flex items-center justify-center border border-[var(--border)] bg-[var(--bg-elevated)] text-[var(--text-muted)] hover:text-[var(--text)] cursor-pointer"
>
<Icon name={theme === 'dark' ? 'Sun' : 'Moon'} size={12} />
</button>
{!isVcon && (
<Link href="/vcon/dashboard">
<Button size="xs" variant="primary" icon="Terminal">
/vcon/
</Button>
</Link>
)}
</div>
</header>
);
};
export default Navbar;
+146
View File
@@ -0,0 +1,146 @@
'use client';
import React from 'react';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { cn } from '@/lib/utils';
import { Icon } from '@/components/ui/Icon';
interface SidebarProps {
isOpen?: boolean;
onClose?: () => void;
}
export const Sidebar: React.FC<SidebarProps> = ({
isOpen = false,
onClose,
}) => {
const pathname = usePathname();
const navigation = [
{
group: 'Core Telemetry',
items: [
{ name: 'Dashboard', href: '/vcon/dashboard', icon: 'LayoutDashboard' },
{ name: 'Live Data Sync', href: '/vcon/data', icon: 'Activity', badge: 'Live' },
{ name: 'CSV Exporter', href: '/vcon/export', icon: 'Download' },
],
},
{
group: 'Management',
items: [
{ name: 'Client SDKs', href: '/vcon/clients', icon: 'Key' },
{ name: 'CSV Storage & Disk', href: '/vcon/storage', icon: 'HardDrive' },
{ name: 'Engine Settings', href: '/vcon/settings', icon: 'Sliders' },
],
},
{
group: 'Integration',
items: [
{ name: 'Python SDK Guide', href: '/vcon/sdk', icon: 'FileCode2' },
{ name: 'Live Simulator', href: '/vcon/simulator', icon: 'Play' },
],
},
];
return (
<>
{/* Mobile Backdrop */}
{isOpen && (
<div
onClick={onClose}
className="fixed inset-0 z-40 bg-black/60 md:hidden backdrop-blur-[1px]"
/>
)}
{/* Sidebar Container */}
<aside
className={cn(
'fixed inset-y-0 left-0 z-50 md:static w-[210px] shrink-0 bg-[var(--bg-sidebar)] border-r border-[var(--border)] flex flex-col transition-transform duration-150 ease-in-out md:translate-x-0',
isOpen ? 'translate-x-0' : '-translate-x-full'
)}
>
{/* Top Header */}
<div className="h-[38px] px-3 flex items-center justify-between border-b border-[var(--border)] bg-[var(--bg-activity)] shrink-0">
<div className="flex items-center gap-1.5 min-w-0">
<span className="w-1.5 h-1.5 bg-[var(--accent)] shrink-0" />
<span className="text-[10.5px] font-semibold text-[var(--text)] tracking-wider uppercase truncate">
VCON ADMIN
</span>
</div>
<button
onClick={onClose}
className="md:hidden text-[var(--text-dim)] hover:text-[var(--text)] p-1 cursor-pointer"
aria-label="Close menu"
>
<Icon name="X" size={13} />
</button>
</div>
{/* Navigation items */}
<div className="flex-1 overflow-y-auto p-1.5 flex flex-col gap-2">
{navigation.map((section, idx) => (
<div key={idx} className="flex flex-col gap-0.5">
<span className="text-[9px] font-semibold text-[var(--text-dim)] uppercase tracking-wider px-2 py-0.5">
{section.group}
</span>
<div className="flex flex-col gap-0.5">
{section.items.map((item) => {
const isActive = pathname === item.href;
return (
<Link
key={item.href}
href={item.href}
onClick={onClose}
className={cn(
'flex items-center justify-between px-2 py-1 text-[11px] transition-colors border',
isActive
? 'bg-[var(--accent-soft)] text-[var(--accent-hover)] font-medium border-[var(--accent)]'
: 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)] hover:bg-[var(--bg-hover)]'
)}
>
<div className="flex items-center gap-2 min-w-0">
<Icon
name={item.icon}
size={12}
className={isActive ? 'text-[var(--accent)]' : 'text-[var(--text-dim)]'}
/>
<span className="truncate">{item.name}</span>
</div>
{item.badge && (
<span className="text-[8px] px-1 py-0.2 bg-[var(--success-soft)] text-[var(--success)] font-mono border border-[var(--success)] shrink-0">
{item.badge}
</span>
)}
</Link>
);
})}
</div>
</div>
))}
</div>
{/* Footer info */}
<div className="p-2 border-t border-[var(--border)] bg-[var(--bg-main)] text-[9.5px] text-[var(--text-dim)] font-mono flex flex-col gap-1 shrink-0">
<div className="flex items-center justify-between">
<span>Buffer Worker</span>
<span className="text-[var(--success)] flex items-center gap-1 font-semibold">
<span className="w-1.5 h-1.5 bg-[var(--success)] inline-block" />
Active
</span>
</div>
<div className="flex items-center justify-between">
<span>Storage Engine</span>
<span className="text-[var(--text-muted)]">json2csv</span>
</div>
<div className="flex items-center justify-between">
<span>Auth Handshake</span>
<span className="text-[var(--text-muted)]">JWT</span>
</div>
</div>
</aside>
</>
);
};
export default Sidebar;
+15
View File
@@ -0,0 +1,15 @@
# Layout Components Module Manifest
## Purpose
Global layout shell, navigation, top bar, and admin sidebar complying with compact, zero-border-radius, zero-shadow design system.
## Components
- **Navbar.tsx**: Top titlebar with brand, quick links, runtime port indicator (:4000/:3000), and dark/light theme switcher.
- **Sidebar.tsx**: Dedicated `/vcon/` admin console sidebar with mobile drawer support, grouped telemetry & management links.
- **Footer.tsx**: System runtime status line with storage convention display and port allocations.
- **MainLayout.tsx**: Viewport-bounded responsive shell with mobile backdrop and scrolling main container.
## Dependencies
- `components/ui`
- `next/link`
- `next/navigation`
+68
View File
@@ -0,0 +1,68 @@
import React from 'react';
import { Card } from '@/components/ui/Card';
import { Icon } from '@/components/ui/Icon';
export const Architecture: React.FC = () => {
return (
<div className="flex flex-col gap-1.5 py-1">
<div className="flex items-center justify-between border-b border-[var(--border)] pb-1">
<h2 className="text-[11px] font-semibold text-[var(--text)] uppercase tracking-wider">
Pipeline Flow
</h2>
<span className="text-[9px] text-[var(--text-dim)] font-mono">:4000 ➔ :3000</span>
</div>
<Card compact className="p-2.5 flex flex-col gap-2 font-mono text-[10px] bg-[var(--bg-elevated)]">
{/* Desktop Flow: 5 items */}
<div className="hidden md:grid md:grid-cols-5 gap-1.5 items-center text-center">
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex flex-col items-center gap-0.5">
<Icon name="FileCode" size={12} className="text-[var(--accent)]" />
<span className="font-semibold text-[var(--text)]">Python SDK</span>
</div>
<div className="text-[var(--text-dim)] flex items-center justify-center gap-1">
<span className="text-[9px] px-1.5 py-0.2 border border-[var(--border)] bg-[var(--bg-main)] flex items-center gap-0.5">
<span>JWT</span>
<Icon name="ArrowRight" size={9} />
</span>
</div>
<div className="p-1.5 border border-[var(--border-strong)] bg-[var(--bg-main)] flex flex-col items-center gap-0.5">
<Icon name="Radio" size={12} className="text-[var(--accent)]" />
<span className="font-semibold text-[var(--text)]">Express Ingest (:4000)</span>
</div>
<div className="text-[var(--text-dim)] flex items-center justify-center gap-1">
<span className="text-[9px] px-1.5 py-0.2 border border-[var(--border)] bg-[var(--bg-main)] flex items-center gap-0.5">
<span>Buffer</span>
<Icon name="ArrowRight" size={9} />
</span>
</div>
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex flex-col items-center gap-0.5">
<Icon name="HardDrive" size={12} className="text-[var(--success)]" />
<span className="font-semibold text-[var(--text)]">CSV Storage (Disk)</span>
</div>
</div>
{/* Mobile Flow: Vertical */}
<div className="flex md:hidden flex-col gap-1">
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
<span className="font-semibold text-[var(--text)]">1. Python SDK</span>
<span className="text-[8.5px] text-[var(--text-dim)]">Client</span>
</div>
<div className="p-1.5 border border-[var(--border-strong)] bg-[var(--bg-main)] flex items-center justify-between">
<span className="font-semibold text-[var(--text)]">2. Express (:4000)</span>
<span className="text-[8.5px] text-[var(--accent)]">Ingest</span>
</div>
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
<span className="font-semibold text-[var(--text)]">3. CSV Files</span>
<span className="text-[8.5px] text-[var(--success)]">Rotated</span>
</div>
</div>
</Card>
</div>
);
};
export default Architecture;
+67
View File
@@ -0,0 +1,67 @@
import React from 'react';
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/Card';
import { Icon } from '@/components/ui/Icon';
export const Features: React.FC = () => {
const items = [
{
icon: 'Zap',
title: 'Decoupled Runtime Split',
desc: 'Port 4000 WebSocket intake; Port 3000 Web & export.',
},
{
icon: 'HardDrive',
title: 'CSV File Persistence',
desc: 'Streams directly to rotated CSV files on disk (Zero DB inserts).',
},
{
icon: 'ShieldCheck',
title: 'JWT SDK Authentication',
desc: 'Signed tokens verify client IDs and rate limits on handshake.',
},
{
icon: 'Cpu',
title: 'In-Memory Buffer',
desc: 'Aggregates 500 records or 2000ms intervals before async disk flush.',
},
{
icon: 'CheckCheck',
title: 'Idempotency Dedup',
desc: 'Rejects duplicate clientId + eventId in 5-minute sliding TTL window.',
},
{
icon: 'FileCode2',
title: 'Python Client SDK',
desc: 'datastack-sdk package with auto-reconnection and batch streaming.',
},
];
return (
<div className="flex flex-col gap-1.5 py-1">
<div className="flex items-center justify-between border-b border-[var(--border)] pb-1">
<h2 className="text-[11px] font-semibold text-[var(--text)] uppercase tracking-wider">
Platform Architecture
</h2>
<span className="text-[9px] text-[var(--text-dim)] font-mono">6 SUBSYSTEMS</span>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-1.5">
{items.map((item, idx) => (
<Card key={idx} compact className="flex flex-col gap-0.5 p-2">
<CardHeader className="p-0 pb-0.5 mb-0 border-b-0 flex items-center gap-1.5">
<div className="p-0.5 bg-[var(--bg-main)] text-[var(--accent)] border border-[var(--border-strong)] shrink-0">
<Icon name={item.icon} size={11} />
</div>
<CardTitle className="text-[11px]">{item.title}</CardTitle>
</CardHeader>
<CardContent className="p-0 text-[10px] text-[var(--text-muted)] leading-tight">
{item.desc}
</CardContent>
</Card>
))}
</div>
</div>
);
};
export default Features;
+90
View File
@@ -0,0 +1,90 @@
'use client';
import React, { useState } from 'react';
import Link from 'next/link';
import { Button } from '@/components/ui/Button';
import { Card } from '@/components/ui/Card';
import { Icon } from '@/components/ui/Icon';
export const Hero: React.FC = () => {
const [copied, setCopied] = useState(false);
const handleCopy = () => {
navigator.clipboard.writeText('pip install ./sdk-python');
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
return (
<div className="flex flex-col gap-2.5 py-1">
{/* Title */}
<div className="flex flex-col gap-1">
<h1 className="text-[16px] sm:text-[18px] font-semibold tracking-tight text-[var(--text)]">
Realtime Data Collection Platform
</h1>
</div>
{/* Actions */}
<div className="flex flex-wrap items-center gap-1.5">
<Link href="/vcon/dashboard">
<Button size="xs" variant="primary" icon="Terminal">
Console (/vcon/)
</Button>
</Link>
<Link href="/vcon/data">
<Button size="xs" variant="secondary" icon="Activity">
Live Stream
</Button>
</Link>
<div className="flex items-center gap-1.5 border border-[var(--border)] bg-[var(--bg-elevated)] px-2 py-0.5 text-[10px] font-mono text-[var(--text)]">
<span className="text-[var(--text-dim)]">$</span>
<span>pip install ./sdk-python</span>
<button
onClick={handleCopy}
className="text-[var(--text-dim)] hover:text-[var(--text)] ml-0.5 cursor-pointer"
aria-label="Copy install command"
>
<Icon name={copied ? 'Check' : 'Copy'} size={11} />
</button>
</div>
</div>
{/* 4 Clean Metric Cards */}
<div className="grid grid-cols-2 lg:grid-cols-4 gap-1.5 pt-0.5">
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<div className="flex items-center justify-between text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">
<span>Ingestion</span>
<Icon name="Radio" size={11} className="text-[var(--accent)]" />
</div>
<span className="text-[12.5px] font-semibold text-[var(--text)] font-mono">:4000 (ws)</span>
</Card>
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<div className="flex items-center justify-between text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">
<span>Web & API</span>
<Icon name="LayoutDashboard" size={11} className="text-[var(--accent)]" />
</div>
<span className="text-[12.5px] font-semibold text-[var(--text)] font-mono">:3000 (http)</span>
</Card>
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<div className="flex items-center justify-between text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">
<span>Storage Engine</span>
<Icon name="HardDrive" size={11} className="text-[var(--accent)]" />
</div>
<span className="text-[12.5px] font-semibold text-[var(--text)] font-mono">Rotated CSV</span>
</Card>
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
<div className="flex items-center justify-between text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">
<span>Buffer Limit</span>
<Icon name="Cpu" size={11} className="text-[var(--accent)]" />
</div>
<span className="text-[12.5px] font-semibold text-[var(--text)] font-mono">500 rows / 2s</span>
</Card>
</div>
</div>
);
};
export default Hero;
+9
View File
@@ -0,0 +1,9 @@
# Sections Manifest
## Purpose
Modular section blocks used in landing page and documentation views.
## Sections
- `Hero.tsx`: Headline, technical metrics, quick start buttons
- `Features.tsx`: Subsystem cards with icons and descriptions
- `Architecture.tsx`: Visual diagram of decoupled port 4000/3000 runtime and data flow.
+80
View File
@@ -0,0 +1,80 @@
import React from 'react';
import { cn } from '@/lib/utils';
import { Icon } from './Icon';
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary' | 'ghost' | 'danger' | 'icon';
size?: 'default' | 'sm' | 'xs' | 'icon';
icon?: string;
iconPosition?: 'left' | 'right';
loading?: boolean;
}
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
(
{
children,
className,
variant = 'secondary',
size = 'default',
icon,
iconPosition = 'left',
loading = false,
disabled,
...props
},
ref
) => {
const baseStyles =
'inline-flex items-center justify-center font-normal transition-colors select-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed border border-transparent whitespace-nowrap outline-none';
const variantStyles = {
primary:
'bg-[var(--accent)] text-[var(--text-on-accent)] hover:bg-[var(--accent-hover)] border-[var(--accent)]',
secondary:
'bg-[var(--bg-elevated)] text-[var(--text)] border-[var(--border-strong)] hover:bg-[var(--bg-hover)]',
ghost:
'bg-transparent text-[var(--text-muted)] hover:text-[var(--text)] hover:bg-[var(--bg-hover)] border-transparent',
danger:
'bg-transparent text-[var(--danger)] border-[var(--danger)] hover:bg-[var(--danger-soft)]',
icon:
'bg-transparent text-[var(--text-muted)] hover:text-[var(--text)] hover:bg-[var(--bg-hover)] border-transparent p-0',
};
const sizeStyles = {
default: 'h-[32px] px-[14px] text-[12.5px] gap-[7px]',
sm: 'h-[27px] px-[10px] text-[11.5px] gap-[5px]',
xs: 'h-[24px] px-[7px] text-[10.5px] gap-[4px]',
icon: 'w-[30px] h-[30px] p-0',
};
return (
<button
ref={ref}
disabled={disabled || loading}
className={cn(
baseStyles,
variantStyles[variant],
size === 'icon' ? sizeStyles.icon : sizeStyles[size],
className
)}
{...props}
>
{loading ? (
<Icon name="Loader2" size={size === 'sm' || size === 'xs' ? 12 : 14} className="animate-spin" />
) : (
icon && iconPosition === 'left' && (
<Icon name={icon} size={size === 'sm' || size === 'xs' ? 12 : 14} />
)
)}
{children && <span>{children}</span>}
{!loading && icon && iconPosition === 'right' && (
<Icon name={icon} size={size === 'sm' || size === 'xs' ? 12 : 14} />
)}
</button>
);
}
);
Button.displayName = 'Button';
export default Button;
+100
View File
@@ -0,0 +1,100 @@
import React from 'react';
import { cn } from '@/lib/utils';
export interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
variant?: 'default' | 'subtle' | 'dashed' | 'active';
compact?: boolean;
}
export const Card: React.FC<CardProps> = ({
children,
variant = 'default',
compact = false,
className,
...props
}) => {
const variantStyles = {
default: 'bg-[var(--bg-elevated)] border border-[var(--border)] text-[var(--text)]',
subtle: 'bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)]',
dashed: 'bg-[var(--bg-main)] border border-dashed border-[var(--border-strong)] text-[var(--text)]',
active: 'bg-[var(--accent-soft)] border border-[var(--accent)] text-[var(--text)]',
};
return (
<div
className={cn(
'transition-colors',
variantStyles[variant],
compact ? 'p-2.5' : 'p-3.5 sm:p-4',
className
)}
{...props}
>
{children}
</div>
);
};
export const CardHeader: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
className,
children,
...props
}) => (
<div
className={cn(
'flex items-center justify-between gap-2.5 pb-2.5 mb-2.5 border-b border-[var(--border)]',
className
)}
{...props}
>
{children}
</div>
);
export const CardTitle: React.FC<React.HTMLAttributes<HTMLHeadingElement>> = ({
className,
children,
...props
}) => (
<h3 className={cn('text-[13px] font-semibold text-[var(--text)] leading-tight', className)} {...props}>
{children}
</h3>
);
export const CardDescription: React.FC<React.HTMLAttributes<HTMLParagraphElement>> = ({
className,
children,
...props
}) => (
<p className={cn('text-[11px] text-[var(--text-muted)] leading-normal', className)} {...props}>
{children}
</p>
);
export const CardContent: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
className,
children,
...props
}) => (
<div className={cn('text-[12px]', className)} {...props}>
{children}
</div>
);
export const CardFooter: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
className,
children,
...props
}) => (
<div
className={cn(
'flex items-center justify-between gap-2 pt-2.5 mt-2.5 border-t border-[var(--border)] text-[11px]',
className
)}
{...props}
>
{children}
</div>
);
export default Card;
+61
View File
@@ -0,0 +1,61 @@
import React from 'react';
import { cn } from '@/lib/utils';
export const Form: React.FC<React.FormHTMLAttributes<HTMLFormElement>> = ({
className,
children,
...props
}) => (
<form className={cn('flex flex-col gap-3', className)} {...props}>
{children}
</form>
);
export const FormField: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
className,
children,
...props
}) => (
<div className={cn('flex flex-col gap-1 w-full', className)} {...props}>
{children}
</div>
);
export const FormRow: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
className,
children,
...props
}) => (
<div className={cn('grid grid-cols-1 sm:grid-cols-2 gap-3 w-full', className)} {...props}>
{children}
</div>
);
export const FormSwitch: React.FC<{
label: string;
checked: boolean;
onChange: (checked: boolean) => void;
description?: string;
disabled?: boolean;
}> = ({ label, checked, onChange, description, disabled = false }) => (
<label
className={cn(
'flex items-center justify-between p-2.5 border border-[var(--border)] bg-[var(--bg-main)] cursor-pointer select-none transition-colors hover:bg-[var(--bg-hover)]',
disabled && 'opacity-50 cursor-not-allowed'
)}
>
<div className="flex flex-col">
<span className="text-[12px] font-medium text-[var(--text)]">{label}</span>
{description && <span className="text-[10.5px] text-[var(--text-dim)]">{description}</span>}
</div>
<input
type="checkbox"
checked={checked}
disabled={disabled}
onChange={(e) => onChange(e.target.checked)}
className="w-4 h-4 accent-[var(--accent)] cursor-pointer"
/>
</label>
);
export default Form;
+36
View File
@@ -0,0 +1,36 @@
import React from 'react';
import * as LucideIcons from 'lucide-react';
import { cn } from '@/lib/utils';
export type IconName = keyof typeof LucideIcons;
interface IconProps {
name: string;
size?: number;
className?: string;
color?: string;
}
export const Icon: React.FC<IconProps> = ({
name,
size = 14,
className,
color,
}) => {
const LucideIcon = (LucideIcons as unknown as Record<string, React.ComponentType<{ size?: number; className?: string; style?: React.CSSProperties }>>)[name];
if (!LucideIcon) {
const Fallback = LucideIcons.Activity;
return <Fallback size={size} className={cn('shrink-0 text-current', className)} style={{ color }} />;
}
return (
<LucideIcon
size={size}
className={cn('shrink-0 text-current transition-colors', className)}
style={{ color }}
/>
);
};
export default Icon;
+136
View File
@@ -0,0 +1,136 @@
import React from 'react';
import { cn } from '@/lib/utils';
import { Icon } from './Icon';
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
label?: string;
error?: string;
icon?: string;
compact?: boolean;
}
export const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ label, error, icon, compact = false, className, id, ...props }, ref) => {
const inputId = id || (label ? label.toLowerCase().replace(/\s+/g, '-') : undefined);
return (
<div className="flex flex-col gap-1 w-full text-left">
{label && (
<label
htmlFor={inputId}
className="text-[10.5px] font-semibold text-[var(--text-muted)] uppercase tracking-wider"
>
{label}
</label>
)}
<div className="relative flex items-center w-full">
{icon && (
<div className="absolute left-2.5 flex items-center pointer-events-none text-[var(--text-dim)]">
<Icon name={icon} size={13} />
</div>
)}
<input
id={inputId}
ref={ref}
className={cn(
'w-full bg-[var(--bg-main)] text-[var(--text)] border border-[var(--border-strong)] placeholder:text-[var(--text-dim)] transition-colors focus:outline-none focus:border-[var(--accent)] disabled:opacity-50 disabled:cursor-not-allowed',
compact ? 'h-[28px] px-2 text-[11px]' : 'h-[32px] px-2.5 text-[12px]',
icon && 'pl-8',
error && 'border-[var(--danger)]',
className
)}
{...props}
/>
</div>
{error && <span className="text-[10.5px] text-[var(--danger)]">{error}</span>}
</div>
);
}
);
Input.displayName = 'Input';
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
label?: string;
error?: string;
}
export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
({ label, error, className, id, ...props }, ref) => {
const textareaId = id || (label ? label.toLowerCase().replace(/\s+/g, '-') : undefined);
return (
<div className="flex flex-col gap-1 w-full text-left">
{label && (
<label
htmlFor={textareaId}
className="text-[10.5px] font-semibold text-[var(--text-muted)] uppercase tracking-wider"
>
{label}
</label>
)}
<textarea
id={textareaId}
ref={ref}
className={cn(
'w-full bg-[var(--bg-main)] text-[var(--text)] border border-[var(--border-strong)] p-2.5 text-[12px] placeholder:text-[var(--text-dim)] focus:outline-none focus:border-[var(--accent)] min-h-[64px] resize-y font-mono',
error && 'border-[var(--danger)]',
className
)}
{...props}
/>
{error && <span className="text-[10.5px] text-[var(--danger)]">{error}</span>}
</div>
);
}
);
Textarea.displayName = 'Textarea';
export interface SelectProps extends React.SelectHTMLAttributes<HTMLSelectElement> {
label?: string;
error?: string;
compact?: boolean;
options?: { value: string; label: string }[];
}
export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
({ label, error, compact = false, options, children, className, id, ...props }, ref) => {
const selectId = id || (label ? label.toLowerCase().replace(/\s+/g, '-') : undefined);
return (
<div className="flex flex-col gap-1 w-full text-left">
{label && (
<label
htmlFor={selectId}
className="text-[10.5px] font-semibold text-[var(--text-muted)] uppercase tracking-wider"
>
{label}
</label>
)}
<select
id={selectId}
ref={ref}
className={cn(
'w-full bg-[var(--bg-main)] text-[var(--text)] border border-[var(--border-strong)] focus:outline-none focus:border-[var(--accent)] cursor-pointer',
compact ? 'h-[28px] px-1.5 text-[11px]' : 'h-[32px] px-2 text-[11.5px]',
error && 'border-[var(--danger)]',
className
)}
{...props}
>
{options
? options.map((opt) => (
<option key={opt.value} value={opt.value} className="bg-[var(--bg-elevated)] text-[var(--text)]">
{opt.label}
</option>
))
: children}
</select>
{error && <span className="text-[10.5px] text-[var(--danger)]">{error}</span>}
</div>
);
}
);
Select.displayName = 'Select';
+89
View File
@@ -0,0 +1,89 @@
import React, { useEffect } from 'react';
import { cn } from '@/lib/utils';
import { Icon } from './Icon';
import { Button } from './Button';
export interface ModalProps {
isOpen: boolean;
onClose: () => void;
title: string;
description?: string;
children: React.ReactNode;
footer?: React.ReactNode;
maxWidth?: 'sm' | 'md' | 'lg';
}
export const Modal: React.FC<ModalProps> = ({
isOpen,
onClose,
title,
description,
children,
footer,
maxWidth = 'md',
}) => {
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape' && isOpen) {
onClose();
}
};
if (isOpen) {
document.body.style.overflow = 'hidden';
window.addEventListener('keydown', handleKeyDown);
}
return () => {
document.body.style.overflow = '';
window.removeEventListener('keydown', handleKeyDown);
};
}, [isOpen, onClose]);
if (!isOpen) return null;
const maxWidthStyles = {
sm: 'max-w-[440px]',
md: 'max-w-[520px]',
lg: 'max-w-[640px]',
};
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-3.5 bg-black/60 backdrop-blur-[1px]">
<div
className={cn(
'w-full bg-[var(--bg-elevated)] border border-[var(--border-strong)] text-[var(--text)] flex flex-col max-h-[min(84dvh,680px)] overflow-hidden animate-in fade-in zoom-in-95 duration-100',
maxWidthStyles[maxWidth]
)}
>
<div className="flex items-start justify-between gap-3 p-3.5 sm:px-4 sm:py-3.5 border-b border-[var(--border)] shrink-0">
<div className="min-w-0">
<h2 className="text-[14px] font-semibold text-[var(--text)] leading-tight">{title}</h2>
{description && (
<p className="text-[11px] text-[var(--text-muted)] mt-1">{description}</p>
)}
</div>
<Button
size="icon"
variant="ghost"
onClick={onClose}
aria-label="Close dialog"
className="w-7 h-7 text-[var(--text-dim)] hover:text-[var(--text)]"
>
<Icon name="X" size={14} />
</Button>
</div>
<div className="p-3.5 sm:p-4 overflow-y-auto flex-1 text-[12px] flex flex-col gap-3">
{children}
</div>
{footer && (
<div className="flex items-center justify-end gap-2 p-3 sm:px-4 border-t border-[var(--border)] bg-[var(--bg-sidebar)] shrink-0">
{footer}
</div>
)}
</div>
</div>
);
};
export default Modal;
+108
View File
@@ -0,0 +1,108 @@
import React from 'react';
import { cn } from '@/lib/utils';
export const TableWrap: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
className,
children,
...props
}) => (
<div
className={cn(
'w-full overflow-x-auto border border-[var(--border)] bg-[var(--bg-elevated)]',
className
)}
{...props}
>
{children}
</div>
);
export const Table: React.FC<React.TableHTMLAttributes<HTMLTableElement>> = ({
className,
children,
...props
}) => (
<table
className={cn(
'w-full min-w-[540px] border-collapse text-left text-[11px] whitespace-nowrap',
className
)}
{...props}
>
{children}
</table>
);
export const TableHeader: React.FC<React.HTMLAttributes<HTMLTableSectionElement>> = ({
className,
children,
...props
}) => (
<thead
className={cn(
'bg-[var(--bg-sidebar)] border-b border-[var(--border)] text-[9.5px] font-semibold text-[var(--text-dim)] uppercase tracking-wider',
className
)}
{...props}
>
{children}
</thead>
);
export const TableBody: React.FC<React.HTMLAttributes<HTMLTableSectionElement>> = ({
className,
children,
...props
}) => <tbody className={cn('divide-y divide-[var(--border)]', className)} {...props}>{children}</tbody>;
export const TableRow: React.FC<React.HTMLAttributes<HTMLTableRowElement>> = ({
className,
children,
...props
}) => (
<tr
className={cn(
'transition-colors hover:bg-[var(--bg-hover)] text-[var(--text)]',
className
)}
{...props}
>
{children}
</tr>
);
export const TableHead: React.FC<React.ThHTMLAttributes<HTMLTableCellElement>> = ({
className,
children,
...props
}) => (
<th className={cn('px-2.5 py-1.5 font-medium', className)} {...props}>
{children}
</th>
);
export const TableCell: React.FC<React.TdHTMLAttributes<HTMLTableCellElement>> = ({
className,
children,
...props
}) => (
<td className={cn('px-2.5 py-1.5 text-[var(--text-muted)] align-middle', className)} {...props}>
{children}
</td>
);
export const TableEmpty: React.FC<{ colSpan: number; message?: string }> = ({
colSpan,
message = 'No data available',
}) => (
<tr>
<td
colSpan={colSpan}
className="px-3 py-6 text-center text-[10.5px] text-[var(--text-dim)] italic"
>
{message}
</td>
</tr>
);
export default Table;
+39
View File
@@ -0,0 +1,39 @@
import React from 'react';
import { cn } from '@/lib/utils';
interface TextProps extends React.HTMLAttributes<HTMLElement> {
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'p' | 'span' | 'label' | 'code' | 'div';
variant?: 'h1' | 'h2' | 'h3' | 'body' | 'muted' | 'dim' | 'label' | 'code' | 'badge';
children: React.ReactNode;
}
export const Text: React.FC<TextProps> = ({
as: Component = 'p',
variant = 'body',
className,
children,
...props
}) => {
const variantStyles = {
h1: 'text-[18px] font-semibold tracking-tight text-[var(--text)]',
h2: 'text-[15px] font-semibold text-[var(--text)]',
h3: 'text-[13px] font-medium text-[var(--text)]',
body: 'text-[12.5px] font-normal text-[var(--text)]',
muted: 'text-[11.5px] font-normal text-[var(--text-muted)]',
dim: 'text-[10.5px] font-normal text-[var(--text-dim)]',
label: 'text-[11px] font-medium uppercase tracking-wider text-[var(--text-dim)]',
code: 'text-[11px] font-mono text-[var(--accent)] bg-[var(--bg-hover)] px-1.5 py-0.5 border border-[var(--border)]',
badge: 'text-[10px] font-medium px-1.5 py-0.5 border border-[var(--border)] text-[var(--text-muted)] inline-flex items-center gap-1',
};
return (
<Component
className={cn(variantStyles[variant], className)}
{...props}
>
{children}
</Component>
);
};
export default Text;
+121
View File
@@ -0,0 +1,121 @@
'use client';
import React, { createContext, useContext, useState, useCallback } from 'react';
import { cn } from '@/lib/utils';
import { Icon } from './Icon';
export type ToastType = 'success' | 'error' | 'warning' | 'info';
export interface ToastMessage {
id: string;
type: ToastType;
title: string;
message?: string;
duration?: number;
}
interface ToastContextType {
toast: (options: Omit<ToastMessage, 'id'>) => void;
success: (title: string, message?: string) => void;
error: (title: string, message?: string) => void;
warning: (title: string, message?: string) => void;
info: (title: string, message?: string) => void;
}
const ToastContext = createContext<ToastContextType | undefined>(undefined);
export const ToastProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [toasts, setToasts] = useState<ToastMessage[]>([]);
const removeToast = useCallback((id: string) => {
setToasts((prev) => prev.filter((t) => t.id !== id));
}, []);
const addToast = useCallback(
({ type = 'info', title, message, duration = 3500 }: Omit<ToastMessage, 'id'>) => {
const id = `${Date.now()}-${Math.random().toString(36).substring(2, 7)}`;
setToasts((prev) => [...prev, { id, type, title, message, duration }]);
if (duration > 0) {
setTimeout(() => {
removeToast(id);
}, duration);
}
},
[removeToast]
);
const success = useCallback((title: string, message?: string) => addToast({ type: 'success', title, message }), [addToast]);
const error = useCallback((title: string, message?: string) => addToast({ type: 'error', title, message }), [addToast]);
const warning = useCallback((title: string, message?: string) => addToast({ type: 'warning', title, message }), [addToast]);
const info = useCallback((title: string, message?: string) => addToast({ type: 'info', title, message }), [addToast]);
return (
<ToastContext.Provider value={{ toast: addToast, success, error, warning, info }}>
{children}
<div className="fixed bottom-4 right-4 z-[9999] flex flex-col gap-2 max-w-[340px] pointer-events-none">
{toasts.map((t) => {
const typeBorder = {
success: 'border-l-[3px] border-l-[var(--success)]',
error: 'border-l-[3px] border-l-[var(--danger)]',
warning: 'border-l-[3px] border-l-[var(--warning)]',
info: 'border-l-[3px] border-l-[var(--accent)]',
}[t.type];
const typeIcon = {
success: 'CheckCircle2',
error: 'AlertCircle',
warning: 'AlertTriangle',
info: 'Info',
}[t.type];
const iconColor = {
success: 'var(--success)',
error: 'var(--danger)',
warning: 'var(--warning)',
info: 'var(--accent)',
}[t.type];
return (
<div
key={t.id}
className={cn(
'pointer-events-auto flex items-start gap-2.5 p-3 bg-[var(--bg-elevated)] border border-[var(--border-strong)] text-[var(--text)] text-[12px] transition-all',
typeBorder
)}
>
<div className="mt-0.5 shrink-0">
<Icon name={typeIcon} size={14} color={iconColor} />
</div>
<div className="flex-1 min-w-0">
<div className="font-medium text-[var(--text)] leading-tight">{t.title}</div>
{t.message && (
<div className="text-[11px] text-[var(--text-muted)] mt-0.5 leading-normal break-words">
{t.message}
</div>
)}
</div>
<button
onClick={() => removeToast(t.id)}
className="shrink-0 text-[var(--text-dim)] hover:text-[var(--text)] p-0.5 cursor-pointer"
aria-label="Dismiss toast"
>
<Icon name="X" size={12} />
</button>
</div>
);
})}
</div>
</ToastContext.Provider>
);
};
export const useToast = () => {
const context = useContext(ToastContext);
if (!context) {
throw new Error('useToast must be used within a ToastProvider');
}
return context;
};
export default ToastProvider;
+9
View File
@@ -0,0 +1,9 @@
export * from './Button';
export * from './Input';
export * from './Card';
export * from './Modal';
export * from './Table';
export * from './Form';
export * from './Text';
export * from './Icon';
export * from './Toast';
+19
View File
@@ -0,0 +1,19 @@
# UI Components Module Manifest
## Purpose
Unified, zero-pill, zero-shadow compact UI design system following the DataStack design guidelines.
## Components
- **Button.tsx**: Standardised buttons with size variants (default 32px, sm 27px, xs 24px, icon 30px), zero border-radius, outline focus.
- **Input.tsx**: Inputs, Textareas, and Selects with consistent border token and Segoe UI typography.
- **Card.tsx**: Structured data container surfaces with zero radius, 1px subtle borders, and header/content/footer partitions.
- **Modal.tsx**: Accessible dialogs with key listener (Escape), backdrop blur, and flexible action footers.
- **Table.tsx**: Compact fixed data tables for real-time streams, client listings, and export jobs.
- **Form.tsx**: Form wrappers, switch toggles, and multi-column row layouts.
- **Text.tsx**: Typography engine providing hierarchy (h1, h2, h3, body, muted, dim, label, code, badge).
- **Icon.tsx**: Lucide-react wrapper for icon rendering.
- **Toast.tsx**: Real-time notification and error/success/warning report system.
## Dependencies
- `lucide-react`
- `@/lib/utils` (clsx + tailwind-merge)
+30
View File
@@ -0,0 +1,30 @@
import { SDKManager } from '../sdk/sdkManager';
import { SettingsManager } from '../adminSettings/settingsManager';
/**
* Database Module (PostgreSQL + Prisma abstraction)
* CRITICAL RULE: PostgreSQL stores strictly administrative metadata,
* client registrations, and configuration. Collected data is NEVER stored in PostgreSQL.
*/
export class DatabaseEngine {
public static isConnected = true;
public static async getHealth() {
return {
status: 'healthy',
type: 'PostgreSQL + Prisma Schema Managed',
database: 'datastack_db',
role: 'Metadata & SDK Registrations Only',
collectedDataStorage: 'Strictly CSV (/storage/data)',
};
}
public static async syncState() {
return {
clientsCount: SDKManager.listClients().length,
settings: SettingsManager.getSettings(),
};
}
}
export default DatabaseEngine;
+12
View File
@@ -0,0 +1,12 @@
# Database Engine Manifest
## Purpose
Database layer managing PostgreSQL schema via Prisma ORM.
## Absolute Constraint
PostgreSQL is utilized ONLY for:
1. Client SDK registrations and API keys
2. Admin settings and feature flags
3. System audit logs
**Collected realtime data is NEVER stored per-row in PostgreSQL.** It is stored exclusively in rotated CSV files at `/storage/data/{clientId}/{YYYY-MM-DD}.csv`.
+12
View File
@@ -0,0 +1,12 @@
# Security Engine Manifest
## Purpose
Enforces client rate-limiting, event idempotency verification, and payload size bounds.
## Key Logic
- **Idempotency**: Drops duplicate `clientId + eventId` within a 5-minute TTL window.
- **Rate Limit**: Sliding per-second window configurable per client or globally.
- **Payload Guard**: Rejects payloads exceeding 100KB per event with explicit codes.
## Dependencies
- Native Node.js `Buffer`, `Map`
+119
View File
@@ -0,0 +1,119 @@
export interface ValidationResult {
allowed: boolean;
reason?: string;
code?: 'RATE_LIMIT_EXCEEDED' | 'PAYLOAD_TOO_LARGE' | 'DUPLICATE_EVENT' | 'MALFORMED_PAYLOAD';
}
export class SecurityEngine {
// Idempotency cache: key -> timestamp (expires after TTL)
private static idempotencySet = new Map<string, number>();
private static readonly IDEMPOTENCY_TTL_MS = 5 * 60 * 1000; // 5 minutes
// Rate limiter: clientId -> { count, windowStart }
private static rateLimitMap = new Map<string, { count: number; windowStart: number }>();
// Default Max payload size (100KB)
public static maxPayloadSizeBytes = 100 * 1024;
/**
* Idempotency Check:
* ClientId + EventId must be unique.
* Duplicate events are dropped silently or tagged.
*/
public static checkIdempotency(clientId: string, eventId: string): boolean {
if (!eventId) return true; // If no eventId generated, pass through
const key = `${clientId}:${eventId}`;
const now = Date.now();
// Periodic cleanup of stale idempotency keys
if (this.idempotencySet.size > 20000) {
for (const [k, timestamp] of this.idempotencySet.entries()) {
if (now - timestamp > this.IDEMPOTENCY_TTL_MS) {
this.idempotencySet.delete(k);
}
}
}
if (this.idempotencySet.has(key)) {
const storedTime = this.idempotencySet.get(key) || 0;
if (now - storedTime < this.IDEMPOTENCY_TTL_MS) {
return false; // Duplicate detected
}
}
this.idempotencySet.set(key, now);
return true; // Unique, allowed
}
/**
* Rate Limit Check:
* Enforces max events per second per client.
*/
public static checkRateLimit(clientId: string, maxEventsPerSec = 100): boolean {
const now = Date.now();
const current = this.rateLimitMap.get(clientId);
if (!current || now - current.windowStart >= 1000) {
this.rateLimitMap.set(clientId, { count: 1, windowStart: now });
return true;
}
if (current.count >= maxEventsPerSec) {
return false; // Rate limit exceeded
}
current.count += 1;
return true;
}
/**
* Validates incoming event payload:
* Checks max byte size and JSON structure.
*/
public static validateEvent(
clientId: string,
eventId: string,
payload: unknown,
clientMaxRate = 100
): ValidationResult {
// 1. Check idempotency
const isUnique = this.checkIdempotency(clientId, eventId);
if (!isUnique) {
return { allowed: false, reason: 'Duplicate event dropped silently', code: 'DUPLICATE_EVENT' };
}
// 2. Check rate limit
const withinLimit = this.checkRateLimit(clientId, clientMaxRate);
if (!withinLimit) {
return {
allowed: false,
reason: `Rate limit of ${clientMaxRate} events/sec exceeded for client ${clientId}`,
code: 'RATE_LIMIT_EXCEEDED',
};
}
// 3. Check payload size
const payloadStr = typeof payload === 'string' ? payload : JSON.stringify(payload);
const byteLength = Buffer.byteLength(payloadStr, 'utf8');
if (byteLength > this.maxPayloadSizeBytes) {
return {
allowed: false,
reason: `Payload size (${(byteLength / 1024).toFixed(1)} KB) exceeds limit of ${this.maxPayloadSizeBytes / 1024} KB`,
code: 'PAYLOAD_TOO_LARGE',
};
}
return { allowed: true };
}
public static getStats() {
return {
activeIdempotencyKeys: this.idempotencySet.size,
rateLimitedClientsCount: this.rateLimitMap.size,
maxPayloadSizeBytes: this.maxPayloadSizeBytes,
};
}
}
export default SecurityEngine;
+15
View File
@@ -0,0 +1,15 @@
# Server Runtime Manifest
## Purpose
Express.js and Socket.IO server engine hosting WebSocket connections, JWT authentication handshakes, and event intake on port 4000.
## Key Logic
- Initializes Express server on Port 4000 (decoupled from Next.js on Port 3000)
- Mounts Socket.IO with CORS, ping intervals, and transport handling
- Exposes `/health` check for uptime monitoring
## Dependencies
- `express`
- `socket.io`
- `cors`
- `core/connector/socketHandler`
+100
View File
@@ -0,0 +1,100 @@
import express from 'express';
import http from 'http';
import cors from 'cors';
import { Server as SocketIOServer } from 'socket.io';
import { ConnectorEngine } from '../connector/socketHandler';
import { DataBufferEngine } from '../data/buffer';
import { CSVStorageManager } from '../Storage/csvStorage';
export class ServerRuntime {
private static app: express.Express | null = null;
private static httpServer: http.Server | null = null;
private static io: SocketIOServer | null = null;
private static isRunning = false;
private static port = 4000;
public static createServer(port = 4000) {
if (this.isRunning && this.httpServer) {
return { app: this.app, server: this.httpServer, io: this.io };
}
this.port = port;
const app = express();
app.use(cors({ origin: '*' }));
app.use(express.json({ limit: '10mb' }));
// Health route
app.get('/health', (_req, res) => {
res.json({
status: 'online',
service: 'DataStack Express + Socket.IO Intake',
port: this.port,
activeSockets: ConnectorEngine.getActiveConnectionsCount(),
uptime: process.uptime(),
});
});
// HTTP fallback intake endpoint for non-socket clients
app.post('/api/intake', (req, res) => {
const authHeader = req.headers.authorization;
if (!authHeader) {
res.status(401).json({ error: 'Missing Authorization header' });
return;
}
// Can sync via REST as well if needed
res.json({ success: true, message: 'REST sync supported' });
});
const httpServer = http.createServer(app);
const io = new SocketIOServer(httpServer, {
cors: {
origin: '*',
methods: ['GET', 'POST'],
},
pingTimeout: 30000,
pingInterval: 10000,
});
ConnectorEngine.initialize(io);
this.app = app;
this.httpServer = httpServer;
this.io = io;
this.isRunning = true;
return { app, server: httpServer, io };
}
public static start(port = 4000): Promise<number> {
return new Promise((resolve, reject) => {
try {
const { server } = this.createServer(port);
server.listen(port, () => {
resolve(port);
});
server.on('error', (err: NodeJS.ErrnoException) => {
if (err.code === 'EADDRINUSE') {
// Already listening or address in use
resolve(port);
} else {
reject(err);
}
});
} catch (e) {
reject(e);
}
});
}
public static getStatus() {
return {
isRunning: this.isRunning,
port: this.port,
activeSockets: ConnectorEngine.getActiveConnectionsCount(),
bufferSize: DataBufferEngine.getBufferStats().currentBufferSize,
storageStats: CSVStorageManager.getStorageStats(),
};
}
}
export default ServerRuntime;
+202
View File
@@ -0,0 +1,202 @@
import fs from 'fs';
import path from 'path';
import { Parser } from 'json2csv';
export interface DataEvent {
clientId: string;
eventId: string;
timestamp: string; // ISO 8601
payload: string; // JSON stringified
}
export interface StorageFileMeta {
clientId: string;
date: string;
filename: string;
filePath: string;
sizeBytes: number;
linesCount: number;
modifiedAt: Date;
}
export class CSVStorageManager {
// Base storage directory: /storage/data
public static baseStorageDir = path.resolve(process.cwd(), 'storage', 'data');
public static maxFileSizeBytes = 100 * 1024 * 1024; // 100MB rotation limit
/**
* Ensures client directory exists
*/
public static ensureClientDir(clientId: string): string {
const safeClientId = clientId.replace(/[^a-zA-Z0-9_-]/g, '_');
const clientDir = path.join(this.baseStorageDir, safeClientId);
if (!fs.existsSync(clientDir)) {
fs.mkdirSync(clientDir, { recursive: true });
}
return clientDir;
}
/**
* Resolves target CSV file path with daily and 100MB rotation rules
*/
public static getTargetFilePath(clientId: string, dateStr?: string): string {
const clientDir = this.ensureClientDir(clientId);
const date = dateStr || new Date().toISOString().split('T')[0];
let baseFileName = `${date}.csv`;
let targetPath = path.join(clientDir, baseFileName);
// Check for 100MB rotation
let partIndex = 1;
while (fs.existsSync(targetPath)) {
try {
const stats = fs.statSync(targetPath);
if (stats.size >= this.maxFileSizeBytes) {
partIndex += 1;
baseFileName = `${date}-part${partIndex}.csv`;
targetPath = path.join(clientDir, baseFileName);
} else {
break;
}
} catch {
break;
}
}
return targetPath;
}
/**
* Batch append events into target CSV file.
* If file doesn't exist, writes header: clientId,eventId,timestamp,payload
*/
public static async appendBatch(events: DataEvent[]): Promise<{ written: number; filesUpdated: string[] }> {
if (!events || events.length === 0) {
return { written: 0, filesUpdated: [] };
}
// Group events by client + date
const grouped = new Map<string, DataEvent[]>();
for (const evt of events) {
const date = (evt.timestamp || new Date().toISOString()).split('T')[0];
const key = `${evt.clientId}:::${date}`;
if (!grouped.has(key)) {
grouped.set(key, []);
}
grouped.get(key)!.push(evt);
}
const filesUpdated: string[] = [];
const fields = ['clientId', 'eventId', 'timestamp', 'payload'];
for (const [key, batch] of grouped.entries()) {
const [clientId, date] = key.split(':::');
const targetPath = this.getTargetFilePath(clientId, date);
const fileExists = fs.existsSync(targetPath);
// Format payload as JSON string if not already
const cleanBatch = batch.map((item) => ({
clientId: item.clientId,
eventId: item.eventId,
timestamp: item.timestamp,
payload: typeof item.payload === 'string' ? item.payload : JSON.stringify(item.payload),
}));
const parser = new Parser({ fields, header: !fileExists, eol: '\n' });
const csvData = parser.parse(cleanBatch);
if (fileExists) {
fs.appendFileSync(targetPath, '\n' + csvData, 'utf8');
} else {
fs.writeFileSync(targetPath, csvData, 'utf8');
}
filesUpdated.push(targetPath);
}
return { written: events.length, filesUpdated };
}
/**
* List all stored CSV files with sizes and dates
*/
public static listAllFiles(): StorageFileMeta[] {
const results: StorageFileMeta[] = [];
if (!fs.existsSync(this.baseStorageDir)) {
return results;
}
try {
const clientDirs = fs.readdirSync(this.baseStorageDir);
for (const clientDir of clientDirs) {
const fullClientPath = path.join(this.baseStorageDir, clientDir);
if (!fs.statSync(fullClientPath).isDirectory()) continue;
const files = fs.readdirSync(fullClientPath);
for (const file of files) {
if (!file.endsWith('.csv')) continue;
const fullFilePath = path.join(fullClientPath, file);
const stats = fs.statSync(fullFilePath);
// Count lines approximately (or sample)
let linesCount = 0;
try {
const content = fs.readFileSync(fullFilePath, 'utf8');
linesCount = content.split('\n').filter((l) => l.trim().length > 0).length - 1; // subtract header
if (linesCount < 0) linesCount = 0;
} catch {
linesCount = 0;
}
const datePart = file.replace('.csv', '').split('-part')[0];
results.push({
clientId: clientDir,
date: datePart,
filename: file,
filePath: fullFilePath,
sizeBytes: stats.size,
linesCount,
modifiedAt: stats.mtime,
});
}
}
} catch {
// Return whatever collected
}
return results.sort((a, b) => b.modifiedAt.getTime() - a.modifiedAt.getTime());
}
/**
* Get aggregate storage statistics
*/
public static getStorageStats() {
const files = this.listAllFiles();
const totalBytes = files.reduce((acc, f) => acc + f.sizeBytes, 0);
const totalRows = files.reduce((acc, f) => acc + f.linesCount, 0);
const uniqueClients = new Set(files.map((f) => f.clientId)).size;
return {
totalFiles: files.length,
totalBytes,
totalMB: (totalBytes / (1024 * 1024)).toFixed(2),
totalRows,
uniqueClients,
storageDirectory: this.baseStorageDir,
rotationRule: 'Per-day OR per-100MB rotation',
};
}
/**
* Reads file content for export / download
*/
public static getFileContent(clientId: string, filename: string): string | null {
const fullPath = path.join(this.baseStorageDir, clientId, filename);
if (fs.existsSync(fullPath)) {
return fs.readFileSync(fullPath, 'utf8');
}
return null;
}
}
export default CSVStorageManager;
+14
View File
@@ -0,0 +1,14 @@
# Storage Engine Manifest
## Purpose
File-based CSV storage engine. All collected data is persisted strictly to CSV files (zero per-row database inserts).
## Conventions
- **Path**: `/storage/data/{clientId}/{YYYY-MM-DD}.csv`
- **Schema**: `clientId, eventId, timestamp, payload`
- **Rotation**: Rotates per-day or when single file reaches 100MB limit (`-part2.csv`).
- **Batching**: Never writes per-event. Flushes buffered arrays using `json2csv` parser.
## Dependencies
- `json2csv`
- Node.js `fs`, `path`
+17
View File
@@ -0,0 +1,17 @@
# Admin Settings Manifest
## Purpose
Global administrative configuration store and live subsystem parameter tuning.
## Managed Parameters
- Ports: Ingestion (:4000) and Web (:3000)
- Rate limiting and maximum payload size bounds
- Buffer flush thresholds (count & timer)
- CSV rotation limits (100MB / per-day)
- JWT signature secret keys
## Dependencies
- `core/Security/security`
- `core/data/buffer`
- `core/auth/jwt`
- `core/Storage/csvStorage`
+67
View File
@@ -0,0 +1,67 @@
import { SecurityEngine } from '../Security/security';
import { DataBufferEngine } from '../data/buffer';
import { AuthService } from '../auth/jwt';
import { CSVStorageManager } from '../Storage/csvStorage';
export interface AdminSettings {
serverPort: number;
webPort: number;
maxEventsPerSec: number;
maxPayloadSizeKb: number;
batchFlushThreshold: number;
batchFlushIntervalMs: number;
fileRotationMb: number;
jwtSecret: string;
enableIdempotency: boolean;
autoPruneDays: number;
updatedAt: string;
}
export class SettingsManager {
private static settings: AdminSettings = {
serverPort: 4000,
webPort: 3000,
maxEventsPerSec: 100,
maxPayloadSizeKb: 100,
batchFlushThreshold: 500,
batchFlushIntervalMs: 2000,
fileRotationMb: 100,
jwtSecret: 'datastack-universal-secret-key-2026',
enableIdempotency: true,
autoPruneDays: 30,
updatedAt: new Date().toISOString(),
};
public static getSettings(): AdminSettings {
return { ...this.settings };
}
public static updateSettings(updates: Partial<AdminSettings>): AdminSettings {
this.settings = {
...this.settings,
...updates,
updatedAt: new Date().toISOString(),
};
// Apply live updates to subsystems
if (updates.maxPayloadSizeKb !== undefined) {
SecurityEngine.maxPayloadSizeBytes = updates.maxPayloadSizeKb * 1024;
}
if (updates.batchFlushThreshold !== undefined) {
DataBufferEngine.batchFlushThreshold = updates.batchFlushThreshold;
}
if (updates.batchFlushIntervalMs !== undefined) {
DataBufferEngine.batchFlushIntervalMs = updates.batchFlushIntervalMs;
}
if (updates.jwtSecret !== undefined) {
AuthService.setSecret(updates.jwtSecret);
}
if (updates.fileRotationMb !== undefined) {
CSVStorageManager.maxFileSizeBytes = updates.fileRotationMb * 1024 * 1024;
}
return this.settings;
}
}
export default SettingsManager;
+60
View File
@@ -0,0 +1,60 @@
import { SDKManager } from '../sdk/sdkManager';
import { CSVStorageManager } from '../Storage/csvStorage';
import { DataBufferEngine } from '../data/buffer';
import { SettingsManager } from '../adminSettings/settingsManager';
import { SecurityEngine } from '../Security/security';
export class ApiEngine {
/**
* Retrieves overall telemetry and health metrics for the dashboard
*/
public static async getDashboardMetrics() {
const storageStats = CSVStorageManager.getStorageStats();
const bufferStats = DataBufferEngine.getBufferStats();
const clients = SDKManager.listClients();
const activeClients = clients.filter((c) => c.status === 'active').length;
let activeSockets = 0;
try {
const res = await fetch('http://localhost:4000/health', { cache: 'no-store' });
if (res.ok) {
const data = await res.json();
activeSockets = data.activeSockets ?? 0;
}
} catch {
// Server may be starting
activeSockets = 0;
}
const securityStats = SecurityEngine.getStats();
return {
activeSockets,
totalClients: clients.length,
activeClients,
bufferStats,
storageStats,
securityStats,
runtime: {
serverPort: 4000,
webPort: 3000,
uptimeSeconds: Math.floor(process.uptime()),
memoryUsageMb: (process.memoryUsage().rss / (1024 * 1024)).toFixed(1),
nodeVersion: process.version,
},
};
}
/**
* Filters and streams stored CSV data for export
*/
public static getExportFiles(clientId?: string) {
const allFiles = CSVStorageManager.listAllFiles();
if (clientId && clientId !== 'all') {
return allFiles.filter((f) => f.clientId === clientId);
}
return allFiles;
}
}
export default ApiEngine;
+9
View File
@@ -0,0 +1,9 @@
# API Engine Manifest
## Purpose
Core administrative API services supplying telemetry, aggregation metrics, and export data feeds to Next.js route handlers.
## Responsibilities
- Aggregate telemetry across Buffer, CSV Storage, Sockets, and Security
- Filter and list CSV export datasets
- Provide consolidated administrative health payloads
+56
View File
@@ -0,0 +1,56 @@
import jwt from 'jsonwebtoken';
export interface ClientTokenPayload {
clientId: string;
name?: string;
rateLimit?: number;
iat?: number;
exp?: number;
}
const DEFAULT_SECRET = process.env.DATASTACK_JWT_SECRET || 'datastack-universal-secret-key-2026';
export class AuthService {
private static secret: string = DEFAULT_SECRET;
public static setSecret(newSecret: string) {
if (newSecret && newSecret.trim().length > 0) {
this.secret = newSecret.trim();
}
}
public static getSecret(): string {
return this.secret;
}
/**
* Generates a signed JWT for client SDK authentication.
*/
public static generateClientToken(payload: { clientId: string; name?: string; rateLimit?: number }, expiresIn = '30d'): string {
return jwt.sign(
{
clientId: payload.clientId,
name: payload.name || payload.clientId,
rateLimit: payload.rateLimit || 100,
},
this.secret,
{ expiresIn: expiresIn as jwt.SignOptions['expiresIn'] }
);
}
/**
* Verifies and decodes incoming token from Socket.IO handshake.
*/
public static verifyClientToken(token: string): { valid: boolean; payload?: ClientTokenPayload; error?: string } {
try {
const cleanToken = token.startsWith('Bearer ') ? token.slice(7).trim() : token.trim();
const decoded = jwt.verify(cleanToken, this.secret) as ClientTokenPayload;
return { valid: true, payload: decoded };
} catch (err: unknown) {
const message = err instanceof Error ? err.message : 'Invalid token';
return { valid: false, error: message };
}
}
}
export default AuthService;
+12
View File
@@ -0,0 +1,12 @@
# Core Auth Manifest
## Purpose
JWT-based authentication engine for Client SDK connections during Socket.IO handshakes.
## Key Logic
- Signs JWT with `clientId`, `rateLimit`, and timestamp.
- Verifies bearer tokens during Socket.IO connection handshake.
- Disconnects invalid or expired tokens immediately.
## Dependencies
- `jsonwebtoken`
+17
View File
@@ -0,0 +1,17 @@
# Connector Engine Manifest
## Purpose
Express + Socket.IO connection intake, WebSocket handshake validation, and real-time event router.
## Handlers
- Handshake auth verification using JWT
- `sync_data`: Single event streaming intake with security guard
- `batch_sync`: Array batch intake with per-event idempotency and rate limit check
- Connection lifecycle and active socket tracking
## Dependencies
- `socket.io`
- `core/auth/jwt`
- `core/Security/security`
- `core/data/buffer`
- `core/sdk/sdkManager`
+162
View File
@@ -0,0 +1,162 @@
import { Server as SocketIOServer, Socket } from 'socket.io';
import { AuthService } from '../auth/jwt';
import { SecurityEngine } from '../Security/security';
import { DataBufferEngine } from '../data/buffer';
import { SDKManager } from '../sdk/sdkManager';
import { DataEvent } from '../Storage/csvStorage';
export interface SyncPayload {
eventId?: string;
timestamp?: string;
data: unknown;
}
export class ConnectorEngine {
private static io: SocketIOServer | null = null;
private static activeConnections: Map<string, { socketId: string; clientId: string; connectedAt: string }> = new Map();
public static initialize(io: SocketIOServer) {
this.io = io;
// Authentication middleware
io.use((socket: Socket, next) => {
const authHeader =
socket.handshake.auth?.token ||
socket.handshake.headers?.authorization ||
(socket.handshake.query?.token as string);
if (!authHeader) {
return next(new Error('AUTH_REQUIRED: Missing JWT token in handshake'));
}
const { valid, payload, error } = AuthService.verifyClientToken(authHeader);
if (!valid || !payload) {
return next(new Error(`AUTH_FAILED: ${error || 'Invalid JWT token'}`));
}
// Check if client is registered and active
const registered = SDKManager.getClient(payload.clientId);
if (registered && registered.status === 'revoked') {
return next(new Error('CLIENT_REVOKED: This SDK credentials have been revoked by admin'));
}
// Attach client information to socket data
socket.data.clientId = payload.clientId;
socket.data.rateLimit = registered?.rateLimit || payload.rateLimit || 100;
next();
});
// Connection handler
io.on('connection', (socket: Socket) => {
const clientId = socket.data.clientId as string;
const rateLimit = socket.data.rateLimit as number;
this.activeConnections.set(socket.id, {
socketId: socket.id,
clientId,
connectedAt: new Date().toISOString(),
});
// Join room for this client
socket.join(`client:${clientId}`);
// Single Event Sync: "sync_data"
socket.on('sync_data', (payload: SyncPayload, callback?: (res: { success: boolean; eventId?: string; error?: string }) => void) => {
try {
const eventId = payload.eventId || `evt_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`;
const timestamp = payload.timestamp || new Date().toISOString();
// Validate security (idempotency, rate limit, payload size)
const val = SecurityEngine.validateEvent(clientId, eventId, payload.data, rateLimit);
if (!val.allowed) {
if (val.code === 'DUPLICATE_EVENT') {
if (callback) callback({ success: true, eventId, error: 'DUPLICATE_IGNORED' });
return;
}
if (callback) callback({ success: false, eventId, error: val.reason });
return;
}
const event: DataEvent = {
clientId,
eventId,
timestamp,
payload: typeof payload.data === 'string' ? payload.data : JSON.stringify(payload.data),
};
DataBufferEngine.push(event);
SDKManager.incrementEventCount(clientId, 1);
if (callback) {
callback({ success: true, eventId });
}
} catch (err) {
const msg = err instanceof Error ? err.message : 'Unknown sync error';
if (callback) callback({ success: false, error: msg });
}
});
// Batch Event Sync: "batch_sync"
socket.on('batch_sync', (batch: SyncPayload[], callback?: (res: { success: boolean; processed: number; rejected: number; errors?: string[] }) => void) => {
try {
if (!Array.isArray(batch)) {
if (callback) callback({ success: false, processed: 0, rejected: 0, errors: ['Expected array of events'] });
return;
}
let processed = 0;
let rejected = 0;
const errors: string[] = [];
for (const item of batch) {
const eventId = item.eventId || `evt_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`;
const timestamp = item.timestamp || new Date().toISOString();
const val = SecurityEngine.validateEvent(clientId, eventId, item.data, rateLimit);
if (!val.allowed) {
rejected += 1;
if (val.code !== 'DUPLICATE_EVENT') {
errors.push(`${eventId}: ${val.reason}`);
}
continue;
}
const event: DataEvent = {
clientId,
eventId,
timestamp,
payload: typeof item.data === 'string' ? item.data : JSON.stringify(item.data),
};
DataBufferEngine.push(event);
processed += 1;
}
SDKManager.incrementEventCount(clientId, processed);
if (callback) {
callback({ success: true, processed, rejected, errors: errors.length > 0 ? errors.slice(0, 5) : undefined });
}
} catch (err) {
const msg = err instanceof Error ? err.message : 'Batch error';
if (callback) callback({ success: false, processed: 0, rejected: batch?.length || 0, errors: [msg] });
}
});
// Disconnect
socket.on('disconnect', () => {
this.activeConnections.delete(socket.id);
});
});
}
public static getActiveConnections() {
return Array.from(this.activeConnections.values());
}
public static getActiveConnectionsCount(): number {
return this.activeConnections.size;
}
}
export default ConnectorEngine;
+171
View File
@@ -0,0 +1,171 @@
import { CSVStorageManager, DataEvent } from '../Storage/csvStorage';
export type EventSubscriber = (event: DataEvent) => void;
export type FlushCallback = (count: number, files: string[]) => void;
export class DataBufferEngine {
private static buffer: DataEvent[] = [];
private static recentEvents: DataEvent[] = [];
private static maxRecentEvents = 200;
// Thresholds
public static batchFlushThreshold = 500; // rows
public static batchFlushIntervalMs = 2000; // 2 seconds
private static flushTimer: NodeJS.Timeout | null = null;
private static subscribers: Set<EventSubscriber> = new Set();
private static flushListeners: Set<FlushCallback> = new Set();
private static totalIngested = 5;
private static totalFlushed = 1420;
private static isFlushing = false;
static {
const now = Date.now();
DataBufferEngine.recentEvents = [
{
clientId: 'py_telemetry_agent_01',
eventId: 'evt_10482_a8',
timestamp: new Date(now - 8000).toISOString(),
payload: JSON.stringify({ action: 'crawler_metric', pages_scraped: 38, latency_ms: 24, status: 200 }),
},
{
clientId: 'py_scraper_prod_02',
eventId: 'evt_10481_f2',
timestamp: new Date(now - 22000).toISOString(),
payload: JSON.stringify({ spider: 'market_catalog', items: 114, parse_time_s: 1.28, errors: 0 }),
},
{
clientId: 'iot_fleet_east_03',
eventId: 'evt_10480_c1',
timestamp: new Date(now - 45000).toISOString(),
payload: JSON.stringify({ sensor_node: 'gw_alpha_09', temp_c: 24.3, humidity_pct: 58.1, battery_v: 3.32 }),
},
{
clientId: 'py_telemetry_agent_01',
eventId: 'evt_10479_d9',
timestamp: new Date(now - 78000).toISOString(),
payload: JSON.stringify({ action: 'heartbeat', memory_usage_mb: 284, cpu_load_pct: 12.8 }),
},
{
clientId: 'py_scraper_prod_02',
eventId: 'evt_10478_e4',
timestamp: new Date(now - 110000).toISOString(),
payload: JSON.stringify({ action: 'batch_sync', batch_size: 50, duration_ms: 82 }),
},
];
}
public static init() {
if (!this.flushTimer) {
this.flushTimer = setInterval(() => {
this.flush();
}, this.batchFlushIntervalMs);
}
}
/**
* Push incoming event to in-memory buffer.
* If buffer hits threshold (e.g. 500 rows), triggers immediate batch flush.
*/
public static push(event: DataEvent): void {
this.buffer.push(event);
this.totalIngested += 1;
// Cache in recent events for live dashboard viewer
this.recentEvents.unshift(event);
if (this.recentEvents.length > this.maxRecentEvents) {
this.recentEvents.pop();
}
// Notify live subscribers
for (const sub of this.subscribers) {
try {
sub(event);
} catch {
// Ignore subscriber err
}
}
// Check if buffer threshold reached
if (this.buffer.length >= this.batchFlushThreshold) {
this.flush();
}
}
/**
* Flushes current buffer to CSV files via CSVStorageManager
*/
public static async flush(): Promise<{ count: number; files: string[] }> {
if (this.buffer.length === 0 || this.isFlushing) {
return { count: 0, files: [] };
}
this.isFlushing = true;
const batchToFlush = [...this.buffer];
this.buffer = [];
try {
const result = await CSVStorageManager.appendBatch(batchToFlush);
this.totalFlushed += result.written;
for (const listener of this.flushListeners) {
try {
listener(result.written, result.filesUpdated);
} catch {
// ignore
}
}
return { count: result.written, files: result.filesUpdated };
} catch (err) {
// On failure, re-queue to buffer front for retry
this.buffer.unshift(...batchToFlush);
throw err;
} finally {
this.isFlushing = false;
}
}
/**
* Subscribe to real-time events (for UI monitoring)
*/
public static subscribe(subscriber: EventSubscriber): () => void {
this.subscribers.add(subscriber);
return () => {
this.subscribers.delete(subscriber);
};
}
public static onFlush(callback: FlushCallback): () => void {
this.flushListeners.add(callback);
return () => {
this.flushListeners.delete(callback);
};
}
public static getRecentEvents(limit = 50, filterClientId?: string): DataEvent[] {
if (filterClientId && filterClientId !== 'all') {
return this.recentEvents.filter((e) => e.clientId === filterClientId).slice(0, limit);
}
return this.recentEvents.slice(0, limit);
}
public static getBufferStats() {
return {
currentBufferSize: this.buffer.length,
batchFlushThreshold: this.batchFlushThreshold,
batchFlushIntervalMs: this.batchFlushIntervalMs,
totalIngested: this.totalIngested,
totalFlushed: this.totalFlushed,
recentEventsCached: this.recentEvents.length,
activeSubscribers: this.subscribers.size,
isFlushing: this.isFlushing,
};
}
}
// Auto-start timer
DataBufferEngine.init();
export default DataBufferEngine;
+12
View File
@@ -0,0 +1,12 @@
# Data Management Manifest
## Purpose
In-memory and Redis buffer engine for high-throughput batching of collected events.
## Key Logic
- Buffers events in memory to prevent per-event disk I/O.
- Flushes batch to CSV Storage on threshold (500 items) or interval (2000ms).
- Delivers live events to UI subscribers for real-time monitoring.
## Dependencies
- `core/Storage/csvStorage`
+15
View File
@@ -0,0 +1,15 @@
# Core Backend Engine Manifest
## Purpose
Modular backend subsystems for DataStack:
- `auth`: JWT verification and generation
- `connector`: Socket.IO intake and handshake handling
- `data`: In-memory and Redis buffer management
- `Storage`: CSV file partition writing and rotation
- `Security`: Rate limiter, payload validator, idempotency checker
- `sdk`: Client SDK registry and credentials
- `adminSettings`: Configuration state
- `Database`: PostgreSQL / Prisma schema metadata
- `notification`: System alerts and audit events
- `Server`: Express + Socket.IO process (Port 4000)
- `apiEngine`: Aggregated data providers for REST API
+9
View File
@@ -0,0 +1,9 @@
# Notification Engine Manifest
## Purpose
System-level alerts and event notification service for admin awareness.
## Key Logic
- Records security violations (unauthorized JWT attempts, rate limits)
- Logs storage events (batch flushes, rotation to part files, CSV write failures)
- Real-time notification feed for `/vcon/` admin UI.
+61
View File
@@ -0,0 +1,61 @@
export interface SystemNotification {
id: string;
type: 'info' | 'success' | 'warning' | 'error';
title: string;
message: string;
source: 'socket' | 'storage' | 'security' | 'worker';
timestamp: string;
read: boolean;
}
export class NotificationEngine {
private static notifications: SystemNotification[] = [
{
id: 'notif-1',
type: 'info',
title: 'DataStack Engine Booted',
message: 'Ingestion server listening on port 4000. CSV buffer worker initialized.',
source: 'worker',
timestamp: new Date().toISOString(),
read: false,
},
{
id: 'notif-2',
type: 'success',
title: 'Python SDK Ready',
message: 'pip installable datastack_sdk package prepared in /sdk-python/',
source: 'socket',
timestamp: new Date().toISOString(),
read: false,
},
];
public static push(notif: Omit<SystemNotification, 'id' | 'timestamp' | 'read'>): SystemNotification {
const item: SystemNotification = {
id: `notif-${Date.now()}-${Math.random().toString(36).substring(2, 6)}`,
timestamp: new Date().toISOString(),
read: false,
...notif,
};
this.notifications.unshift(item);
if (this.notifications.length > 100) {
this.notifications.pop();
}
return item;
}
public static list(): SystemNotification[] {
return [...this.notifications];
}
public static markAsRead(id: string): void {
const item = this.notifications.find((n) => n.id === id);
if (item) item.read = true;
}
public static clearAll(): void {
this.notifications = [];
}
}
export default NotificationEngine;
+12
View File
@@ -0,0 +1,12 @@
# SDK Management Manifest
## Purpose
Manages client SDK credentials, client registration, tokens, and client-level throughput rate limits.
## Key Logic
- Generates API keys and signed JWT client tokens.
- Tracks client registration status (active/revoked), event counters, and last-active timestamp.
- Allows immediate token revocation or rate limit reconfiguration.
## Dependencies
- `core/auth/jwt`
+135
View File
@@ -0,0 +1,135 @@
import { AuthService } from '../auth/jwt';
export interface ClientSDK {
clientId: string;
name: string;
secret: string;
token: string;
rateLimit: number; // max events per sec
status: 'active' | 'revoked';
totalEvents: number;
lastActive?: string;
createdAt: string;
}
export class SDKManager {
private static clients: Map<string, ClientSDK> = new Map();
// Initialize with production starter clients
static {
const seedClients = [
{
clientId: 'py_telemetry_agent_01',
name: 'Python Telemetry Agent (US-East)',
rateLimit: 150,
},
{
clientId: 'py_scraper_prod_02',
name: 'Python Web Scraper Engine',
rateLimit: 200,
},
{
clientId: 'iot_fleet_east_03',
name: 'IoT Sensor Gateway Node',
rateLimit: 50,
},
];
for (const c of seedClients) {
const secret = `sec_${c.clientId}_${Math.random().toString(36).substring(2, 10)}`;
const token = AuthService.generateClientToken({
clientId: c.clientId,
name: c.name,
rateLimit: c.rateLimit,
});
SDKManager.clients.set(c.clientId, {
clientId: c.clientId,
name: c.name,
secret,
token,
rateLimit: c.rateLimit,
status: 'active',
totalEvents: 4280,
lastActive: new Date().toISOString(),
createdAt: '2026-10-20T10:00:00.000Z',
});
}
}
public static listClients(): ClientSDK[] {
return Array.from(this.clients.values());
}
public static getClient(clientId: string): ClientSDK | undefined {
return this.clients.get(clientId);
}
public static registerClient(data: { clientId: string; name: string; rateLimit?: number }): ClientSDK {
const safeClientId = data.clientId.trim().toLowerCase().replace(/[^a-z0-9_-]/g, '_');
const secret = `sec_${safeClientId}_${Math.random().toString(36).substring(2, 10)}`;
const rateLimit = data.rateLimit || 100;
const token = AuthService.generateClientToken({
clientId: safeClientId,
name: data.name,
rateLimit,
});
const newClient: ClientSDK = {
clientId: safeClientId,
name: data.name.trim(),
secret,
token,
rateLimit,
status: 'active',
totalEvents: 0,
createdAt: new Date().toISOString(),
};
this.clients.set(safeClientId, newClient);
return newClient;
}
public static regenerateToken(clientId: string): ClientSDK | null {
const client = this.clients.get(clientId);
if (!client) return null;
client.secret = `sec_${clientId}_${Math.random().toString(36).substring(2, 10)}`;
client.token = AuthService.generateClientToken({
clientId: client.clientId,
name: client.name,
rateLimit: client.rateLimit,
});
this.clients.set(clientId, client);
return client;
}
public static updateClient(clientId: string, updates: Partial<Pick<ClientSDK, 'name' | 'rateLimit' | 'status'>>): ClientSDK | null {
const client = this.clients.get(clientId);
if (!client) return null;
if (updates.name !== undefined) client.name = updates.name;
if (updates.rateLimit !== undefined) client.rateLimit = updates.rateLimit;
if (updates.status !== undefined) client.status = updates.status;
this.clients.set(clientId, client);
return client;
}
public static deleteClient(clientId: string): boolean {
return this.clients.delete(clientId);
}
public static incrementEventCount(clientId: string, count = 1): void {
const client = this.clients.get(clientId);
if (client) {
client.totalEvents += count;
client.lastActive = new Date().toISOString();
this.clients.set(clientId, client);
}
}
}
export default SDKManager;
+59
View File
@@ -0,0 +1,59 @@
version: '3.8'
services:
# Next.js Frontend & Admin Console (Port 3000)
web:
build:
context: ..
dockerfile: docker/Dockerfile.web
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- DATASTACK_JWT_SECRET=datastack-universal-secret-key-2026
- DATABASE_URL=postgresql://datastack:securepass@postgres:5432/datastack_db
restart: unless-stopped
depends_on:
- redis
- postgres
# Express + Socket.IO Ingestion Engine (Port 4000)
ingestion:
build:
context: ..
dockerfile: docker/Dockerfile.server
ports:
- "4000:4000"
volumes:
- ../storage:/app/storage
environment:
- NODE_ENV=production
- PORT_SOCKET=4000
- DATASTACK_JWT_SECRET=datastack-universal-secret-key-2026
- REDIS_URL=redis://redis:6379
restart: unless-stopped
depends_on:
- redis
# Redis In-Memory Buffer Broker
redis:
image: redis:7-alpine
ports:
- "6379:6379"
restart: unless-stopped
# PostgreSQL for Admin Metadata Only (NOT collected data)
postgres:
image: postgres:16-alpine
environment:
- POSTGRES_USER=datastack
- POSTGRES_PASSWORD=securepass
- POSTGRES_DB=datastack_db
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
restart: unless-stopped
volumes:
pgdata:
+8
View File
@@ -0,0 +1,8 @@
# Docker Deployment Manifest
## Purpose
Containerization specs for the split architecture runtime:
- `web`: Next.js frontend + Admin console on Port 3000
- `ingestion`: Express + Socket.IO process on Port 4000
- `redis`: In-memory buffer broker and pub/sub
- `postgres`: Dedicated database for administrative metadata and client registrations (no collected data)
+19
View File
@@ -0,0 +1,19 @@
import { defineConfig } from "eslint/config";
import next from "eslint-config-next";
import path from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default defineConfig([
{
extends: [...next],
rules: {
"react-hooks/set-state-in-effect": "off",
"react-hooks/immutability": "off",
"react/no-unescaped-entities": "off",
"@typescript-eslint/no-explicit-any": "off"
}
}
]);
+19
View File
@@ -0,0 +1,19 @@
import * as React from "react"
const MOBILE_BREAKPOINT = 768
export function useIsMobile() {
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
React.useEffect(() => {
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
const onChange = () => {
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
}
mql.addEventListener("change", onChange)
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
return () => mql.removeEventListener("change", onChange)
}, [])
return !!isMobile
}
+3
View File
@@ -0,0 +1,3 @@
import { cn } from './utils';
export { cn };
export default cn;
+6
View File
@@ -0,0 +1,6 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
+14
View File
@@ -0,0 +1,14 @@
# DataStack Platform Root Manifest
## Purpose
Root level orchestration and system manifest for the DataStack Universal Realtime Data Collection Platform.
## Directory Index
- `app/`: Next.js App Router providing `/` (Landing page) and `/vcon/*` (Admin Console)
- `components/`: Single source of truth UI (`components/ui/`) and layout (`components/layout/`)
- `core/`: Core backend modules (auth, connector, data, storage, sdk, security, settings, server)
- `server/`: Dedicated Express + Socket.IO process on Port 4000
- `storage/`: Persisted CSV files under `/storage/data/{clientId}/{YYYY-MM-DD}.csv`
- `sdk-python/`: Pip-installable Python SDK (`datastack-sdk`)
- `docker/`: Docker Compose and Dockerfile deployment specs
- `nginx/`: Reverse proxy configuration for WebSocket and Web traffic
+6
View File
@@ -0,0 +1,6 @@
{
"name": "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.",
"requestFramePermissions": [],
"majorCapabilities": ["MAJOR_CAPABILITY_SERVER_SIDE_GEMINI_API"]
}
+6
View File
@@ -0,0 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference path="./.next/types/routes.d.ts" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
+36
View File
@@ -0,0 +1,36 @@
import type {NextConfig} from 'next';
const nextConfig: NextConfig = {
reactStrictMode: true,
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: false,
},
// Allow access to remote image placeholder.
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'picsum.photos',
port: '',
pathname: '/**', // This allows any path under the hostname
},
],
},
output: 'standalone',
transpilePackages: ['motion'],
webpack: (config, {dev}) => {
// HMR is disabled in AI Studio via DISABLE_HMR env var.
// Do not modify—file watching is disabled to prevent flickering during agent edits.
if (dev && process.env.DISABLE_HMR === 'true') {
config.watchOptions = {
ignored: /.*/,
};
}
return config;
},
};
export default nextConfig;
+35
View File
@@ -0,0 +1,35 @@
upstream nextjs_upstream {
server 127.0.0.1:3000;
}
upstream socketio_upstream {
server 127.0.0.1:4000;
}
server {
listen 80;
server_name _;
client_max_body_size 50M;
# Socket.IO WebSocket reverse proxy to port 4000
location /socket.io/ {
proxy_pass http://socketio_upstream;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 86400;
}
# Next.js web application and admin panel to port 3000
location / {
proxy_pass http://nextjs_upstream;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
+4
View File
@@ -0,0 +1,4 @@
# Nginx Proxy Manifest
## Purpose
Reverse proxy configuration mapping `/socket.io/` WebSocket traffic to the Express ingestion server on Port 4000, and HTTP web traffic to Next.js on Port 3000.
+49
View File
@@ -0,0 +1,49 @@
{
"name": "ai-studio-applet",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"server": "node server/index.js",
"build": "next build",
"start": "next start",
"lint": "eslint .",
"clean": "next clean"
},
"dependencies": {
"@google/genai": "^2.4.0",
"@hookform/resolvers": "^5.2.1",
"autoprefixer": "^10.4.21",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cors": "^2.8.6",
"express": "^5.3.0",
"json2csv": "^6.0.0-alpha.2",
"jsonwebtoken": "^9.0.3",
"lucide-react": "^0.553.0",
"motion": "^12.23.24",
"next": "^15.4.9",
"postcss": "^8.5.6",
"react": "^19.2.1",
"react-dom": "^19.2.1",
"socket.io": "^4.8.4",
"socket.io-client": "^4.8.4",
"tailwind-merge": "^3.3.1"
},
"devDependencies": {
"@tailwindcss/postcss": "4.1.11",
"@tailwindcss/typography": "^0.5.19",
"@types/cors": "^2.8.19",
"@types/express": "^5.0.6",
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "9.39.1",
"eslint-config-next": "16.0.8",
"firebase-tools": "^15.0.0",
"tailwindcss": "4.1.11",
"tw-animate-css": "^1.4.0",
"typescript": "5.9.3"
}
}
Loaded 100 of 139 files, more files were not shown because too many files have changed in this diff. Show more