@@ -295,6 +295,54 @@ src/components/
295295- React Context for local/auth state
296296- Form state via React Hook Form
297297
298+ ### API Routing Pattern
299+
300+ ** Service-Prefixed Routes** (Unified Architecture):
301+
302+ All API requests use service-prefixed paths that are proxied by Vite to backend services:
303+
304+ ```
305+ /server/* → Backend API server
306+ /chat/* → Chat agent service
307+ /rpc/* → Ethereum RPC node
308+ ```
309+
310+ ** Key Files** :
311+ - ` src/shared/config/api-routes.ts ` - Single source of truth for all API routes
312+ - ` vite.config.ts ` - Proxy configuration (strips prefixes before forwarding)
313+ - ` src/shared/config/runtime.ts ` - Minimal config (only environment flags)
314+
315+ ** Example Usage** :
316+ ``` typescript
317+ import { API_PATHS } from ' @/shared/config/api-routes' ;
318+
319+ // Backend API call
320+ fetch (` ${API_PATHS .SERVER_API }/auth/login ` ); // → /server/api/v1/auth/login
321+
322+ // Chat agent call
323+ fetch (API_PATHS .CHAT_STREAM ); // → /chat/api/v1/chat/stream
324+
325+ // RPC call (uses proxy in dev, external HTTPS in production)
326+ new Web3Provider (DEFAULT_ETHEREUM_RPC_URL ); // → /rpc or https://...
327+ ```
328+
329+ ** Environment Variables** :
330+ - ** Runtime** (application code):
331+ - ` VITE_SERVER_ENVIRONMENT ` : 'local' | 'staging' | 'sandbox' | 'production'
332+ - ` VITE_ETHEREUM_RPC_URL ` : Optional external RPC URL (production only)
333+
334+ - ** Vite Config** (proxy targets):
335+ - ` VITE_SERVER_URL ` : Backend service URL (for proxy)
336+ - ` VITE_CHAT_AGENT_URL ` : Chat agent service URL (for proxy)
337+ - ` VITE_ETHEREUM_RPC_URL ` : RPC node URL (for proxy)
338+
339+ ** Benefits** :
340+ - Single source of truth prevents path inconsistencies
341+ - Type-safe route references
342+ - No hardcoded URLs in API clients
343+ - Vite proxy handles dev/production routing automatically
344+ - Avoids mixed content errors (HTTPS page → HTTP API)
345+
298346## Important Notes
299347
300348### TypeScript Configuration
0 commit comments