Files
blackroad-operating-system/kernel/typescript/types.ts
Claude dbdd8bd148 Add BlackRoad OS Kernel, DNS Infrastructure, and Complete Service Registry
This commit introduces a comprehensive infrastructure overhaul that transforms
BlackRoad OS into a true distributed operating system with unified kernel,
DNS-aware service discovery, and standardized syscall APIs.

## New Infrastructure Components

### 1. Kernel Module (kernel/typescript/)
- Complete TypeScript kernel implementation for all services
- Service registry with production and dev DNS mappings
- RPC client for inter-service communication
- Event bus, job queue, state management
- Structured logging with log levels
- Full type safety with TypeScript

Modules:
- types.ts: Complete type definitions
- serviceRegistry.ts: DNS-aware service discovery
- identity.ts: Service identity and metadata
- config.ts: Environment-aware configuration
- logger.ts: Structured logging
- rpc.ts: Inter-service RPC client
- events.ts: Event bus (pub/sub)
- jobs.ts: Background job queue
- state.ts: Key-value state management
- index.ts: Main exports

### 2. DNS Infrastructure Documentation (infra/DNS.md)
- Complete Cloudflare DNS mapping
- Railway production and dev endpoints
- Email configuration (MX, SPF, DKIM, DMARC)
- SSL/TLS, security, and monitoring settings
- Service-to-domain mapping
- Health check configuration

Production Services:
- operator.blackroad.systems
- core.blackroad.systems
- api.blackroad.systems
- console.blackroad.systems
- docs.blackroad.systems
- web.blackroad.systems
- os.blackroad.systems
- app.blackroad.systems

### 3. Service Registry & Architecture (INFRASTRUCTURE.md)
- Canonical service registry with all endpoints
- Monorepo-to-satellite deployment model
- Service-as-process architecture
- DNS-as-filesystem model
- Inter-service communication patterns
- Service lifecycle management
- Complete environment variable documentation

### 4. Syscall API Specification (SYSCALL_API.md)
- Standard kernel API for all services
- Required syscalls: health, version, identity, RPC
- Optional syscalls: logging, metrics, events, jobs, state
- Complete API documentation with examples
- Express.js implementation guide

Core Endpoints:
- GET /health
- GET /version
- GET /v1/sys/identity
- GET /v1/sys/health
- POST /v1/sys/rpc
- POST /v1/sys/event
- POST /v1/sys/job
- GET/PUT /v1/sys/state

### 5. Railway Deployment Guide (docs/RAILWAY_DEPLOYMENT.md)
- Step-by-step deployment instructions
- Environment variable configuration
- Monitoring and health checks
- Troubleshooting guide
- Best practices for Railway deployment

### 6. Atlas Kernel Scaffold Prompt (prompts/atlas/ATLAS_KERNEL_SCAFFOLD.md)
- Complete prompt for generating new services
- Auto-generates full kernel implementation
- Includes all DNS and Railway mappings
- Production-ready output with zero TODOs

### 7. GitHub Workflow Templates (templates/github-workflows/)
- deploy.yml: Railway auto-deployment
- test.yml: Test suite with coverage
- validate-kernel.yml: Kernel validation
- README.md: Template documentation

## Updated Files

### CLAUDE.md
- Added "Kernel Architecture & DNS Infrastructure" section
- Updated Table of Contents
- Added service architecture diagram
- Documented all new infrastructure files
- Updated repository structure with new directories
- Added kernel and infrastructure to critical path files

## Architecture Impact

This update establishes BlackRoad OS as a distributed operating system where:
- Each Railway service = OS process
- Each Cloudflare domain = mount point
- All services communicate via syscalls
- Unified kernel ensures interoperability
- DNS-aware service discovery
- Production and development environments

## Service Discovery

Services can now discover and call each other:
```typescript
import { rpc } from './kernel';
const user = await rpc.call('core', 'getUserById', { id: 123 });
```

## DNS Mappings

Production:
- operator.blackroad.systems → blackroad-os-operator-production-3983.up.railway.app
- core.blackroad.systems → 9gw4d0h2.up.railway.app
- api.blackroad.systems → ac7bx15h.up.railway.app

Internal (Railway):
- blackroad-os-operator.railway.internal:8001
- blackroad-os-core.railway.internal:8000
- blackroad-os-api.railway.internal:8000

## Next Steps

1. Sync kernel to satellite repos
2. Implement syscall endpoints in all services
3. Update services to use RPC for inter-service calls
4. Configure Cloudflare health checks
5. Deploy updated services to Railway

---

Files Added:
- INFRASTRUCTURE.md
- SYSCALL_API.md
- infra/DNS.md
- docs/RAILWAY_DEPLOYMENT.md
- kernel/typescript/* (9 modules + README)
- prompts/atlas/ATLAS_KERNEL_SCAFFOLD.md
- templates/github-workflows/* (4 files)

Files Modified:
- CLAUDE.md

Total: 22 new files, 1 updated file
2025-11-20 00:48:41 +00:00

267 lines
5.8 KiB
TypeScript

/**
* BlackRoad OS - Kernel Type Definitions
*
* Shared TypeScript types for the BlackRoad OS kernel layer.
* All services must use these types for interoperability.
*
* @version 2.0
* @author Atlas (Infrastructure Architect)
*/
export type Environment = 'production' | 'development' | 'staging' | 'test';
export type ServiceRole =
| 'core'
| 'api'
| 'operator'
| 'web'
| 'console'
| 'docs'
| 'shell'
| 'root';
export type HealthStatus = 'healthy' | 'degraded' | 'unhealthy';
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'fatal';
export type JobStatus =
| 'pending'
| 'queued'
| 'running'
| 'completed'
| 'failed'
| 'cancelled';
/**
* Service endpoint configuration
*/
export interface ServiceEndpoint {
name: string;
role: ServiceRole;
production: {
cloudflare: string; // Public DNS (Cloudflare)
railway: string; // Railway public URL
internal: string; // Railway internal DNS
proxy?: string; // Railway proxy (if applicable)
};
development: {
railway: string; // Dev Railway URL
internal: string; // Dev internal DNS
proxy?: string; // Dev proxy
};
port: number; // Service port
healthCheck: string; // Health check path
satelliteRepo: string; // GitHub satellite repo
}
/**
* Kernel identity exposed via /v1/sys/identity
*/
export interface KernelIdentity {
service: string; // e.g., "blackroad-os-core"
role: ServiceRole; // e.g., "core", "api", "operator"
version: string; // e.g., "1.0.0"
environment: Environment; // "production" | "development"
dns: {
cloudflare: string; // Public DNS
railway: string; // Railway URL
internal: string; // Internal DNS
};
runtime: {
railwayHost: string; // RAILWAY_STATIC_URL
internalHost: string; // service.railway.internal
port: number; // Service port
pid: number; // Process ID
uptime: number; // Process uptime (seconds)
};
health: {
status: HealthStatus;
uptime: number; // Service uptime (seconds)
lastCheck: string; // ISO timestamp
};
capabilities: string[]; // ["rpc", "events", "jobs", "state"]
}
/**
* Extended health check response
*/
export interface HealthCheck {
status: HealthStatus;
timestamp: string; // ISO timestamp
uptime: number; // Seconds
memory: {
rss: number; // Resident Set Size (bytes)
heapTotal: number; // Total heap (bytes)
heapUsed: number; // Used heap (bytes)
external: number; // External memory (bytes)
};
checks: {
database?: HealthCheckResult;
redis?: HealthCheckResult;
dependencies?: HealthCheckResult;
[key: string]: HealthCheckResult | undefined;
};
}
export interface HealthCheckResult {
status: 'ok' | 'degraded' | 'down';
message?: string;
latency?: number; // Milliseconds
}
/**
* Version information
*/
export interface VersionInfo {
version: string; // Package version
service: string; // Service name
commit?: string; // Git commit hash
buildTime?: string; // ISO timestamp
nodeVersion: string; // Node.js version
environment: Environment;
}
/**
* Configuration object
*/
export interface KernelConfig {
service: {
name: string;
role: ServiceRole;
version: string;
environment: Environment;
port: number;
};
railway: {
staticUrl?: string;
environment?: string;
projectId?: string;
};
urls: {
operator: string;
core: string;
api: string;
console: string;
docs: string;
web: string;
os: string;
};
internalUrls: {
operator: string;
core: string;
api: string;
console: string;
docs: string;
web: string;
};
features: {
rpc: boolean;
events: boolean;
jobs: boolean;
state: boolean;
};
}
/**
* Log entry
*/
export interface LogEntry {
id: string; // UUID
timestamp: string; // ISO timestamp
level: LogLevel;
message: string;
service: string;
meta?: Record<string, any>;
}
/**
* Metric entry
*/
export interface MetricEntry {
id: string; // UUID
timestamp: string; // ISO timestamp
name: string; // Metric name (e.g., "http.request.duration")
value: number;
unit?: string; // e.g., "ms", "bytes", "count"
tags?: Record<string, string>;
}
/**
* RPC request
*/
export interface RPCRequest {
method: string; // Method name
params?: Record<string, any>;
timeout?: number; // Milliseconds
}
/**
* RPC response
*/
export interface RPCResponse<T = any> {
result?: T;
error?: {
code: string;
message: string;
details?: any;
};
}
/**
* Event
*/
export interface Event {
id: string; // UUID
event: string; // Event name
timestamp: string; // ISO timestamp
source: string; // Service that emitted
data?: Record<string, any>;
}
/**
* Job definition
*/
export interface Job {
id: string; // UUID
name: string; // Job name
params?: Record<string, any>;
schedule?: string; // Cron expression (optional)
status: JobStatus;
createdAt: string; // ISO timestamp
startedAt?: string; // ISO timestamp
completedAt?: string; // ISO timestamp
result?: any;
error?: {
message: string;
stack?: string;
};
}
/**
* State entry
*/
export interface StateEntry {
key: string;
value: any;
version: number; // Optimistic locking
updatedAt: string; // ISO timestamp
}
/**
* API Response wrapper
*/
export interface APIResponse<T = any> {
ok: boolean;
data?: T;
error?: {
code: string;
message: string;
details?: any;
};
meta?: {
timestamp: string;
requestId?: string;
version?: string;
};
}