refactor: 优化项目结构 — 修复拼写、提取共享 interceptor、扁平化 db 目录、清理空包

This commit is contained in:
2026-03-05 10:58:55 +08:00
parent 0438b52c93
commit 0cd8b57d24
13 changed files with 55 additions and 121 deletions

View File

@@ -54,24 +54,28 @@ bun test -t "pattern" # Run tests matching pattern
```
src/
├── client/ # Client-side code
│ ├── orpc.ts # ORPC isomorphic client
│ └── query-client.ts # TanStack Query client
│ ├── orpc.ts # ORPC isomorphic client (internal)
│ └── query-client.ts # TanStack Query utils (used by components)
├── components/ # React components
├── routes/ # TanStack Router file routes
│ ├── __root.tsx # Root layout
│ ├── index.tsx # Home page
│ └── api/
── rpc.$.ts # ORPC HTTP endpoint
── $.ts # OpenAPI handler + Scalar docs
│ ├── health.ts # Health check endpoint
│ └── rpc.$.ts # ORPC RPC handler
├── server/ # Server-side code
│ ├── api/ # ORPC layer
│ │ ├── contracts/ # Input/output schemas (Zod)
│ │ ├── middlewares/ # Middleware (db provider, auth)
│ │ ├── routers/ # Handler implementations
│ │ ├── interceptors.ts # Shared error interceptors
│ │ ├── context.ts # Request context
│ │ ├── server.ts # ORPC server instance
│ │ └── types.ts # Type exports
│ └── db/
│ ├── schema/ # Drizzle table definitions
│ ├── fields.ts # Shared field builders (id, createdAt, updatedAt)
│ ├── relations.ts # Drizzle relations (defineRelations, RQBv2)
│ └── index.ts # Database instance (postgres-js driver)
├── env.ts # Environment variable validation
@@ -122,7 +126,7 @@ export const router = os.router({ feature })
### 4. Use in Components
```typescript
import { useSuspenseQuery, useMutation } from '@tanstack/react-query'
import { orpc } from '@/client/orpc'
import { orpc } from '@/client/query-client'
const { data } = useSuspenseQuery(orpc.feature.list.queryOptions())
const mutation = useMutation(orpc.feature.create.mutationOptions())