liven 0.0.3

LIVEN is a fast, lightweight database built to capture, store, and stream data in real time.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
import {
  Server,
  HardDrive,
  CheckCircle2,
  Activity,
  Trash2,
  Zap,
  RefreshCw,
} from "lucide-react";
import { Metrics, ActivityLog } from "../types";
import { formatBytes, dbPort as defaultDbPort } from "../utils/api";
import TelemetryChart from "../components/TelemetryChart";

export interface DashboardProps {
  metrics: Metrics;
  streams: string[];
  wsConnected: boolean;
  activities: ActivityLog[];
  setActivities: React.Dispatch<React.SetStateAction<ActivityLog[]>>;
  ingestChart: number[];
  queryChart: number[];
  activityFilter: "all" | "storage" | "query" | "stream" | "server";
  setActivityFilter: (
    filter: "all" | "storage" | "query" | "stream" | "server",
  ) => void;
  dbPort?: string;
  webuiPort?: string;
  resolvedTheme: "light" | "dark";
}

export default function Dashboard({
  metrics,
  streams,
  wsConnected,
  activities,
  setActivities,
  ingestChart,
  queryChart,
  activityFilter,
  setActivityFilter,
  dbPort = defaultDbPort,
  webuiPort,
  resolvedTheme,
}: DashboardProps) {
  return (
    <div className="space-y-8">
      {/* SERVER HOST AND PORT ENDPOINT INFO */}
      <div className="bg-white dark:bg-zinc-900 p-4 rounded-md flex flex-wrap items-center justify-between gap-4 transition-all">
        <div className="flex items-center gap-3">
          <div className="w-8 h-8 rounded bg-zinc-100 dark:bg-zinc-900 flex items-center justify-center text-zinc-500 dark:text-zinc-400 shrink-0">
            <Server className="w-4 h-4" />
          </div>
          <div>
            <h4 className="font-semibold text-zinc-900 dark:text-zinc-100 text-sm tracking-wide">
              LIVEN Active Instance
            </h4>
          </div>
        </div>

        <div className="flex flex-wrap items-center gap-3 text-xs">
          <div className="flex items-center gap-2 px-3 py-1.5 rounded bg-zinc-50 dark:bg-zinc-900/60 border border-zinc-500/10 font-mono">
            <span className="text-zinc-400 font-medium  tracking-wider text-[9px]">
              Host
            </span>
            <span className="text-zinc-850 dark:text-zinc-250 font-semibold">
              {window.location.hostname || "127.0.0.1"}
            </span>
          </div>

          <div className="flex items-center gap-2 px-3 py-1.5 rounded bg-zinc-50 dark:bg-zinc-900/60 border border-zinc-500/10 font-mono">
            <span className="text-zinc-400 font-medium  tracking-wider text-[9px]">
              DB Port
            </span>
            <span className="text-zinc-850 dark:text-zinc-250 font-semibold">
              {dbPort}
            </span>
          </div>

          <div className="flex items-center gap-2 px-3 py-1.5 rounded bg-zinc-50 dark:bg-zinc-900/60 border border-zinc-500/10 font-mono">
            <span className="text-zinc-400 font-medium  tracking-wider text-[9px]">
              WEB UI Port
            </span>
            <span className="text-zinc-850 dark:text-zinc-250 font-semibold">
              {webuiPort || window.location.port || "43120"}
            </span>
          </div>
        </div>
      </div>

      {/* TOP METRICS GLASS CARDS */}
      <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
        {/* Metric 1 */}
        <div className="bg-white dark:bg-zinc-900 text-card-foreground rounded-xl shadow-[0_1px_3px_rgba(0,0,0,0.04)] p-5 border-0 relative overflow-hidden group">
          <span className="text-[10px] font-semibold tracking-wider text-zinc-400  block mb-1">
            Database Size
          </span>
          <h3 className="text-2xl font-semibold tracking-tight text-zinc-900 dark:text-zinc-50">
            {formatBytes(metrics.disk_size)}
          </h3>
          <p className="text-[11px] text-primary mt-2 font-mono tabular-nums">
            RAM Usage:{" "}
            <span className="font-semibold text-zinc-700 dark:text-zinc-300">
              {(metrics.ram_usage / (1024 * 1024)).toFixed(2)} MB
            </span>
          </p>
        </div>

        {/* Metric 2 */}
        <div className="bg-white dark:bg-zinc-900 text-card-foreground rounded-xl shadow-[0_1px_3px_rgba(0,0,0,0.04)] p-5 border-0 relative overflow-hidden group">
          <span className="text-[10px] font-semibold tracking-wider text-zinc-400  block mb-1">
            Total Active Streams
          </span>
          <h3 className="text-2xl font-semibold tracking-tight text-zinc-900 dark:text-zinc-50">
            {metrics.total_streams || streams.length}
          </h3>
          <p className="text-[11px] text-primary mt-2 font-medium">
            Discoverable database streams
          </p>
        </div>

        {/* Metric 3 */}
        <div className="bg-white dark:bg-zinc-900 text-card-foreground rounded-xl shadow-[0_1px_3px_rgba(0,0,0,0.04)] p-5 border-0 relative overflow-hidden group">
          <span className="text-[10px] font-semibold tracking-wider text-zinc-400  block mb-1">
            Total Active Keys
          </span>
          <h3 className="text-2xl font-semibold tracking-tight text-zinc-900 dark:text-zinc-50">
            {metrics.key_count.toLocaleString()}
          </h3>
          <p className="text-[11px] text-primary mt-2 font-medium">
            In-Memory SkipMap Index
          </p>
        </div>

        {/* Metric 4 */}
        <div className="bg-white dark:bg-zinc-900 text-card-foreground rounded-xl shadow-[0_1px_3px_rgba(0,0,0,0.04)] p-5 border-0 relative overflow-hidden group">
          <span className="text-[10px] font-semibold tracking-wider text-zinc-400  block mb-1">
            Compacted Engine State
          </span>
          <div className="flex items-center gap-2">
            <span className="h-2 w-2 rounded-full bg-accent animate-pulse shadow-glow" />
            <span className="text-2xl font-bold tracking-tight text-foreground">
              Healthy
            </span>
          </div>
          <p className="text-[11px] text-accent mt-2 font-medium">
            Background thread online
          </p>
        </div>
      </div>

      {/* GRAPHS TELEMETRY PANEL */}
      <TelemetryChart
        readsData={queryChart}
        writesData={ingestChart}
        resolvedTheme={resolvedTheme}
        title="Performance"
        description="Live data throughput"
      />

      {/* VIVO LIVE ACTIVITIES AUDIT LOG */}
      <div className="bg-white dark:bg-zinc-900 p-6 rounded-md space-y-4">
        <div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
          <div className="flex items-center gap-3">
            <div className="w-8 h-8 rounded bg-zinc-100 dark:bg-zinc-900 flex items-center justify-center text-zinc-500 dark:text-zinc-400">
              <Activity className="w-4 h-4" />
            </div>
            <div>
              <h4 className="font-semibold text-zinc-900 dark:text-zinc-100 text-sm flex items-center gap-2">
                Audit Trail
              </h4>
            </div>
          </div>

          <div className="flex items-center gap-2">
            <button
              onClick={() => setActivities([])}
              className="px-3 py-1.5 rounded border border-zinc-500/10 hover:bg-zinc-100 dark:hover:bg-zinc-900 text-zinc-500 dark:text-zinc-400 hover:text-zinc-800 dark:hover:text-zinc-200 text-xs font-semibold flex items-center gap-1.5 transition-colors"
              title="Clear activity log history"
            >
              <Trash2 className="w-3.5 h-3.5" />
              Clear Logs
            </button>
          </div>
        </div>

        {/* Filters Row */}
        <div className="flex flex-wrap gap-1.5 border-b border-zinc-900/5 dark:border-zinc-100/5 pb-3">
          {(["all", "storage", "query", "stream", "server"] as const).map(
            (cat) => {
              const count =
                cat === "all"
                  ? activities.length
                  : activities.filter((a) => a.category === cat).length;

              const isActive = activityFilter === cat;
              return (
                <button
                  key={cat}
                  onClick={() => setActivityFilter(cat)}
                  className={`px-2.5 py-1 rounded text-xs font-medium capitalize transition-colors ${
                    isActive
                      ? "bg-zinc-900 dark:bg-zinc-100 text-white dark:text-zinc-950"
                      : "bg-zinc-100 hover:bg-zinc-200 dark:bg-zinc-900 dark:hover:bg-zinc-800 text-zinc-500 dark:text-zinc-400"
                  }`}
                >
                  {cat === "all" ? "All Events" : cat}
                  <span
                    className={`ml-1.5 px-1.5 py-0.5 rounded-full text-[10px] font-mono font-medium ${
                      isActive
                        ? "bg-white/20 dark:bg-black/10 text-white dark:text-zinc-950"
                        : "bg-zinc-200 dark:bg-zinc-800 text-zinc-650 dark:text-zinc-350"
                    }`}
                  >
                    {count}
                  </span>
                </button>
              );
            },
          )}
        </div>

        {/* Audit items list */}
        <div className="max-h-72 overflow-y-auto pr-1 space-y-2.5 font-mono text-[11px] leading-relaxed">
          {activities.filter(
            (a) => activityFilter === "all" || a.category === activityFilter,
          ).length === 0 ? (
            <div className="p-10 text-center text-zinc-400 dark:text-zinc-500 font-medium">
              No active logs trace found matching category &quot;
              {activityFilter}&quot;. Perform queries or insert records to
              trigger activity events.
            </div>
          ) : (
            activities
              .filter(
                (a) =>
                  activityFilter === "all" || a.category === activityFilter,
              )
              .map((act) => {
                let levelText =
                  "text-zinc-500 dark:text-zinc-400 font-mono text-[10px]";
                if (act.type === "success") {
                  levelText = "text-accent font-mono text-[10px]";
                } else if (act.type === "warn") {
                  levelText =
                    "text-amber-500 dark:text-amber-400 font-mono text-[10px]";
                } else if (act.type === "error") {
                  levelText =
                    "text-rose-500 dark:text-rose-400 font-mono text-[10px]";
                }

                const categoryBadge =
                  "bg-zinc-100 dark:bg-zinc-900 text-zinc-500 dark:text-zinc-400 border border-zinc-500/10 font-mono text-[9px] tracking-wider px-2 py-0.5 rounded";

                return (
                  <div
                    key={act.id}
                    className="p-3 rounded bg-zinc-50/30 dark:bg-zinc-900/10 flex items-start gap-4 transition-all duration-200 hover:bg-zinc-100/30 dark:hover:bg-zinc-900/30 border border-zinc-900/[0.02] dark:border-zinc-100/[0.02]"
                  >
                    <span className="text-zinc-400 dark:text-zinc-600 font-medium shrink-0">
                      [{act.timestamp}]
                    </span>

                    <span className={` shrink-0 ${categoryBadge}`}>
                      {act.category}
                    </span>

                    <div className="flex-1 text-zinc-700 dark:text-zinc-300 break-all">
                      {act.message}
                    </div>

                    <span className={` shrink-0 ${levelText}`}>{act.type}</span>
                  </div>
                );
              })
          )}
        </div>
      </div>

      {/* LOG COMPACTION & SYSTEM SPECS */}
      <div className="grid grid-cols-1 md:grid-cols-1 gap-6">
        {/* System specs */}
        <div className="bg-white dark:bg-zinc-900 p-6 rounded-md md:col-span-2">
          <h4 className="font-semibold text-zinc-900 dark:text-zinc-100 mb-4">
            System Status
          </h4>
          <div>
            <div className="grid grid-cols-2 lg:grid-cols-4 gap-3 mb-4 bg-zinc-50/50 dark:bg-zinc-900/40 p-3 rounded border border-zinc-500/5 text-xs font-mono">
              <div>
                <span className="block text-[10px] text-zinc-400 font-medium  tracking-wider">
                  Segments
                </span>
                <span className="font-semibold text-zinc-800 dark:text-zinc-200">
                  {metrics ? metrics.segments : "0"}
                </span>
              </div>
              <div>
                <span className="block text-[10px] text-zinc-400 font-medium  tracking-wider">
                  Storage
                </span>
                <span className="font-semibold text-zinc-800 dark:text-zinc-200">
                  {metrics ? formatBytes(metrics.disk_size) : "0 B"}
                </span>
              </div>
              <div>
                <span className="block text-[10px] text-zinc-400 font-medium  tracking-wider">
                  Seq ID
                </span>
                <span className="font-semibold text-zinc-800 dark:text-zinc-200">
                  #
                  {metrics
                    ? metrics.sequence_id > 0
                      ? metrics.sequence_id - 1
                      : 0
                    : "0"}
                </span>
              </div>
              <div>
                <span className="block text-[10px] text-zinc-400 font-medium  tracking-wider">
                  Compaction
                </span>
                <div className="flex items-center gap-1.5 text-xs font-mono font-medium text-zinc-650 dark:text-zinc-350  px-2 py-0.5 rounded w-fit">
                  <span
                    className={`w-1.5 h-1.5 rounded-full ${wsConnected ? "bg-accent animate-pulse" : "bg-rose-500"}`}
                  />
                  <span>
                    {wsConnected ? "Auto Compaction: ACTIVE" : "Offline"}
                  </span>
                </div>
              </div>
            </div>
          </div>
          <div className="grid grid-cols-1 sm:grid-cols-4 gap-4">
            {/* Card 1: Concurrency */}
            <div className="p-4 rounded bg-zinc-50/30 dark:bg-[#121214]/30 border border-zinc-500/5 flex flex-col justify-between space-y-3">
              <div className="flex items-start gap-3">
                <div className="p-2 rounded bg-zinc-100 dark:bg-zinc-800/80 text-zinc-600 dark:text-zinc-400 shrink-0">
                  <Zap className="w-4 h-4" />
                </div>
                <div>
                  <span className="text-xs font-semibold text-zinc-900 dark:text-zinc-100">
                    Concurrency Architecture
                  </span>
                  <p className="text-[11px] text-zinc-400 dark:text-zinc-500 mt-0.5">
                    crossbeam_skiplist index provider
                  </p>
                </div>
              </div>
              <div className="flex items-center gap-1.5 text-xs font-mono font-medium text-zinc-650 dark:text-zinc-350 bg-zinc-150/30 dark:bg-zinc-800/20 px-2 py-0.5 rounded border border-zinc-500/10 w-fit">
                <span className="w-1.5 h-1.5 rounded-full bg-accent animate-pulse" />
                <span>
                  {metrics ? metrics.key_count.toLocaleString() : "0"} indexed
                  keys
                </span>
              </div>
            </div>

            {/* Card 2: Integrity Checking */}
            <div className="p-4 rounded bg-zinc-50/30 dark:bg-[#121214]/30 border border-zinc-500/5 flex flex-col justify-between space-y-3">
              <div className="flex items-start gap-3">
                <div className="p-2 rounded bg-zinc-100 dark:bg-zinc-800/80 text-zinc-600 dark:text-zinc-400 shrink-0">
                  <CheckCircle2 className="w-4 h-4" />
                </div>
                <div>
                  <span className="text-xs font-semibold text-zinc-900 dark:text-zinc-100">
                    Integrity Checking
                  </span>
                  <p className="text-[11px] text-zinc-400 dark:text-zinc-500 mt-0.5">
                    Checksum status: Active & Verifying
                  </p>
                </div>
              </div>
              <div className="flex items-center gap-1.5 text-xs font-mono font-medium text-zinc-650 dark:text-zinc-350 bg-zinc-150/30 dark:bg-zinc-800/20 px-2 py-0.5 rounded border border-zinc-500/10 w-fit">
                <span
                  className={`w-1.5 h-1.5 rounded-full ${wsConnected ? "bg-accent animate-pulse" : "bg-rose-500"}`}
                />
                <span>{wsConnected ? "100% Integrity Guard" : "Offline"}</span>
              </div>
            </div>

            {/* Card 3: File Locking */}
            <div className="p-4 rounded bg-zinc-50/30 dark:bg-[#121214]/30 border border-zinc-500/5 flex flex-col justify-between space-y-3">
              <div className="flex items-start gap-3">
                <div className="p-2 rounded bg-zinc-100 dark:bg-zinc-800/80 text-zinc-600 dark:text-zinc-400 shrink-0">
                  <HardDrive className="w-4 h-4" />
                </div>
                <div>
                  <span className="text-xs font-semibold text-zinc-900 dark:text-zinc-100">
                    Cooperative Locking
                  </span>
                  <p className="text-[11px] text-zinc-400 dark:text-zinc-500 mt-0.5">
                    Exclusive Directory Lock via fs2
                  </p>
                </div>
              </div>
              <div className="flex items-center gap-1.5 text-xs font-mono font-medium text-zinc-650 dark:text-zinc-350 bg-zinc-150/30 dark:bg-zinc-800/20 px-2 py-0.5 rounded border border-zinc-500/10 w-fit">
                <span
                  className={`w-1.5 h-1.5 rounded-full ${wsConnected ? "bg-accent animate-pulse" : "bg-rose-500"}`}
                />
                <span>{wsConnected ? "Segment Lock: ACTIVE" : "Offline"}</span>
              </div>
            </div>

            {/* Card 4: Flushing */}
            <div className="p-4 rounded bg-zinc-50/30 dark:bg-[#121214]/30 border border-zinc-500/5 flex flex-col justify-between space-y-3">
              <div className="flex items-start gap-3">
                <div className="p-2 rounded bg-zinc-100 dark:bg-zinc-800/80 text-zinc-600 dark:text-zinc-400 shrink-0">
                  <RefreshCw className="w-4 h-4" />
                </div>
                <div>
                  <span className="text-xs font-semibold text-zinc-900 dark:text-zinc-100">
                    Flushing Mechanism
                  </span>
                  <p className="text-[11px] text-zinc-400 dark:text-zinc-500 mt-0.5">
                    I/O Sync Strategy: fdatasync
                  </p>
                </div>
              </div>
              <div className="flex items-center gap-1.5 text-xs font-mono font-medium text-zinc-650 dark:text-zinc-350 bg-zinc-150/30 dark:bg-zinc-800/20 px-2 py-0.5 rounded border border-zinc-500/10 w-fit">
                <span
                  className={`w-1.5 h-1.5 rounded-full ${wsConnected ? "bg-accent animate-pulse" : "bg-rose-500"}`}
                />
                <span>Sync: 0.24ms latency</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}