import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { useQuery } from "@tanstack/react-query"; import { Activity, Server, Monitor, Globe, Clock, GitBranch, Bot, AlertCircle } from "lucide-react"; interface BeaconRecord { id: string; name: string; version: string; platform: string; environment: string; has_claude_code: boolean; has_git: boolean; event: 'startup' | 'heartbeat' | 'shutdown' | 'custom'; timestamp: string; uptime?: number; git?: { branch: string; commit: string; remote: string; }; replit?: { id: string; slug: string; owner: string; url: string; }; last_seen: string; } interface BeaconStats { total_beacons: number; active_apps: number; platforms: Record; recent_activity: number; } export function BeaconDashboard() { const { data: stats, isLoading: statsLoading } = useQuery({ queryKey: ['/api/beacon/stats'], refetchInterval: 30000, // Refresh every 30 seconds }); const { data: historyData, isLoading: historyLoading } = useQuery({ queryKey: ['/api/beacon/history'], refetchInterval: 30000, }); const { data: healthData } = useQuery({ queryKey: ['/api/beacon/health'], refetchInterval: 60000, // Check health every minute }); const beaconStats = stats as BeaconStats | undefined; const beacons = (historyData as { beacons: BeaconRecord[] } | undefined)?.beacons || []; const healthInfo = healthData as any; const isHealthy = healthInfo?.status === 'ok' && healthInfo?.enabled; const formatUptime = (seconds?: number): string => { if (!seconds) return 'N/A'; const hours = Math.floor(seconds / 3600); const minutes = Math.floor((seconds % 3600) / 60); return `${hours}h ${minutes}m`; }; const getPlatformIcon = (platform: string) => { switch (platform) { case 'replit': return '🔴'; case 'github-actions': return '🐙'; case 'vercel': return '▲'; case 'netlify': return '🟢'; case 'heroku': return '🟣'; case 'aws-lambda': return '🟠'; default: return '🖥️'; } }; const getEventColor = (event: string) => { switch (event) { case 'startup': return 'bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400'; case 'heartbeat': return 'bg-blue-100 text-blue-800 dark:bg-blue-900/20 dark:text-blue-400'; case 'shutdown': return 'bg-red-100 text-red-800 dark:bg-red-900/20 dark:text-red-400'; case 'custom': return 'bg-purple-100 text-purple-800 dark:bg-purple-900/20 dark:text-purple-400'; default: return 'bg-gray-100 text-gray-800 dark:bg-gray-900/20 dark:text-gray-400'; } }; if (statsLoading || historyLoading) { return (
{[...Array(4)].map((_, i) => (
))}
); } return (
{/* Header */}

ChittyBeacon Tracking

Real-time app monitoring and platform detection across the ChittyChain ecosystem

{isHealthy ? ( Active ) : ( Inactive )}
{/* Statistics Overview */}

{beaconStats?.total_beacons || 0}

Total Beacons

{beaconStats?.active_apps || 0}

Active Apps

{Object.keys(beaconStats?.platforms || {}).length}

Platforms

{beaconStats?.recent_activity || 0}

Recent Activity (1h)

{/* Platform Distribution */} {beaconStats?.platforms && Object.keys(beaconStats.platforms).length > 0 && ( Platform Distribution
{Object.entries(beaconStats.platforms).map(([platform, count]) => (
{getPlatformIcon(platform)}

{platform.replace('-', ' ')}

{count} beacons

))}
)} {/* Recent Beacon Activity */} Recent Beacon Activity {beacons.length === 0 ? (

No beacon activity detected yet

Apps will appear here once they start sending tracking data

) : ( beacons.slice(0, 10).map((beacon, index) => (
{getPlatformIcon(beacon.platform)}

{beacon.name}

v{beacon.version} {beacon.platform} {beacon.has_claude_code && ( <>
Claude
)} {beacon.has_git && ( <>
Git
)}
{beacon.event}

{new Date(beacon.timestamp).toLocaleTimeString()}

{beacon.uptime && (

Uptime: {formatUptime(beacon.uptime)}

)}
)) )}
{/* App Details */} {healthInfo?.app && ( Current App Information

App Details

Name: {healthInfo.app.name}

Version: {healthInfo.app.version}

Platform: {healthInfo.app.platform}

Environment: {healthInfo.app.environment}

Node Version: {healthInfo.app.node_version}

{healthInfo.app.git && (

Git Information

Branch: {healthInfo.app.git.branch}

Commit: {healthInfo.app.git.commit}

)}
)}
); }