+32
-12
CLAUDE.md
+32
-12
CLAUDE.md
···
165
165
4. Test with `bun run dev`
166
166
5. See `packages/client/CLAUDE.md` for patterns
167
167
168
-
### Type Sharing Between Packages
168
+
### Path Aliases
169
169
170
-
If you need to share types from server to client:
171
-
1. Add workspace dependency in `packages/client/package.json`:
172
-
```json
173
-
"dependencies": {
174
-
"@watproto/server": "workspace:*"
175
-
}
176
-
```
177
-
2. Import types (not runtime code):
178
-
```typescript
179
-
import type { Account } from '@watproto/server/src/db/schema'
180
-
```
170
+
The monorepo uses TypeScript path aliases for cleaner imports:
171
+
172
+
**Configured in `tsconfig.root.json`:**
173
+
- `@api/*` → `packages/server/src/*` - Server internal imports
174
+
- `@www/*` → `packages/client/app/*` - Client internal imports
175
+
176
+
**Server Usage** (`packages/server`):
177
+
```typescript
178
+
import { db } from '@api/db/db'
179
+
import env from '@api/lib/env'
180
+
import { createOrUpdateAccount } from '@api/lib/account'
181
+
```
182
+
183
+
**Client Usage** (`packages/client`):
184
+
```typescript
185
+
// Client internal imports
186
+
import { Header } from '@www/components/Header'
187
+
import { apiClient } from '@www/lib/api'
188
+
189
+
// Import server types (type-only imports)
190
+
import type { app } from '@api/index'
191
+
import type { Account } from '@api/db/schema'
192
+
```
193
+
194
+
**Benefits:**
195
+
- Clean, consistent import paths across the monorepo
196
+
- No relative path traversal (`../../..`)
197
+
- Type sharing between packages without workspace dependencies
198
+
- Vite and Bun automatically resolve these paths
199
+
200
+
**Note:** Only import types from server to client, never runtime code.
181
201
182
202
## Future Expansion
183
203
+47
-7
packages/client/CLAUDE.md
+47
-7
packages/client/CLAUDE.md
···
118
118
}
119
119
```
120
120
121
-
**Type Sharing** (when needed):
122
-
- Can import types from server package via workspace dependencies
123
-
- Add to dependencies: `"@watproto/server": "workspace:*"`
124
-
- Import: `import type { AccountType } from '@watproto/server/src/db/schema'`
121
+
**Type Sharing with Server:**
122
+
The client can import server types using the `@api/*` path alias:
123
+
124
+
```typescript
125
+
// Import server types (type-only imports)
126
+
import type { app } from '@api/index' // For Eden Treaty type-safe API client
127
+
import type { Account } from '@api/db/schema' // Database types
128
+
import type { SessionData } from '@api/lib/session' // Session types
129
+
130
+
// Use in your code
131
+
const apiClient = treaty<typeof app>(API_URL) // Type-safe API client
132
+
```
133
+
134
+
**Important:** Only import types from server (`import type`), never runtime code
125
135
126
136
### Styling
127
137
···
180
190
- Access via `import.meta.env.VITE_*`
181
191
- Never commit `.env.local` to git
182
192
183
-
### TypeScript Configuration
184
-
- Path aliases configured in `tsconfig.json`
185
-
- Vite handles path resolution via `vite-tsconfig-paths` plugin
193
+
### Path Aliases
194
+
195
+
The client uses path aliases for clean imports:
196
+
197
+
**Configuration** (in root `tsconfig.root.json`):
198
+
- `@www/*` → `packages/client/app/*` - Client internal imports
199
+
- `@api/*` → `packages/server/src/*` - Server type imports
200
+
201
+
**Usage Examples:**
202
+
```typescript
203
+
// Client internal imports
204
+
import { Header } from '@www/components/Header'
205
+
import { UserMenu } from '@www/components/UserMenu'
206
+
import { apiClient } from '@www/lib/api'
207
+
import { env } from '@www/lib/env'
208
+
209
+
// Server type imports (type-only)
210
+
import type { app } from '@api/index'
211
+
import type { Account } from '@api/db/schema'
212
+
```
213
+
214
+
**Benefits:**
215
+
- Clean, consistent import paths
216
+
- No relative path traversal (`../../../components/Header`)
217
+
- Type-safe API calls using server types
218
+
- Better refactoring support
219
+
220
+
**Vite Configuration:**
221
+
- Uses `vite-tsconfig-paths` plugin to resolve aliases
222
+
- Automatically picks up paths from root `tsconfig.root.json`
223
+
224
+
**TypeScript:**
186
225
- Type generation via `react-router typegen` command
226
+
- Strict mode enabled for better type safety
187
227
188
228
### Build & Deployment
189
229
- Production build outputs to `build/` directory
+22
-2
packages/server/CLAUDE.md
+22
-2
packages/server/CLAUDE.md
···
175
175
## Key Implementation Details
176
176
177
177
### Path Aliases
178
-
- Use `@/*` imports for `src/*` files (configured in tsconfig.json)
179
-
- Use `@/../*` for parent directory access (e.g., `@/../jwks.json`)
178
+
179
+
The server uses the `@api/*` path alias for clean internal imports:
180
+
181
+
**Configuration** (in root `tsconfig.root.json`):
182
+
- `@api/*` → `packages/server/src/*`
183
+
184
+
**Usage Examples:**
185
+
```typescript
186
+
import { db } from '@api/db/db'
187
+
import env from '@api/lib/env'
188
+
import { createOrUpdateAccount } from '@api/lib/account'
189
+
import { type Account } from '@api/db/schema'
190
+
import keys from '@api/../jwks.json' // Parent directory access
191
+
```
192
+
193
+
**Benefits:**
194
+
- Consistent import paths regardless of file depth
195
+
- No relative path hell (`../../../lib/env`)
196
+
- Better refactoring support
197
+
- Shared with client for type imports
198
+
199
+
**Note:** Use `@api/../*` for accessing files in the package root (e.g., `jwks.json`)
180
200
181
201
### OAuth Security
182
202
- Cookies are httpOnly, secure, sameSite=lax