High-Level Architecture
- Presentation Layer: React-based SPA with TypeScript
- Application Layer: Supabase Edge Functions (Deno runtime)
- Data Layer: PostgreSQL with Row Level Security (RLS)
Core Components
Frontend Application
React SPA
Single-page application built with React 18, TypeScript, and Vite for optimal performance and developer experience.
- Framework: React 18.3 with concurrent features
- Language: TypeScript 5.8 with strict mode
- Build Tool: Vite 5.4 with SWC compiler
- Routing: React Router v6 with nested layouts
- UI Library: shadcn/ui + Radix UI primitives
- Styling: Tailwind CSS 3.4 with custom design system
src/App.tsx- Application entry point with routing configurationsrc/components/AuthProvider.tsx- Authentication context and state managementsrc/components/AppSidebar.tsx- Navigation with role-based renderingsrc/hooks/useZitadelSSO.ts- SSO authentication hook with PKCE
Component Architecture
The application follows a hierarchical component structure:src/App.tsx:36-81 for complete routing configuration.
State Management Strategy
Server State
React Query manages all server data with automatic caching, refetching, and synchronization.
Client State
React Context + hooks for authentication, theme, and UI state.
src/components/AuthProvider.tsx):
AuthProvider automatically:
- Listens to Supabase auth state changes
- Fetches user profile, roles, and Zitadel identity on login
- Provides helper functions for permission checking
- Manages sign-out and session cleanup
Backend Services
Supabase Platform
Comprehensive backend-as-a-service providing PostgreSQL database, authentication, edge functions, and real-time subscriptions.
PostgreSQL Database
Database Schema (src/integrations/supabase/types.ts):
The system uses a comprehensive relational schema with the following key tables:
Core Tables
Core Tables
- profiles: User profiles with organization membership
- organizations: Multi-tenant organization management
- user_roles: Role assignments (many-to-many)
- user_groups: Group memberships
- resources: Applications and infrastructure resources
- user_resource_access: Access grants with time bounds
Identity & Auth Tables
Identity & Auth Tables
- zitadel_configurations: OIDC provider settings per organization
- user_zitadel_identities: Links users to Zitadel accounts
- zitadel_group_mappings: Maps Zitadel groups to local groups
- authentik_configurations: Alternative SSO provider support
Infrastructure Tables
Infrastructure Tables
- cloud_providers: AWS, Azure, GCP credentials
- hypervisors: VMware, Proxmox, KVM connections
- netbird_configurations: VPN network settings
- devices: Enrolled user devices
- sessions: Active access sessions
Audit & Compliance
Audit & Compliance
- audit_logs: Comprehensive event logging
- policies: Access policies and rules
- enrollment_tokens: Device enrollment tokens
Edge Functions
Serverless functions running on Deno for backend logic:zitadel-api
Handles OIDC token exchange, userinfo retrieval, and group synchronization
device-enrollment
Manages device registration and trust verification
session-launcher
Provisions and launches resource access sessions
netbird-proxy
Proxies requests to Netbird API for VPN management
supabase/functions/zitadel-api/index.ts):
This critical function handles the SSO callback flow:
IMPLEMENTATION_SUMMARY.md:9-105 for complete authentication flow details.
External Integrations
Zitadel
OIDC identity provider for SSO authentication
Netbird
Mesh VPN for secure network connectivity
Headscale
Self-hosted Tailscale control plane
Zitadel Integration
Configuration (ZITADEL_NETBIRD_SETUP.md):
Zitadel provides enterprise SSO with comprehensive OIDC support:
- Issuer URL:
https://manager.kappa4.com - Client Type: Public (PKCE)
- Scopes:
openid profile email urn:zitadel:iam:org:project:id:zitadel:aud - Claims: Groups/roles, organization ID, user metadata
See
IMPLEMENTATION_SUMMARY.md:78-109 for detailed flow documentation.
Netbird VPN Integration
Netbird provides a WireGuard-based mesh VPN that eliminates the need for traditional VPN concentrators. Each device connects peer-to-peer with automatic NAT traversal.
- Automatic peer discovery
- NAT traversal with STUN/TURN
- End-to-end encryption (WireGuard)
- Access control lists (ACLs)
- Network routes and DNS
supabase/functions/netbird-proxy):
The portal proxies Netbird API requests for:
- Device enrollment and key management
- ACL synchronization based on user access grants
- Network route management
- DNS configuration
Data Flow Diagrams
Authentication Flow
Resource Access Flow
Group Synchronization Flow
When a user logs in via Zitadel SSO, their groups are automatically synchronized:Security Architecture
Defense in Depth
The system implements multiple security layers:Layer 1: Network Isolation
Layer 1: Network Isolation
VPN-Only Access: Portal accessible only via Netbird VPN
- Server binds to internal interface only
- Firewall rules block external access
- No public DNS records
Layer 2: Authentication
Layer 2: Authentication
Multi-Factor SSO: Zitadel OIDC with MFA enforcement
- PKCE flow (SHA-256)
- State parameter (CSRF protection)
- Nonce parameter (replay protection)
- Token rotation
src/hooks/useZitadelSSO.ts for implementation.Layer 3: Authorization
Layer 3: Authorization
Layer 4: Data Isolation
Layer 4: Data Isolation
Row Level Security (RLS): PostgreSQL policies enforce data boundaries
- Organization-level isolation
- User can only see own organization’s data
- Admins restricted to their organization
- Global admins see all (with policy exception)
Layer 5: Audit Logging
Layer 5: Audit Logging
Comprehensive Audit Trail: All security events logged
- Authentication attempts (success/failure)
- Authorization decisions
- Resource access grants/revocations
- Administrative actions
- Configuration changes
Security Best Practices
Deployment Architecture
Development Environment
Production Environment
Infrastructure Components
Application Server
Specs: 2 CPU, 4GB RAM, 20GB SSDSoftware: Nginx, Node.js (build only)Network: Netbird client connected
Database Server
Platform: Supabase Cloud or Self-HostedSpecs: PostgreSQL 15, 4GB RAM minimumBackup: Daily automated backups
Identity Provider
Platform: Zitadel at manager.kappa4.comConfig: OIDC application with PKCEMFA: Enforced for all users
VPN Infrastructure
Platform: Netbird management serverNetwork: 100.64.0.0/10 address spaceEncryption: WireGuard end-to-end
Scalability Considerations
Horizontal Scaling
The architecture supports horizontal scaling at multiple levels:- Frontend: Static assets served via CDN (future)
- Edge Functions: Auto-scale based on load (Supabase)
- Database: Read replicas for query distribution
- VPN: Mesh architecture scales with devices
Performance Optimizations
Code Splitting
React lazy loading and route-based chunking reduce initial bundle size
React Query Cache
Intelligent caching reduces API calls and improves UX
Database Indexing
Indexes on foreign keys and frequently queried columns
Connection Pooling
Supabase Pooler for efficient database connections
Monitoring & Observability
Logging Strategy
- Application Logs
- Edge Function Logs
- Database Logs
- Audit Logs
- Browser console (development)
- Sentry or similar (production)
- Error boundaries for graceful failures
Future Architecture Enhancements
Microservices
Split monolithic edge functions into specialized microservices
Event Bus
Implement event-driven architecture for real-time updates
GraphQL API
Add GraphQL layer for flexible client queries
Multi-Region
Deploy across multiple regions for global availability
Related Documentation
Features Overview
Explore all system capabilities and features
Getting Started
Deploy your first instance
Configuration Guide
Configure SSO, VPN, and integrations
Database Schema
Complete database schema reference