Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 | 1x 1x 1x 1x 1x 1x 122x 122x 122x 122x 61x 219x 192x 192x 192x 192x 61x 61x 61x 61x 1x 131x 131x 131x 131x 176x 176x 132x 132x 132x 132x 88x 88x 88x 88x 2x 43x 44x 42x 84x 42x 42x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 2x 2x 2x 2x 1x 1x 134x 134x 134x 134x 134x 134x 134x 134x 134x 670x 1876x 1x 1x 1x 1x 1x 1x 1x 1x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 59x 59x 59x 15x 15x 15x 15x 15x 15x 61x 61x 61x 61x 61x 15x 44x 42x 41x 41x 41x 41x 41x 80x 41x 162x 162x 154x 8x 8x 41x 1x 58x 58x 160x 58x 58x 160x 59x 58x 58x 160x 73x 73x 160x 160x 160x 160x 160x 73x 160x 160x 160x 15x 1x 1x 1x 134x 136x 30x 120x 120x 45x 45x 45x 61x | "use client";
import { fetchApi } from "@/lib/api";
import { ComponentActions } from "@/components/ComponentActions";
import { COMPONENT_INFO, type ComponentMeta } from "@/lib/edc/component-info";
import {
AZURE_EGRESS_FREE_GIB,
AZURE_EGRESS_USD_PER_GIB,
AZURE_FILES_USD_PER_GIB,
costForEnvironment,
formatEur,
formatUsd,
USD_TO_EUR,
type AcaAppSpec,
} from "@/lib/azure-pricing";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import {
Activity,
AlertTriangle,
BarChart2,
ChevronDown,
ChevronRight,
Cpu,
HardDrive,
Info,
Loader2,
Network,
RefreshCw,
Server,
Shield,
Users,
Workflow,
X,
} from "lucide-react";
// ---------------------------------------------------------------------------
// Types — Layer view (existing API)
// ---------------------------------------------------------------------------
interface MemInfo {
usedMB: number;
limitMB: number;
percent: number;
}
interface ComponentInfo {
container: string;
component: string;
layer: string;
status: "healthy" | "unhealthy" | "running" | "stopped" | "unknown";
uptime: string;
cpu: number;
mem: MemInfo;
}
interface ParticipantInfo {
id: string;
displayName: string;
organization: string;
role: string;
did: string;
state: string;
profileCount: number;
}
interface Snapshot {
timestamp: string;
dockerAvailable: boolean;
metricsSource?: "docker" | "azure-monitor" | "none";
// Set to "azure" when the API server detects DEPLOYMENT_TARGET=azure.
// This drives the Azure-vs-StackIT cost panel choice independently of
// whether the live metrics call succeeded.
deploymentTarget?: "azure" | "docker" | "stackit" | "unknown";
components: ComponentInfo[];
participants: ParticipantInfo[];
}
interface HistoryEntry {
ts: number;
cpu: number;
mem: number;
}
interface PeakEntry {
maxCpu: number;
maxMemMB: number;
since: number;
}
// ---------------------------------------------------------------------------
// Types — Topology view (new API)
// ---------------------------------------------------------------------------
type Severity = "critical" | "warning" | "healthy" | "unknown";
interface TopoComponent {
name: string;
container: string;
status: string;
severity: Severity;
cpu: number;
memMB: number;
uptime: string;
}
interface TopoParticipant {
id: string;
displayName: string;
organization: string;
role: string;
did: string;
state: string;
health: Severity;
components: TopoComponent[];
}
interface InfraComponent extends TopoComponent {
layer: string;
}
interface TopologyData {
timestamp: string;
dockerAvailable: boolean;
// True when per-participant CPU/MEM values represent a participant's
// share of shared infrastructure (ACA case), not an independent
// per-container reservation. Drives the "shared" annotation.
metricsShared?: boolean;
participants: TopoParticipant[];
infrastructure: InfraComponent[];
summary: {
totalParticipants: number;
degradedParticipants: number;
totalInfra: number;
};
clusterMetrics?: {
currentCpu: number;
currentMemMB: number;
last24h: { peakCpu: number; peakMemMB: number; samples: number };
prev24h: { peakCpu: number; peakMemMB: number; samples: number };
};
}
type ViewMode = "layer" | "participant";
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
const REFRESH_INTERVAL = 30_000;
const MAX_HISTORY = 2880;
const LAYER_META: Record<
string,
{ label: string; icon: React.ComponentType<any>; color: string }
> = {
"edc-core": {
label: "EDC-V Core",
icon: Server,
color: "text-[var(--accent)]",
},
identity: {
label: "Identity & Trust",
icon: Shield,
color: "text-[var(--accent)]",
},
cfm: {
label: "Connector Fabric Manager",
icon: Workflow,
color: "text-[var(--success-text)]",
},
infrastructure: {
label: "Infrastructure",
icon: HardDrive,
color: "text-[var(--warning-text)]",
},
};
const STATUS_COLORS: Record<string, string> = {
healthy: "bg-emerald-500",
running: "bg-blue-500",
unhealthy: "bg-red-500",
stopped: "bg-gray-600",
unknown: "bg-gray-500",
};
const SEVERITY_STYLES: Record<
Severity,
{ dot: string; border: string; bg: string }
> = {
critical: {
dot: "bg-red-500 animate-pulse",
border: "border-red-500/60",
bg: "bg-red-900/10",
},
warning: {
dot: "bg-yellow-500",
border: "border-yellow-500/40",
bg: "bg-yellow-900/10",
},
healthy: {
dot: "bg-emerald-500",
border: "border-[var(--border)]",
bg: "",
},
unknown: {
dot: "bg-gray-500",
border: "border-[var(--border)]",
bg: "",
},
};
const ROLE_COLORS: Record<string, string> = {
DATA_HOLDER: "bg-blue-500/20 text-[var(--accent)]",
DATA_USER: "bg-[var(--badge-active-bg)] text-[var(--badge-active-text)]",
HDAB: "bg-purple-500/20 text-[var(--accent)]",
"health-data-access-body": "bg-purple-500/20 text-[var(--accent)]",
"data-holder": "bg-blue-500/20 text-[var(--accent)]",
"data-user": "bg-[var(--badge-active-bg)] text-[var(--badge-active-text)]",
};
// ---------------------------------------------------------------------------
// Sparkline SVG
// ---------------------------------------------------------------------------
function Sparkline({
data,
max,
color,
width = 80,
height = 24,
}: {
data: number[];
max: number;
color: string;
width?: number;
height?: number;
}) {
Eif (data.length < 2)
return (
<span className="text-[10px] text-[var(--text-secondary)]">
collecting…
</span>
);
const effectiveMax = max > 0 ? max : 1;
const points = data.map((v, i) => {
const x = (i / (data.length - 1)) * width;
const y =
height - (Math.min(v, effectiveMax) / effectiveMax) * (height - 2) - 1;
return `${x},${y}`;
});
return (
<svg width={width} height={height} className="inline-block">
<polyline
fill="none"
stroke={color}
strokeWidth="1.5"
strokeLinejoin="round"
points={points.join(" ")}
/>
</svg>
);
}
// ---------------------------------------------------------------------------
// Status badge
// ---------------------------------------------------------------------------
function StatusBadge({ status }: { status: string }) {
return (
<span className="flex items-center gap-1.5">
<span
className={`w-2 h-2 rounded-full ${
STATUS_COLORS[status] || STATUS_COLORS.unknown
}`}
/>
<span className="text-xs capitalize">{status}</span>
</span>
);
}
// ---------------------------------------------------------------------------
// Severity dot
// ---------------------------------------------------------------------------
function SeverityDot({ severity }: { severity: Severity }) {
return (
<span
className={`w-2.5 h-2.5 rounded-full inline-block ${SEVERITY_STYLES[severity].dot}`}
title={severity}
/>
);
}
// ---------------------------------------------------------------------------
// Info Popover — ⓘ button that shows component metadata
// ---------------------------------------------------------------------------
function InfoPopover({ name }: { name: string }) {
const [open, setOpen] = useState(false);
const meta: ComponentMeta | undefined = COMPONENT_INFO[name];
Iif (!meta) return null;
return (
<span className="relative inline-block">
<button
onClick={(e) => {
e.stopPropagation();
setOpen(!open);
}}
className="text-[var(--text-secondary)] hover:text-teal-800 dark:hover:text-teal-300 transition-colors p-0.5"
title={`Info: ${name}`}
>
<Info size={13} />
</button>
{open && (
<>
{/* Backdrop */}
<div className="fixed inset-0 z-30" onClick={() => setOpen(false)} />
{/* Popover */}
<div className="absolute z-40 left-6 top-0 w-80 bg-[var(--surface-2)] border border-[var(--border-ui)] rounded-xl shadow-2xl p-4 text-xs space-y-2">
<div className="flex items-center justify-between mb-1">
<span className="font-semibold text-sm text-[var(--text-primary)]">
{name}
</span>
<button
onClick={() => setOpen(false)}
className="text-[var(--text-secondary)] hover:text-[var(--text-primary)]"
>
<X size={14} />
</button>
</div>
<p className="text-[var(--text-secondary)] leading-relaxed">
{meta.description}
</p>
<div className="grid grid-cols-[80px_1fr] gap-y-1.5 gap-x-2 pt-1 border-t border-[var(--border)]">
<span className="text-[var(--text-secondary)]">Protocol</span>
<span className="text-[var(--text-primary)]">
{meta.protocol}
</span>
<span className="text-[var(--text-secondary)]">Ports</span>
<span className="text-[var(--text-primary)] font-mono text-[11px]">
{meta.ports}
</span>
<span className="text-[var(--text-secondary)]">Depends on</span>
<span className="text-[var(--text-primary)]">
{meta.dependsOn.length > 0 ? meta.dependsOn.join(", ") : "None"}
</span>
<span className="text-[var(--text-secondary)]">Health</span>
<span className="text-[var(--text-primary)]">
{meta.healthSource}
</span>
</div>
</div>
</>
)}
</span>
);
}
// ---------------------------------------------------------------------------
// Component Row (Layer view)
// ---------------------------------------------------------------------------
function ComponentRow({
comp,
history,
}: {
comp: ComponentInfo;
history: HistoryEntry[];
}) {
const cpuData = history.map((h) => h.cpu);
const memData = history.map((h) => h.mem);
const maxCpu = Math.max(...cpuData, 1);
return (
<tr className="border-b border-[var(--border)] hover:bg-[var(--surface-2)]/40 transition-colors">
<td className="py-2.5 px-3 text-sm font-medium text-[var(--text-primary)]">
<span className="flex items-center gap-1.5">
{comp.component}
<InfoPopover name={comp.component} />
</span>
</td>
<td className="py-2.5 px-3">
<StatusBadge status={comp.status} />
</td>
<td className="py-2.5 px-3 text-xs text-[var(--text-secondary)] tabular-nums">
{comp.uptime}
</td>
<td className="py-2.5 px-3">
<div className="flex items-center gap-2">
<span className="text-xs tabular-nums text-[var(--text-primary)] w-12 text-right">
{comp.cpu.toFixed(1)}%
</span>
<Sparkline data={cpuData} max={maxCpu} color="#60a5fa" />
</div>
</td>
<td className="py-2.5 px-3">
<div className="flex items-center gap-2">
<span className="text-xs tabular-nums text-[var(--text-primary)] w-16 text-right">
{comp.mem.usedMB < 1 ? "<1" : Math.round(comp.mem.usedMB)} MB
</span>
<Sparkline
data={memData}
max={comp.mem.limitMB || 100}
color="#a78bfa"
/>
</div>
</td>
<td className="py-2.5 px-3 text-xs text-[var(--text-secondary)] tabular-nums">
{comp.mem.percent.toFixed(1)}%
</td>
</tr>
);
}
// ---------------------------------------------------------------------------
// Topology Component Card (Participant view)
// ---------------------------------------------------------------------------
// Hoisted out of AzureCostEstimatorPanel so TopoComponentCard can use it too.
// Kept in sync with the diagnosis catalogue at
// /api/admin/components/[name]/diagnosis.
const KNOWN_BROKEN_ACA_APPS = new Set<string>([
"mvhd-controlplane",
"mvhd-dp-fhir",
"mvhd-dp-omop",
"mvhd-identityhub",
"mvhd-issuerservice",
"mvhd-tenant-mgr",
"mvhd-provision-mgr",
]);
function TopoComponentCard({
comp,
metricsShared = false,
}: {
comp: TopoComponent;
// When true the same underlying ACA app serves every participant. The
// CPU/MEM numbers are real (the container's actual draw) but identical
// across rows; we render a small "shared" suffix so users understand
// why eight rows show the same value.
metricsShared?: boolean;
}) {
const sev = SEVERITY_STYLES[comp.severity];
const sharedTitle = metricsShared
? "Shared ACA container — same value applies to every participant. See Layer View for the cluster total."
: undefined;
const isBroken =
KNOWN_BROKEN_ACA_APPS.has(comp.container) ||
comp.severity === "critical" ||
comp.severity === "warning";
return (
<div
className={`border rounded-lg p-3 ${sev.border} ${sev.bg} transition-colors`}
>
<div className="flex items-center justify-between mb-1.5">
<span className="flex items-center gap-1.5 text-xs font-medium text-[var(--text-primary)]">
<SeverityDot severity={comp.severity} />
{comp.name}
<InfoPopover name={comp.name} />
</span>
<span className="text-[10px] text-[var(--text-secondary)] capitalize">
{comp.status}
{metricsShared && (
<span
className="ml-1 italic text-[9px] text-[var(--text-secondary)]"
title={sharedTitle}
>
· shared
</span>
)}
</span>
</div>
<div className="grid grid-cols-3 gap-1 text-[10px] text-[var(--text-secondary)]">
<span title={sharedTitle}>
<Cpu size={9} className="inline mr-0.5" />
{`${comp.cpu.toFixed(1)}%`}
</span>
<span title={sharedTitle}>
<HardDrive size={9} className="inline mr-0.5" />
{`${comp.memMB < 1 ? "<1" : Math.round(comp.memMB)} MB`}
</span>
<span className="text-right" title={sharedTitle}>
{comp.uptime}
</span>
</div>
<ComponentActions name={comp.container} isBroken={isBroken} />
</div>
);
}
// ---------------------------------------------------------------------------
// Participant Topology Section (expandable)
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Resource summary helper
// ---------------------------------------------------------------------------
function ResourceSummary({
components,
label,
metricsShared = false,
}: {
components: TopoComponent[];
peaks?: Map<string, PeakEntry>;
label?: string;
// When true the backend has zeroed per-participant CPU/MEM because
// those containers are shared on this deployment (Azure ACA). Render a
// "shared — see Layer View" marker instead of a meaningless 0.0%.
metricsShared?: boolean;
}) {
const totalCpu = components.reduce((s, c) => s + c.cpu, 0);
const totalMem = components.reduce((s, c) => s + c.memMB, 0);
const fmtMem = (mb: number) =>
mb > 1024 ? `${(mb / 1024).toFixed(1)} GB` : `${Math.round(mb)} MB`;
Iif (metricsShared) {
return (
<div className="flex items-center gap-2 text-xs text-[var(--text-secondary)] italic">
{label && <span className="mr-1">{label}</span>}
<span title="Containers are shared across all participants on this deployment — per-container CPU/MEM is shown in Layer View.">
shared infrastructure — see Layer View
</span>
</div>
);
}
return (
<div className="flex items-center gap-x-4 text-xs text-[var(--text-secondary)]">
{label && (
<span className="text-[var(--text-secondary)] mr-1">{label}</span>
)}
<span className="flex items-center gap-1 tabular-nums">
<Cpu size={10} className="text-[var(--accent)]" />
<span className="text-[var(--text-primary)] font-medium">
CPU {totalCpu.toFixed(1)}%
</span>
</span>
<span className="flex items-center gap-1 tabular-nums">
<HardDrive size={10} className="text-[var(--accent)]" />
<span className="text-[var(--text-primary)] font-medium">
MEM {fmtMem(totalMem)}
</span>
</span>
</div>
);
}
// ---------------------------------------------------------------------------
// Trend arrow — compares current window to previous window
// ---------------------------------------------------------------------------
function TrendArrow({
current,
previous,
hasPrevData,
}: {
current: number;
previous: number;
hasPrevData: boolean;
}) {
if (!hasPrevData)
return <span className="text-[var(--text-secondary)]">—</span>;
const delta = current - previous;
const pct =
previous > 0 ? Math.round((delta / previous) * 100) : delta > 0 ? 100 : 0;
if (Math.abs(pct) < 3) return <span title="Stable vs yesterday">→</span>;
if (delta > 0)
return (
<span
className="text-[var(--danger-text)]"
title={`+${pct}% vs yesterday`}
>
↑
</span>
);
return (
<span className="text-[var(--success-text)]" title={`${pct}% vs yesterday`}>
↓
</span>
);
}
// ---------------------------------------------------------------------------
// Cluster Resource Banner — 24h peaks with day-over-day trend
// ---------------------------------------------------------------------------
function ClusterResourceBanner({
metrics,
}: {
metrics: NonNullable<TopologyData["clusterMetrics"]>;
}) {
const fmtMem = (mb: number) =>
mb > 1024 ? `${(mb / 1024).toFixed(1)} GB` : `${Math.round(mb)} MB`;
const hasPrev = metrics.prev24h.samples > 0;
return (
<div className="flex flex-wrap items-center gap-x-6 gap-y-2 border border-[var(--border)] rounded-xl px-4 py-3 mb-6 bg-[var(--surface)]/40">
<div className="flex items-center gap-2 text-xs text-[var(--text-secondary)]">
<Activity
size={14}
className="text-teal-800 dark:text-teal-300 shrink-0"
/>
<span className="font-medium text-[var(--text-primary)]">Cluster</span>
</div>
{/* Current */}
<div className="flex items-center gap-1.5 text-xs">
<Cpu size={11} className="text-[var(--accent)]" />
<span className="text-[var(--text-primary)] tabular-nums">
{metrics.currentCpu.toFixed(1)}%
</span>
<span className="text-[var(--text-secondary)]">now</span>
</div>
<div className="flex items-center gap-1.5 text-xs">
<HardDrive size={11} className="text-[var(--accent)]" />
<span className="text-[var(--text-primary)] tabular-nums">
{fmtMem(metrics.currentMemMB)}
</span>
<span className="text-[var(--text-secondary)]">now</span>
</div>
<span className="text-[var(--text-secondary)]">│</span>
{/* 24h peaks */}
<div className="flex items-center gap-1 text-xs">
<TrendArrow
current={metrics.last24h.peakCpu}
previous={metrics.prev24h.peakCpu}
hasPrevData={hasPrev}
/>
<span className="text-[var(--accent)] tabular-nums font-medium">
CPU {metrics.last24h.peakCpu.toFixed(1)}%
</span>
<span className="text-[var(--text-secondary)]">peak 24h</span>
</div>
<div className="flex items-center gap-1 text-xs">
<TrendArrow
current={metrics.last24h.peakMemMB}
previous={metrics.prev24h.peakMemMB}
hasPrevData={hasPrev}
/>
<span className="text-[var(--accent)] tabular-nums font-medium">
MEM {fmtMem(metrics.last24h.peakMemMB)}
</span>
<span className="text-[var(--text-secondary)]">peak 24h</span>
</div>
{metrics.last24h.samples > 0 && (
<span
className="text-[10px] text-[var(--text-secondary)]"
title="Number of data points collected in the last 24h"
>
({metrics.last24h.samples} samples)
</span>
)}
</div>
);
}
function ParticipantTopologySection({
participant,
peaks,
metricsShared = false,
}: {
participant: TopoParticipant;
peaks: Map<string, PeakEntry>;
metricsShared?: boolean;
}) {
const [expanded, setExpanded] = useState(
participant.health === "critical" || participant.health === "warning",
);
const sev = SEVERITY_STYLES[participant.health];
const roleClass =
ROLE_COLORS[participant.role] ||
"bg-gray-500/20 text-[var(--text-secondary)]";
return (
<div
className={`border rounded-xl ${sev.border} ${sev.bg} overflow-hidden transition-all`}
>
{/* Header bar — click to expand/collapse */}
<button
onClick={() => setExpanded(!expanded)}
className="w-full flex items-center gap-3 px-4 py-3 text-left hover:bg-[var(--surface-2)]/40 transition-colors"
>
{expanded ? (
<ChevronDown
size={14}
className="text-[var(--text-secondary)] shrink-0"
/>
) : (
<ChevronRight
size={14}
className="text-[var(--text-secondary)] shrink-0"
/>
)}
<SeverityDot severity={participant.health} />
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 flex-wrap">
<span className="font-semibold text-sm text-[var(--text-primary)]">
{participant.displayName}
</span>
<span className="text-xs text-[var(--text-secondary)]">
{participant.organization}
</span>
</div>
<ResourceSummary
components={participant.components}
peaks={peaks}
metricsShared={metricsShared}
/>
</div>
<span
className={`text-[10px] font-medium px-2 py-0.5 rounded-full shrink-0 ${roleClass}`}
>
{participant.role}
</span>
<span className="text-[10px] text-[var(--text-secondary)] shrink-0">
{participant.components.length} services
</span>
</button>
{/* Expanded: DID + component grid */}
{expanded && (
<div className="px-4 pb-4 pt-1 border-t border-[var(--border)]/60">
<div className="flex items-center gap-4 text-[11px] text-[var(--text-secondary)] mb-3">
<span>
DID:{" "}
<span className="font-mono text-[var(--text-secondary)]">
{participant.did.length > 40
? participant.did.slice(0, 40) + "…"
: participant.did}
</span>
</span>
<span>
State:{" "}
<span
className={
participant.state === "CREATED"
? "text-[var(--success-text)]"
: "text-[var(--warning-text)]"
}
>
{participant.state}
</span>
</span>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-2">
{participant.components.map((c) => (
<TopoComponentCard
key={c.container}
comp={c}
metricsShared={metricsShared}
/>
))}
</div>
</div>
)}
</div>
);
}
// ---------------------------------------------------------------------------
// Critical Banner
// ---------------------------------------------------------------------------
function CriticalBanner({
degraded,
total,
participants,
}: {
degraded: number;
total: number;
participants: TopoParticipant[];
}) {
if (degraded === 0) return null;
const names = participants
.filter((p) => p.health === "critical" || p.health === "warning")
.map((p) => p.displayName);
return (
<div className="flex items-center gap-3 border border-red-500/40 bg-red-900/15 rounded-xl px-4 py-3 mb-6">
<AlertTriangle size={18} className="text-[var(--danger-text)] shrink-0" />
<div className="text-sm">
<span className="font-semibold text-[var(--danger-text)]">
{degraded} of {total} participants degraded
</span>
<span className="text-[var(--text-secondary)] ml-2">
— {names.join(", ")}
</span>
</div>
</div>
);
}
// ---------------------------------------------------------------------------
// Cost Estimator — StackIT server mapping + per-participant breakdown
// ---------------------------------------------------------------------------
// StackIT-equivalent node definitions (STACKIT Compute Engine, Frankfurt DC)
// Prices in EUR/month, based on European sovereign cloud rates (GDPR-ready).
const STACKIT_NODES = [
{
id: "neo4j",
label: "Graph DB (Neo4j)",
flavor: "4 vCPU / 8 GB RAM",
eur: 48,
components: ["Neo4j", "Neo4j Proxy"],
note: "Handles 5 300+ nodes across FHIR, OMOP, SNOMED, ICD-10, LOINC layers",
},
{
id: "datastore",
label: "Data Store (PostgreSQL + NATS)",
flavor: "2 vCPU / 4 GB RAM",
eur: 28,
components: ["PostgreSQL", "NATS"],
note: "Metadata for all 19 JAD services + async event bus",
},
{
id: "identity",
label: "Identity & Secrets",
flavor: "2 vCPU / 4 GB RAM",
eur: 28,
components: ["Keycloak", "Vault", "Traefik"],
note: "OIDC/PKCE SSO, secrets management, TLS termination",
},
{
id: "cfm",
label: "CFM Platform",
flavor: "2 vCPU / 4 GB RAM",
eur: 28,
components: [
"Tenant Manager",
"Provision Manager",
"EDC-V Agent",
"Keycloak Agent",
"Onboarding Agent",
"Registration Agent",
],
note: "Connector Fabric Manager orchestrates participant onboarding & provisioning",
},
{
id: "ui",
label: "UI / API Gateway",
flavor: "1 vCPU / 2 GB RAM",
eur: 14,
components: ["UI"],
note: "Next.js frontend + Neo4j proxy API bridge",
},
];
// Per-participant allocation: 2 GB RAM target (StackIT smallest compute tier)
const PER_PARTICIPANT_COMPUTE_EUR = 13; // 1 vCPU / 2 GB → ~€13/month
const PER_PARTICIPANT_STORAGE_GB = 2; // base allocation per participant
const HEALTH_DATA_STORAGE_GB = 10; // additional for DATA_HOLDER role (avg)
const STORAGE_EUR_PER_GB = 0.08; // StackIT block storage €0.08/GB/month
// Network: Control Plane ↔ Data Plane (DSP negotiation + transfer receipts)
const CP_DP_TRAFFIC_MB = 300; // ~300 MB/month per participant (DSP messages + audit)
const NETWORK_EUR_PER_GB = 0.09; // StackIT egress €0.09/GB
// Log injection: participant audit logs → centralised SIEM/Loki
const LOG_INJECTION_MB = 150; // ~150 MB/month per participant (EHDS Article 50 audit trail)
const LOG_EUR_PER_GB = 0.75; // log ingestion/storage (ELK/Loki service ~€0.75/GB)
const SHARED_EUR = STACKIT_NODES.reduce((s, n) => s + n.eur, 0);
function perParticipantEur(isDataHolder: boolean) {
const storage =
(PER_PARTICIPANT_STORAGE_GB + (isDataHolder ? HEALTH_DATA_STORAGE_GB : 0)) *
STORAGE_EUR_PER_GB;
const network = (CP_DP_TRAFFIC_MB / 1024) * NETWORK_EUR_PER_GB;
const logs = (LOG_INJECTION_MB / 1024) * LOG_EUR_PER_GB;
return PER_PARTICIPANT_COMPUTE_EUR + storage + network + logs;
}
const PER_USER_EUR = Math.round(perParticipantEur(false) * 100) / 100;
const PER_DATA_HOLDER_EUR = Math.round(perParticipantEur(true) * 100) / 100;
function CostEstimatorPanel({
participantCount,
}: {
participantCount: number;
}) {
const [count, setCount] = useState(participantCount);
// assume 60 % data holders, 40 % data users (typical EHDS mix)
const dataHolders = Math.round(count * 0.6);
const dataUsers = count - dataHolders;
const participantCost =
dataHolders * PER_DATA_HOLDER_EUR + dataUsers * PER_USER_EUR;
const total = SHARED_EUR + participantCost;
const perParticipant = count > 0 ? total / count : 0;
const networkTotal = (count * CP_DP_TRAFFIC_MB) / 1024; // GB/month total
const logTotal = (count * LOG_INJECTION_MB) / 1024; // GB/month total
return (
<div className="border border-[var(--border)] rounded-xl p-5 mt-10 space-y-6">
{/* Header */}
<div className="flex items-center justify-between flex-wrap gap-3">
<h2 className="font-semibold text-sm flex items-center gap-2 text-[var(--text-primary)]">
<BarChart2 size={16} className="text-[var(--success-text)]" />
Monthly Cost Estimate — STACKIT (Frankfurt)
</h2>
<div className="flex items-center gap-3 text-xs text-[var(--text-secondary)]">
<label className="flex items-center gap-2">
<Users size={13} />
Participants:
<input
type="range"
min={1}
max={200}
value={count}
onChange={(e) => setCount(Number(e.target.value))}
className="w-28 accent-emerald-500"
/>
<span className="font-mono font-semibold text-[var(--text-primary)] w-6 text-right">
{count}
</span>
</label>
</div>
</div>
{/* StackIT node grid */}
<div>
<p className="text-[11px] text-[var(--text-secondary)] mb-2 uppercase tracking-wide">
Shared Infrastructure (fixed)
</p>
<div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-2">
{STACKIT_NODES.map((n) => (
<div
key={n.id}
className="border border-[var(--border)] rounded-lg p-3 bg-[var(--surface)]/40"
>
<div className="flex items-center justify-between mb-1">
<span className="text-xs font-medium text-[var(--text-primary)]">
{n.label}
</span>
<span className="text-xs font-mono text-[var(--success-text)]">
€{n.eur}/mo
</span>
</div>
<p className="text-[10px] text-[var(--text-secondary)] font-mono mb-1.5">
{n.flavor}
</p>
<div className="flex flex-wrap gap-1">
{n.components.map((c) => (
<span
key={c}
className="text-[9px] px-1.5 py-0.5 rounded bg-[var(--surface-2)] text-[var(--text-secondary)]"
>
{c}
</span>
))}
</div>
<p className="text-[9px] text-[var(--text-secondary)] mt-1.5 leading-relaxed">
{n.note}
</p>
</div>
))}
</div>
<p className="text-xs text-[var(--text-secondary)] mt-2 text-right">
Shared fixed:{" "}
<span className="font-mono text-[var(--text-primary)]">
€{SHARED_EUR}/mo
</span>
</p>
</div>
{/* Per-participant breakdown */}
<div>
<p className="text-[11px] text-[var(--text-secondary)] mb-2 uppercase tracking-wide">
Per-Participant Cost (2 GB allocation)
</p>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-2 text-xs">
<div className="border border-[var(--border)] rounded-lg p-3 bg-[var(--surface)]/40">
<div className="text-[var(--text-secondary)] mb-0.5">Compute</div>
<div className="font-mono text-[var(--text-primary)]">
€{PER_PARTICIPANT_COMPUTE_EUR}/mo
</div>
<div className="text-[10px] text-[var(--text-secondary)] mt-1">
1 vCPU / 2 GB — Control Plane + Identity Hub + Issuer Service
</div>
</div>
<div className="border border-[var(--border)] rounded-lg p-3 bg-[var(--surface)]/40">
<div className="text-[var(--text-secondary)] mb-0.5">Storage</div>
<div className="font-mono text-[var(--text-primary)]">
€{(PER_PARTICIPANT_STORAGE_GB * STORAGE_EUR_PER_GB).toFixed(2)}{" "}
<span className="text-[var(--text-secondary)] text-[10px]">
(+€{(HEALTH_DATA_STORAGE_GB * STORAGE_EUR_PER_GB).toFixed(2)}{" "}
data holders)
</span>
</div>
<div className="text-[10px] text-[var(--text-secondary)] mt-1">
{PER_PARTICIPANT_STORAGE_GB} GB base · {HEALTH_DATA_STORAGE_GB} GB
health records · €{STORAGE_EUR_PER_GB}/GB/mo
</div>
</div>
<div className="border border-[var(--border)] rounded-lg p-3 bg-[var(--surface)]/40">
<div className="flex items-center gap-1 text-[var(--text-secondary)] mb-0.5">
<Network size={11} />
CP↔DP Network
</div>
<div className="font-mono text-[var(--text-primary)]">
€{((CP_DP_TRAFFIC_MB / 1024) * NETWORK_EUR_PER_GB).toFixed(3)}/mo
</div>
<div className="text-[10px] text-[var(--text-secondary)] mt-1">
{CP_DP_TRAFFIC_MB} MB/mo per participant (DSP negotiation +
transfer receipts + audit) · €{NETWORK_EUR_PER_GB}/GB egress
</div>
</div>
<div className="border border-[var(--border)] rounded-lg p-3 bg-[var(--surface)]/40">
<div className="text-[var(--text-secondary)] mb-0.5">
Log Injection
</div>
<div className="font-mono text-[var(--text-primary)]">
€{((LOG_INJECTION_MB / 1024) * LOG_EUR_PER_GB).toFixed(3)}/mo
</div>
<div className="text-[10px] text-[var(--text-secondary)] mt-1">
{LOG_INJECTION_MB} MB/mo EHDS Article 50 audit trail → SIEM/Loki ·
€{LOG_EUR_PER_GB}/GB
</div>
</div>
</div>
</div>
{/* Totals */}
<div className="border border-[var(--border)] rounded-xl p-4 bg-[var(--surface)]/60">
<div className="grid grid-cols-2 sm:grid-cols-4 gap-4 text-center">
<div>
<div className="text-[10px] text-[var(--text-secondary)] mb-1">
Shared fixed
</div>
<div className="font-mono text-lg font-semibold text-[var(--text-primary)]">
€{SHARED_EUR}
</div>
</div>
<div>
<div className="text-[10px] text-[var(--text-secondary)] mb-1">
{count} × participants
</div>
<div className="font-mono text-lg font-semibold text-[var(--text-primary)]">
€{participantCost.toFixed(0)}
</div>
</div>
<div>
<div className="text-[10px] text-[var(--text-secondary)] mb-1">
Network ({(networkTotal + logTotal).toFixed(1)} GB/mo)
</div>
<div className="font-mono text-lg font-semibold text-[var(--text-primary)]">
€
{(
networkTotal * NETWORK_EUR_PER_GB +
logTotal * LOG_EUR_PER_GB
).toFixed(1)}
</div>
</div>
<div className="border-l border-[var(--border)]">
<div className="text-[10px] text-[var(--text-secondary)] mb-1">
Total / month
</div>
<div className="font-mono text-xl font-bold text-[var(--success-text)]">
€{total.toFixed(0)}
</div>
<div className="text-[10px] text-[var(--text-secondary)] mt-0.5">
€{perParticipant.toFixed(2)}/participant
</div>
</div>
</div>
<p className="text-[9px] text-[var(--text-secondary)] mt-3 text-center">
Assumes 60 % DATA_HOLDER / 40 % DATA_USER mix · STACKIT Frankfurt ·
prices excl. VAT · does not include Kubernetes management fee or
premium support
</p>
</div>
</div>
);
}
// ---------------------------------------------------------------------------
// Azure Container Apps Cost Estimator — real reservations from /api/admin/components
// ---------------------------------------------------------------------------
// Hard-coded reservations mirror scripts/azure/*.sh. These are the minReplicas
// defaults under ADR-018 Workaround B (24×7, no scale-down). If Ops bumps a
// reservation, the live panel reflects it via the `snapshot.components` memLimit
// field; we keep this map as the fallback source of truth for names + memory.
const ACA_APP_SPECS: AcaAppSpec[] = [
{ name: "mvhd-controlplane", cpu: 0.5, memGiB: 1.0, minReplicas: 1 },
{ name: "mvhd-dp-fhir", cpu: 0.5, memGiB: 1.0, minReplicas: 1 },
{ name: "mvhd-dp-omop", cpu: 0.5, memGiB: 1.0, minReplicas: 1 },
{ name: "mvhd-identityhub", cpu: 0.5, memGiB: 1.0, minReplicas: 1 },
{ name: "mvhd-issuerservice", cpu: 0.25, memGiB: 0.5, minReplicas: 1 },
{ name: "mvhd-keycloak", cpu: 1.0, memGiB: 2.0, minReplicas: 1 },
{ name: "mvhd-vault", cpu: 0.25, memGiB: 0.5, minReplicas: 1 },
{ name: "mvhd-tenant-mgr", cpu: 0.5, memGiB: 1.0, minReplicas: 1 },
{ name: "mvhd-provision-mgr", cpu: 0.5, memGiB: 1.0, minReplicas: 1 },
{ name: "mvhd-postgres", cpu: 1.0, memGiB: 2.0, minReplicas: 1 },
{ name: "mvhd-nats", cpu: 0.25, memGiB: 0.5, minReplicas: 1 },
{ name: "mvhd-neo4j", cpu: 1.0, memGiB: 4.0, minReplicas: 1 },
{ name: "mvhd-neo4j-proxy", cpu: 0.25, memGiB: 0.5, minReplicas: 1 },
{ name: "mvhd-ui", cpu: 0.5, memGiB: 1.0, minReplicas: 1 },
];
// Storage GiB — derived from the Azure Files share quotas declared in
// scripts/azure/env.sh (neo4j-data 10 + neo4j-logs 5 + pg-data 20 + vault-data
// 2 = 37 GiB). Premium tier is billed on provisioned size, so this is what
// shows up on the bill regardless of actual usage. Constants kept inline so
// the page stays renderable without an extra ARM call.
const SHARE_NEO4J_DATA_GIB = 10;
const SHARE_NEO4J_LOGS_GIB = 5;
const SHARE_PG_DATA_GIB = 20;
const SHARE_VAULT_DATA_GIB = 2;
const COMPUTED_STORAGE_GIB =
SHARE_NEO4J_DATA_GIB +
SHARE_NEO4J_LOGS_GIB +
SHARE_PG_DATA_GIB +
SHARE_VAULT_DATA_GIB;
// Egress estimate (per participant, GB / month):
// - CP_DP_TRAFFIC_MB + LOG_INJECTION_MB above (DSP messages + audit log
// injection) — roughly 450 MB/participant
// - UI traffic: ~500 MB / participant / month for typical exploratory
// dashboard use (graph rendering, FHIR responses)
// Plus a small infra baseline (Keycloak introspection, NATS publish to
// external SIEM hooks, ACR pulls when scaling).
const EGRESS_PER_PARTICIPANT_MB =
CP_DP_TRAFFIC_MB + LOG_INJECTION_MB + /* user-facing UI */ 500;
const EGRESS_INFRA_BASELINE_GB = 2;
function computeEgressGiB(participantCount: number): number {
const fromParticipants =
(EGRESS_PER_PARTICIPANT_MB * participantCount) / 1024;
return Math.ceil(fromParticipants + EGRESS_INFRA_BASELINE_GB);
}
function AzureCostEstimatorPanel({
liveComponents,
participantCount,
}: {
liveComponents: ComponentInfo[];
participantCount: number;
}) {
// Storage and egress are derived from environment configuration + participant
// count rather than slider input, so the figure shown is what the deployment
// actually generates today. See COMPUTED_STORAGE_GIB / computeEgressGiB above.
const storageGiB = COMPUTED_STORAGE_GIB;
const egressGiB = computeEgressGiB(participantCount);
// Prefer live memory reservations from the API (more accurate if ops changed them)
const specs = useMemo<AcaAppSpec[]>(() => {
return ACA_APP_SPECS.map((fallback) => {
const live = liveComponents.find((c) => c.container === fallback.name);
if (!live || live.mem.limitMB <= 0) return fallback;
return {
...fallback,
memGiB: Math.round((live.mem.limitMB / 1024) * 100) / 100,
};
});
}, [liveComponents]);
const cost = useMemo(
() => costForEnvironment(specs, { storageGiB, egressGiB }),
[specs, storageGiB, egressGiB],
);
const totalVcpu = specs.reduce((s, a) => s + a.cpu, 0);
const totalMemGiB = specs.reduce((s, a) => s + a.memGiB, 0);
return (
<div className="border border-[var(--border)] rounded-xl p-5 mt-10 space-y-6">
{/* Header */}
<div className="flex items-center justify-between flex-wrap gap-3">
<h2 className="font-semibold text-sm flex items-center gap-2 text-[var(--text-primary)]">
<BarChart2 size={16} className="text-[var(--success-text)]" />
Monthly Cost Estimate — Azure Container Apps (Consumption, 24×7)
</h2>
<div className="flex items-center gap-4 text-xs text-[var(--text-secondary)]">
<span
className="flex items-center gap-1.5"
title={`Sum of Azure Files share quotas: neo4j-data ${SHARE_NEO4J_DATA_GIB} + neo4j-logs ${SHARE_NEO4J_LOGS_GIB} + pg-data ${SHARE_PG_DATA_GIB} + vault-data ${SHARE_VAULT_DATA_GIB} GiB. Configured in scripts/azure/env.sh.`}
>
<HardDrive size={13} />
Storage:{" "}
<span className="font-mono font-semibold text-[var(--text-primary)]">
{storageGiB} GiB
</span>
</span>
<span
className="flex items-center gap-1.5"
title={`Estimated: (${EGRESS_PER_PARTICIPANT_MB} MB/participant × ${participantCount} participants) + ${EGRESS_INFRA_BASELINE_GB} GB infra baseline. Includes DSP messaging, audit log injection, and user-facing UI traffic.`}
>
<Network size={13} />
Egress (est.):{" "}
<span className="font-mono font-semibold text-[var(--text-primary)]">
{egressGiB} GiB
</span>
</span>
</div>
</div>
{/* App grid — sorted by cost descending */}
<div>
<p className="text-[11px] text-[var(--text-secondary)] mb-2 uppercase tracking-wide">
Container Apps — Compute (vCPU + Memory, 24×7 minReplicas=1)
</p>
<div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-2">
{[...cost.apps]
.sort((a, b) => b.totalUsd - a.totalUsd)
.map((app) => {
const spec = specs.find((s) => s.name === app.name)!;
return (
<div
key={app.name}
className="border border-[var(--border)] rounded-lg p-3 bg-[var(--surface)]/40"
>
<div className="flex items-center justify-between mb-1">
<span className="text-xs font-medium text-[var(--text-primary)] font-mono">
{app.name}
</span>
<span className="text-xs font-mono text-[var(--success-text)]">
{formatUsd(app.totalUsd)}/mo
</span>
</div>
<p className="text-[10px] text-[var(--text-secondary)] font-mono mb-1">
{spec.cpu} vCPU · {spec.memGiB} GiB RAM
</p>
<div className="flex gap-3 text-[9px] text-[var(--text-secondary)]">
<span>CPU {formatUsd(app.vcpuUsd)}</span>
<span>MEM {formatUsd(app.memUsd)}</span>
</div>
</div>
);
})}
</div>
<p className="text-xs text-[var(--text-secondary)] mt-2 text-right">
Gross compute:{" "}
<span className="font-mono text-[var(--text-primary)]">
{formatUsd(cost.grossVcpuUsd + cost.grossMemUsd)}/mo
</span>{" "}
· Free tier credit:{" "}
<span className="font-mono text-[var(--success-text)]">
−{formatUsd(cost.freeCreditUsd)}
</span>
</p>
</div>
{/* Storage + egress breakdown */}
<div>
<p className="text-[11px] text-[var(--text-secondary)] mb-2 uppercase tracking-wide">
Storage & Network
</p>
<div className="grid grid-cols-1 sm:grid-cols-3 gap-2 text-xs">
<div className="border border-[var(--border)] rounded-lg p-3 bg-[var(--surface)]/40">
<div className="text-[var(--text-secondary)] mb-0.5">
Azure Files (Premium ZRS)
</div>
<div className="font-mono text-[var(--text-primary)]">
{formatUsd(cost.storageUsd)}/mo
</div>
<div className="text-[10px] text-[var(--text-secondary)] mt-1">
{storageGiB} GiB · ${AZURE_FILES_USD_PER_GIB}/GiB·mo · Neo4j + PG
+ Vault volumes
</div>
</div>
<div className="border border-[var(--border)] rounded-lg p-3 bg-[var(--surface)]/40">
<div className="text-[var(--text-secondary)] mb-0.5">
Egress (outbound)
</div>
<div className="font-mono text-[var(--text-primary)]">
{formatUsd(cost.egressUsd)}/mo
</div>
<div className="text-[10px] text-[var(--text-secondary)] mt-1">
{egressGiB} GiB · first {AZURE_EGRESS_FREE_GIB} GiB free · then $
{AZURE_EGRESS_USD_PER_GIB}/GiB
</div>
</div>
<div className="border border-[var(--border)] rounded-lg p-3 bg-[var(--surface)]/40">
<div className="text-[var(--text-secondary)] mb-0.5">
Environment totals
</div>
<div className="font-mono text-[var(--text-primary)]">
{totalVcpu.toFixed(2)} vCPU · {totalMemGiB.toFixed(1)} GiB
</div>
<div className="text-[10px] text-[var(--text-secondary)] mt-1">
{specs.length} Container Apps · Workaround B (no Log Analytics)
</div>
</div>
</div>
</div>
{/* Totals */}
<div className="border border-[var(--border)] rounded-xl p-4 bg-[var(--surface)]/60">
<div className="grid grid-cols-2 sm:grid-cols-4 gap-4 text-center">
<div>
<div className="text-[10px] text-[var(--text-secondary)] mb-1">
Compute (net)
</div>
<div className="font-mono text-lg font-semibold text-[var(--text-primary)]">
{formatUsd(cost.computeUsd)}
</div>
</div>
<div>
<div className="text-[10px] text-[var(--text-secondary)] mb-1">
Storage
</div>
<div className="font-mono text-lg font-semibold text-[var(--text-primary)]">
{formatUsd(cost.storageUsd)}
</div>
</div>
<div>
<div className="text-[10px] text-[var(--text-secondary)] mb-1">
Egress
</div>
<div className="font-mono text-lg font-semibold text-[var(--text-primary)]">
{formatUsd(cost.egressUsd)}
</div>
</div>
<div className="border-l border-[var(--border)]">
<div className="text-[10px] text-[var(--text-secondary)] mb-1">
Total / month
</div>
<div className="font-mono text-xl font-bold text-[var(--success-text)]">
{formatUsd(cost.totalUsd)}
</div>
<div className="text-[10px] text-[var(--text-secondary)] mt-0.5">
≈ {formatEur(cost.totalEur)} (@ {USD_TO_EUR} EUR/USD)
</div>
</div>
</div>
<p className="text-[9px] text-[var(--text-secondary)] mt-3 text-center">
Azure Container Apps Consumption plan · West Europe list prices · 24×7
minReplicas=1 · free tier (180 K vCPU-s + 360 K GiB-s) applied ·
ADR-018 Workaround B (no Log Analytics Workspace)
</p>
</div>
</div>
);
}
// ---------------------------------------------------------------------------
// Page Component
// ---------------------------------------------------------------------------
export default function AdminComponentsPage() {
// Layer view state
const [snapshot, setSnapshot] = useState<Snapshot | null>(null);
const historyRef = useRef<Map<string, HistoryEntry[]>>(new Map());
const [historyVersion, setHistoryVersion] = useState(0);
// Topology view state
const [topology, setTopology] = useState<TopologyData | null>(null);
const peaksRef = useRef<Map<string, PeakEntry>>(new Map());
const [_peakV, setPeakV] = useState(0);
// Shared state
const [viewMode, setViewMode] = useState<ViewMode>("participant");
const [loading, setLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false);
const [autoRefresh, setAutoRefresh] = useState(true);
const fetchData = useCallback(
async (isManual = false) => {
if (isManual) setRefreshing(true);
try {
if (viewMode === "layer") {
const res = await fetchApi("/api/admin/components");
Iif (!res.ok) return;
const data: Snapshot = await res.json();
setSnapshot(data);
const now = Date.now();
for (const comp of data.components) {
const key = comp.container;
const entries = historyRef.current.get(key) || [];
entries.push({ ts: now, cpu: comp.cpu, mem: comp.mem.usedMB });
while (entries.length > MAX_HISTORY) entries.shift();
historyRef.current.set(key, entries);
}
setHistoryVersion((v) => v + 1);
} else {
const res = await fetchApi("/api/admin/components/topology");
if (!res.ok) return;
const data: TopologyData = await res.json();
setTopology(data);
// Track peak CPU / Memory per container
const now = Date.now();
const cutoff = now - 24 * 60 * 60 * 1000;
const allComps = [
...data.participants.flatMap((p) => p.components),
...data.infrastructure,
];
for (const c of allComps) {
const prev = peaksRef.current.get(c.container);
if (!prev || prev.since < cutoff) {
peaksRef.current.set(c.container, {
maxCpu: c.cpu,
maxMemMB: c.memMB,
since: now,
});
} else {
prev.maxCpu = Math.max(prev.maxCpu, c.cpu);
prev.maxMemMB = Math.max(prev.maxMemMB, c.memMB);
}
}
setPeakV((v) => v + 1);
}
} catch (err) {
console.error("Failed to fetch components:", err);
} finally {
setLoading(false);
if (isManual) setRefreshing(false);
}
},
[viewMode],
);
useEffect(() => {
setLoading(true);
fetchData();
}, [fetchData]);
useEffect(() => {
if (!autoRefresh) return;
const timer = setInterval(() => fetchData(), REFRESH_INTERVAL);
return () => clearInterval(timer);
}, [autoRefresh, fetchData]);
// Layer view helpers
const grouped = (snapshot?.components || []).reduce(
(acc, c) => {
(acc[c.layer] ??= []).push(c);
return acc;
},
{} as Record<string, ComponentInfo[]>,
);
const totalServices = snapshot?.components.length || 0;
const healthyCount =
snapshot?.components.filter((c) => c.status === "healthy").length || 0;
const runningCount =
snapshot?.components.filter((c) => c.status === "running").length || 0;
const totalCpu = snapshot?.components.reduce((s, c) => s + c.cpu, 0) || 0;
// Match the per-row display so the user's manual count of visible values
// adds up to the shown total. Per-row shows "<1" for sub-1 MB (contributes
// 0) and Math.round(usedMB) otherwise — sum the same quantities.
const totalMem =
snapshot?.components.reduce(
(s, c) => s + (c.mem.usedMB < 1 ? 0 : Math.round(c.mem.usedMB)),
0,
) || 0;
void historyVersion;
const timestamp =
viewMode === "layer" ? snapshot?.timestamp : topology?.timestamp;
return (
<div className="min-h-screen bg-[var(--bg)]">
<div className="max-w-7xl mx-auto px-8 py-10">
{/* ── Page header ── */}
<div className="flex flex-col md:flex-row md:items-end justify-between gap-4 mb-8">
<div>
<h1 className="page-header">EDC Components</h1>
<p className="text-[var(--text-secondary)] text-lg mt-1">
Infrastructure health · CPU & memory per service
</p>
</div>
<div className="flex items-center gap-2 px-4 py-2 bg-[var(--success)]/10 text-[var(--success-text)] rounded-full border border-[var(--success)]/20 text-sm font-bold tracking-tight">
<span className="w-2 h-2 rounded-full bg-[var(--success)] animate-pulse" />
LIVE MONITORING
</div>
</div>
{/* Controls bar */}
<div className="flex items-center justify-between mb-6 flex-wrap gap-2">
<div className="flex items-center gap-4 text-xs text-[var(--text-secondary)]">
{/* View toggle */}
<div className="flex bg-[var(--surface)] p-1 rounded-xl border border-[var(--border)]">
<button
onClick={() => setViewMode("layer")}
className={`px-4 py-1.5 text-xs font-bold rounded-lg transition-all ${
viewMode === "layer"
? "bg-[var(--surface-card)] shadow-sm text-[var(--accent)]"
: "text-[var(--text-secondary)] hover:text-[var(--text-primary)]"
}`}
>
Layer View
</button>
<button
onClick={() => setViewMode("participant")}
className={`px-4 py-1.5 text-xs font-bold rounded-lg transition-all ${
viewMode === "participant"
? "bg-[var(--surface-card)] shadow-sm text-[var(--accent)]"
: "text-[var(--text-secondary)] hover:text-[var(--text-primary)]"
}`}
>
Participant View
</button>
</div>
{/* Stats summary for layer view */}
{viewMode === "layer" && snapshot && (
<>
<span>{totalServices} services</span>
<span>·</span>
<span className="text-[var(--success-text)]">
{healthyCount} healthy
</span>
<span className="text-[var(--accent)]">
{runningCount} running
</span>
<span>·</span>
<span>
<Cpu size={11} className="inline mr-0.5" />
{totalCpu.toFixed(1)}% total
</span>
<span>·</span>
<span>
<HardDrive size={11} className="inline mr-0.5" />
{totalMem > 1024
? `${(totalMem / 1024).toFixed(1)} GB`
: `${Math.round(totalMem)} MB`}{" "}
total
</span>
</>
)}
{/* Stats summary for participant view */}
{viewMode === "participant" && topology && (
<>
<span>{topology.summary.totalParticipants} participants</span>
<span>·</span>
<span>{topology.summary.totalInfra} infra services</span>
{topology.summary.degradedParticipants > 0 && (
<>
<span>·</span>
<span className="text-[var(--danger-text)]">
{topology.summary.degradedParticipants} degraded
</span>
</>
)}
{topology.metricsShared && (
<>
<span>·</span>
<span
className="italic text-[var(--text-secondary)]"
title="Participants are logical DIDs on this deployment — they share the same ACA containers. Switch to Layer View for real per-container CPU/MEM from Azure Monitor."
>
shared infrastructure (see Layer View for metrics)
</span>
</>
)}
</>
)}
</div>
<div className="flex items-center gap-3">
<label className="flex items-center gap-1.5 text-xs text-[var(--text-secondary)] cursor-pointer">
<input
type="checkbox"
checked={autoRefresh}
onChange={(e) => setAutoRefresh(e.target.checked)}
className="rounded border-[var(--border-ui)] bg-[var(--surface-2)] text-teal-800 dark:text-teal-300 focus:ring-layer2 w-3.5 h-3.5"
/>
Auto-refresh (30s)
</label>
<button
onClick={() => fetchData(true)}
disabled={refreshing}
className="flex items-center gap-1.5 px-3 py-1.5 text-xs border border-[var(--border)] rounded-lg hover:border-layer2 transition-colors disabled:opacity-50"
>
<RefreshCw
size={12}
className={refreshing ? "animate-spin" : ""}
/>
Refresh
</button>
</div>
</div>
{loading ? (
<div className="flex items-center gap-2 text-[var(--text-secondary)]">
<Loader2 size={16} className="animate-spin" />
Loading EDC components…
</div>
) : viewMode === "participant" ? (
/* ═══════════════════════════════════════════════════════════════
PARTICIPANT VIEW
═══════════════════════════════════════════════════════════════ */
topology && (
<>
{/* Cluster resource banner */}
{topology.clusterMetrics && (
<ClusterResourceBanner metrics={topology.clusterMetrics} />
)}
{/* Critical banner */}
<CriticalBanner
degraded={topology.summary.degradedParticipants}
total={topology.summary.totalParticipants}
participants={topology.participants}
/>
{/* Participant topology sections */}
<div className="space-y-3 mb-8">
<h2 className="font-semibold text-sm flex items-center gap-2 text-[var(--text-primary)] mb-3">
<Users
size={16}
className="text-teal-800 dark:text-teal-300"
/>
Dataspace Participants
<span className="text-xs font-normal text-[var(--text-secondary)]">
({topology.participants.length})
</span>
</h2>
{topology.participants.map((p) => (
<ParticipantTopologySection
key={p.id}
participant={p}
peaks={peaksRef.current}
metricsShared={Boolean(topology.metricsShared)}
/>
))}
</div>
{/* Shared infrastructure */}
{topology.infrastructure.length > 0 && (
<div className="mb-8">
<div className="flex items-start justify-between mb-3 flex-wrap gap-2">
<h2 className="font-semibold text-sm flex items-center gap-2 text-[var(--text-primary)]">
<HardDrive
size={16}
className="text-[var(--warning-text)]"
/>
Shared Infrastructure & CFM
<span className="text-xs font-normal text-[var(--text-secondary)]">
({topology.infrastructure.length})
</span>
</h2>
<ResourceSummary
components={topology.infrastructure}
peaks={peaksRef.current}
/>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-2">
{topology.infrastructure.map((c) => (
<TopoComponentCard key={c.container} comp={c} />
))}
</div>
</div>
)}
{/* Docker unavailable */}
{!topology.dockerAvailable && (
<div className="border border-yellow-600/40 bg-yellow-900/20 rounded-xl p-4 text-sm text-[var(--warning-text)]">
<strong>Docker socket not available.</strong> CPU and memory
metrics require the Docker socket to be mounted.
</div>
)}
</>
)
) : (
/* ═══════════════════════════════════════════════════════════════
LAYER VIEW (original)
═══════════════════════════════════════════════════════════════ */
<>
{/* Participants */}
{snapshot && snapshot.participants.length > 0 && (
<div className="mb-8">
<h2 className="font-semibold text-sm mb-4 flex items-center gap-2 text-[var(--text-primary)]">
<Users
size={16}
className="text-teal-800 dark:text-teal-300"
/>
Dataspace Participants
<span className="text-xs font-normal text-[var(--text-secondary)]">
({snapshot.participants.length})
</span>
</h2>
<div className="overflow-x-auto border border-[var(--border)] rounded-xl">
<table className="w-full text-left">
<thead>
<tr className="border-b border-[var(--border)] bg-[var(--surface)]/60">
<th className="py-2 px-3 text-xs font-medium text-[var(--text-secondary)] w-48">
Participant
</th>
<th className="py-2 px-3 text-xs font-medium text-[var(--text-secondary)] w-32">
Role
</th>
<th className="py-2 px-3 text-xs font-medium text-[var(--text-secondary)]">
DID
</th>
<th className="py-2 px-3 text-xs font-medium text-[var(--text-secondary)] w-28">
State
</th>
<th className="py-2 px-3 text-xs font-medium text-[var(--text-secondary)] w-20 text-center">
Profiles
</th>
</tr>
</thead>
<tbody>
{snapshot.participants.map((p) => (
<tr
key={p.id}
className="border-b border-[var(--border)] hover:bg-[var(--surface-2)]/40 transition-colors"
>
<td className="py-2.5 px-3">
<div className="font-semibold text-sm text-[var(--text-primary)]">
{p.displayName}
</div>
<div className="text-[11px] text-[var(--text-secondary)]">
{p.organization}
</div>
</td>
<td className="py-2.5 px-3">
<span
className={`text-[10px] font-medium px-2 py-0.5 rounded-full ${
ROLE_COLORS[p.role] ||
"bg-gray-500/20 text-[var(--text-secondary)]"
}`}
>
{p.role}
</span>
</td>
<td className="py-2.5 px-3 font-mono text-[11px] text-[var(--text-secondary)]">
{p.did}
</td>
<td className="py-2.5 px-3">
<span
className={`text-xs font-medium ${
p.state === "CREATED"
? "text-[var(--success-text)]"
: "text-[var(--warning-text)]"
}`}
>
{p.state}
</span>
</td>
<td className="py-2.5 px-3 text-xs text-[var(--text-primary)] text-center">
{p.profileCount}
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
)}
{/* Component tables per layer */}
{["edc-core", "identity", "cfm", "infrastructure"].map((layer) => {
const items = grouped[layer];
if (!items || items.length === 0) return null;
const meta = LAYER_META[layer];
const LayerIcon = meta.icon;
return (
<div key={layer} className="mb-8">
<h2 className="font-semibold text-sm mb-3 flex items-center gap-2 text-[var(--text-primary)]">
<LayerIcon size={16} className={meta.color} />
{meta.label}
<span className="text-xs font-normal text-[var(--text-secondary)]">
({items.length})
</span>
</h2>
<div className="overflow-x-auto border border-[var(--border)] rounded-xl">
<table className="w-full text-left">
<thead>
<tr className="border-b border-[var(--border)] bg-[var(--surface)]/60">
<th className="py-2 px-3 text-xs font-medium text-[var(--text-secondary)] w-48">
Component
</th>
<th className="py-2 px-3 text-xs font-medium text-[var(--text-secondary)] w-28">
Health
</th>
<th className="py-2 px-3 text-xs font-medium text-[var(--text-secondary)] w-24">
Uptime
</th>
<th className="py-2 px-3 text-xs font-medium text-[var(--text-secondary)] w-40">
CPU (Last 24h)
</th>
<th className="py-2 px-3 text-xs font-medium text-[var(--text-secondary)] w-44">
Memory (Last 24h)
</th>
<th className="py-2 px-3 text-xs font-medium text-[var(--text-secondary)] w-16">
Mem %
</th>
</tr>
</thead>
<tbody>
{items.map((comp) => (
<ComponentRow
key={comp.container}
comp={comp}
history={
historyRef.current.get(comp.container) || []
}
/>
))}
</tbody>
</table>
</div>
</div>
);
})}
{/* Docker unavailable banner — hidden on Azure deployments
(where Docker socket is genuinely not present and metrics come
from Azure Monitor instead). */}
{snapshot &&
!snapshot.dockerAvailable &&
snapshot.metricsSource !== "azure-monitor" &&
snapshot.deploymentTarget !== "azure" && (
<div className="border border-yellow-600/40 bg-yellow-900/20 rounded-xl p-4 text-sm text-[var(--warning-text)]">
<strong>Docker socket not available.</strong> CPU and memory
metrics require the Docker socket to be mounted.
</div>
)}
</>
)}
{/* Cost estimator — Azure on ACA deployment, StackIT otherwise.
Azure is detected from EITHER endpoint's deploy-target signal
(/api/admin/components snapshot OR the topology endpoint's
metricsShared flag). Layered OR means the Azure panel surfaces
as soon as any Azure signal is present — e.g. when participant
topology knows we're on ACA but the snapshot call raced the
Azure Monitor role binding. */}
{snapshot?.deploymentTarget === "azure" ||
snapshot?.metricsSource === "azure-monitor" ||
topology?.metricsShared === true ? (
<AzureCostEstimatorPanel
liveComponents={snapshot?.components ?? []}
participantCount={
viewMode === "participant"
? topology?.summary.totalParticipants ?? 5
: snapshot?.participants.length ?? 5
}
/>
) : (
<CostEstimatorPanel
participantCount={
viewMode === "participant"
? topology?.summary.totalParticipants ?? 5
: snapshot?.participants.length ?? 5
}
/>
)}
{/* Timestamp */}
{timestamp && (
<p className="text-[10px] text-[var(--text-secondary)] mt-4">
Last updated: {new Date(timestamp).toLocaleString()}
</p>
)}
</div>
</div>
);
}
|