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,25 @@
// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
// 1. Insert activity feed entry
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
// See AGENTS.md for full rules.
import { NextRequest, NextResponse } from 'next/server';
import { withAuth, requireWorkspaceAccess } from '@/lib/auth';
import { db, activityFeed } from '@project-e/db';
import { and, desc, eq } from 'drizzle-orm';
type RouteContext = { params: Promise<{ domainId: string }> };
// GET /api/domains/[domainId]/dashboard/widgets/activity-feed
export const GET = withAuth<RouteContext>(async (request: NextRequest, user, context) => {
const { domainId } = await context!.params;
await requireWorkspaceAccess(domainId);
const items = await db.select()
.from(activityFeed)
.where(eq(activityFeed.workspaceId, domainId))
.orderBy(desc(activityFeed.createdAt))
.limit(20);
return NextResponse.json({ items });
});
@@ -0,0 +1,50 @@
// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
// 1. Insert activity feed entry
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
// See AGENTS.md for full rules.
import { NextRequest, NextResponse } from 'next/server';
import { withAuth, requireWorkspaceAccess } from '@/lib/auth';
import { db, habits, habitCompletions } from '@project-e/db';
import { and, eq, gte, isNull, lte, sql } from 'drizzle-orm';
type RouteContext = { params: Promise<{ domainId: string }> };
// GET /api/domains/[domainId]/dashboard/widgets/habit-checklist
export const GET = withAuth<RouteContext>(async (request: NextRequest, user, context) => {
const { domainId } = await context!.params;
await requireWorkspaceAccess(domainId);
const today = new Date();
today.setHours(0, 0, 0, 0);
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
const activeHabits = await db.select()
.from(habits)
.where(and(
eq(habits.domainId, domainId),
eq(habits.active, true),
isNull(habits.deletedAt),
));
// Check which habits are completed today
const items = [];
for (const habit of activeHabits) {
const [completion] = await db.select({ count: sql<number>`count(*)` })
.from(habitCompletions)
.where(and(
eq(habitCompletions.habitId, habit.id),
gte(habitCompletions.date, today),
lte(habitCompletions.date, tomorrow),
));
const completed = Number(completion?.count || 0) > 0;
items.push({
...habit,
completedToday: completed,
});
}
return NextResponse.json({ items });
});
@@ -0,0 +1,54 @@
// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
// 1. Insert activity feed entry
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
// See AGENTS.md for full rules.
import { NextRequest, NextResponse } from 'next/server';
import { withAuth, requireWorkspaceAccess } from '@/lib/auth';
import { db, projects, tasks } from '@project-e/db';
import { and, eq, inArray, isNull, sql } from 'drizzle-orm';
type RouteContext = { params: Promise<{ domainId: string }> };
// GET /api/domains/[domainId]/dashboard/widgets/project-progress
export const GET = withAuth<RouteContext>(async (request: NextRequest, user, context) => {
const { domainId } = await context!.params;
await requireWorkspaceAccess(domainId);
const activeProjects = await db.select()
.from(projects)
.where(and(
eq(projects.domainId, domainId),
inArray(projects.status, ['active', 'paused']),
isNull(projects.deletedAt),
));
// Compute progress for each project
const items = [];
for (const project of activeProjects) {
const [totalResult] = await db.select({ count: sql<number>`count(*)` })
.from(tasks)
.where(and(eq(tasks.projectId, project.id), isNull(tasks.deletedAt)));
const [completedResult] = await db.select({ count: sql<number>`count(*)` })
.from(tasks)
.where(and(eq(tasks.projectId, project.id), eq(tasks.status, 'done'), isNull(tasks.deletedAt)));
const total = Number(totalResult?.count || 0);
const completed = Number(completedResult?.count || 0);
const progress = total > 0 ? Math.round((completed / total) * 100) : 0;
items.push({
id: project.id,
name: project.name,
status: project.status,
color: project.color,
targetDate: project.targetDate,
taskCount: total,
completedCount: completed,
progress,
});
}
return NextResponse.json({ items });
});
@@ -0,0 +1,34 @@
// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
// 1. Insert activity feed entry
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
// See AGENTS.md for full rules.
import { NextRequest, NextResponse } from 'next/server';
import { withAuth, requireWorkspaceAccess } from '@/lib/auth';
import { db, notes } from '@project-e/db';
import { and, desc, eq, isNull } from 'drizzle-orm';
type RouteContext = { params: Promise<{ domainId: string }> };
// GET /api/domains/[domainId]/dashboard/widgets/recent-notes
export const GET = withAuth<RouteContext>(async (request: NextRequest, user, context) => {
const { domainId } = await context!.params;
await requireWorkspaceAccess(domainId);
const items = await db.select({
id: notes.id,
title: notes.title,
updatedAt: notes.updatedAt,
isPinned: notes.isPinned,
})
.from(notes)
.where(and(
eq(notes.domainId, domainId),
eq(notes.isArchived, false),
isNull(notes.deletedAt),
))
.orderBy(desc(notes.updatedAt))
.limit(5);
return NextResponse.json({ items });
});
@@ -0,0 +1,35 @@
// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
// 1. Insert activity feed entry
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
// See AGENTS.md for full rules.
import { NextRequest, NextResponse } from 'next/server';
import { withAuth, requireWorkspaceAccess } from '@/lib/auth';
import { db, tasks, habits, habitCompletions, projects, notes, activityFeed, domains } from '@project-e/db';
import { and, asc, desc, eq, gte, inArray, isNull, lte, sql } from 'drizzle-orm';
type RouteContext = { params: Promise<{ domainId: string }> };
// GET /api/domains/[domainId]/dashboard/widgets/today-tasks
export const GET = withAuth<RouteContext>(async (request: NextRequest, user, context) => {
const { domainId } = await context!.params;
await requireWorkspaceAccess(domainId);
const today = new Date();
today.setHours(0, 0, 0, 0);
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
const items = await db.select()
.from(tasks)
.where(and(
eq(tasks.domainId, domainId),
isNull(tasks.deletedAt),
gte(tasks.dueDate, today),
lte(tasks.dueDate, tomorrow),
))
.orderBy(asc(tasks.priority))
.limit(10);
return NextResponse.json({ items });
});
@@ -0,0 +1,63 @@
// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
// 1. Insert activity feed entry
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
// See AGENTS.md for full rules.
import { NextRequest, NextResponse } from 'next/server';
import { withAuth, requireWorkspaceAccess } from '@/lib/auth';
import { db, tasks, projects, sections } from '@project-e/db';
import { and, asc, eq, gte, isNull, lte, sql } from 'drizzle-orm';
type RouteContext = { params: Promise<{ domainId: string }> };
// GET /api/domains/[domainId]/dashboard/widgets/upcoming-calendar
export const GET = withAuth<RouteContext>(async (request: NextRequest, user, context) => {
const { domainId } = await context!.params;
await requireWorkspaceAccess(domainId);
const today = new Date();
today.setHours(0, 0, 0, 0);
const nextWeek = new Date(today);
nextWeek.setDate(nextWeek.getDate() + 7);
// Tasks due in next 7 days
const upcomingTasks = await db.select({
id: tasks.id,
title: tasks.title,
dueDate: tasks.dueDate,
priority: tasks.priority,
status: tasks.status,
})
.from(tasks)
.where(and(
eq(tasks.domainId, domainId),
isNull(tasks.deletedAt),
gte(tasks.dueDate, today),
lte(tasks.dueDate, nextWeek),
))
.orderBy(asc(tasks.dueDate))
.limit(10);
// Projects with target dates in next 7 days
const upcomingProjects = await db.select({
id: projects.id,
name: projects.name,
targetDate: projects.targetDate,
status: projects.status,
color: projects.color,
})
.from(projects)
.where(and(
eq(projects.domainId, domainId),
isNull(projects.deletedAt),
gte(projects.targetDate, today),
lte(projects.targetDate, nextWeek),
))
.orderBy(asc(projects.targetDate))
.limit(5);
return NextResponse.json({
tasks: upcomingTasks,
projects: upcomingProjects,
});
});
@@ -0,0 +1,66 @@
// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
// 1. Insert activity feed entry
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
// See AGENTS.md for full rules.
import { NextRequest, NextResponse } from 'next/server';
import { withAuth, requireWorkspaceAccess } from '@/lib/auth';
import { db, tasks, habits, habitCompletions } from '@project-e/db';
import { and, eq, gte, isNull, lte, sql } from 'drizzle-orm';
type RouteContext = { params: Promise<{ domainId: string }> };
// GET /api/domains/[domainId]/dashboard/widgets/weekly-stats
export const GET = withAuth<RouteContext>(async (request: NextRequest, user, context) => {
const { domainId } = await context!.params;
await requireWorkspaceAccess(domainId);
const now = new Date();
const weekStart = new Date(now);
weekStart.setDate(weekStart.getDate() - weekStart.getDay());
weekStart.setHours(0, 0, 0, 0);
const weekEnd = new Date(weekStart);
weekEnd.setDate(weekEnd.getDate() + 7);
// Task completions this week
const [taskCompletions] = await db.select({ count: sql<number>`count(*)` })
.from(tasks)
.where(and(
eq(tasks.domainId, domainId),
eq(tasks.status, 'done'),
gte(tasks.completedAt, weekStart),
lte(tasks.completedAt, weekEnd),
isNull(tasks.deletedAt),
));
// Habit completions this week
const [habitCompletionsCount] = await db.select({ count: sql<number>`count(*)` })
.from(habitCompletions)
.innerJoin(habits, eq(habitCompletions.habitId, habits.id))
.where(and(
eq(habits.domainId, domainId),
gte(habitCompletions.date, weekStart),
lte(habitCompletions.date, weekEnd),
isNull(habits.deletedAt),
));
// Streak counts
const activeHabits = await db.select({ id: habits.id, streakCount: habits.streakCount, bestStreak: habits.bestStreak })
.from(habits)
.where(and(
eq(habits.domainId, domainId),
eq(habits.active, true),
isNull(habits.deletedAt),
));
const totalStreak = activeHabits.reduce((sum, h) => sum + (h.streakCount || 0), 0);
const bestStreak = Math.max(...activeHabits.map(h => h.bestStreak || 0), 0);
return NextResponse.json({
taskCompletions: Number(taskCompletions?.count || 0),
habitCompletions: Number(habitCompletionsCount?.count || 0),
totalStreak,
bestStreak,
activeHabits: activeHabits.length,
});
});