chore(v2): establish protocol and test foundation

This commit is contained in:
2026-07-27 18:44:47 +02:00
parent 33b0c21292
commit 791f4526f9
86 changed files with 4060 additions and 2582 deletions
+3670
View File
File diff suppressed because it is too large Load Diff
+21 -22
View File
@@ -1,36 +1,35 @@
{
"name": "backup-tool-frontend",
"private": true,
"version": "0.0.1",
"version": "2.0.0-dev.0",
"type": "module",
"packageManager": "npm@10.9.2",
"engines": {
"node": "22.17.1"
},
"scripts": {
"dev": "vite",
"typecheck": "tsc --noEmit",
"test": "vitest run --passWithNoTests",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.21.0",
"@tanstack/react-query": "^5.17.0",
"axios": "^1.6.5",
"react-hook-form": "^7.49.0",
"recharts": "^2.10.0",
"lucide-react": "^0.303.0",
"clsx": "^2.1.0"
"react": "19.2.8",
"react-dom": "19.2.8"
},
"devDependencies": {
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.16",
"postcss": "^8.4.32",
"tailwindcss": "^3.4.0",
"typescript": "^5.2.2",
"vite": "^5.0.8",
"vitest": "^1.1.0",
"@testing-library/react": "^14.1.0",
"@testing-library/jest-dom": "^6.2.0",
"jsdom": "^23.0.0"
"@testing-library/jest-dom": "7.0.0",
"@testing-library/react": "16.3.2",
"@types/react": "19.2.17",
"@types/react-dom": "19.2.3",
"@vitejs/plugin-react": "6.0.4",
"autoprefixer": "10.5.4",
"jsdom": "30.0.0",
"postcss": "8.5.23",
"tailwindcss": "3.4.19",
"typescript": "7.0.2",
"vite": "8.1.5",
"vitest": "4.1.10"
}
}
-33
View File
@@ -1,33 +0,0 @@
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Layout } from './components/Layout';
import { Dashboard } from './pages/Dashboard';
import { Backups } from './pages/Backups';
import { Settings } from './pages/Settings';
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 5 * 60 * 1000,
retry: 1,
},
},
});
function App() {
return (
<QueryClientProvider client={queryClient}>
<BrowserRouter>
<Layout>
<Routes>
<Route path="/" element={<Dashboard />} />
<Route path="/backups" element={<Backups />} />
<Route path="/settings" element={<Settings />} />
</Routes>
</Layout>
</BrowserRouter>
</QueryClientProvider>
);
}
export default App;
-62
View File
@@ -1,62 +0,0 @@
import axios from 'axios';
const API_BASE_URL = '/api';
export const apiClient = axios.create({
baseURL: API_BASE_URL,
headers: {
'Content-Type': 'application/json',
},
});
export interface BackupSource {
id: string;
name: string;
type: string;
config: Record<string, unknown>;
created_at: string;
updated_at: string;
}
export interface BackupJob {
id: string;
source_id: string;
status: 'pending' | 'running' | 'completed' | 'failed';
started_at: string | null;
completed_at: string | null;
error_message: string | null;
created_at: string;
}
export interface DashboardStats {
total_sources: number;
total_jobs: number;
completed_jobs: number;
failed_jobs: number;
pending_jobs: number;
}
export const sourcesApi = {
getAll: () => apiClient.get<BackupSource[]>('/sources'),
getById: (id: string) => apiClient.get<BackupSource>(`/sources/${id}`),
create: (data: Omit<BackupSource, 'id' | 'created_at' | 'updated_at'>) =>
apiClient.post<BackupSource>('/sources', data),
update: (id: string, data: Partial<BackupSource>) =>
apiClient.put<BackupSource>(`/sources/${id}`, data),
delete: (id: string) => apiClient.delete(`/sources/${id}`),
};
export const jobsApi = {
getAll: () => apiClient.get<BackupJob[]>('/jobs'),
getById: (id: string) => apiClient.get<BackupJob>(`/jobs/${id}`),
create: (sourceId: string) =>
apiClient.post<BackupJob>('/jobs', { source_id: sourceId }),
delete: (id: string) => apiClient.delete(`/jobs/${id}`),
getLogs: (id: string) => apiClient.get<string>(`/jobs/${id}/logs`),
};
export const dashboardApi = {
getStats: () => apiClient.get<DashboardStats>('/dashboard/stats'),
getRecentJobs: (limit: number = 10) =>
apiClient.get<BackupJob[]>(`/dashboard/recent-jobs?limit=${limit}`),
};
View File
+16
View File
@@ -0,0 +1,16 @@
export function App() {
return (
<main className="min-h-screen bg-slate-950 p-8 text-slate-100">
<section className="mx-auto max-w-3xl rounded-xl border border-slate-800 bg-slate-900 p-8">
<p className="text-sm font-semibold uppercase tracking-widest text-emerald-400">
Backup Tool v2
</p>
<h1 className="mt-3 text-3xl font-bold">Protocol foundation ready</h1>
<p className="mt-4 text-slate-300">
Operator workflows are added as their versioned API contracts become
executable.
</p>
</section>
</main>
);
}
-80
View File
@@ -1,80 +0,0 @@
import { Link, useLocation } from 'react-router-dom';
import { LayoutDashboard, Archive, Settings, Menu } from 'lucide-react';
import { useState } from 'react';
interface LayoutProps {
children: React.ReactNode;
}
const navItems = [
{ path: '/', label: 'Dashboard', icon: LayoutDashboard },
{ path: '/backups', label: 'Backups', icon: Archive },
{ path: '/settings', label: 'Settings', icon: Settings },
];
export function Layout({ children }: LayoutProps) {
const location = useLocation();
const [sidebarOpen, setSidebarOpen] = useState(false);
return (
<div className="flex h-screen bg-gray-50">
{/* Mobile sidebar overlay */}
{sidebarOpen && (
<div
className="fixed inset-0 bg-black/50 z-40 lg:hidden"
onClick={() => setSidebarOpen(false)}
/>
)}
{/* Sidebar */}
<aside
className={`fixed lg:static inset-y-0 left-0 z-50 w-64 bg-white border-r border-gray-200 transform transition-transform duration-200 ease-in-out lg:transform-none ${
sidebarOpen ? 'translate-x-0' : '-translate-x-full'
}`}
>
<div className="flex items-center h-16 px-6 border-b border-gray-200">
<h1 className="text-xl font-bold text-gray-900">Backup Tool</h1>
</div>
<nav className="p-4 space-y-1">
{navItems.map((item) => {
const Icon = item.icon;
const isActive = location.pathname === item.path;
return (
<Link
key={item.path}
to={item.path}
onClick={() => setSidebarOpen(false)}
className={`flex items-center gap-3 px-4 py-3 rounded-lg text-sm font-medium transition-colors ${
isActive
? 'bg-blue-50 text-blue-700'
: 'text-gray-700 hover:bg-gray-100'
}`}
>
<Icon className="w-5 h-5" />
{item.label}
</Link>
);
})}
</nav>
</aside>
{/* Main content */}
<div className="flex-1 flex flex-col min-w-0">
{/* Mobile header */}
<header className="lg:hidden flex items-center h-16 px-4 bg-white border-b border-gray-200">
<button
onClick={() => setSidebarOpen(true)}
className="p-2 -ml-2 text-gray-600 hover:bg-gray-100 rounded-lg"
>
<Menu className="w-6 h-6" />
</button>
<span className="ml-3 text-lg font-semibold text-gray-900">
Backup Tool
</span>
</header>
<main className="flex-1 overflow-auto p-6">{children}</main>
</div>
</div>
);
}
+16 -9
View File
@@ -1,10 +1,17 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './index.css'
import React from "react";
import ReactDOM from "react-dom/client";
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
import { App } from "./app/App";
import "./index.css";
const root = document.getElementById("root");
if (!root) {
throw new Error("Missing #root element");
}
ReactDOM.createRoot(root).render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
-238
View File
@@ -1,238 +0,0 @@
import { useState } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { Play, Trash2, Plus } from 'lucide-react';
import { jobsApi, sourcesApi } from '../api/client';
import type { BackupJob, BackupSource } from '../api/client';
function StatusBadge({ status }: { status: string }) {
const styles = {
pending: 'bg-yellow-100 text-yellow-800',
running: 'bg-blue-100 text-blue-800',
completed: 'bg-green-100 text-green-800',
failed: 'bg-red-100 text-red-800',
};
return (
<span
className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${
styles[status as keyof typeof styles] || 'bg-gray-100 text-gray-800'
}`}
>
{status}
</span>
);
}
function CreateJobModal({
onClose,
}: {
onClose: () => void;
}) {
const queryClient = useQueryClient();
const [sourceId, setSourceId] = useState('');
const { data: sources } = useQuery({
queryKey: ['sources'],
queryFn: () => sourcesApi.getAll().then((res) => res.data),
});
const createMutation = useMutation({
mutationFn: (sid: string) => jobsApi.create(sid),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['jobs'] });
onClose();
},
});
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (sourceId) {
createMutation.mutate(sourceId);
}
};
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
<div className="bg-white rounded-lg shadow-xl w-full max-w-md mx-4">
<div className="px-6 py-4 border-b border-gray-200">
<h3 className="text-lg font-semibold text-gray-900">
Create Backup Job
</h3>
</div>
<form onSubmit={handleSubmit} className="p-6 space-y-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Source
</label>
<select
value={sourceId}
onChange={(e) => setSourceId(e.target.value)}
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
required
>
<option value="">Select a source...</option>
{sources?.map((source: BackupSource) => (
<option key={source.id} value={source.id}>
{source.name} ({source.type})
</option>
))}
</select>
</div>
<div className="flex justify-end gap-3 pt-2">
<button
type="button"
onClick={onClose}
className="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50"
>
Cancel
</button>
<button
type="submit"
disabled={!sourceId || createMutation.isPending}
className="px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 disabled:opacity-50"
>
{createMutation.isPending ? 'Creating...' : 'Create Job'}
</button>
</div>
</form>
</div>
</div>
);
}
export function Backups() {
const [showModal, setShowModal] = useState(false);
const queryClient = useQueryClient();
const { data: jobs, isLoading } = useQuery({
queryKey: ['jobs'],
queryFn: () => jobsApi.getAll().then((res) => res.data),
});
const { data: sources } = useQuery({
queryKey: ['sources'],
queryFn: () => sourcesApi.getAll().then((res) => res.data),
});
const deleteMutation = useMutation({
mutationFn: (id: string) => jobsApi.delete(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['jobs'] });
},
});
const runMutation = useMutation({
mutationFn: (id: string) => jobsApi.create(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['jobs'] });
},
});
const getSourceName = (sourceId: string) => {
const source = sources?.find((s: BackupSource) => s.id === sourceId);
return source?.name || sourceId.slice(0, 8);
};
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<h2 className="text-2xl font-bold text-gray-900">Backups</h2>
<button
onClick={() => setShowModal(true)}
className="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700"
>
<Plus className="w-4 h-4" />
New Job
</button>
</div>
<div className="bg-white rounded-lg border border-gray-200 overflow-hidden">
<table className="min-w-full divide-y divide-gray-200">
<thead className="bg-gray-50">
<tr>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Job ID
</th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Source
</th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Status
</th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Started
</th>
<th className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
Actions
</th>
</tr>
</thead>
<tbody className="bg-white divide-y divide-gray-200">
{isLoading && (
<tr>
<td
colSpan={5}
className="px-6 py-8 text-center text-gray-500"
>
Loading...
</td>
</tr>
)}
{jobs?.length === 0 && !isLoading && (
<tr>
<td
colSpan={5}
className="px-6 py-8 text-center text-gray-500"
>
No backup jobs yet. Create one to get started.
</td>
</tr>
)}
{jobs?.map((job: BackupJob) => (
<tr key={job.id} className="hover:bg-gray-50">
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
{job.id.slice(0, 8)}
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-600">
{getSourceName(job.source_id)}
</td>
<td className="px-6 py-4 whitespace-nowrap">
<StatusBadge status={job.status} />
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{job.started_at
? new Date(job.started_at).toLocaleString()
: 'Not started'}
</td>
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<div className="flex items-center justify-end gap-2">
<button
onClick={() => runMutation.mutate(job.source_id)}
disabled={job.status === 'running'}
className="p-1 text-gray-600 hover:text-blue-600 disabled:opacity-50"
title="Run job"
>
<Play className="w-4 h-4" />
</button>
<button
onClick={() => {
if (confirm('Delete this job?')) {
deleteMutation.mutate(job.id);
}
}}
className="p-1 text-gray-600 hover:text-red-600"
title="Delete job"
>
<Trash2 className="w-4 h-4" />
</button>
</div>
</td>
</tr>
))}
</tbody>
</table>
</div>
{showModal && <CreateJobModal onClose={() => setShowModal(false)} />}
</div>
);
}
-141
View File
@@ -1,141 +0,0 @@
import { useQuery } from '@tanstack/react-query';
import { Activity, Archive, AlertTriangle, CheckCircle } from 'lucide-react';
import { dashboardApi } from '../api/client';
function StatCard({
title,
value,
icon: Icon,
color,
}: {
title: string;
value: number;
icon: React.ElementType;
color: string;
}) {
return (
<div className="bg-white rounded-lg border border-gray-200 p-6">
<div className="flex items-center justify-between">
<div>
<p className="text-sm font-medium text-gray-600">{title}</p>
<p className="mt-2 text-3xl font-bold text-gray-900">{value}</p>
</div>
<div className={`p-3 rounded-lg ${color}`}>
<Icon className="w-6 h-6 text-white" />
</div>
</div>
</div>
);
}
function StatusBadge({ status }: { status: string }) {
const styles = {
pending: 'bg-yellow-100 text-yellow-800',
running: 'bg-blue-100 text-blue-800',
completed: 'bg-green-100 text-green-800',
failed: 'bg-red-100 text-red-800',
};
return (
<span
className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${
styles[status as keyof typeof styles] || 'bg-gray-100 text-gray-800'
}`}
>
{status}
</span>
);
}
export function Dashboard() {
const { data: stats } = useQuery({
queryKey: ['dashboard-stats'],
queryFn: () => dashboardApi.getStats().then((res) => res.data),
});
const { data: recentJobs } = useQuery({
queryKey: ['recent-jobs'],
queryFn: () => dashboardApi.getRecentJobs(5).then((res) => res.data),
});
const activeJobs = stats?.pending_jobs || 0;
const recentFailures = stats?.failed_jobs || 0;
return (
<div className="space-y-6">
<h2 className="text-2xl font-bold text-gray-900">Dashboard</h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
<StatCard
title="Active Jobs"
value={activeJobs}
icon={Activity}
color="bg-blue-500"
/>
<StatCard
title="Total Backups"
value={stats?.total_jobs || 0}
icon={Archive}
color="bg-green-500"
/>
<StatCard
title="Completed"
value={stats?.completed_jobs || 0}
icon={CheckCircle}
color="bg-indigo-500"
/>
<StatCard
title="Recent Failures"
value={recentFailures}
icon={AlertTriangle}
color="bg-red-500"
/>
</div>
<div className="bg-white rounded-lg border border-gray-200">
<div className="px-6 py-4 border-b border-gray-200">
<h3 className="text-lg font-semibold text-gray-900">
Recent Activity
</h3>
</div>
<div className="divide-y divide-gray-200">
{recentJobs?.length === 0 && (
<div className="px-6 py-8 text-center text-gray-500">
No recent activity
</div>
)}
{recentJobs?.map((job) => (
<div
key={job.id}
className="px-6 py-4 flex items-center justify-between"
>
<div className="flex items-center gap-3">
<div
className={`w-2 h-2 rounded-full ${
job.status === 'completed'
? 'bg-green-500'
: job.status === 'failed'
? 'bg-red-500'
: job.status === 'running'
? 'bg-blue-500'
: 'bg-yellow-500'
}`}
/>
<div>
<p className="text-sm font-medium text-gray-900">
Job {job.id.slice(0, 8)}
</p>
<p className="text-xs text-gray-500">
{job.created_at
? new Date(job.created_at).toLocaleString()
: 'Unknown'}
</p>
</div>
</div>
<StatusBadge status={job.status} />
</div>
))}
</div>
</div>
</div>
);
}
-205
View File
@@ -1,205 +0,0 @@
import { useState } from 'react';
const tabs = [
{ id: 'general', label: 'General' },
{ id: 'notifications', label: 'Notifications' },
{ id: 'security', label: 'Security' },
{ id: 'logs', label: 'Logs' },
];
function GeneralSettings() {
return (
<div className="space-y-6">
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Backup Retention (days)
</label>
<input
type="number"
defaultValue={30}
className="w-full max-w-xs rounded-lg border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Default Backup Strategy
</label>
<select
defaultValue="incremental"
className="w-full max-w-xs rounded-lg border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
>
<option value="full">Full</option>
<option value="incremental">Incremental</option>
<option value="differential">Differential</option>
</select>
</div>
<div className="flex items-center gap-3">
<input
type="checkbox"
id="auto-cleanup"
defaultChecked
className="w-4 h-4 text-blue-600 rounded border-gray-300"
/>
<label htmlFor="auto-cleanup" className="text-sm text-gray-700">
Enable automatic cleanup of old backups
</label>
</div>
</div>
);
}
function NotificationSettings() {
return (
<div className="space-y-6">
<div className="flex items-center gap-3">
<input
type="checkbox"
id="email-notify"
defaultChecked
className="w-4 h-4 text-blue-600 rounded border-gray-300"
/>
<label htmlFor="email-notify" className="text-sm text-gray-700">
Enable email notifications
</label>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Email Address
</label>
<input
type="email"
placeholder="admin@example.com"
className="w-full max-w-md rounded-lg border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
<div className="flex items-center gap-3">
<input
type="checkbox"
id="notify-failures"
defaultChecked
className="w-4 h-4 text-blue-600 rounded border-gray-300"
/>
<label htmlFor="notify-failures" className="text-sm text-gray-700">
Notify on backup failures only
</label>
</div>
</div>
);
}
function SecuritySettings() {
return (
<div className="space-y-6">
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Encryption Key
</label>
<input
type="password"
placeholder="Enter encryption key"
className="w-full max-w-md rounded-lg border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
<div className="flex items-center gap-3">
<input
type="checkbox"
id="encrypt-backups"
className="w-4 h-4 text-blue-600 rounded border-gray-300"
/>
<label htmlFor="encrypt-backups" className="text-sm text-gray-700">
Encrypt all backups
</label>
</div>
<div className="flex items-center gap-3">
<input
type="checkbox"
id="require-auth"
defaultChecked
className="w-4 h-4 text-blue-600 rounded border-gray-300"
/>
<label htmlFor="require-auth" className="text-sm text-gray-700">
Require authentication for API access
</label>
</div>
</div>
);
}
function LogSettings() {
return (
<div className="space-y-6">
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Log Level
</label>
<select
defaultValue="info"
className="w-full max-w-xs rounded-lg border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
>
<option value="debug">Debug</option>
<option value="info">Info</option>
<option value="warn">Warning</option>
<option value="error">Error</option>
</select>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Log Retention (days)
</label>
<input
type="number"
defaultValue={7}
className="w-full max-w-xs rounded-lg border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
<div className="flex items-center gap-3">
<input
type="checkbox"
id="verbose-logs"
className="w-4 h-4 text-blue-600 rounded border-gray-300"
/>
<label htmlFor="verbose-logs" className="text-sm text-gray-700">
Enable verbose logging
</label>
</div>
</div>
);
}
export function Settings() {
const [activeTab, setActiveTab] = useState('general');
const tabContent = {
general: <GeneralSettings />,
notifications: <NotificationSettings />,
security: <SecuritySettings />,
logs: <LogSettings />,
};
return (
<div className="space-y-6">
<h2 className="text-2xl font-bold text-gray-900">Settings</h2>
<div className="bg-white rounded-lg border border-gray-200">
<div className="border-b border-gray-200">
<nav className="flex -mb-px">
{tabs.map((tab) => (
<button
key={tab.id}
onClick={() => setActiveTab(tab.id)}
className={`px-6 py-3 text-sm font-medium border-b-2 transition-colors ${
activeTab === tab.id
? 'border-blue-500 text-blue-600'
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'
}`}
>
{tab.label}
</button>
))}
</nav>
</div>
<div className="p-6">{tabContent[activeTab as keyof typeof tabContent]}</div>
</div>
</div>
);
}
+1
View File
@@ -0,0 +1 @@
/// <reference types="vite/client" />