Architecture
Kun is a configuration engine — not a server. It sits as the configuration layer on top of Anthropic's product suite, running both technical and business sides of Databayt.
5-Layer Architecture
Layer 5: Company Operations
Cowork | Claude Apps | Enterprise Connectors
Ali (business) | Samia (content) | Team coordination
Layer 4: Coordination & Automation
Agent Teams | Scheduled Tasks | CI/CD | Channels
Layer 3: KUN CONFIGURATION ENGINE (core value)
CLAUDE.md | 40 Agents | 25 Skills | 18 MCP Servers
8 Rules | 5 Hooks | 6 Memory | 100+ Keywords
Layer 2: Developer Surfaces (Anthropic-provided)
CLI | VS Code | JetBrains | Desktop | Web | iOS
Layer 1: Foundation (Anthropic-provided)
Opus 4.6 | Sonnet 4.6 | Haiku 4.5 | 1M Context | API
Team Roles
| Member | Role |
|---|---|
| Abdout | Builder |
| Ali | QA Engineer + Sales |
| Samia | R&D & Kun Caretaker |
| Sedon | Executor |
Layer 3: The Engine (Kun's Core)
CLAUDE.md Hierarchy
Priority (High → Low):
1. Project-level ~/project/CLAUDE.md — Project context
2. Repo-level ~/project/.claude/CLAUDE.md — Keywords, workflows
3. User-level ~/.claude/CLAUDE.md — Stack, preferences
4. Pattern library /Users/abdout/codebase/ — Core patterns
Agent Fleet (40 agents, 4 tiers)
captain (Tier 0 — company brain)
├── Business (Tier 1): revenue, growth, support
├── Product (Tier 2): product, analyst
└── Tech Leadership (Tier 3): tech-lead, ops, guardian
└── orchestration → 31 specialist agents
| Tier | Agents | Domain |
|---|---|---|
| Tier 0 (1) | captain | CEO brain, weekly allocation, revenue strategy |
| Tier 1 (3) | revenue, growth, support | Business operations |
| Tier 2 (2) | product, analyst | Product roadmap, market intelligence |
| Tier 3 (3) | tech-lead, ops, guardian | Architecture, infra, security |
| Stack (7) | nextjs, react, typescript, tailwind, prisma, shadcn, authjs | Technology expertise |
| Design (4) | orchestration, architecture, pattern, structure | System design |
| UI (4) | shadcn, atom, template, block | Component hierarchy |
| DevOps (3) | build, deploy, test | Development lifecycle |
| VCS (2) | git, github | Version control |
| Specialized (8) | middleware, i18n, semantic, sse, optimize, performance, comment, icon | Domain expertise |
| Reference (4) | hogwarts, souq, mkan, shifa | Product-specific patterns |
MCP Ecosystem (18 servers)
| Category | Servers |
|---|---|
| UI & Design | shadcn, figma, tailwind, a11y, storybook |
| Testing | browser (headless), browser-headed |
| DevOps | github, vercel, sentry, gcloud |
| Data & Auth | neon, postgres, stripe, keychain |
| Knowledge | ref, context7 |
| Project Mgmt | linear |
Rules Engine (8 rules)
Auto-activate on file patterns: auth, i18n, prisma, tailwind, testing, deployment, multi-repo, org-refs.
Hook Automation (5 hooks)
| Event | Action |
|---|---|
| SessionStart | Print model + timestamp |
| PreToolUse (pnpm dev) | Kill port 3000 |
| PostToolUse (pnpm dev) | Open Chrome |
| PostToolUse (Write/Edit) | Run Prettier |
| Stop | Log session end |
Layer 4: Coordination
Agent Teams (Experimental)
Lead agent coordinates teammate agents, each in isolated git worktrees. No merge conflicts. Consolidated PR.
Cross-Device Flow
Phone (iOS) ──Dispatch──▶ Desktop App ──/teleport──▶ Terminal (CLI)
◀──────── Remote Control ──────────────────────────────┘
Scheduled Tasks
| Type | Runs On | Use Case |
|---|---|---|
| Cloud | Anthropic infra (computer off) | Health checks, dependency updates |
| Desktop | Local (app open) | Recurring builds |
| /loop | Active session | Poll deploy status |
3-Channel Communication
| Channel | Medium | Direction | Purpose |
|---|---|---|---|
| Dispatch | Apple Notes → Dispatch (Captain, Cowork, Inbox) | Async, bidirectional | Updates, decisions, handoffs |
| GitHub Issues | databayt/*/issues | Structured work items | Tasks with labels, milestones, assignees |
| Claude Native | Code / Cowork / Voice | Real-time | Building, planning, quick decisions |
Cowork ↔ Code Bridge
Cowork (think): plan → create issues → write to Dispatch/Cowork
Code (do): read Dispatch/Cowork → pick up issues → execute → report back
Shared state: ~/.claude/ (agents, memory, settings, rules). Same brain, two modes.
Layer 5: Business Operations
Team Workflows
| Member | Role | Primary Workflows |
|---|---|---|
| Abdout | Builder | dev → build → push → deploy |
| Ali | QA + Sales | Testing, issue reports, outreach (sales@databayt.org) |
| Samia | R&D | Claude/Anthropic research, sharing economy, Kun care |
| Sedon | Executor | Clear task maps, Saudi operations |
Hogwarts Pilot (King Fahad Schools)
Developer: handover admission → 5-pass QA → deploy to ed.databayt.org
Business: Cowork → onboarding plan → Arabic welcome email → training agenda
Content: Cowork → Arabic user guide → screenshots → voiceover
Repository Map
databayt/ (14 repos)
├── Products
│ ├── hogwarts — Education SaaS (FLAGSHIP, daily commits)
│ ├── mkan — Rental marketplace (Phase 1 done)
│ ├── souq — E-commerce (MVP, paused)
│ └── shifa — Medical platform (early, paused)
├── Libraries
│ ├── codebase — Pattern library (54 ui + 62 atoms + 31 templates)
│ ├── shadcn — UI components (shadcn/ui fork)
│ └── radix — UI primitives (Radix fork)
├── Engine
│ └── kun — Configuration engine (this repo)
├── Mobile & Marketing
│ ├── swift-app — iOS app (Swift 6/SwiftUI)
│ └── marketing — Landing pages
└── Other
├── spma — Internal tool
├── apple — Design R&D
├── distributed-computer — Rust/blockchain concept
└── .github — Org profile
Security
| Layer | Mechanism |
|---|---|
| Anthropic | SSO/SCIM, audit logging, SOC 2, no training on data |
| Kun config | 4 deny rules (rm -rf, DROP TABLE, etc.), 38 explicit allow rules |
| Hooks | PreToolUse guards validate before execution |
| Secrets | macOS Keychain MCP, never in git |
| Accessibility | Screen reader compatibility, VoiceOver testing |
Architecture Decision Records
ADR-001: Configuration Over Infrastructure
Decision: Use Anthropic's products as-is, configure don't build. Rationale: 4-person team can't maintain custom infrastructure alongside 5 products.
ADR-002: Opus 4.6 Default
Decision: Use Opus for all agents, Haiku only for explore subagents. Rationale: Quality over speed for a small team where every output matters.
ADR-003: Single Subscription Model
Decision: One Max 20x ($200/month) shared via Desktop/Web. Rationale: $500/month burn with $5K capital = 10 months runway. Add Pro seats ($20) when revenue grows.
ADR-004: Hogwarts-First Development
Decision: All engine features validated through Hogwarts pilot first. Rationale: King Fahad Schools is the revenue pipeline. Ship what pays.
ADR-005: Shared Component Library
Decision: All products pull from databayt/codebase. Rationale: 54 UI + 62 atoms + 31 templates = don't rebuild across 5 products.
Architecture Principles
- Configuration over infrastructure — Don't build what Anthropic ships
- Architecture-first — Humans design, AI generates within constraints
- Guardrails as training data — CLAUDE.md, agents, rules shape output
- Full spectrum — Technical AND business operations
- Anthropic-native — Use products as designed
On This Page
Architecture5-Layer ArchitectureTeam RolesLayer 3: The Engine (Kun's Core)CLAUDE.md HierarchyAgent Fleet (40 agents, 4 tiers)MCP Ecosystem (18 servers)Rules Engine (8 rules)Hook Automation (5 hooks)Layer 4: CoordinationAgent Teams (Experimental)Cross-Device FlowScheduled Tasks3-Channel CommunicationCowork ↔ Code BridgeLayer 5: Business OperationsTeam WorkflowsHogwarts Pilot (King Fahad Schools)Repository MapSecurityArchitecture Decision RecordsADR-001: Configuration Over InfrastructureADR-002: Opus 4.6 DefaultADR-003: Single Subscription ModelADR-004: Hogwarts-First DevelopmentADR-005: Shared Component LibraryArchitecture Principles