Architecture

5-layer Anthropic-native engine architecture for Databayt

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

MemberRole
AbdoutBuilder
AliQA Engineer + Sales
SamiaR&D & Kun Caretaker
SedonExecutor

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
TierAgentsDomain
Tier 0 (1)captainCEO brain, weekly allocation, revenue strategy
Tier 1 (3)revenue, growth, supportBusiness operations
Tier 2 (2)product, analystProduct roadmap, market intelligence
Tier 3 (3)tech-lead, ops, guardianArchitecture, infra, security
Stack (7)nextjs, react, typescript, tailwind, prisma, shadcn, authjsTechnology expertise
Design (4)orchestration, architecture, pattern, structureSystem design
UI (4)shadcn, atom, template, blockComponent hierarchy
DevOps (3)build, deploy, testDevelopment lifecycle
VCS (2)git, githubVersion control
Specialized (8)middleware, i18n, semantic, sse, optimize, performance, comment, iconDomain expertise
Reference (4)hogwarts, souq, mkan, shifaProduct-specific patterns

MCP Ecosystem (18 servers)

CategoryServers
UI & Designshadcn, figma, tailwind, a11y, storybook
Testingbrowser (headless), browser-headed
DevOpsgithub, vercel, sentry, gcloud
Data & Authneon, postgres, stripe, keychain
Knowledgeref, context7
Project Mgmtlinear

Rules Engine (8 rules)

Auto-activate on file patterns: auth, i18n, prisma, tailwind, testing, deployment, multi-repo, org-refs.

Hook Automation (5 hooks)

EventAction
SessionStartPrint model + timestamp
PreToolUse (pnpm dev)Kill port 3000
PostToolUse (pnpm dev)Open Chrome
PostToolUse (Write/Edit)Run Prettier
StopLog 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

TypeRuns OnUse Case
CloudAnthropic infra (computer off)Health checks, dependency updates
DesktopLocal (app open)Recurring builds
/loopActive sessionPoll deploy status

3-Channel Communication

ChannelMediumDirectionPurpose
DispatchApple Notes → Dispatch (Captain, Cowork, Inbox)Async, bidirectionalUpdates, decisions, handoffs
GitHub Issuesdatabayt/*/issuesStructured work itemsTasks with labels, milestones, assignees
Claude NativeCode / Cowork / VoiceReal-timeBuilding, 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

MemberRolePrimary Workflows
AbdoutBuilderdev → build → push → deploy
AliQA + SalesTesting, issue reports, outreach (sales@databayt.org)
SamiaR&DClaude/Anthropic research, sharing economy, Kun care
SedonExecutorClear 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

LayerMechanism
AnthropicSSO/SCIM, audit logging, SOC 2, no training on data
Kun config4 deny rules (rm -rf, DROP TABLE, etc.), 38 explicit allow rules
HooksPreToolUse guards validate before execution
SecretsmacOS Keychain MCP, never in git
AccessibilityScreen 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

  1. Configuration over infrastructure — Don't build what Anthropic ships
  2. Architecture-first — Humans design, AI generates within constraints
  3. Guardrails as training data — CLAUDE.md, agents, rules shape output
  4. Full spectrum — Technical AND business operations
  5. Anthropic-native — Use products as designed