mirror of
https://github.com/blackboxprogramming/BlackRoad-Operating-System.git
synced 2026-03-17 01:57:11 -05:00
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
158 lines
4.0 KiB
TypeScript
158 lines
4.0 KiB
TypeScript
/**
|
|
* BlackRoad OS - RPC Client
|
|
*
|
|
* Inter-service Remote Procedure Call (RPC) client.
|
|
* Uses Railway internal DNS for optimal performance.
|
|
*
|
|
* @version 2.0
|
|
* @author Atlas (Infrastructure Architect)
|
|
*/
|
|
|
|
import { RPCRequest, RPCResponse, KernelIdentity, Environment } from './types';
|
|
import { getInternalUrl, getServiceUrl } from './serviceRegistry';
|
|
import { logger } from './logger';
|
|
import { kernelConfig } from './config';
|
|
|
|
/**
|
|
* RPC Client for inter-service communication
|
|
*/
|
|
export class RPCClient {
|
|
private environment: Environment;
|
|
private timeout: number;
|
|
|
|
constructor(environment?: Environment, timeout: number = 10000) {
|
|
this.environment = environment || kernelConfig.service.environment;
|
|
this.timeout = timeout;
|
|
}
|
|
|
|
/**
|
|
* Call a remote procedure on another service
|
|
*/
|
|
async call<T = any>(
|
|
service: string,
|
|
method: string,
|
|
params?: Record<string, any>,
|
|
timeout?: number
|
|
): Promise<T> {
|
|
const url = getInternalUrl(service, this.environment);
|
|
const requestTimeout = timeout || this.timeout;
|
|
|
|
const requestBody: RPCRequest = {
|
|
method,
|
|
params,
|
|
timeout: requestTimeout,
|
|
};
|
|
|
|
logger.debug(`[RPC] Calling ${service}.${method}`, { service, method, params });
|
|
|
|
try {
|
|
const controller = new AbortController();
|
|
const timeoutId = setTimeout(() => controller.abort(), requestTimeout);
|
|
|
|
const response = await fetch(`${url}/v1/sys/rpc`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-Service-Name': kernelConfig.service.name,
|
|
'X-Service-Role': kernelConfig.service.role,
|
|
},
|
|
body: JSON.stringify(requestBody),
|
|
signal: controller.signal,
|
|
});
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`RPC call failed: ${response.status} ${response.statusText}`);
|
|
}
|
|
|
|
const data: RPCResponse<T> = await response.json();
|
|
|
|
if (data.error) {
|
|
throw new Error(`RPC error: ${data.error.message}`);
|
|
}
|
|
|
|
logger.debug(`[RPC] Call successful: ${service}.${method}`);
|
|
return data.result as T;
|
|
} catch (error) {
|
|
logger.error(`[RPC] Call failed: ${service}.${method}`, {
|
|
error: error instanceof Error ? error.message : String(error),
|
|
});
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get health status of a service
|
|
*/
|
|
async getHealth(service: string): Promise<any> {
|
|
const url = getInternalUrl(service, this.environment);
|
|
|
|
try {
|
|
const response = await fetch(`${url}/health`, {
|
|
headers: {
|
|
'X-Service-Name': kernelConfig.service.name,
|
|
'X-Service-Role': kernelConfig.service.role,
|
|
},
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Health check failed: ${response.status}`);
|
|
}
|
|
|
|
return response.json();
|
|
} catch (error) {
|
|
logger.error(`[RPC] Health check failed: ${service}`, {
|
|
error: error instanceof Error ? error.message : String(error),
|
|
});
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get identity of a service
|
|
*/
|
|
async getIdentity(service: string): Promise<KernelIdentity> {
|
|
const url = getInternalUrl(service, this.environment);
|
|
|
|
try {
|
|
const response = await fetch(`${url}/v1/sys/identity`, {
|
|
headers: {
|
|
'X-Service-Name': kernelConfig.service.name,
|
|
'X-Service-Role': kernelConfig.service.role,
|
|
},
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Identity fetch failed: ${response.status}`);
|
|
}
|
|
|
|
return response.json();
|
|
} catch (error) {
|
|
logger.error(`[RPC] Identity fetch failed: ${service}`, {
|
|
error: error instanceof Error ? error.message : String(error),
|
|
});
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Ping a service (check if reachable)
|
|
*/
|
|
async ping(service: string): Promise<boolean> {
|
|
try {
|
|
await this.getHealth(service);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Global RPC client instance
|
|
*/
|
|
export const rpc = new RPCClient();
|
|
|
|
export default rpc;
|