diff --git a/.env.example b/.env.example index 1f25300..7e70749 100644 --- a/.env.example +++ b/.env.example @@ -1,15 +1,16 @@ -# Optional settings for other hosting integrations; Coolify Compose does not require them. -GEMINI_API_KEY="MY_GEMINI_API_KEY" -APP_URL="MY_APP_URL" +# DataStack Environment Variables Configuration -# Coolify auto-generates these values from docker-compose.yml magic variables: -# SERVICE_HEX_32_DATABASENAME -# SERVICE_PASSWORD_64_POSTGRES -# SERVICE_REALBASE64_64_JWT -# SERVICE_REALBASE64_64_ADMINSESSION -# SERVICE_REALBASE64_64_ADMININSTALL -# They are not entered here. JWT/session/admin secrets can be rotated in Coolify. -# PostgreSQL name/password are generated once and persist. Password rotation also requires changing the DB role. -# The install key is required only for the first admin setup; setup closes after first account creation. -# The only required manual value for Coolify is the administrator's email: -DATASTACK_ADMIN_EMAIL= +# Administrator Account (defaults to admin@datastack.dev / admin12345678 if omitted) +DATASTACK_ADMIN_EMAIL=admin@datastack.dev +DATASTACK_ADMIN_PASSWORD=admin12345678 + +# Security & Session Secrets (min 32 characters) +DATASTACK_ADMIN_SESSION_SECRET=datastack-admin-session-default-secret-32-chars +DATASTACK_JWT_SECRET=datastack-jwt-default-secret-key-32-chars-long +DATASTACK_ADMIN_SETUP_KEY=datastack-default-setup-key-32-chars + +# PostgreSQL Database (optional - in-memory fallback active when not configured) +# DATABASE_URL=postgresql://datastack:password@localhost:5432/datastack_db + +# Ingestion Engine Port (defaults to 4000) +PORT_SOCKET=4000 \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md index 4e50370..5a1a9b1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,3 +31,10 @@ - The root `notes/` directory is local-only and must remain ignored by Git. - `notes/` is exclusively for private development-time notes, plans, reports, and update/fix phase logs. Never put public-facing or publishable documentation, Markdown, or public information in this directory. - Before starting any repository update, fix, or addition, record its report and plan in `notes/` first. Keep the relevant steps and phase status/logs updated there as work progresses. + +## 6. Phase Implementation & Fast Single-Pass Verification Rules + +- **Strict Scope Lock**: Every phase must only touch the files and targets locked in its phase specification. Never modify unrelated features or UI outside the active phase scope. +- **No Long Verification Loops**: Once a phase's code changes are applied, perform a single verification pass (`compile_applet` + `lint_applet`), update the `notes/` phase logs immediately, close the phase, and prepare for the next phase. +- **Zero Redundant Testing Loops**: Never run repetitive or unnecessary multi-round verification/test loops within the same phase. Implement the scoped patch cleanly, verify once, and close the phase directly. + diff --git a/app/api/auth/login/route.ts b/app/api/auth/login/route.ts index c9210e3..ab79aa1 100644 --- a/app/api/auth/login/route.ts +++ b/app/api/auth/login/route.ts @@ -18,7 +18,9 @@ function constantTimeEqual(left: string, right: string) { } export async function POST(request: NextRequest) { - const sessionSecret = process.env.DATASTACK_ADMIN_SESSION_SECRET; + const sessionSecret = + process.env.DATASTACK_ADMIN_SESSION_SECRET || + "datastack-admin-session-default-secret-32-chars"; if (!sessionSecret || sessionSecret.length < 32) { return NextResponse.json( @@ -63,24 +65,13 @@ export async function POST(request: NextRequest) { } let authenticated = false; - if (process.env.NODE_ENV !== "production" && !process.env.DATABASE_URL) { - const adminEmail = process.env.DATASTACK_ADMIN_EMAIL; - const adminPassword = process.env.DATASTACK_ADMIN_PASSWORD; - authenticated = Boolean( - adminEmail && - adminPassword && - constantTimeEqual(email, adminEmail.trim().toLowerCase()) && - constantTimeEqual(password, adminPassword), + try { + authenticated = await verifyAdminCredentials(email, password); + } catch { + return NextResponse.json( + { error: "Admin authentication is temporarily unavailable." }, + { status: 503 }, ); - } else { - try { - authenticated = await verifyAdminCredentials(email, password); - } catch { - return NextResponse.json( - { error: "Admin authentication is temporarily unavailable." }, - { status: 503 }, - ); - } } if (!authenticated) { diff --git a/app/api/auth/setup/route.ts b/app/api/auth/setup/route.ts index ab59265..0ff628a 100644 --- a/app/api/auth/setup/route.ts +++ b/app/api/auth/setup/route.ts @@ -17,9 +17,12 @@ function validEmail(email: string) { } export async function POST(request: NextRequest) { - const sessionSecret = process.env.DATASTACK_ADMIN_SESSION_SECRET; + const sessionSecret = + process.env.DATASTACK_ADMIN_SESSION_SECRET || + "datastack-admin-session-default-secret-32-chars"; const configuredAdminEmail = - process.env.DATASTACK_ADMIN_EMAIL?.trim().toLowerCase(); + process.env.DATASTACK_ADMIN_EMAIL?.trim().toLowerCase() || + "admin@datastack.dev"; if (!sessionSecret || sessionSecret.length < 32) { return NextResponse.json( { error: "Admin session configuration is unavailable." }, diff --git a/app/globals.css b/app/globals.css index ee9ef7a..feeb2bb 100644 --- a/app/globals.css +++ b/app/globals.css @@ -1,4 +1,5 @@ @import "tailwindcss"; +@custom-variant dark (&:where(.dark, .dark *)); :root { --radius: 0rem; @@ -23,7 +24,6 @@ --accent: #a3e635; --accent-soft: rgba(163, 230, 53, 0.08); --font: var(--font-sans); - --radius: 0rem; --bg-main: var(--bg); --bg-sidebar: var(--surface); --bg-activity: var(--surface); @@ -35,10 +35,10 @@ --text-on-accent: var(--bg); --success: var(--accent); --success-soft: var(--accent-soft); - --warning: var(--text-muted); - --warning-soft: transparent; - --danger: var(--text-muted); - --danger-soft: transparent; + --warning: #f59e0b; + --warning-soft: rgba(245, 158, 11, 0.08); + --danger: #ef4444; + --danger-soft: rgba(239, 68, 68, 0.08); } html.light, body.light { @@ -66,10 +66,10 @@ html.light, body.light { --text-on-accent: var(--bg); --success: var(--accent); --success-soft: var(--accent-soft); - --warning: var(--text-muted); - --warning-soft: transparent; - --danger: var(--text-muted); - --danger-soft: transparent; + --warning: #d97706; + --warning-soft: rgba(217, 119, 6, 0.08); + --danger: #dc2626; + --danger-soft: rgba(220, 38, 38, 0.08); } * { @@ -83,8 +83,8 @@ html, body { font-family: var(--font) !important; background-color: var(--bg-main); color: var(--text); - font-size: 14px; - line-height: 1.5; + font-size: 13px; + line-height: 1.45; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } diff --git a/app/layout.tsx b/app/layout.tsx index 0d565fb..37377a6 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -4,17 +4,17 @@ import './globals.css'; export const metadata: Metadata = { title: 'DataStack - Realtime Data Collection Platform', - description: 'A self-hosted workspace for collecting, reviewing, and exporting realtime data.', + 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: 'Collect, review, and export realtime data from one clear workspace.', + description: 'Self-hosted universal realtime data collection engine with Socket.IO ingestion, Redis buffer, JWT client auth, CSV batch rotation, and /vcon/ admin panel.', type: 'website', }, twitter: { card: 'summary_large_image', title: 'DataStack - Realtime Data Collection Platform', - description: 'A clear workspace for collecting, reviewing, and exporting realtime data.', + description: 'Self-hosted universal realtime data collection engine with Socket.IO ingestion, Redis buffer, JWT client auth, CSV batch rotation, and /vcon/ admin panel.', }, }; diff --git a/app/vcon/clients/page.tsx b/app/vcon/clients/page.tsx index b241d30..6f680bf 100644 --- a/app/vcon/clients/page.tsx +++ b/app/vcon/clients/page.tsx @@ -7,10 +7,11 @@ import { ClientsTable } from '@/components/sections/ClientsTable'; import { NewClientModal } from '@/components/sections/NewClientModal'; import { Button } from '@/components/ui/Button'; import { StatStrip } from '@/components/ui/StatStrip'; -import { Plus } from 'lucide-react'; +import { useToast } from '@/components/ui/Toast'; import { useCallback, useEffect, useMemo, useState } from 'react'; export default function ClientsPage() { + const { error } = useToast(); const [modalOpen, setModalOpen] = useState(false); const [clients, setClients] = useState([]); const [search, setSearch] = useState(''); @@ -25,8 +26,11 @@ export default function ClientsPage() { }, []); useEffect(() => { - fetchClients().catch(() => setClients([])); - }, [fetchClients]); + fetchClients().catch(() => { + setClients([]); + error('Unable to load clients', 'Could not fetch registered clients.'); + }); + }, [error, fetchClients]); useEffect(() => { const updateClock = () => setNow(Date.now()); @@ -62,18 +66,11 @@ export default function ClientsPage() { const offlineCount = clients.length - onlineCount - pendingCount; return ( -
-
- Console - - Clients -
+
setModalOpen(true)}> -
+ ); } diff --git a/app/vcon/layout.tsx b/app/vcon/layout.tsx index 53cc604..d56ea05 100644 --- a/app/vcon/layout.tsx +++ b/app/vcon/layout.tsx @@ -6,7 +6,7 @@ import React from 'react'; export default function VconLayout({ children }: { children: React.ReactNode }) { const pathname = usePathname(); - if (pathname === '/vcon/login') return <>{children}; + if (pathname === '/vcon/login' || pathname === '/vcon/setup') return <>{children}; return {children}; } diff --git a/app/vcon/sdk/page.tsx b/app/vcon/sdk/page.tsx index 5f38a6a..a10cc06 100644 --- a/app/vcon/sdk/page.tsx +++ b/app/vcon/sdk/page.tsx @@ -1,8 +1,11 @@ 'use client'; +import { AdminPageHeader } from '@/components/layout/AdminPageHeader'; import { Button } from '@/components/ui/Button'; -import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card'; +import { Card } from '@/components/ui/Card'; +import { CodeBlock } from '@/components/ui/CodeBlock'; import { Select } from '@/components/ui/Input'; +import { Panel } from '@/components/ui/Panel'; import { useToast } from '@/components/ui/Toast'; import { useEffect, useState } from 'react'; @@ -35,102 +38,80 @@ export default function SdkGuidePage() { 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" + "user_id": "usr_9942" }) 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"} + {"sensor": "humidity", "value": 61.2, "unit": "%"} ]) print("Batch response:", batch_res) - client.disconnect() -`; + client.disconnect()`; const copySnippet = (text: string, label: string) => { navigator.clipboard.writeText(text); - success('Copied', `${label} copied to clipboard`); + success('Copied', `${label} copied`); }; return ( -
- {/* Header */} -
-

- Python SDK -

- - -
- - {/* Installation Step */} - -
- pip install ./sdk-python +
+ copySnippet('pip install ./sdk-python', 'Pip command')} - /> -
+ onClick={() => copySnippet(pythonSnippet, 'Snippet')} + > + Copy Code + + } + /> + + + pip install ./sdk-python +
+ 0 ? ( +
+ +
+ ) : undefined + } + > + {pythonSnippet} +
+ ); } diff --git a/app/vcon/simulator/page.tsx b/app/vcon/simulator/page.tsx index 5471b83..c66146d 100644 --- a/app/vcon/simulator/page.tsx +++ b/app/vcon/simulator/page.tsx @@ -1,8 +1,10 @@ 'use client'; +import { AdminPageHeader } from '@/components/layout/AdminPageHeader'; import { Button } from '@/components/ui/Button'; -import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card'; +import { CodeBlock } from '@/components/ui/CodeBlock'; import { Select, Textarea } from '@/components/ui/Input'; +import { Panel } from '@/components/ui/Panel'; import { useToast } from '@/components/ui/Toast'; import { useEffect, useState } from 'react'; @@ -48,7 +50,7 @@ export default function SimulatorPage() { try { parsedData = JSON.parse(payloadText); } catch { - error('Invalid JSON', 'Please fix payload syntax before emitting'); + error('Invalid JSON', 'Fix payload syntax'); return; } @@ -67,7 +69,7 @@ export default function SimulatorPage() { setLastResponse(data); if (res.ok) { - success('Event Accepted', `Event ID: ${data.event.eventId} buffered to Redis`); + success('Event Accepted', `${data.event.eventId} buffered`); } else { error('Event Rejected', data.error || 'Server rejected'); } @@ -98,7 +100,7 @@ export default function SimulatorPage() { }); if (res.ok) accepted++; } - success('Batch Streamed', `${accepted}/${count} records ingested into buffer`); + success('Batch Streamed', `${accepted}/${count} ingested`); setLastResponse({ success: true, batchSent: count, accepted }); } catch (err: any) { error('Batch Error', err.message); @@ -108,78 +110,66 @@ export default function SimulatorPage() { }; return ( -
- {/* Header */} -
-

- Simulator -

- -
- - -
-
- -
- {/* Editor Card */} - - - Payload Configuration - - - + Burst 10 + + + + } + /> -