Files
Zero/apps/server
devin-ai-integration[bot] b709dfcba4 Centralize env imports from cloudflare:workers (#1792)
# Centralize env imports from cloudflare:workers

## Summary

This PR centralizes all `env` imports from `cloudflare:workers` in the `apps/server` directory by creating a single centralized file (`src/env.ts`) that exports both the runtime `env` and its type. All 19 files that previously imported `env` directly from `cloudflare:workers` have been updated to use the centralized import.

**Key Changes:**
- Created `apps/server/src/env.ts` to export `env` and `Env` type centrally
- Updated 19 files across the server codebase to import from centralized location
- Preserved type safety by exporting `Env` type for use in type definitions
- Maintained all existing functionality while improving maintainability

This change makes env-related maintenance easier and ensures consistency across the codebase. All `env` bindings are now imported from a single source of truth.

## Review & Testing Checklist for Human

- [ ] **Verify import paths are correct** - Spot check 3-4 files with different relative paths (e.g., `src/main.ts` uses `./env`, `src/lib/utils.ts` uses `../env`, `src/trpc/routes/ai/compose.ts` uses `../../../env`) to ensure no typos in path calculations
- [ ] **Test core env-dependent functionality** - Beyond server startup, verify that authentication, AI services, and email processing work correctly since these heavily depend on env bindings
- [ ] **Confirm build works properly** - Run the full build process to catch any import resolution issues that might not surface during dev server startup
- [ ] **Verify type safety** - Check that TypeScript compilation passes and that the `Env` type export works correctly in `ctx.ts` and other type definitions

**Recommended Test Plan:**
1. Start the dev server and confirm it runs without errors
2. Test a few core user flows that depend on env variables (login, AI features, email sync)
3. Run any available test suites to catch regressions
4. Build the project for production to verify no import issues

---

### Diagram

```mermaid
%%{ init : { "theme" : "default" }}%%
graph TD
    env["apps/server/src/env.ts<br/>(NEW CENTRALIZED FILE)"]:::major-edit
    
    main["apps/server/src/main.ts"]:::major-edit
    ctx["apps/server/src/ctx.ts"]:::major-edit
    services["apps/server/src/lib/services.ts"]:::minor-edit
    utils["apps/server/src/lib/utils.ts"]:::minor-edit
    auth["apps/server/src/lib/auth.ts"]:::minor-edit
    google["apps/server/src/lib/driver/google.ts"]:::minor-edit
    compose["apps/server/src/trpc/routes/ai/compose.ts"]:::minor-edit
    
    cloudflare["'cloudflare:workers'<br/>(External Module)"]:::context
    
    env --> main
    env --> ctx
    env --> services
    env --> utils
    env --> auth
    env --> google
    env --> compose
    
    cloudflare --> env
    cloudflare --> main
    
    main -.->|"Also imports WorkerEntrypoint,<br/>DurableObject, RpcTarget"| cloudflare
    
    subgraph Legend
        L1["Major Edit"]:::major-edit
        L2["Minor Edit"]:::minor-edit  
        L3["Context/No Edit"]:::context
    end

classDef major-edit fill:#90EE90
classDef minor-edit fill:#87CEEB
classDef context fill:#FFFFFF
```

### Notes

- The centralized `env.ts` file exports both the runtime `env` and its TypeScript type for maximum flexibility
- Some files like `main.ts` and `routes/chat.ts` still import other items from `cloudflare:workers` (WorkerEntrypoint, DurableObject, RpcTarget) - only the `env` import was moved
- Server startup testing was successful, confirming basic functionality works
- This change improves maintainability by providing a single point of control for env imports

**Session Info:** Requested by Adam (@MrgSub)  
**Link to Devin run:** https://app.devin.ai/sessions/d31157d47fdb432c961bf8fae7248dd1
    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Centralized all env imports from cloudflare:workers into a single src/env.ts file in apps/server, updating 19 files to use this shared import for better maintainability and type safety.

- **Refactors**
  - Created src/env.ts to export env and its type.
  - Updated all server files to import env from the new centralized file.

<!-- End of auto-generated description by cubic. -->
2025-08-01 09:26:07 -07:00
..
2025-05-23 19:20:17 +05:30