Files
blackroad-operating-system/kernel/typescript/serviceRegistry.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

269 lines
7.8 KiB
TypeScript

/**
* BlackRoad OS - Service Registry
*
* Complete, production-accurate service registry for all BlackRoad OS services.
* This is the single source of truth for service discovery.
*
* @version 2.0
* @author Atlas (Infrastructure Architect)
*/
import { ServiceEndpoint, ServiceRole } from './types';
/**
* Complete service registry with all production + dev URLs
*/
export const SERVICE_REGISTRY: Record<string, ServiceEndpoint> = {
operator: {
name: 'blackroad-os-operator',
role: 'operator',
production: {
cloudflare: 'https://operator.blackroad.systems',
railway: 'https://blackroad-os-operator-production-3983.up.railway.app',
internal: 'http://blackroad-os-operator.railway.internal:8001',
proxy: 'caboose.proxy.rlwy.net:45194',
},
development: {
railway: 'https://blackroad-os-operator-dev.up.railway.app',
internal: 'http://blackroad-os-operator.railway.internal:8001',
proxy: 'caboose.proxy.rlwy.net:45194',
},
port: 8001,
healthCheck: '/health',
satelliteRepo: 'BlackRoad-OS/blackroad-os-operator',
},
core: {
name: 'blackroad-os-core',
role: 'core',
production: {
cloudflare: 'https://core.blackroad.systems',
railway: 'https://9gw4d0h2.up.railway.app',
internal: 'http://blackroad-os-core.railway.internal:8000',
proxy: 'hopper.proxy.rlwy.net:10593',
},
development: {
railway: 'https://blackroad-os-core-dev-19b6.up.railway.app',
internal: 'http://blackroad-os-core.railway.internal:8000',
proxy: 'hopper.proxy.rlwy.net:10593',
},
port: 8000,
healthCheck: '/health',
satelliteRepo: 'BlackRoad-OS/blackroad-os-core',
},
api: {
name: 'blackroad-os-api',
role: 'api',
production: {
cloudflare: 'https://api.blackroad.systems',
railway: 'https://ac7bx15h.up.railway.app',
internal: 'http://blackroad-os-api.railway.internal:8000',
},
development: {
railway: 'https://blackroad-os-api-dev-ddcb.up.railway.app',
internal: 'http://blackroad-os-api.railway.internal:8000',
},
port: 8000,
healthCheck: '/health',
satelliteRepo: 'BlackRoad-OS/blackroad-os-api',
},
app: {
name: 'blackroad-operating-system',
role: 'shell',
production: {
cloudflare: 'https://app.blackroad.systems',
railway: 'https://blackroad-operating-system-production.up.railway.app',
internal: 'http://blackroad-operating-system.railway.internal:8000',
proxy: 'metro.proxy.rlwy.net:32948',
},
development: {
railway: 'https://blackroad-operating-system-dev.up.railway.app',
internal: 'http://blackroad-operating-system.railway.internal:8000',
proxy: 'metro.proxy.rlwy.net:32948',
},
port: 8000,
healthCheck: '/health',
satelliteRepo: 'BlackRoad-OS/blackroad-operating-system',
},
console: {
name: 'blackroad-os-prism-console',
role: 'console',
production: {
cloudflare: 'https://console.blackroad.systems',
railway: 'https://qqr1r4hd.up.railway.app',
internal: 'http://blackroad-os-prism-console.railway.internal:8000',
proxy: 'hopper.proxy.rlwy.net:38896',
},
development: {
railway: 'https://blackroad-os-prism-console-dev.up.railway.app',
internal: 'http://blackroad-os-prism-console.railway.internal:8000',
proxy: 'hopper.proxy.rlwy.net:38896',
},
port: 8000,
healthCheck: '/health',
satelliteRepo: 'BlackRoad-OS/blackroad-os-prism-console',
},
docs: {
name: 'blackroad-os-docs',
role: 'docs',
production: {
cloudflare: 'https://docs.blackroad.systems',
railway: 'https://2izt9kog.up.railway.app',
internal: 'http://blackroad-os-docs.railway.internal:8000',
},
development: {
railway: 'https://blackroad-os-docs-dev.up.railway.app',
internal: 'http://blackroad-os-docs.railway.internal:8000',
},
port: 8000,
healthCheck: '/health',
satelliteRepo: 'BlackRoad-OS/blackroad-os-docs',
},
web: {
name: 'blackroad-os-web',
role: 'web',
production: {
cloudflare: 'https://web.blackroad.systems',
railway: 'https://blackroad-os-web-production-3bbb.up.railway.app',
internal: 'http://blackroad-os-web.railway.internal:8000',
proxy: 'interchange.proxy.rlwy.net:59770',
},
development: {
railway: 'https://blackroad-os-web-dev.up.railway.app',
internal: 'http://blackroad-os-web.railway.internal:8000',
proxy: 'interchange.proxy.rlwy.net:59770',
},
port: 8000,
healthCheck: '/health',
satelliteRepo: 'BlackRoad-OS/blackroad-os-web',
},
os: {
name: 'blackroad-os-interface',
role: 'shell',
production: {
cloudflare: 'https://os.blackroad.systems',
railway: 'https://vtrb1hrx.up.railway.app',
internal: 'http://blackroad-os-interface.railway.internal:8000',
},
development: {
railway: 'https://blackroad-os-interface-dev.up.railway.app',
internal: 'http://blackroad-os-interface.railway.internal:8000',
},
port: 8000,
healthCheck: '/health',
satelliteRepo: 'BlackRoad-OS/blackroad-os-interface',
},
root: {
name: 'blackroad-os-root',
role: 'root',
production: {
cloudflare: 'https://blackroad.systems',
railway: 'https://kng9hpna.up.railway.app',
internal: 'http://blackroad-os-root.railway.internal:8000',
},
development: {
railway: 'https://blackroad-os-root-dev.up.railway.app',
internal: 'http://blackroad-os-root.railway.internal:8000',
},
port: 8000,
healthCheck: '/health',
satelliteRepo: 'BlackRoad-OS/blackroad-os-root',
},
};
/**
* Get service URL by service name, environment, and URL type
*/
export function getServiceUrl(
serviceName: string,
environment: 'production' | 'development' = 'production',
urlType: 'cloudflare' | 'railway' | 'internal' = 'cloudflare'
): string {
const service = SERVICE_REGISTRY[serviceName];
if (!service) {
throw new Error(`Unknown service: ${serviceName}`);
}
if (urlType === 'cloudflare' && environment === 'production') {
return service.production.cloudflare;
}
const envConfig = environment === 'production' ? service.production : service.development;
return urlType === 'internal' ? envConfig.internal : envConfig.railway;
}
/**
* Get all registered service names
*/
export function getAllServices(): string[] {
return Object.keys(SERVICE_REGISTRY);
}
/**
* Get service by role
*/
export function getServiceByRole(role: ServiceRole): ServiceEndpoint | undefined {
return Object.values(SERVICE_REGISTRY).find((s) => s.role === role);
}
/**
* Get all services by role
*/
export function getServicesByRole(role: ServiceRole): ServiceEndpoint[] {
return Object.values(SERVICE_REGISTRY).filter((s) => s.role === role);
}
/**
* Check if a service exists in the registry
*/
export function hasService(serviceName: string): boolean {
return serviceName in SERVICE_REGISTRY;
}
/**
* Get service endpoint configuration
*/
export function getService(serviceName: string): ServiceEndpoint {
const service = SERVICE_REGISTRY[serviceName];
if (!service) {
throw new Error(`Unknown service: ${serviceName}`);
}
return service;
}
/**
* Get internal URL for inter-service communication
* Prefers Railway internal DNS for performance
*/
export function getInternalUrl(
serviceName: string,
environment: 'production' | 'development' = 'production'
): string {
return getServiceUrl(serviceName, environment, 'internal');
}
/**
* Get public URL (Cloudflare DNS)
*/
export function getPublicUrl(
serviceName: string,
environment: 'production' | 'development' = 'production'
): string {
if (environment === 'production') {
return getServiceUrl(serviceName, environment, 'cloudflare');
}
return getServiceUrl(serviceName, environment, 'railway');
}
/**
* Export for convenience
*/
export default SERVICE_REGISTRY;