Objective
Migrate from a server-proxied (remote functions) API architecture to a direct client-to-backend API integration in our SvelteKit (Svelte 5) frontend application. The goal is to streamline the application structure, enhance scalability, and modernize authentication/token management, while maintaining developer ergonomics, robust security (with http-only cookies and access tokens), and complete parity in feature support.
Motivation
The existing use of SvelteKit remote functions introduces a redundant proxy layer for API communication, which increases complexity and obscures the client/server boundary. Shifting to a direct client-side API model simplifies architecture, improves performance, and better leverages modern Svelte patterns. Authentication should rely on secure, standards-based mechanisms: the backend will continue setting refresh tokens via http-only cookies, while access tokens will be managed client-side (e.g., localStorage with in-memory cache) and transparently sent with each request.
Migration Steps
1. Backend CORS & API Service Refactor
2. Query Management Refactor
3. Client-Side Form Handling
4. Direct Command Execution
5. Authentication & Token Handling Redesign
6. Cleanup & Documentation
Acceptance Criteria
- No SvelteKit remote function proxies remain; all API interaction is direct.
- Feature parity, authentication (with refresh token in http-only cookie, access token client-side), SSR support, and robust error handling are preserved.
- All code follows TypeScript strict mode, object-oriented patterns, and Svelte 5 runes best practices.
- Developer onboarding/documentation is clear regarding new API and auth flows.
This migration is critical for scaling the frontend platform with clean separation of concerns, improved security posture, and modern Svelte paradigms.
Objective
Migrate from a server-proxied (remote functions) API architecture to a direct client-to-backend API integration in our SvelteKit (Svelte 5) frontend application. The goal is to streamline the application structure, enhance scalability, and modernize authentication/token management, while maintaining developer ergonomics, robust security (with http-only cookies and access tokens), and complete parity in feature support.
Motivation
The existing use of SvelteKit remote functions introduces a redundant proxy layer for API communication, which increases complexity and obscures the client/server boundary. Shifting to a direct client-side API model simplifies architecture, improves performance, and better leverages modern Svelte patterns. Authentication should rely on secure, standards-based mechanisms: the backend will continue setting refresh tokens via http-only cookies, while access tokens will be managed client-side (e.g., localStorage with in-memory cache) and transparently sent with each request.
Migration Steps
1. Backend CORS & API Service Refactor
ApiService.tsinto an object-oriented class supporting instantiation in both SSR and browser contexts.createClientApiClient()factory for browser$env/dynamic/public.2. Query Management Refactor
createQuery()leveraging Svelte 5 runes ($state,$derived).{ current, loading, error, refresh() }and full type safety for query state.tasks.remote.ts,user.remote.ts,task.remote.ts) to use the new query utility and direct client API calls.getRequestEvent()and server cookie handling.3. Client-Side Form Handling
createForm()abstraction with Valibot validation.submittingstate, field-level errors, and action handler for SvelteKit-enhanced forms.goto().login.remote.ts,submit.remote.ts).4. Direct Command Execution
command()wrappers (e.g.,contests.remote.ts,registration-requests.remote.ts).5. Authentication & Token Handling Redesign
TokenManagerandAuthServicefor robust client-side access token lifecycle:hooks.server.ts).+page.tsload functions (usinggoto()).6. Cleanup & Documentation
*.remote.tsfiles.svelte.config.js(removeexperimental.remoteFunctions).Acceptance Criteria
This migration is critical for scaling the frontend platform with clean separation of concerns, improved security posture, and modern Svelte paradigms.