T1/Phase 1: scaffold Vite SPA + Hono API + Bun worker

- apps/web: Vite + React 19 + TanStack Router/Query + shadcn/ui
   - apps/api: Hono + Bun on :3001 with /api/health, /api/auth/*, /mcp stubs
   - apps/worker: Bun worker stub, DB connection, graceful SIGTERM
   - apps/web-legacy/: old Next.js code moved aside (preserved for T2-T8 reference)
   - Dockerfiles: api (Bun), worker (Bun), spa (multi-stage Caddy)
   - Caddyfile: serves dist + reverse-proxies /api/* + /mcp to api
   - docker-compose.yml: 4-service target (api, spa, db, worker)
   - packages/db/src/client.ts: shared Drizzle client for api + worker
   - db/client.ts: root-level alias for convenience

   Parent: t_e1cbd87d -> t_24c9c3fd (T0)
This commit is contained in:
Hermes
2026-08-01 01:15:31 +00:00
parent 9203aee758
commit fca56ab77e
312 changed files with 3489 additions and 196 deletions
@@ -0,0 +1,176 @@
'use client';
import { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { toast } from 'sonner';
interface ProjectCreateDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
domainId: string;
onCreated: () => void;
}
export function ProjectCreateDialog({
open,
onOpenChange,
domainId,
onCreated,
}: ProjectCreateDialogProps) {
const [name, setName] = useState('');
const [description, setDescription] = useState('');
const [status, setStatus] = useState<'active' | 'paused' | 'completed' | 'archived'>('active');
const [color, setColor] = useState('');
const [targetDate, setTargetDate] = useState('');
const [submitting, setSubmitting] = useState(false);
const [error, setError] = useState('');
useEffect(() => {
if (open) {
setName('');
setDescription('');
setStatus('active');
setColor('');
setTargetDate('');
setError('');
}
}, [open]);
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
if (!domainId) {
setError('No domain selected');
return;
}
setSubmitting(true);
setError('');
const body: Record<string, unknown> = { name, status };
if (description) body.description = description;
if (color) body.color = color;
if (targetDate) body.targetDate = new Date(targetDate).toISOString();
try {
const response = await fetch(`/api/domains/${domainId}/projects`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
if (!response.ok) {
const err = await response.json();
throw new Error(err.error?.message || 'Unable to create project');
}
toast.success('Project created');
onOpenChange(false);
onCreated();
} catch (err) {
setError(err instanceof Error ? err.message : 'Unable to create project');
} finally {
setSubmitting(false);
}
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[500px]">
<DialogHeader>
<DialogTitle>New Project</DialogTitle>
<DialogDescription>Create a new project to organize your work.</DialogDescription>
</DialogHeader>
<form className="space-y-4" onSubmit={handleSubmit}>
<div className="space-y-2">
<Label htmlFor="project-name">Name *</Label>
<Input
id="project-name"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Project name"
autoFocus
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="project-description">Description</Label>
<Textarea
id="project-description"
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="Optional description..."
rows={2}
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="project-status">Status</Label>
<Select value={status} onValueChange={(v) => setStatus(v as any)}>
<SelectTrigger id="project-status">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="active">Active</SelectItem>
<SelectItem value="paused">Paused</SelectItem>
<SelectItem value="completed">Completed</SelectItem>
<SelectItem value="archived">Archived</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="project-color">Color</Label>
<Input
id="project-color"
type="color"
value={color}
onChange={(e) => setColor(e.target.value)}
className="h-10"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="project-target-date">Target date</Label>
<Input
id="project-target-date"
type="date"
value={targetDate}
onChange={(e) => setTargetDate(e.target.value)}
/>
</div>
{error && <p className="text-sm text-destructive" role="alert">{error}</p>}
<DialogFooter>
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button type="submit" disabled={submitting || !name || !domainId}>
{submitting ? 'Creating...' : 'Create Project'}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
);
}
@@ -0,0 +1,254 @@
'use client';
import { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { toast } from 'sonner';
interface Project {
id: string;
name: string;
description: string | null;
status: 'active' | 'paused' | 'completed' | 'archived';
domainId: string;
color: string | null;
icon: string | null;
targetDate: string | null;
}
interface ProjectEditDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
project: Project;
domainId: string;
onUpdated: () => void;
}
export function ProjectEditDialog({
open,
onOpenChange,
project,
domainId,
onUpdated,
}: ProjectEditDialogProps) {
const [name, setName] = useState('');
const [description, setDescription] = useState('');
const [status, setStatus] = useState<'active' | 'paused' | 'completed' | 'archived'>('active');
const [color, setColor] = useState('');
const [targetDate, setTargetDate] = useState('');
const [submitting, setSubmitting] = useState(false);
const [error, setError] = useState('');
const [archiveOpen, setArchiveOpen] = useState(false);
const [archiving, setArchiving] = useState(false);
useEffect(() => {
if (open && project) {
setName(project.name);
setDescription(project.description || '');
setStatus(project.status);
setColor(project.color || '');
setTargetDate(project.targetDate ? project.targetDate.split('T')[0] : '');
setError('');
}
}, [open, project]);
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
if (!domainId) {
setError('No domain selected');
return;
}
setSubmitting(true);
setError('');
const body: Record<string, unknown> = { name, status };
if (description) body.description = description;
if (color) body.color = color;
if (targetDate) body.targetDate = new Date(targetDate).toISOString();
try {
const response = await fetch(`/api/domains/${domainId}/projects/${project.id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
if (!response.ok) {
const err = await response.json();
throw new Error(err.error?.message || 'Unable to update project');
}
toast.success('Project updated');
onOpenChange(false);
onUpdated();
} catch (err) {
setError(err instanceof Error ? err.message : 'Unable to update project');
} finally {
setSubmitting(false);
}
}
async function handleArchive() {
setArchiving(true);
try {
const response = await fetch(`/api/domains/${domainId}/projects/${project.id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ status: 'archived' }),
});
if (!response.ok) {
const err = await response.json();
throw new Error(err.error?.message || 'Unable to archive project');
}
toast.success('Project archived');
setArchiveOpen(false);
onOpenChange(false);
onUpdated();
} catch (err) {
toast.error(err instanceof Error ? err.message : 'Unable to archive project');
} finally {
setArchiving(false);
}
}
return (
<>
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[500px]">
<DialogHeader>
<DialogTitle>Edit Project</DialogTitle>
<DialogDescription>Update your project details.</DialogDescription>
</DialogHeader>
<form className="space-y-4" onSubmit={handleSubmit}>
<div className="space-y-2">
<Label htmlFor="edit-project-name">Name *</Label>
<Input
id="edit-project-name"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Project name"
autoFocus
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="edit-project-description">Description</Label>
<Textarea
id="edit-project-description"
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="Optional description..."
rows={2}
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="edit-project-status">Status</Label>
<Select value={status} onValueChange={(v) => setStatus(v as any)}>
<SelectTrigger id="edit-project-status">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="active">Active</SelectItem>
<SelectItem value="paused">Paused</SelectItem>
<SelectItem value="completed">Completed</SelectItem>
<SelectItem value="archived">Archived</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="edit-project-color">Color</Label>
<Input
id="edit-project-color"
type="color"
value={color}
onChange={(e) => setColor(e.target.value)}
className="h-10"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="edit-project-target-date">Target date</Label>
<Input
id="edit-project-target-date"
type="date"
value={targetDate}
onChange={(e) => setTargetDate(e.target.value)}
/>
</div>
{error && <p className="text-sm text-destructive" role="alert">{error}</p>}
<DialogFooter className="flex items-center justify-between sm:justify-between">
<Button
type="button"
variant="destructive"
onClick={() => setArchiveOpen(true)}
>
Archive
</Button>
<div className="flex gap-2">
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button type="submit" disabled={submitting || !name || !domainId}>
{submitting ? 'Saving...' : 'Save'}
</Button>
</div>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
<AlertDialog open={archiveOpen} onOpenChange={setArchiveOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Archive Project</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to archive &quot;{project.name}&quot;? It will be hidden from the active list.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={handleArchive} disabled={archiving}>
{archiving ? 'Archiving...' : 'Archive'}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
);
}
@@ -0,0 +1,126 @@
'use client';
import { useMemo } from 'react';
interface Section {
id: string;
name: string;
kind: 'section' | 'milestone';
status: 'planned' | 'in_progress' | 'complete';
targetDate: string | null;
sortOrder: number;
}
interface ProjectTimelineProps {
sections: Section[];
projectTargetDate: string | null;
}
const statusColors: Record<string, string> = {
planned: 'bg-gray-200 dark:bg-gray-700',
in_progress: 'bg-blue-400 dark:bg-blue-600',
complete: 'bg-green-400 dark:bg-green-600',
};
const kindBadge: Record<string, string> = {
section: 'bg-muted text-muted-foreground',
milestone: 'bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200',
};
export function ProjectTimeline({ sections, projectTargetDate }: ProjectTimelineProps) {
const { startDate, totalDays } = useMemo(() => {
if (sections.length === 0) return { startDate: new Date(), totalDays: 30 };
const dates = sections
.filter((s) => s.targetDate)
.map((s) => new Date(s.targetDate!));
if (projectTargetDate) dates.push(new Date(projectTargetDate));
if (dates.length === 0) {
// No dates at all — show a default 30-day window
const now = new Date();
return { startDate: now, totalDays: 30 };
}
const minDate = new Date(Math.min(...dates.map((d) => d.getTime())));
const maxDate = new Date(Math.max(...dates.map((d) => d.getTime())));
const diff = Math.max((maxDate.getTime() - minDate.getTime()) / (1000 * 60 * 60 * 24), 14);
return { startDate: minDate, totalDays: Math.ceil(diff) };
}, [sections, projectTargetDate]);
if (sections.length === 0) return null;
return (
<div className="mt-6">
<h3 className="mb-3 text-sm font-semibold">Timeline</h3>
<div className="rounded-lg border bg-card p-4">
{/* Header row */}
<div className="mb-2 flex items-center gap-2 text-xs text-muted-foreground">
<span className="w-40 shrink-0">Section</span>
<div className="relative flex-1 h-4">
<div className="absolute inset-0 flex">
{Array.from({ length: Math.min(totalDays, 60) }).map((_, i) => (
<div
key={i}
className="flex-1 border-r border-border/30"
style={i % 7 === 0 ? { borderRightWidth: 2 } : {}}
/>
))}
</div>
</div>
</div>
{/* Section rows */}
<div className="space-y-2">
{sections.map((section) => {
if (!section.targetDate) return null;
const sectionDate = new Date(section.targetDate);
const dayOffset = Math.max(
0,
Math.round((sectionDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24))
);
const barWidth = Math.max(8, Math.min(100, (1 / Math.max(totalDays, 1)) * 100));
return (
<div key={section.id} className="flex items-center gap-2">
<div className="flex w-40 shrink-0 items-center gap-2">
<span
className={`inline-flex items-center rounded px-1.5 py-0.5 text-[10px] font-medium ${
kindBadge[section.kind] || kindBadge.section
}`}
>
{section.kind === 'milestone' ? 'M' : 'S'}
</span>
<span className="truncate text-sm">{section.name}</span>
</div>
<div className="relative flex-1 h-6">
<div
className={`absolute top-1 h-4 rounded ${
statusColors[section.status] || statusColors.planned
}`}
style={{
left: `${(dayOffset / Math.max(totalDays, 1)) * 100}%`,
width: `${barWidth}%`,
minWidth: 8,
}}
title={`${section.name}${section.status}${sectionDate.toLocaleDateString()}`}
/>
</div>
</div>
);
})}
</div>
{/* Project target date marker */}
{projectTargetDate && (
<div className="mt-3 flex items-center gap-2 border-t pt-2 text-xs text-muted-foreground">
<span className="w-40 shrink-0">Target date</span>
<span>{new Date(projectTargetDate).toLocaleDateString()}</span>
</div>
)}
</div>
</div>
);
}
@@ -0,0 +1,261 @@
'use client';
import { useState, useEffect } from 'react';
import { Button } from '@/components/ui/button';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { toast } from 'sonner';
interface Section {
id: string;
name: string;
projectId: string;
kind: 'section' | 'milestone';
status: 'planned' | 'in_progress' | 'complete';
targetDate: string | null;
sortOrder: number;
}
interface SectionDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
projectId: string;
domainId: string;
onCreated: () => void;
existingSection?: Section;
}
export function SectionDialog({
open,
onOpenChange,
projectId,
domainId,
onCreated,
existingSection,
}: SectionDialogProps) {
const isEdit = !!existingSection;
const [name, setName] = useState('');
const [kind, setKind] = useState<'section' | 'milestone'>('section');
const [status, setStatus] = useState<'planned' | 'in_progress' | 'complete'>('planned');
const [targetDate, setTargetDate] = useState('');
const [submitting, setSubmitting] = useState(false);
const [error, setError] = useState('');
const [deleteOpen, setDeleteOpen] = useState(false);
const [deleting, setDeleting] = useState(false);
useEffect(() => {
if (open) {
if (existingSection) {
setName(existingSection.name);
setKind(existingSection.kind);
setStatus(existingSection.status);
setTargetDate(existingSection.targetDate ? existingSection.targetDate.split('T')[0] : '');
} else {
setName('');
setKind('section');
setStatus('planned');
setTargetDate('');
}
setError('');
}
}, [open, existingSection]);
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
if (!name) {
setError('Name is required');
return;
}
setSubmitting(true);
setError('');
const body: Record<string, unknown> = { name, kind, status };
if (targetDate) body.targetDate = new Date(targetDate).toISOString();
try {
let response: Response;
if (isEdit && existingSection) {
response = await fetch(`/api/domains/${domainId}/projects/${projectId}/sections/${existingSection.id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
} else {
response = await fetch(`/api/domains/${domainId}/projects/${projectId}/sections`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
}
if (!response.ok) {
const err = await response.json();
throw new Error(err.error?.message || `Unable to ${isEdit ? 'update' : 'create'} section`);
}
toast.success(isEdit ? 'Section updated' : 'Section created');
onOpenChange(false);
onCreated();
} catch (err) {
setError(err instanceof Error ? err.message : `Unable to ${isEdit ? 'update' : 'create'} section`);
} finally {
setSubmitting(false);
}
}
async function handleDelete() {
if (!existingSection) return;
setDeleting(true);
try {
const response = await fetch(`/api/domains/${domainId}/projects/${projectId}/sections/${existingSection.id}`, {
method: 'DELETE',
});
if (!response.ok) {
const err = await response.json();
throw new Error(err.error?.message || 'Unable to delete section');
}
toast.success('Section deleted');
setDeleteOpen(false);
onOpenChange(false);
onCreated();
} catch (err) {
toast.error(err instanceof Error ? err.message : 'Unable to delete section');
} finally {
setDeleting(false);
}
}
return (
<>
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[450px]">
<DialogHeader>
<DialogTitle>{isEdit ? 'Edit Section' : 'New Section'}</DialogTitle>
<DialogDescription>
{isEdit ? 'Update this section or milestone.' : 'Add a section or milestone to organize tasks.'}
</DialogDescription>
</DialogHeader>
<form className="space-y-4" onSubmit={handleSubmit}>
<div className="space-y-2">
<Label htmlFor="section-name">Name *</Label>
<Input
id="section-name"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="e.g. Backend, Design, Launch"
autoFocus
required
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="section-kind">Kind</Label>
<Select value={kind} onValueChange={(v) => setKind(v as any)}>
<SelectTrigger id="section-kind">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="section">Section</SelectItem>
<SelectItem value="milestone">Milestone</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="section-status">Status</Label>
<Select value={status} onValueChange={(v) => setStatus(v as any)}>
<SelectTrigger id="section-status">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="planned">Planned</SelectItem>
<SelectItem value="in_progress">In Progress</SelectItem>
<SelectItem value="complete">Complete</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="section-target-date">Target date</Label>
<Input
id="section-target-date"
type="date"
value={targetDate}
onChange={(e) => setTargetDate(e.target.value)}
/>
</div>
{error && <p className="text-sm text-destructive" role="alert">{error}</p>}
<DialogFooter className="flex items-center justify-between sm:justify-between">
{isEdit && (
<Button
type="button"
variant="destructive"
onClick={() => setDeleteOpen(true)}
>
Delete
</Button>
)}
<div className="flex gap-2">
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button type="submit" disabled={submitting || !name}>
{submitting ? (isEdit ? 'Saving...' : 'Creating...') : (isEdit ? 'Save' : 'Create Section')}
</Button>
</div>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete Section</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to delete &quot;{existingSection?.name}&quot;? This action cannot be undone.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={handleDelete} disabled={deleting}>
{deleting ? 'Deleting...' : 'Delete'}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
);
}