Skip to main content

Overview

Orphelix is built on a modern, scalable architecture that combines Next.js 15, React 19, and Kubernetes client libraries to deliver a responsive, real-time dashboard experience.

Frontend Stack

React 19, Material-UI v7, TanStack Query, Zustand

Backend Stack

Next.js 15 API Routes, Kubernetes Client Node, SSE

Data Layer

SQLite (better-sqlite3), Zustand stores, LocalStorage

Real-time

Server-Sent Events (SSE), Kubernetes Watch API

System Architecture

Orphelix follows a client-server architecture with real-time capabilities:

Core Components

Frontend Layer

Component Structure:
  • app/components/ - Reusable UI components
  • app/app/ - Page components (Next.js App Router)
  • Material-UI v7 for design system
  • Custom glass-morphism styling (Liquid Glass preset)
Key Components:
  • Layout: Header, Sidebar, TopBar
  • Dashboard: StatsGrid, ResourceOverview, CriticalAlerts
  • Resources: DeploymentCard, PodCard, NodeCard
  • GitHub: FileEditor, PRCreator, RepoBrowser
  • Topology: TopologyGraph, TopologyNode
Component Pattern:
Zustand Stores:Multiple stores for different concerns:
  • useModeStore: App mode (demo/real), context, namespace
  • useGitHubStore: GitHub repo, branch, pending PRs, edit basket
  • useClusterAliases: Cluster friendly names
  • useCriticalIssuesSettings: Critical issue monitoring preferences
  • useSidebarPins: Sidebar navigation pins
Persistence:
  • Demo mode data: LocalStorage only
  • Real mode data: SQLite database synced via API
  • GitHub settings: LocalStorage
Example:
TanStack Query (React Query):Centralized data fetching with caching, refetching, and real-time updates.Custom Hooks:
  • useDeployments() - Fetch deployments
  • usePods() - Fetch pods
  • useNodes() - Fetch nodes
  • useEvents() - Fetch events
  • useDashboard() - Fetch dashboard summary
Features:
  • Automatic refetching (configurable interval)
  • Optimistic updates
  • Error retry logic
  • Cache invalidation
  • Background refetching
Example:

Backend Layer

API Structure:RESTful API routes in app/api/:
  • GET /api/deployments - List deployments
  • GET /api/deployments/[name] - Get deployment details
  • POST /api/deployments/[name]/restart - Restart deployment
  • GET /api/pods - List pods
  • GET /api/pods/[name]/logs - Stream pod logs
  • GET /api/nodes - List nodes
  • GET /api/events - List events
  • GET /api/stream - SSE endpoint for real-time updates
Route Pattern:
Client Configuration:Located in lib/k8s/client.ts:
  • Singleton pattern with client reinitialization for auth tokens
  • Supports multiple authentication methods
  • Context switching via kubeconfig
  • Token refresh for AWS EKS/GCP GKE/Azure AKS
API Clients:
  • getAppsApi() - Deployments, StatefulSets, DaemonSets
  • getCoreApi() - Pods, Services, ConfigMaps, Secrets, Nodes
  • getAutoscalingApi() - HPAs
  • getBatchApi() - Jobs, CronJobs
  • getNetworkingApi() - Ingress
Authentication Flow:
Why Reinitialize?Cloud providers (AWS EKS, GCP GKE, Azure AKS) use exec auth that generates short-lived tokens. Reinitializing the client on each request ensures fresh tokens are retrieved.
Server-Sent Events:app/api/stream/route.ts provides real-time Kubernetes updates:What it watches:
  • Deployment changes (added, modified, deleted)
  • Pod changes (created, status changed, deleted)
  • Kubernetes Events (normal, warning, error)
Event Types:
  • connected - Client connected successfully
  • heartbeat - Keep-alive ping (every 30s)
  • deployment - Deployment change
  • pod - Pod change
  • event - Kubernetes event
  • error - Watch error or connection issue
Implementation:
Client Connection:
GitHub App Authentication:Located in app/api/github/:
  • GitHub App for organization/repo access
  • OAuth flow via NextAuth.js
  • Installation-level access tokens
  • Octokit REST client
Key Features:
  • File browsing (/api/github/tree)
  • File content reading (/api/github/file)
  • Branch management (/api/github/branches)
  • PR creation (/api/github/create-pr)
  • Multi-file PR (/api/github/create-multi-file-pr)
  • Kustomize support (/api/github/kustomize)
  • AI file matching (/api/github/match-file)
Authentication Flow:
File Matching (AI-powered):

Data Layer

Database File:orphelix.db in project root (uses better-sqlite3)Tables:
  • user_settings - App mode, context, namespace, preferences
  • github_settings - Selected repo, branch
  • github_pending_prs - PRs created from Orphelix
  • github_edit_basket - Staged file edits for multi-file PR
  • cluster_aliases - Friendly names for clusters
  • critical_issues_settings - Which resources to monitor
  • sidebar_pins - Pinned navigation items
Schema:
Services:Database access via service layer in lib/db/services.ts:
  • UserSettingsService - CRUD for user settings
  • GitHubSettingsService - CRUD for GitHub settings
  • ClusterAliasesService - CRUD for aliases
  • CriticalIssuesService - CRUD for critical issue settings
  • SidebarPinsService - CRUD for sidebar pins
Example:
Mock Data:Located in lib/mocks/data.ts:
  • 15 mock deployments (various statuses)
  • 42 mock pods (Running, Pending, CrashLoopBackOff, etc.)
  • 3 mock nodes (different resource allocations)
  • 25 ConfigMaps & Secrets
  • 5 HPAs
  • 150+ mock events
Data Generation:
Demo Mode Detection:
Client-Server Sync:Zustand stores sync with SQLite database via API:Flow:
  1. User changes setting in UI
  2. Zustand store updates local state
  3. Store calls syncStateToServer()
  4. POST request to /api/settings
  5. API route updates SQLite database
Code:
Initialization:On app load, fetch settings from database:

Data Flow

Request Flow (Read Operations)

Real-time Flow (SSE)

Write Flow (Deployment Restart)

Design Patterns

API Route Pattern

All API routes follow consistent structure:

Custom Hook Pattern

TanStack Query hooks follow consistent pattern:

Kubernetes Client Pattern

Consistent K8s client initialization with token refresh:

Error Handling

Frontend Error Handling

Backend Error Handling

Performance Optimizations

TanStack Query Cache:
  • Cache data for 10s (staleTime)
  • Auto-refetch every 30s (refetchInterval)
  • Invalidate on mutations
  • Background refetching when window focused
React Component Memoization:
Database Prepared Statements:
SSE vs Polling:
  • SSE for real-time updates (low latency, server push)
  • Polling as fallback (30s interval)
  • Heartbeat to detect disconnections (30s)
Event Debouncing:
Selective Invalidation:
WAL Mode:
WAL (Write-Ahead Logging) improves concurrency:
  • Readers don’t block writers
  • Writers don’t block readers
  • Better performance for read-heavy workloads
Indexes:
Transactions:
Code Splitting:Next.js automatic code splitting per routeDynamic Imports:
Tree Shaking:Import only what you need:

Security

GitHub App Authentication:
  • OAuth flow via NextAuth.js
  • Access tokens stored in session
  • Installation tokens for organization access
  • Token refresh handled automatically
Kubernetes Authentication:
  • Uses kubeconfig credentials
  • Supports client certificates, bearer tokens, exec auth
  • No credentials stored by Orphelix
  • Delegates to Kubernetes API server
RBAC:Orphelix respects Kubernetes RBAC:
  • User permissions determined by kubeconfig credentials
  • 403 errors shown when unauthorized
  • No elevation of privileges
GitHub Permissions:
  • Read access to repository contents
  • Write access to create branches/PRs
  • Respect organization permissions
Secrets Masking:
OpenAI Privacy:When AI features enabled:
  • Deployment YAML sent to OpenAI
  • Pod logs (last 100 lines) sent
  • Event messages sent
  • Secret values masked before sending
Local Storage:
  • No secrets stored in localStorage
  • Only UI preferences and non-sensitive data
  • GitHub tokens in httpOnly cookies

Scalability

Multi-Cluster Support

Namespace Isolation

Resource Limits

Next Steps

Tech Stack

Detailed technology stack overview

Project Structure

File organization and conventions

Getting Started

Set up development environment

API Reference

Complete API documentation