Skip to main content

Overview

The K8s Scheduler frontend is a modern React 19 single-page application built with TypeScript, Vite, and TanStack Query. It provides a responsive UI for managing deployments, sandboxes, secrets, teams, and billing.

Tech Stack

React 19

Latest React with concurrent features

TypeScript

Type-safe development experience

Vite

Fast build tool and dev server

TanStack Query

Powerful data fetching and caching

Project Structure

Source: ui/src/ directory structure

API Client

The frontend uses a custom API client built on the Fetch API with automatic error handling and session management.

Client Implementation

ui/src/api/client.ts
Source: ui/src/api/client.ts:1-104

Key Features

  • Credential handling: Automatic cookie-based session management
  • Error handling: Structured error responses with ApiError class
  • 401 handling: Throws errors for React Router to handle redirects
  • 204 handling: Returns undefined for No Content responses
  • Type safety: Full TypeScript generics support

TanStack Query Hooks

The application uses TanStack Query (React Query v5) for data fetching, caching, and state management.

Available Hooks

Source: ui/src/api/hooks/ directory

Example Hook Usage

Application Structure

Entry Point

ui/src/main.tsx
Source: ui/src/main.tsx:1-11

App Component

ui/src/App.tsx
Source: ui/src/App.tsx:1-22

Routing

The application uses React Router v7 with nested routes and protected routes.

Route Configuration

ui/src/routes/index.tsx
Source: ui/src/routes/index.tsx:24-106

Protected Routes

All authenticated routes are wrapped in <ProtectedRoute> which:
  1. Checks for valid session
  2. Redirects to /signin if unauthorized
  3. Handles 401 errors from API

Component Organization

Layout Components

  • AppShell: Main layout with navigation, sidebar, and content area
  • ProtectedRoute: Authentication guard
  • Navigation: Top navigation bar with user menu
  • Sidebar: Left sidebar with feature navigation

Feature Components

Source: ui/src/components/ directory structure

Pages

Available Pages

Source: ui/src/pages/ directory

Development Setup

Prerequisites

package.json
Source: ui/package.json:12-42

Vite Configuration

vite.config.ts
Source: ui/vite.config.ts:1-24

Development Commands

Key Features

Path Aliasing

Vite is configured with @ alias pointing to src/ for clean imports:

Development Proxy

Vite proxies API requests to the Go backend during development:
  • /api/* → http://localhost:8080
  • /auth/* → http://localhost:8080
  • /oauth2/* → http://localhost:8080
Source: ui/vite.config.ts:14-21

Hot Module Replacement

Vite provides instant HMR for React components with state preservation.

TypeScript Strict Mode

The project uses TypeScript strict mode for maximum type safety:
tsconfig.json

State Management

The application uses TanStack Query for server state and React Context for UI state:
  • Server state: TanStack Query handles all API data
  • Auth state: AuthProvider context for user session
  • Theme state: ThemeProvider context for dark/light mode
  • Local state: React hooks (useState, useReducer)

Styling

The UI uses Tailwind CSS 4 with the Vite plugin for instant compilation:
Source: ui/vite.config.ts:3,8

Build Output

Production builds are optimized with:
  • Code splitting
  • Tree shaking
  • Asset optimization
  • Minification
Build output goes to ui/dist/ and is served by the Go backend.

Server Architecture

Go backend with HTTP handlers and middleware

Operator

Kubernetes operator for deployment reconciliation