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
React Components
React Components
Component Structure:
app/components/- Reusable UI componentsapp/app/- Page components (Next.js App Router)- Material-UI v7 for design system
- Custom glass-morphism styling (Liquid Glass preset)
- Layout:
Header,Sidebar,TopBar - Dashboard:
StatsGrid,ResourceOverview,CriticalAlerts - Resources:
DeploymentCard,PodCard,NodeCard - GitHub:
FileEditor,PRCreator,RepoBrowser - Topology:
TopologyGraph,TopologyNode
State Management
State Management
Zustand Stores:Multiple stores for different concerns:
useModeStore: App mode (demo/real), context, namespaceuseGitHubStore: GitHub repo, branch, pending PRs, edit basketuseClusterAliases: Cluster friendly namesuseCriticalIssuesSettings: Critical issue monitoring preferencesuseSidebarPins: Sidebar navigation pins
- Demo mode data: LocalStorage only
- Real mode data: SQLite database synced via API
- GitHub settings: LocalStorage
Data Fetching
Data Fetching
TanStack Query (React Query):Centralized data fetching with caching, refetching, and real-time updates.Custom Hooks:
useDeployments()- Fetch deploymentsusePods()- Fetch podsuseNodes()- Fetch nodesuseEvents()- Fetch eventsuseDashboard()- Fetch dashboard summary
- Automatic refetching (configurable interval)
- Optimistic updates
- Error retry logic
- Cache invalidation
- Background refetching
Backend Layer
Next.js API Routes
Next.js API Routes
API Structure:RESTful API routes in
app/api/:GET /api/deployments- List deploymentsGET /api/deployments/[name]- Get deployment detailsPOST /api/deployments/[name]/restart- Restart deploymentGET /api/pods- List podsGET /api/pods/[name]/logs- Stream pod logsGET /api/nodes- List nodesGET /api/events- List eventsGET /api/stream- SSE endpoint for real-time updates
Kubernetes Client
Kubernetes Client
Client Configuration:Located in Why Reinitialize?Cloud providers (AWS EKS, GCP GKE, Azure AKS) use
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
getAppsApi()- Deployments, StatefulSets, DaemonSetsgetCoreApi()- Pods, Services, ConfigMaps, Secrets, NodesgetAutoscalingApi()- HPAsgetBatchApi()- Jobs, CronJobsgetNetworkingApi()- Ingress
exec auth that generates short-lived tokens. Reinitializing the client on each request ensures fresh tokens are retrieved.Real-time Updates (SSE)
Real-time Updates (SSE)
Server-Sent Events:Client Connection:
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)
connected- Client connected successfullyheartbeat- Keep-alive ping (every 30s)deployment- Deployment changepod- Pod changeevent- Kubernetes eventerror- Watch error or connection issue
GitHub Integration
GitHub Integration
GitHub App Authentication:Located in File Matching (AI-powered):
app/api/github/:- GitHub App for organization/repo access
- OAuth flow via NextAuth.js
- Installation-level access tokens
- Octokit REST client
- 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)
Data Layer
SQLite Database
SQLite Database
Database File:Services:Database access via service layer in
orphelix.db in project root (uses better-sqlite3)Tables:user_settings- App mode, context, namespace, preferencesgithub_settings- Selected repo, branchgithub_pending_prs- PRs created from Orphelixgithub_edit_basket- Staged file edits for multi-file PRcluster_aliases- Friendly names for clusterscritical_issues_settings- Which resources to monitorsidebar_pins- Pinned navigation items
lib/db/services.ts:UserSettingsService- CRUD for user settingsGitHubSettingsService- CRUD for GitHub settingsClusterAliasesService- CRUD for aliasesCriticalIssuesService- CRUD for critical issue settingsSidebarPinsService- CRUD for sidebar pins
Demo Mode Data
Demo Mode Data
Mock Data:Located in Demo Mode Detection:
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
State Synchronization
State Synchronization
Client-Server Sync:Zustand stores sync with SQLite database via API:Flow:Initialization:On app load, fetch settings from database:
- User changes setting in UI
- Zustand store updates local state
- Store calls
syncStateToServer() - POST request to
/api/settings - API route updates SQLite 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
Caching Strategy
Caching Strategy
TanStack Query Cache:Database Prepared Statements:
- Cache data for 10s (
staleTime) - Auto-refetch every 30s (
refetchInterval) - Invalidate on mutations
- Background refetching when window focused
Real-time Optimization
Real-time Optimization
SSE vs Polling:Selective Invalidation:
- SSE for real-time updates (low latency, server push)
- Polling as fallback (30s interval)
- Heartbeat to detect disconnections (30s)
Database Performance
Database Performance
WAL Mode:WAL (Write-Ahead Logging) improves concurrency:Transactions:
- Readers don’t block writers
- Writers don’t block readers
- Better performance for read-heavy workloads
Bundle Optimization
Bundle Optimization
Code Splitting:Next.js automatic code splitting per routeDynamic Imports:Tree Shaking:Import only what you need:
Security
Authentication
Authentication
GitHub App Authentication:
- OAuth flow via NextAuth.js
- Access tokens stored in session
- Installation tokens for organization access
- Token refresh handled automatically
- Uses kubeconfig credentials
- Supports client certificates, bearer tokens, exec auth
- No credentials stored by Orphelix
- Delegates to Kubernetes API server
Authorization
Authorization
Data Privacy
Data Privacy
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
- No secrets stored in localStorage
- Only UI preferences and non-sensitive data
- GitHub tokens in httpOnly cookies