Compare commits

...

15 Commits

Author SHA1 Message Date
imbytecat 036afb8d20 chore: remove React Compiler and @rolldown/plugin-babel 2026-04-01 18:26:09 +08:00
imbytecat 688252fd49 chore(deps): bump @biomejs/biome to 2.4.9 and @orpc/* to 1.13.11 2026-03-26 01:14:09 +08:00
imbytecat 42c2fff7cd chore: update VS Code TypeScript SDK path 2026-03-25 09:58:50 +08:00
imbytecat 034f570794 chore(deps): update TanStack devtools packages 2026-03-25 09:51:21 +08:00
imbytecat ea5935e29b chore(deps): remove babel-plugin-react-compiler 2026-03-25 09:45:37 +08:00
imbytecat 3663f3d010 chore(deps): add @rolldown/plugin-babel and update dependencies
- Add @rolldown/plugin-babel for React compiler support
- Update TypeScript to 6.0.2
- Update TanStack packages (@tanstack/react-query, @tanstack/react-router, @tanstack/react-start)
- Update @vitejs/plugin-react to 6.0.1
- Update Vite to 8.0.2 and Nitro nightly
- Refactor vite.config.ts to use separate babel plugin with reactCompilerPreset
2026-03-25 09:44:13 +08:00
imbytecat 9d1beab2e1 chore: migrate to TypeScript 6.0.2
- Upgrade typescript from 5.9.3 to 6.0.2
- Add explicit types: ['node'] to base tsconfig (TS6 breaking change)
- Remove deprecated baseUrl from server tsconfig
- All typecheck passing
2026-03-25 09:23:07 +08:00
imbytecat 88326c4992 refactor(server): 改用 Vite 原生 tsconfig 路径解析 2026-03-22 01:27:47 +08:00
imbytecat 4e2bc5b8dc chore(deps): 更新 bun lock 2026-03-22 00:39:25 +08:00
imbytecat 9da3df6ad7 chore: 升级 monorepo 依赖版本 2026-03-22 00:02:55 +08:00
imbytecat 9d8a38a4c4 fix: 修正 ORPC handler 语义、加固 Electron 安全、优化构建与运行时配置
- todo.router: create 错误码 NOT_FOUND → INTERNAL_SERVER_ERROR,remove 增加存在性检查
- __root: devtools 仅在 DEV 环境渲染
- Electron: 添加 will-navigate 导航拦截、显式安全 webPreferences、deny-all 权限请求
- sidecar: 空 catch 块补充意图注释,新增 lastResolvedUrl getter
- todo.contract: 硬编码 omit 改用 generatedFieldKeys
- router: QueryClient 添加 staleTime/retry 默认值
- turbo: build 任务精细化 inputs 提升缓存命中率
- fields: id() 改为模块私有
2026-03-05 14:06:43 +08:00
imbytecat cd7448c3b3 docs: 统一使用 bun run <script> 避免与 Bun 内置子命令冲突
bun build 会调用 Bun 内置 bundler 而非 package.json script,
将所有文档中的 bun <script> 改为 bun run <script> 以避免歧义。
bun test 保留不变(直接使用 Bun 内置 test runner)。
2026-03-05 12:57:26 +08:00
imbytecat 58d7a453b6 style: 将 biome lineWidth 从默认 80 调整为 120 2026-03-05 12:28:18 +08:00
imbytecat afc3b66efa refactor: 移除根 package.json 中冗余的 --filter 参数
Turbo 会自动只在定义了对应 script 的包上执行任务,无需手动指定 filter。
2026-03-05 12:08:48 +08:00
imbytecat 3c97e9c3eb refactor: 移除根 turbo.json 中冗余的 compile/dist 任务定义
子包 turbo.json(extends root)已各自定义了完整配置,
根级重复注册无实际作用。
2026-03-05 12:06:11 +08:00
26 changed files with 486 additions and 596 deletions
+1
View File
@@ -43,6 +43,7 @@
"files.watcherExclude": { "files.watcherExclude": {
"**/routeTree.gen.ts": true "**/routeTree.gen.ts": true
}, },
"js/ts.tsdk.path": "node_modules/typescript/lib",
"search.exclude": { "search.exclude": {
"**/routeTree.gen.ts": true "**/routeTree.gen.ts": true
} }
+46 -47
View File
@@ -4,7 +4,7 @@ Guidelines for AI agents working in this Bun monorepo.
## Project Overview ## Project Overview
> **This project uses [Bun](https://bun.sh) exclusively as both the JavaScript runtime and package manager. Do NOT use Node.js / npm / yarn / pnpm. All commands start with `bun` — use `bun install` for dependencies and `bun run` / `bun <script>` for scripts. Never use `npm`, `npx`, or `node`.** > **This project uses [Bun](https://bun.sh) exclusively as both the JavaScript runtime and package manager. Do NOT use Node.js / npm / yarn / pnpm. All commands start with `bun` — use `bun install` for dependencies and `bun run <script>` for scripts. Always prefer `bun run <script>` over `bun <script>` to avoid conflicts with Bun built-in subcommands (e.g. `bun build` invokes Bun's bundler, NOT your package.json script). Never use `npm`, `npx`, or `node`.**
- **Monorepo**: Bun workspaces + Turborepo orchestration - **Monorepo**: Bun workspaces + Turborepo orchestration
- **Runtime**: Bun (see `mise.toml` for version) — **NOT Node.js** - **Runtime**: Bun (see `mise.toml` for version) — **NOT Node.js**
@@ -18,57 +18,57 @@ Guidelines for AI agents working in this Bun monorepo.
### Root Commands (via Turbo) ### Root Commands (via Turbo)
```bash ```bash
bun dev # Start all apps in dev mode bun run dev # Start all apps in dev mode
bun build # Build all apps bun run build # Build all apps
bun compile # Compile server to standalone binary (current platform) bun run compile # Compile server to standalone binary (current platform)
bun compile:darwin # Compile server for macOS (arm64 + x64) bun run compile:darwin # Compile server for macOS (arm64 + x64)
bun compile:linux # Compile server for Linux (x64 + arm64) bun run compile:linux # Compile server for Linux (x64 + arm64)
bun compile:windows # Compile server for Windows x64 bun run compile:windows # Compile server for Windows x64
bun dist # Package desktop distributable (current platform) bun run dist # Package desktop distributable (current platform)
bun dist:linux # Package desktop for Linux (x64 + arm64) bun run dist:linux # Package desktop for Linux (x64 + arm64)
bun dist:mac # Package desktop for macOS (arm64 + x64) bun run dist:mac # Package desktop for macOS (arm64 + x64)
bun dist:win # Package desktop for Windows x64 bun run dist:win # Package desktop for Windows x64
bun fix # Lint + format (Biome auto-fix) bun run fix # Lint + format (Biome auto-fix)
bun typecheck # TypeScript check across monorepo bun run typecheck # TypeScript check across monorepo
``` ```
### Server App (`apps/server`) ### Server App (`apps/server`)
```bash ```bash
bun dev # Vite dev server (localhost:3000) bun run dev # Vite dev server (localhost:3000)
bun build # Production build -> .output/ bun run build # Production build -> .output/
bun compile # Compile to standalone binary (current platform) bun run compile # Compile to standalone binary (current platform)
bun compile:darwin # Compile for macOS (arm64 + x64) bun run compile:darwin # Compile for macOS (arm64 + x64)
bun compile:darwin:arm64 # Compile for macOS arm64 bun run compile:darwin:arm64 # Compile for macOS arm64
bun compile:darwin:x64 # Compile for macOS x64 bun run compile:darwin:x64 # Compile for macOS x64
bun compile:linux # Compile for Linux (x64 + arm64) bun run compile:linux # Compile for Linux (x64 + arm64)
bun compile:linux:arm64 # Compile for Linux arm64 bun run compile:linux:arm64 # Compile for Linux arm64
bun compile:linux:x64 # Compile for Linux x64 bun run compile:linux:x64 # Compile for Linux x64
bun compile:windows # Compile for Windows (default: x64) bun run compile:windows # Compile for Windows (default: x64)
bun compile:windows:x64 # Compile for Windows x64 bun run compile:windows:x64 # Compile for Windows x64
bun fix # Biome auto-fix bun run fix # Biome auto-fix
bun typecheck # TypeScript check bun run typecheck # TypeScript check
# Database (Drizzle) # Database (Drizzle)
bun db:generate # Generate migrations from schema bun run db:generate # Generate migrations from schema
bun db:migrate # Run migrations bun run db:migrate # Run migrations
bun db:push # Push schema (dev only) bun run db:push # Push schema (dev only)
bun db:studio # Open Drizzle Studio bun run db:studio # Open Drizzle Studio
``` ```
### Desktop App (`apps/desktop`) ### Desktop App (`apps/desktop`)
```bash ```bash
bun dev # electron-vite dev mode (requires server dev running) bun run dev # electron-vite dev mode (requires server dev running)
bun build # electron-vite build (main + preload) bun run build # electron-vite build (main + preload)
bun dist # Build + package for current platform bun run dist # Build + package for current platform
bun dist:linux # Build + package for Linux (x64 + arm64) bun run dist:linux # Build + package for Linux (x64 + arm64)
bun dist:linux:x64 # Build + package for Linux x64 bun run dist:linux:x64 # Build + package for Linux x64
bun dist:linux:arm64 # Build + package for Linux arm64 bun run dist:linux:arm64 # Build + package for Linux arm64
bun dist:mac # Build + package for macOS (arm64 + x64) bun run dist:mac # Build + package for macOS (arm64 + x64)
bun dist:mac:arm64 # Build + package for macOS arm64 bun run dist:mac:arm64 # Build + package for macOS arm64
bun dist:mac:x64 # Build + package for macOS x64 bun run dist:mac:x64 # Build + package for macOS x64
bun dist:win # Build + package for Windows x64 bun run dist:win # Build + package for Windows x64
bun fix # Biome auto-fix bun run fix # Biome auto-fix
bun typecheck # TypeScript check bun run typecheck # TypeScript check
``` ```
### Testing ### Testing
@@ -113,7 +113,6 @@ import type { ReactNode } from 'react'
- Components: arrow functions (enforced by Biome) - Components: arrow functions (enforced by Biome)
- Routes: TanStack Router file conventions (`export const Route = createFileRoute(...)`) - Routes: TanStack Router file conventions (`export const Route = createFileRoute(...)`)
- Data fetching: `useSuspenseQuery(orpc.feature.list.queryOptions())` - Data fetching: `useSuspenseQuery(orpc.feature.list.queryOptions())`
- Let React Compiler handle memoization (no manual `useMemo`/`useCallback`)
### Error Handling ### Error Handling
- Use `try-catch` for async operations; throw descriptive errors - Use `try-catch` for async operations; throw descriptive errors
@@ -160,7 +159,7 @@ export const myTable = pgTable('my_table', {
## Critical Rules ## Critical Rules
**DO:** **DO:**
- Run `bun fix` before committing - Run `bun run fix` before committing
- Use `@/*` path aliases (not relative imports) - Use `@/*` path aliases (not relative imports)
- Include `createdAt`/`updatedAt` on all tables - Include `createdAt`/`updatedAt` on all tables
- Use `catalog:` for dependency versions - Use `catalog:` for dependency versions
@@ -178,9 +177,9 @@ export const myTable = pgTable('my_table', {
## Git Workflow ## Git Workflow
1. Make changes following style guide 1. Make changes following style guide
2. `bun fix` - auto-format and lint 2. `bun run fix` - auto-format and lint
3. `bun typecheck` - verify types 3. `bun run typecheck` - verify types
4. `bun dev` - test locally 4. `bun run dev` - test locally
5. Commit with descriptive message 5. Commit with descriptive message
## Directory Structure ## Directory Structure
+18 -18
View File
@@ -4,7 +4,7 @@ Thin Electron shell hosting the fullstack server app.
## Tech Stack ## Tech Stack
> **⚠️ This project uses Bun as the package manager. Runtime is Electron (Node.js). Never use `npm`, `npx`, `yarn`, or `pnpm`.** > **⚠️ This project uses Bun as the package manager. Runtime is Electron (Node.js). Always use `bun run <script>` (not `bun <script>`) to avoid conflicts with Bun built-in subcommands. Never use `npm`, `npx`, `yarn`, or `pnpm`.**
- **Type**: Electron desktop shell - **Type**: Electron desktop shell
- **Design**: Server-driven desktop (thin native window hosting web app) - **Design**: Server-driven desktop (thin native window hosting web app)
@@ -22,18 +22,18 @@ Thin Electron shell hosting the fullstack server app.
## Commands ## Commands
```bash ```bash
bun dev # electron-vite dev (requires server dev running) bun run dev # electron-vite dev (requires server dev running)
bun build # electron-vite build (main + preload) bun run build # electron-vite build (main + preload)
bun dist # Build + package for current platform bun run dist # Build + package for current platform
bun dist:linux # Build + package for Linux (x64 + arm64) bun run dist:linux # Build + package for Linux (x64 + arm64)
bun dist:linux:x64 # Build + package for Linux x64 bun run dist:linux:x64 # Build + package for Linux x64
bun dist:linux:arm64 # Build + package for Linux arm64 bun run dist:linux:arm64 # Build + package for Linux arm64
bun dist:mac # Build + package for macOS (arm64 + x64) bun run dist:mac # Build + package for macOS (arm64 + x64)
bun dist:mac:arm64 # Build + package for macOS arm64 bun run dist:mac:arm64 # Build + package for macOS arm64
bun dist:mac:x64 # Build + package for macOS x64 bun run dist:mac:x64 # Build + package for macOS x64
bun dist:win # Build + package for Windows x64 bun run dist:win # Build + package for Windows x64
bun fix # Biome auto-fix bun run fix # Biome auto-fix
bun typecheck # TypeScript check bun run typecheck # TypeScript check
``` ```
## Directory Structure ## Directory Structure
@@ -56,13 +56,13 @@ bun typecheck # TypeScript check
## Development Workflow ## Development Workflow
1. **Start server**: `bun dev` in `apps/server` (or use root `bun dev` via Turbo). 1. **Start server**: `bun run dev` in `apps/server` (or use root `bun run dev` via Turbo).
2. **Start desktop**: `bun dev` in `apps/desktop`. 2. **Start desktop**: `bun run dev` in `apps/desktop`.
3. **Connection**: Main process polls `localhost:3000` until responsive, then opens BrowserWindow. 3. **Connection**: Main process polls `localhost:3000` until responsive, then opens BrowserWindow.
## Production Build Workflow ## Production Build Workflow
From monorepo root, run `bun dist` to execute the full pipeline automatically (via Turbo task dependencies): From monorepo root, run `bun run dist` to execute the full pipeline automatically (via Turbo task dependencies):
1. **Build server**: `apps/server``vite build``.output/` 1. **Build server**: `apps/server``vite build``.output/`
2. **Compile server**: `apps/server``bun compile.ts --target ...``out/server-{os}-{arch}` 2. **Compile server**: `apps/server``bun compile.ts --target ...``out/server-{os}-{arch}`
@@ -70,8 +70,8 @@ From monorepo root, run `bun dist` to execute the full pipeline automatically (v
The `electron-builder.yml` `extraResources` config reads binaries directly from `../server/out/`, no manual copy needed. The `electron-builder.yml` `extraResources` config reads binaries directly from `../server/out/`, no manual copy needed.
To build for a specific platform explicitly, use `bun dist:linux` / `bun dist:mac` / `bun dist:win` in `apps/desktop`. To build for a specific platform explicitly, use `bun run dist:linux` / `bun run dist:mac` / `bun run dist:win` in `apps/desktop`.
For single-arch output, use `bun dist:linux:x64`, `bun dist:linux:arm64`, `bun dist:mac:x64`, or `bun dist:mac:arm64`. For single-arch output, use `bun run dist:linux:x64`, `bun run dist:linux:arm64`, `bun run dist:mac:x64`, or `bun run dist:mac:arm64`.
## Development Principles ## Development Principles
+26 -4
View File
@@ -1,5 +1,5 @@
import { join } from 'node:path' import { join } from 'node:path'
import { app, BrowserWindow, dialog, shell } from 'electron' import { app, BrowserWindow, dialog, session, shell } from 'electron'
import { createSidecarRuntime } from './sidecar' import { createSidecarRuntime } from './sidecar'
const DEV_SERVER_URL = 'http://localhost:3000' const DEV_SERVER_URL = 'http://localhost:3000'
@@ -28,8 +28,7 @@ const sidecar = createSidecarRuntime({
}, },
}) })
const toErrorMessage = (error: unknown): string => const toErrorMessage = (error: unknown): string => (error instanceof Error ? error.message : String(error))
error instanceof Error ? error.message : String(error)
const canOpenExternally = (url: string): boolean => { const canOpenExternally = (url: string): boolean => {
try { try {
@@ -62,6 +61,8 @@ const createWindow = async () => {
webPreferences: { webPreferences: {
preload: join(__dirname, '../preload/index.js'), preload: join(__dirname, '../preload/index.js'),
sandbox: true, sandbox: true,
contextIsolation: true,
nodeIntegration: false,
}, },
}) })
mainWindow = windowRef mainWindow = windowRef
@@ -79,6 +80,21 @@ const createWindow = async () => {
return { action: 'deny' } return { action: 'deny' }
}) })
windowRef.webContents.on('will-navigate', (event, url) => {
const allowed = [DEV_SERVER_URL, sidecar.lastResolvedUrl].filter((v): v is string => v != null)
const isAllowed = allowed.some((origin) => url.startsWith(origin))
if (!isAllowed) {
event.preventDefault()
if (canOpenExternally(url)) {
void shell.openExternal(url)
} else if (!app.isPackaged) {
console.warn(`Blocked navigation to: ${url}`)
}
}
})
windowRef.on('closed', () => { windowRef.on('closed', () => {
if (mainWindow === windowRef) { if (mainWindow === windowRef) {
mainWindow = null mainWindow = null
@@ -152,7 +168,13 @@ const handleWindowCreationError = (error: unknown, context: string) => {
app app
.whenReady() .whenReady()
.then(() => ensureWindow()) .then(() => {
session.defaultSession.setPermissionRequestHandler((_webContents, _permission, callback) => {
callback(false)
})
return ensureWindow()
})
.catch((error) => { .catch((error) => {
handleWindowCreationError(error, 'Failed to create window') handleWindowCreationError(error, 'Failed to create window')
}) })
+16 -28
View File
@@ -27,14 +27,12 @@ type SidecarRuntimeOptions = {
type SidecarRuntime = { type SidecarRuntime = {
resolveUrl: () => Promise<string> resolveUrl: () => Promise<string>
stop: () => void stop: () => void
lastResolvedUrl: string | null
} }
const sleep = (ms: number): Promise<void> => const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms))
new Promise((resolve) => setTimeout(resolve, ms))
const isProcessAlive = ( const isProcessAlive = (processToCheck: ChildProcess | null): processToCheck is ChildProcess => {
processToCheck: ChildProcess | null,
): processToCheck is ChildProcess => {
if (!processToCheck || !processToCheck.pid) { if (!processToCheck || !processToCheck.pid) {
return false return false
} }
@@ -75,17 +73,15 @@ const isServerReady = async (url: string): Promise<boolean> => {
return true return true
} }
} catch {} } catch {
// Expected: probe request fails while server is still starting up
}
} }
return false return false
} }
const waitForServer = async ( const waitForServer = async (url: string, isQuitting: () => boolean, processRef?: ChildProcess): Promise<boolean> => {
url: string,
isQuitting: () => boolean,
processRef?: ChildProcess,
): Promise<boolean> => {
const start = Date.now() const start = Date.now()
while (Date.now() - start < SERVER_READY_TIMEOUT_MS && !isQuitting()) { while (Date.now() - start < SERVER_READY_TIMEOUT_MS && !isQuitting()) {
if (processRef && processRef.exitCode !== null) { if (processRef && processRef.exitCode !== null) {
@@ -119,9 +115,7 @@ const formatUnexpectedStopMessage = (
return `Server process exited unexpectedly (code ${code ?? 'unknown'}, signal ${signal ?? 'none'}).` return `Server process exited unexpectedly (code ${code ?? 'unknown'}, signal ${signal ?? 'none'}).`
} }
export const createSidecarRuntime = ( export const createSidecarRuntime = (options: SidecarRuntimeOptions): SidecarRuntime => {
options: SidecarRuntimeOptions,
): SidecarRuntime => {
const state: SidecarState = { const state: SidecarState = {
process: null, process: null,
startup: null, startup: null,
@@ -162,9 +156,7 @@ export const createSidecarRuntime = (
resetState(processRef) resetState(processRef)
if (!options.isQuitting() && hadReadyServer) { if (!options.isQuitting() && hadReadyServer) {
options.onUnexpectedStop( options.onUnexpectedStop('The background service crashed unexpectedly. Please restart the app.')
'The background service crashed unexpectedly. Please restart the app.',
)
return return
} }
@@ -180,9 +172,7 @@ export const createSidecarRuntime = (
resetState(processRef) resetState(processRef)
if (!options.isQuitting() && hadReadyServer) { if (!options.isQuitting() && hadReadyServer) {
options.onUnexpectedStop( options.onUnexpectedStop(formatUnexpectedStopMessage(options.isPackaged, code, signal))
formatUnexpectedStopMessage(options.isPackaged, code, signal),
)
} }
}) })
} }
@@ -222,11 +212,7 @@ export const createSidecarRuntime = (
state.process = processRef state.process = processRef
attachLifecycleHandlers(processRef) attachLifecycleHandlers(processRef)
const ready = await waitForServer( const ready = await waitForServer(nextServerUrl, options.isQuitting, processRef)
nextServerUrl,
options.isQuitting,
processRef,
)
if (ready && isProcessAlive(processRef)) { if (ready && isProcessAlive(processRef)) {
state.url = nextServerUrl state.url = nextServerUrl
return nextServerUrl return nextServerUrl
@@ -253,16 +239,18 @@ export const createSidecarRuntime = (
const ready = await waitForServer(options.devServerUrl, options.isQuitting) const ready = await waitForServer(options.devServerUrl, options.isQuitting)
if (!ready) { if (!ready) {
throw new Error( throw new Error('Dev server not responding. Run `bun dev` in apps/server first.')
'Dev server not responding. Run `bun dev` in apps/server first.',
)
} }
state.url = options.devServerUrl
return options.devServerUrl return options.devServerUrl
} }
return { return {
resolveUrl, resolveUrl,
stop, stop,
get lastResolvedUrl() {
return state.url
},
} }
} }
@@ -13,12 +13,7 @@ export const SplashApp = () => {
ease: [0.16, 1, 0.3, 1], ease: [0.16, 1, 0.3, 1],
}} }}
> >
<img <img alt="Logo" className="h-20 w-auto object-contain" draggable={false} src={logoImage} />
alt="Logo"
className="h-20 w-auto object-contain"
draggable={false}
src={logoImage}
/>
<div className="relative h-[4px] w-36 overflow-hidden rounded-full bg-zinc-100"> <div className="relative h-[4px] w-36 overflow-hidden rounded-full bg-zinc-100">
<motion.div <motion.div
+2 -10
View File
@@ -10,11 +10,7 @@
"outputs": ["dist/**"] "outputs": ["dist/**"]
}, },
"dist:linux": { "dist:linux": {
"dependsOn": [ "dependsOn": ["build", "@furtherverse/server#compile:linux:arm64", "@furtherverse/server#compile:linux:x64"],
"build",
"@furtherverse/server#compile:linux:arm64",
"@furtherverse/server#compile:linux:x64"
],
"outputs": ["dist/**"] "outputs": ["dist/**"]
}, },
"dist:linux:arm64": { "dist:linux:arm64": {
@@ -26,11 +22,7 @@
"outputs": ["dist/**"] "outputs": ["dist/**"]
}, },
"dist:mac": { "dist:mac": {
"dependsOn": [ "dependsOn": ["build", "@furtherverse/server#compile:darwin:arm64", "@furtherverse/server#compile:darwin:x64"],
"build",
"@furtherverse/server#compile:darwin:arm64",
"@furtherverse/server#compile:darwin:x64"
],
"outputs": ["dist/**"] "outputs": ["dist/**"]
}, },
"dist:mac:arm64": { "dist:mac:arm64": {
+19 -20
View File
@@ -4,7 +4,7 @@ TanStack Start fullstack web app with ORPC (contract-first RPC).
## Tech Stack ## Tech Stack
> **⚠️ This project uses Bun — NOT Node.js / npm. All commands use `bun`. Never use `npm`, `npx`, or `node`.** > **⚠️ This project uses Bun — NOT Node.js / npm. All commands use `bun`. Always use `bun run <script>` (not `bun <script>`) to avoid conflicts with Bun built-in subcommands. Never use `npm`, `npx`, or `node`.**
- **Framework**: TanStack Start (React 19 SSR, file-based routing) - **Framework**: TanStack Start (React 19 SSR, file-based routing)
- **Runtime**: Bun — **NOT Node.js** - **Runtime**: Bun — **NOT Node.js**
@@ -20,29 +20,29 @@ TanStack Start fullstack web app with ORPC (contract-first RPC).
```bash ```bash
# Development # Development
bun dev # Vite dev server (localhost:3000) bun run dev # Vite dev server (localhost:3000)
bun db:studio # Drizzle Studio GUI bun run db:studio # Drizzle Studio GUI
# Build # Build
bun build # Production build → .output/ bun run build # Production build → .output/
bun compile # Compile to standalone binary (current platform, depends on build) bun run compile # Compile to standalone binary (current platform, depends on build)
bun compile:darwin # Compile for macOS (arm64 + x64) bun run compile:darwin # Compile for macOS (arm64 + x64)
bun compile:darwin:arm64 # Compile for macOS arm64 bun run compile:darwin:arm64 # Compile for macOS arm64
bun compile:darwin:x64 # Compile for macOS x64 bun run compile:darwin:x64 # Compile for macOS x64
bun compile:linux # Compile for Linux (x64 + arm64) bun run compile:linux # Compile for Linux (x64 + arm64)
bun compile:linux:arm64 # Compile for Linux arm64 bun run compile:linux:arm64 # Compile for Linux arm64
bun compile:linux:x64 # Compile for Linux x64 bun run compile:linux:x64 # Compile for Linux x64
bun compile:windows # Compile for Windows (default: x64) bun run compile:windows # Compile for Windows (default: x64)
bun compile:windows:x64 # Compile for Windows x64 bun run compile:windows:x64 # Compile for Windows x64
# Code Quality # Code Quality
bun fix # Biome auto-fix bun run fix # Biome auto-fix
bun typecheck # TypeScript check bun run typecheck # TypeScript check
# Database # Database
bun db:generate # Generate migrations from schema bun run db:generate # Generate migrations from schema
bun db:migrate # Run migrations bun run db:migrate # Run migrations
bun db:push # Push schema directly (dev only) bun run db:push # Push schema directly (dev only)
# Testing (not yet configured) # Testing (not yet configured)
bun test path/to/test.ts # Run single test bun test path/to/test.ts # Run single test
@@ -226,7 +226,6 @@ import type { ReactNode } from 'react'
### React ### React
- Use arrow functions for components (Biome enforced) - Use arrow functions for components (Biome enforced)
- Use `useSuspenseQuery` for guaranteed data - Use `useSuspenseQuery` for guaranteed data
- Let React Compiler handle memoization (no manual `useMemo`/`useCallback`)
## Environment Variables ## Environment Variables
@@ -257,7 +256,7 @@ export const env = createEnv({
## Critical Rules ## Critical Rules
**DO:** **DO:**
- Run `bun fix` before committing - Run `bun run fix` before committing
- Use `@/*` path aliases - Use `@/*` path aliases
- Include `createdAt`/`updatedAt` on all tables - Include `createdAt`/`updatedAt` on all tables
- Use `ORPCError` with proper codes - Use `ORPCError` with proper codes
+2 -7
View File
@@ -24,9 +24,7 @@ const { values } = parseArgs({
const resolveTarget = (): Bun.Build.CompileTarget => { const resolveTarget = (): Bun.Build.CompileTarget => {
if (values.target !== undefined) { if (values.target !== undefined) {
if (!isSupportedTarget(values.target)) { if (!isSupportedTarget(values.target)) {
throw new Error( throw new Error(`Invalid target: ${values.target}\nAllowed: ${SUPPORTED_TARGETS.join(', ')}`)
`Invalid target: ${values.target}\nAllowed: ${SUPPORTED_TARGETS.join(', ')}`,
)
} }
return values.target return values.target
} }
@@ -45,10 +43,7 @@ const main = async () => {
const outfile = `server-${suffix}` const outfile = `server-${suffix}`
await mkdir(OUTDIR, { recursive: true }) await mkdir(OUTDIR, { recursive: true })
await Promise.all([ await Promise.all([rm(`${OUTDIR}/${outfile}`, { force: true }), rm(`${OUTDIR}/${outfile}.exe`, { force: true })])
rm(`${OUTDIR}/${outfile}`, { force: true }),
rm(`${OUTDIR}/${outfile}.exe`, { force: true }),
])
const result = await Bun.build({ const result = await Bun.build({
entrypoints: [ENTRYPOINT], entrypoints: [ENTRYPOINT],
+1 -3
View File
@@ -50,11 +50,9 @@
"@tanstack/react-router-devtools": "catalog:", "@tanstack/react-router-devtools": "catalog:",
"@types/bun": "catalog:", "@types/bun": "catalog:",
"@vitejs/plugin-react": "catalog:", "@vitejs/plugin-react": "catalog:",
"babel-plugin-react-compiler": "catalog:",
"drizzle-kit": "catalog:", "drizzle-kit": "catalog:",
"nitro": "catalog:", "nitro": "catalog:",
"tailwindcss": "catalog:", "tailwindcss": "catalog:",
"vite": "catalog:", "vite": "catalog:"
"vite-tsconfig-paths": "catalog:"
} }
} }
+8 -1
View File
@@ -5,7 +5,14 @@ import type { RouterContext } from './routes/__root'
import { routeTree } from './routeTree.gen' import { routeTree } from './routeTree.gen'
export const getRouter = () => { export const getRouter = () => {
const queryClient = new QueryClient() const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 30 * 1000,
retry: 1,
},
},
})
const router = createRouter({ const router = createRouter({
routeTree, routeTree,
+3 -5
View File
@@ -1,11 +1,7 @@
import { TanStackDevtools } from '@tanstack/react-devtools' import { TanStackDevtools } from '@tanstack/react-devtools'
import type { QueryClient } from '@tanstack/react-query' import type { QueryClient } from '@tanstack/react-query'
import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools' import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
import { import { createRootRouteWithContext, HeadContent, Scripts } from '@tanstack/react-router'
createRootRouteWithContext,
HeadContent,
Scripts,
} from '@tanstack/react-router'
import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools' import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools'
import type { ReactNode } from 'react' import type { ReactNode } from 'react'
import { ErrorComponent } from '@/components/Error' import { ErrorComponent } from '@/components/Error'
@@ -50,6 +46,7 @@ function RootDocument({ children }: Readonly<{ children: ReactNode }>) {
</head> </head>
<body> <body>
{children} {children}
{import.meta.env.DEV && (
<TanStackDevtools <TanStackDevtools
config={{ config={{
position: 'bottom-right', position: 'bottom-right',
@@ -65,6 +62,7 @@ function RootDocument({ children }: Readonly<{ children: ReactNode }>) {
}, },
]} ]}
/> />
)}
<Scripts /> <Scripts />
</body> </body>
</html> </html>
+5 -20
View File
@@ -53,9 +53,7 @@ function Todos() {
{/* Header */} {/* Header */}
<div className="flex items-end justify-between"> <div className="flex items-end justify-between">
<div> <div>
<h1 className="text-3xl font-bold text-slate-900 tracking-tight"> <h1 className="text-3xl font-bold text-slate-900 tracking-tight"></h1>
</h1>
<p className="text-slate-500 mt-1"></p> <p className="text-slate-500 mt-1"></p>
</div> </div>
<div className="text-right"> <div className="text-right">
@@ -63,9 +61,7 @@ function Todos() {
{completedCount} {completedCount}
<span className="text-slate-400 text-lg">/{totalCount}</span> <span className="text-slate-400 text-lg">/{totalCount}</span>
</div> </div>
<div className="text-xs font-medium text-slate-400 uppercase tracking-wider"> <div className="text-xs font-medium text-slate-400 uppercase tracking-wider"></div>
</div>
</div> </div>
</div> </div>
@@ -112,18 +108,11 @@ function Todos() {
stroke="currentColor" stroke="currentColor"
aria-hidden="true" aria-hidden="true"
> >
<path <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={1.5}
d="M12 6v6m0 0v6m0-6h6m-6 0H6"
/>
</svg> </svg>
</div> </div>
<p className="text-slate-500 text-lg font-medium"></p> <p className="text-slate-500 text-lg font-medium"></p>
<p className="text-slate-400 text-sm mt-1"> <p className="text-slate-400 text-sm mt-1"></p>
</p>
</div> </div>
) : ( ) : (
todos.map((todo) => ( todos.map((todo) => (
@@ -151,11 +140,7 @@ function Todos() {
strokeWidth={3} strokeWidth={3}
aria-hidden="true" aria-hidden="true"
> >
<path <path strokeLinecap="round" strokeLinejoin="round" d="M5 13l4 4L19 7" />
strokeLinecap="round"
strokeLinejoin="round"
d="M5 13l4 4L19 7"
/>
</svg> </svg>
)} )}
</button> </button>
@@ -1,25 +1,14 @@
import { oc } from '@orpc/contract' import { oc } from '@orpc/contract'
import { import { createInsertSchema, createSelectSchema, createUpdateSchema } from 'drizzle-orm/zod'
createInsertSchema,
createSelectSchema,
createUpdateSchema,
} from 'drizzle-orm/zod'
import { z } from 'zod' import { z } from 'zod'
import { generatedFieldKeys } from '@/server/db/fields'
import { todoTable } from '@/server/db/schema' import { todoTable } from '@/server/db/schema'
const selectSchema = createSelectSchema(todoTable) const selectSchema = createSelectSchema(todoTable)
const insertSchema = createInsertSchema(todoTable).omit({ const insertSchema = createInsertSchema(todoTable).omit(generatedFieldKeys)
id: true,
createdAt: true,
updatedAt: true,
})
const updateSchema = createUpdateSchema(todoTable).omit({ const updateSchema = createUpdateSchema(todoTable).omit(generatedFieldKeys)
id: true,
createdAt: true,
updatedAt: true,
})
export const list = oc.input(z.void()).output(z.array(selectSchema)) export const list = oc.input(z.void()).output(z.array(selectSchema))
+2 -10
View File
@@ -6,11 +6,7 @@ export const logError = (error: unknown) => {
} }
export const handleValidationError = (error: unknown) => { export const handleValidationError = (error: unknown) => {
if ( if (error instanceof ORPCError && error.code === 'BAD_REQUEST' && error.cause instanceof ValidationError) {
error instanceof ORPCError &&
error.code === 'BAD_REQUEST' &&
error.cause instanceof ValidationError
) {
// If you only use Zod you can safely cast to ZodIssue[] (per ORPC official docs) // If you only use Zod you can safely cast to ZodIssue[] (per ORPC official docs)
const zodError = new z.ZodError(error.cause.issues as z.core.$ZodIssue[]) const zodError = new z.ZodError(error.cause.issues as z.core.$ZodIssue[])
@@ -22,11 +18,7 @@ export const handleValidationError = (error: unknown) => {
}) })
} }
if ( if (error instanceof ORPCError && error.code === 'INTERNAL_SERVER_ERROR' && error.cause instanceof ValidationError) {
error instanceof ORPCError &&
error.code === 'INTERNAL_SERVER_ERROR' &&
error.cause instanceof ValidationError
) {
throw new ORPCError('OUTPUT_VALIDATION_FAILED', { throw new ORPCError('OUTPUT_VALIDATION_FAILED', {
cause: error.cause, cause: error.cause,
}) })
@@ -11,29 +11,18 @@ export const list = os.todo.list.use(db).handler(async ({ context }) => {
return todos return todos
}) })
export const create = os.todo.create export const create = os.todo.create.use(db).handler(async ({ context, input }) => {
.use(db) const [newTodo] = await context.db.insert(todoTable).values(input).returning()
.handler(async ({ context, input }) => {
const [newTodo] = await context.db
.insert(todoTable)
.values(input)
.returning()
if (!newTodo) { if (!newTodo) {
throw new ORPCError('NOT_FOUND') throw new ORPCError('INTERNAL_SERVER_ERROR', { message: 'Failed to create todo' })
} }
return newTodo return newTodo
}) })
export const update = os.todo.update export const update = os.todo.update.use(db).handler(async ({ context, input }) => {
.use(db) const [updatedTodo] = await context.db.update(todoTable).set(input.data).where(eq(todoTable.id, input.id)).returning()
.handler(async ({ context, input }) => {
const [updatedTodo] = await context.db
.update(todoTable)
.set(input.data)
.where(eq(todoTable.id, input.id))
.returning()
if (!updatedTodo) { if (!updatedTodo) {
throw new ORPCError('NOT_FOUND') throw new ORPCError('NOT_FOUND')
@@ -42,8 +31,10 @@ export const update = os.todo.update
return updatedTodo return updatedTodo
}) })
export const remove = os.todo.remove export const remove = os.todo.remove.use(db).handler(async ({ context, input }) => {
.use(db) const [deleted] = await context.db.delete(todoTable).where(eq(todoTable.id, input.id)).returning({ id: todoTable.id })
.handler(async ({ context, input }) => {
await context.db.delete(todoTable).where(eq(todoTable.id, input.id)) if (!deleted) {
throw new ORPCError('NOT_FOUND')
}
}) })
+1 -5
View File
@@ -1,8 +1,4 @@
import type { import type { ContractRouterClient, InferContractRouterInputs, InferContractRouterOutputs } from '@orpc/contract'
ContractRouterClient,
InferContractRouterInputs,
InferContractRouterOutputs,
} from '@orpc/contract'
import type { Contract } from './contracts' import type { Contract } from './contracts'
export type RouterClient = ContractRouterClient<Contract> export type RouterClient = ContractRouterClient<Contract>
+3 -6
View File
@@ -4,7 +4,7 @@ import { v7 as uuidv7 } from 'uuid'
// id // id
export const id = (name: string) => uuid(name) const id = (name: string) => uuid(name)
export const pk = (name: string, strategy?: 'native' | 'extension') => { export const pk = (name: string, strategy?: 'native' | 'extension') => {
switch (strategy) { switch (strategy) {
// PG 18+ // PG 18+
@@ -25,8 +25,7 @@ export const pk = (name: string, strategy?: 'native' | 'extension') => {
// timestamp // timestamp
export const createdAt = (name = 'created_at') => export const createdAt = (name = 'created_at') => timestamp(name, { withTimezone: true }).notNull().defaultNow()
timestamp(name, { withTimezone: true }).notNull().defaultNow()
export const updatedAt = (name = 'updated_at') => export const updatedAt = (name = 'updated_at') =>
timestamp(name, { withTimezone: true }) timestamp(name, { withTimezone: true })
@@ -43,9 +42,7 @@ export const generatedFields = {
} }
// Helper to create omit keys from generatedFields // Helper to create omit keys from generatedFields
const createGeneratedFieldKeys = <T extends Record<string, unknown>>( const createGeneratedFieldKeys = <T extends Record<string, unknown>>(fields: T): Record<keyof T, true> => {
fields: T,
): Record<keyof T, true> => {
return Object.keys(fields).reduce( return Object.keys(fields).reduce(
(acc, key) => { (acc, key) => {
acc[key as keyof T] = true acc[key as keyof T] = true
-1
View File
@@ -1,7 +1,6 @@
{ {
"extends": "@furtherverse/tsconfig/react.json", "extends": "@furtherverse/tsconfig/react.json",
"compilerOptions": { "compilerOptions": {
"baseUrl": ".",
"paths": { "paths": {
"@/*": ["./src/*"] "@/*": ["./src/*"]
} }
+1
View File
@@ -4,6 +4,7 @@
"tasks": { "tasks": {
"build": { "build": {
"env": ["NODE_ENV", "VITE_*"], "env": ["NODE_ENV", "VITE_*"],
"inputs": ["src/**", "public/**", "package.json", "tsconfig.json", "vite.config.ts"],
"outputs": [".output/**"] "outputs": [".output/**"]
}, },
"compile": { "compile": {
+4 -7
View File
@@ -4,25 +4,22 @@ import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
import { nitro } from 'nitro/vite' import { nitro } from 'nitro/vite'
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'
export default defineConfig({ export default defineConfig({
clearScreen: false, clearScreen: false,
plugins: [ plugins: [
tanstackDevtools(), tanstackDevtools(),
tailwindcss(), tailwindcss(),
tsconfigPaths(),
tanstackStart(), tanstackStart(),
react({ react(),
babel: {
plugins: ['babel-plugin-react-compiler'],
},
}),
nitro({ nitro({
preset: 'bun', preset: 'bun',
serveStatic: 'inline', serveStatic: 'inline',
}), }),
], ],
resolve: {
tsconfigPaths: true,
},
server: { server: {
port: 3000, port: 3000,
strictPort: true, strictPort: true,
+2 -1
View File
@@ -11,7 +11,8 @@
"formatter": { "formatter": {
"enabled": true, "enabled": true,
"indentStyle": "space", "indentStyle": "space",
"lineEnding": "lf" "lineEnding": "lf",
"lineWidth": 120
}, },
"linter": { "linter": {
"enabled": true, "enabled": true,
+245 -260
View File
File diff suppressed because it is too large Load Diff
+34 -36
View File
@@ -9,59 +9,57 @@
], ],
"scripts": { "scripts": {
"build": "turbo run build", "build": "turbo run build",
"compile": "turbo run compile --filter=@furtherverse/server", "compile": "turbo run compile",
"compile:darwin": "turbo run compile:darwin --filter=@furtherverse/server", "compile:darwin": "turbo run compile:darwin",
"compile:linux": "turbo run compile:linux --filter=@furtherverse/server", "compile:linux": "turbo run compile:linux",
"compile:windows": "turbo run compile:windows --filter=@furtherverse/server", "compile:windows": "turbo run compile:windows",
"dev": "turbo run dev", "dev": "turbo run dev",
"dist": "turbo run dist --filter=@furtherverse/desktop", "dist": "turbo run dist",
"dist:linux": "turbo run dist:linux --filter=@furtherverse/desktop", "dist:linux": "turbo run dist:linux",
"dist:mac": "turbo run dist:mac --filter=@furtherverse/desktop", "dist:mac": "turbo run dist:mac",
"dist:win": "turbo run dist:win --filter=@furtherverse/desktop", "dist:win": "turbo run dist:win",
"fix": "turbo run fix", "fix": "turbo run fix",
"typecheck": "turbo run typecheck" "typecheck": "turbo run typecheck"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "^2.4.5", "@biomejs/biome": "^2.4.9",
"turbo": "^2.8.13", "turbo": "^2.8.20",
"typescript": "^5.9.3" "typescript": "^6.0.2"
}, },
"catalog": { "catalog": {
"@orpc/client": "^1.13.6", "@orpc/client": "^1.13.11",
"@orpc/contract": "^1.13.6", "@orpc/contract": "^1.13.11",
"@orpc/openapi": "^1.13.6", "@orpc/openapi": "^1.13.11",
"@orpc/server": "^1.13.6", "@orpc/server": "^1.13.11",
"@orpc/tanstack-query": "^1.13.6", "@orpc/tanstack-query": "^1.13.11",
"@orpc/zod": "^1.13.6", "@orpc/zod": "^1.13.11",
"@t3-oss/env-core": "^0.13.10", "@t3-oss/env-core": "^0.13.11",
"@tailwindcss/vite": "^4.2.1", "@tailwindcss/vite": "^4.2.2",
"@tanstack/devtools-vite": "^0.5.3", "@tanstack/devtools-vite": "^0.6.0",
"@tanstack/react-devtools": "^0.9.9", "@tanstack/react-devtools": "^0.10.0",
"@tanstack/react-query": "^5.90.21", "@tanstack/react-query": "^5.95.2",
"@tanstack/react-query-devtools": "^5.91.3", "@tanstack/react-query-devtools": "^5.95.2",
"@tanstack/react-router": "^1.166.2", "@tanstack/react-router": "^1.168.3",
"@tanstack/react-router-devtools": "^1.166.2", "@tanstack/react-router-devtools": "^1.166.11",
"@tanstack/react-router-ssr-query": "^1.166.2", "@tanstack/react-router-ssr-query": "^1.166.10",
"@tanstack/react-start": "^1.166.2", "@tanstack/react-start": "^1.167.6",
"@types/bun": "^1.3.10", "@types/bun": "^1.3.11",
"@types/node": "^24.11.0", "@types/node": "^24.12.0",
"@vitejs/plugin-react": "^5.1.4", "@vitejs/plugin-react": "^6.0.1",
"babel-plugin-react-compiler": "^1.0.0",
"drizzle-kit": "1.0.0-beta.15-859cf75", "drizzle-kit": "1.0.0-beta.15-859cf75",
"drizzle-orm": "1.0.0-beta.15-859cf75", "drizzle-orm": "1.0.0-beta.15-859cf75",
"electron": "^34.0.0", "electron": "^34.0.0",
"electron-builder": "^26.8.1", "electron-builder": "^26.8.1",
"electron-vite": "^5.0.0", "electron-vite": "^5.0.0",
"motion": "^12.35.0", "motion": "^12.38.0",
"nitro": "npm:nitro-nightly@3.0.1-20260227-181935-bfbb207c", "nitro": "npm:nitro-nightly@3.0.1-20260324-103046-9ce219ca",
"postgres": "^3.4.8", "postgres": "^3.4.8",
"react": "^19.2.4", "react": "^19.2.4",
"react-dom": "^19.2.4", "react-dom": "^19.2.4",
"tailwindcss": "^4.2.1", "tailwindcss": "^4.2.2",
"tree-kill": "^1.2.2", "tree-kill": "^1.2.2",
"uuid": "^13.0.0", "uuid": "^13.0.0",
"vite": "^8.0.0-beta.16", "vite": "^8.0.2",
"vite-tsconfig-paths": "^6.1.1",
"zod": "^4.3.6" "zod": "^4.3.6"
}, },
"overrides": { "overrides": {
+3 -1
View File
@@ -20,7 +20,9 @@
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true, "noUncheckedSideEffectImports": true,
"noUncheckedIndexedAccess": true, "noUncheckedIndexedAccess": true,
"noImplicitOverride": true "noImplicitOverride": true,
"types": ["bun"]
}, },
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }
+1 -38
View File
@@ -6,52 +6,15 @@
"build": { "build": {
"dependsOn": ["^build"] "dependsOn": ["^build"]
}, },
"compile": {
"dependsOn": ["build"],
"cache": false
},
"compile:darwin": {
"dependsOn": ["build"],
"cache": false
},
"compile:linux": {
"dependsOn": ["build"],
"cache": false
},
"compile:windows": {
"dependsOn": ["build"],
"cache": false
},
"dev": { "dev": {
"cache": false, "cache": false,
"persistent": true "persistent": true
}, },
"dist": {
"dependsOn": ["build"],
"cache": false
},
"dist:linux": {
"dependsOn": ["build"],
"cache": false
},
"dist:mac": {
"dependsOn": ["build"],
"cache": false
},
"dist:win": {
"dependsOn": ["build"],
"cache": false
},
"fix": { "fix": {
"cache": false "cache": false
}, },
"typecheck": { "typecheck": {
"inputs": [ "inputs": ["package.json", "tsconfig.json", "tsconfig.*.json", "**/*.{ts,tsx,d.ts}"],
"package.json",
"tsconfig.json",
"tsconfig.*.json",
"**/*.{ts,tsx,d.ts}"
],
"outputs": [] "outputs": []
} }
}, },