> ## Documentation Index
> Fetch the complete documentation index at: https://orphelix.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Developer Overview

> Technical overview for developers contributing to Orphelix

## Welcome, Developer!

This section contains comprehensive technical documentation for developers who want to:

* Understand the architecture
* Contribute to the project
* Extend functionality
* Debug issues
* Deploy Orphelix

## Technology Stack

> [card] Frontend
>
> * **Next.js 15** - React framework with App Router
> * **React 19** - UI library
> * **Material-UI v7** - Component library
> * **TypeScript 5.7** - Type safety

> [card] State Management
>
> * **TanStack Query v5** - Data fetching & caching
> * **Zustand** - Global state (theme, mode, namespace)
> * **Context API** - Search state management

> [card] Backend
>
> * **Next.js API Routes** - Serverless functions
> * **@kubernetes/client-node** - K8s API client
> * **Server-Sent Events** - Real-time updates

> [card] Testing
>
> * **Vitest** - Unit testing framework
> * **Playwright** - E2E testing
> * **React Testing Library** - Component testing

## Architecture Overview

Orphelix follows a modern, scalable architecture:

```mermaid theme={null}
graph TB
    subgraph Browser["Browser (Client)"]
        React["React<br/>Components"]
        MUI["Material-UI<br/>Styles"]
        Zustand["Zustand<br/>Store"]

        React --> TanStack
        MUI --> TanStack
        Zustand --> TanStack

        TanStack["TanStack Query<br/>(Data Fetching)"]
    end

    TanStack -->|HTTP/SSE| API["Next.js API Routes<br/>(Server-side)"]

    API --> K8s["Kubernetes<br/>Client"]
    API --> SSE["SSE<br/>Watches"]
    API --> GitHub["GitHub<br/>API"]

    K8s -->|kubectl| Cluster["Kubernetes API<br/>Cluster"]

    style Browser fill:#667EEA,stroke:#764BA2,stroke-width:3px,color:#fff
    style API fill:#764BA2,stroke:#667EEA,stroke-width:2px,color:#fff
    style Cluster fill:#326CE5,stroke:#326CE5,stroke-width:2px,color:#fff
    style TanStack fill:#FF4154,stroke:#FF4154,stroke-width:2px,color:#fff
    style K8s fill:#326CE5,stroke:#326CE5,stroke-width:2px,color:#fff
    style GitHub fill:#24292e,stroke:#24292e,stroke-width:2px,color:#fff
```

## Key Design Patterns

### 1. API Route Architecture

All Kubernetes operations are server-side to prevent credentials exposure:

```typescript theme={null}
// app/api/deployments/route.ts
export async function GET(request: Request) {
  const kc = getKubeConfig()
  const k8sApi = kc.makeApiClient(AppsV1Api)

  const { data } = await k8sApi.listNamespacedDeployment({
    namespace: 'default'
  })

  return NextResponse.json(deployments)
}
```

### 2. TanStack Query Hooks

Consistent data fetching pattern with caching:

```typescript theme={null}
export function useDeployments() {
  return useQuery({
    queryKey: ['deployments', namespace],
    queryFn: () => fetch('/api/deployments').then(r => r.json()),
    refetchInterval: 30000, // Auto-refresh every 30s
  })
}
```

### 3. Real-time Updates with SSE

Server-Sent Events for live cluster updates:

```typescript theme={null}
// Server
const stream = new ReadableStream({
  start(controller) {
    watcher.on('ADDED', (obj) => {
      controller.enqueue(`data: ${JSON.stringify(obj)}\n\n`)
    })
  }
})

// Client
useEffect(() => {
  const eventSource = new EventSource('/api/realtime')
  eventSource.onmessage = (event) => {
    queryClient.invalidateQueries(['deployments'])
  }
}, [])
```

### 4. Component Structure

Consistent component organization:

```
app/
  components/
    common/          # Reusable components
    layout/          # Layout components
    [resource]/      # Resource-specific components
  [resource]/        # Pages
    page.tsx         # List view
    [name]/
      page.tsx       # Detail view
```

## Getting Started

**1. Set up your environment**

See [Getting Started](https://orphelix.mintlify.site/developer/getting-started.md) for setup instructions

**2. Understand the architecture**

Read [Architecture](https://orphelix.mintlify.site/developer/architecture.md) for detailed system design

**3. Review the tech stack**

Check [Tech Stack](https://orphelix.mintlify.site/developer/tech-stack.md) for technology decisions

**4. Run tests**

Follow [Testing Guide](https://orphelix.mintlify.site/developer/testing.md) to run and write tests

**5. Start contributing**

See [Contributing](https://orphelix.mintlify.site/developer/contributing.md) for contribution guidelines

## Quick Links

> [card] [API Reference](https://orphelix.mintlify.site/developer/api/introduction.md)
>
> REST API documentation

> [card] [Testing](https://orphelix.mintlify.site/developer/testing.md)
>
> Testing strategy and guides

> [card] [Contributing](https://orphelix.mintlify.site/developer/contributing.md)
>
> How to contribute code

## Development Principles

> [accordion] Security First
>
> * Never expose cluster credentials to browser
> * All K8s operations are server-side
> * Secrets values are never displayed
> * GitHub App tokens in HTTP-only cookies

> [accordion] Performance
>
> * Aggressive caching with TanStack Query
> * Server-Side Rendering (SSR) for initial load
> * Code splitting with Next.js dynamic imports
> * Optimistic UI updates

> [accordion] Type Safety
>
> * Strict TypeScript configuration
> * Full type coverage for K8s resources
> * Type-safe API routes
> * No `any` types allowed

> [accordion] Testability
>
> * 214+ unit tests with Vitest
> * 93+ E2E tests with Playwright
> * Mock data for demo mode
> * Test coverage reporting

## Repository Structure

```
orphelix/
├── app/                    # Next.js app directory
│   ├── api/               # API routes
│   ├── components/        # React components
│   └── [resources]/       # Page routes
├── lib/                   # Utilities & hooks
│   ├── hooks/            # TanStack Query hooks
│   ├── utils/            # Helper functions
│   └── store/            # Zustand store
├── types/                 # TypeScript definitions
├── __tests__/            # Unit tests
├── e2e/                  # E2E tests
└── docs/                 # Documentation
```

## Next Steps

Choose your path:

> [card] [I want to contribute code](https://orphelix.mintlify.site/developer/contributing.md)
>
> Read the contributing guide

> [card] [I want to understand the architecture](https://orphelix.mintlify.site/developer/architecture.md)
>
> Explore the architecture

> [card] [I want to add tests](https://orphelix.mintlify.site/developer/testing.md)
>
> Learn about testing

> [card] [I want to deploy Orphelix](https://orphelix.mintlify.site/developer/deployment.md)
>
> See deployment options


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.