Tech Stack β
π PDL Architecture: This page covers the technical implementation stack. For the data generation architecture (PDL, generators, packages), see Architecture Overview.
System Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PHONY - ARCHITECTURE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β UNIFIED CLI: phony (Foundation) β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ β
β β β β
β β PURPOSE: Single tool for entire workflow (like gh, vercel) β β
β β LICENSE: MIT (fully open source) β β
β β DISTRIBUTION: Single binary, no dependencies β β
β β β β
β β OFFLINE (No Auth): β β
β β $ phony train input.txt --locale tr_TR -o names.phony β β
β β $ phony train data.csv --column name -o model.phony β β
β β $ phony info model.phony # Show model metadata β β
β β β β
β β CLOUD (After: phony login): β β
β β $ phony models push/pull # Cloud model library β β
β β $ phony sync # Database sync β β
β β $ phony mock start/deploy # Mock API β β
β β $ phony generate --count 1M # High-speed generation (5M/s) β β
β β β β
β β WHY UNIFIED CLI: β β
β β β’ Offline-first (training always free, no auth needed) β β
β β β’ Progressive disclosure (cloud features unlock with login) β β
β β β’ Language-agnostic (PHP dev, Python dev, anyone can use) β β
β β β’ Single binary distribution (curl | sh install) β β
β β β’ Same core reused in Cloud backend (Rust) β β
β β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β OSS GENERATION LIBRARIES β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ β
β β β β
β β PURPOSE: Generate data from .phony models (GENERATION ONLY) β β
β β APPROACH: Pure native implementation per language β β
β β DEVELOPMENT: AI-assisted (AI writes, human reviews) β β
β β FORMAT: Reads .phony model format (created by Rust CLI) β β
β β β β
β β TIMELINE: β β
β β βββ Year 1 Q1-Q2: PHP/Laravel (phonycloud/phony-php) β β
β β βββ Year 2: Python (phonycloud/phony-python) β
Revenue β β
β β βββ Year 3: TypeScript (@phonycloud/phony) - Optional β β
β β βββ Future: Community contributions for other languages β β
β β β β
β β WHAT OSS PACKAGES DO: β β
β β βββ Load .phony models (bundled or custom) β β
β β βββ Generate data (N-gram weighted random walk) β β
β β βββ Deterministic output (seed support) β β
β β βββ Framework integrations (Laravel, FastAPI, etc.) β β
β β β β
β β WHAT OSS PACKAGES DON'T DO: β β
β β βββ Training (use Rust CLI or Phony Cloud instead) β β
β β β β
β β PERFORMANCE: ~10-50K records/sec (good enough for typical use) β β
β β MAINTENANCE: Community can maintain non-PHP implementations β β
β β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β CLOUD PLATFORM β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ β
β β β β
β β STACK: Nuxt + Go + Rust (3 languages) β β
β β β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β
β β β NUXT β β GO β β RUST β β β
β β β Dashboard β β Engine β β Core β β β
β β β β β β β β β β
β β β β’ Vue 3 β β β’ DB Sync β β β’ N-gram β β β
β β β β’ TypeScriptβ β β β’ Mock API β β β β’ Train β β β
β β β β’ Auth β β β’ Training β β β’ Generate β β β
β β β β’ Billing β β β’ pgx (DB) β β β’ Model I/O β β β
β β β β β β β β β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β
β β β β
β β RUST CORE: phony-core (via crates.io) + cloud FFI, compiled via CGO β β
β β NO LARAVEL: Go handles all backend (sync, API, processing) β β
β β PERFORMANCE: ~5M records/sec (Rust-powered) β β
β β SCALE: TB-level database sync capable β β
β β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β MONETIZATION STRATEGY β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ β
β β β β
β β TRAINING: β β
β β βββ Rust CLI: FREE, full speed, MIT licensed β β
β β βββ Phony Cloud: Paid convenience (Web UI, DB column training) β β
β β β β
β β GENERATION (This is where monetization happens): β β
β β βββ OSS (Free): Native per language, ~10-50K/sec, "good enough" β β
β β βββ Cloud (Paid): Rust-powered, ~5M/sec, 50-100x faster β β
β β β β
β β INFRASTRUCTURE (Cloud-only): β β
β β βββ Mock API hosting β β
β β βββ Database Sync β β
β β βββ Team collaboration β β
β β βββ Scheduled jobs, snapshots β β
β β β β
β β KEY INSIGHT: β β
β β Training = one-time operation (free, builds trust) β β
β β Generation = continuous operation (speed matters, monetizable) β β
β β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββWhy This Architecture? β
| Decision | Rationale |
|---|---|
| No Laravel | Go already handles sync/API; Laravel would be overhead |
| Nuxt for Dashboard | Vue familiarity (from Inertia), TypeScript, easy deploy |
| Go for Engine | Best DB libraries (pgx), great concurrency, fast HTTP |
| Rust for Core | Maximum N-gram performance, memory efficiency |
| Pure native OSS | Easy install, no binary deps, community maintainable |
| AI-assisted dev | Makes unfamiliar languages feasible |
| JSON + gzip | Native in all languages, zero external dependencies |
.phony Model Format β
The .phony format is designed for maximum portability and zero external dependencies.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β .PHONY FILE FORMAT β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β FILE STRUCTURE: β
β βββββββββββββββ β
β .phony file = gzip compressed JSON β
β β
β Read: gzdecode(file) β json_decode() β native data structure β
β Write: json_encode() β gzencode() β file β
β β
β DEBUG: β
β $ gunzip -c model.phony | jq . β
β $ zcat model.phony | python -m json.tool β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β WHY THIS FORMAT: β
β ββββββββββββββββ β
β β JSON: Native in PHP, Python, JS, Go, Rust (no external deps) β
β β gzip: Native in PHP, Python, JS, Go, Rust (no external deps) β
β β Human debuggable: gunzip + jq for inspection β
β β LookupList structure: O(log n) weighted random selection β
β β Markov graph: O(1) lookup for generation β
β β
β SIZE EXAMPLE: β
β βββββββββββββ β
β 100K N-grams: β
β βββ Raw JSON: ~8 MB β
β βββ Gzipped: ~2 MB (75% reduction) β
β βββ In RAM (loaded): ~10 MB (native hash maps) β
β β
β PERFORMANCE: β
β ββββββββββββ β
β Load time (2MB file): ~50-100ms (decompress + parse) β
β Generation: ~0.01ms per output (O(1) hash lookup) β
β Throughput: 10-100K generations/sec β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββDetailed Specification: For complete JSON schema, LookupList format, Element structure, and Markov chain graph details, see N-gram Models Architecture.
Format Versioning β
| Version | Changes | Compatibility |
|---|---|---|
| 1 | Initial release | Current |
Future versions will maintain backward compatibility. Version field allows graceful migration.
Code Examples β
PHP (Reading):
function loadPhonyModel(string $path): array {
$compressed = file_get_contents($path);
$json = gzdecode($compressed);
return json_decode($json, true);
}
// Usage
$model = loadPhonyModel('tr_TR/names.phony');
$tokens = $model['tokens'];
$bigrams = $model['ngrams']['2'];Python (Reading):
import gzip
import json
def load_phony_model(path: str) -> dict:
with gzip.open(path, 'rt', encoding='utf-8') as f:
return json.load(f)
# Usage
model = load_phony_model('tr_TR/names.phony')
tokens = model['tokens']
bigrams = model['ngrams']['2']JavaScript (Reading):
import { gunzipSync } from 'zlib';
import { readFileSync } from 'fs';
function loadPhonyModel(path) {
const compressed = readFileSync(path);
const json = gunzipSync(compressed).toString('utf-8');
return JSON.parse(json);
}
// Usage
const model = loadPhonyModel('tr_TR/names.phony');
const tokens = model.tokens;
const bigrams = model.ngrams['2'];Timeline β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β IMPLEMENTATION TIMELINE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β YEAR 1 Q1-Q2: FOUNDATION β
β βββββββββββββββββββββββββ β
β Week 1-4: Rust (phony-core + phony-cli) β
β βββ phony-core: N-gram algorithms, model I/O β
β βββ phony-cli: train, info, validate, stats commands β
β βββ .phony format (gzipped JSON, zero dependencies) β
β βββ Pre-train bundled models (tr_TR, en_US, etc.) β
β β
β Week 5-10: PHP Generation Library (phonycloud/phony-php) β
β βββ Load .phony models (from CLI) β
β βββ N-gram generation (native PHP) β
β βββ Deterministic seed support β
β βββ Pre-trained models bundled β
β β
β Week 11-14: Laravel Integration (phonycloud/phony-laravel) β
β βββ Service provider, facades β
β βββ Factory integration β
β βββ Artisan commands β
β β
β YEAR 1 Q3-Q4: CLOUD MVP β
β ββββββββββββββββββββββββ β
β Week 1-4: Rust (phony-core + cloud FFI + optimizations) β
β Week 5-10: Go Engine (sync, mock API, training orchestration) β
β Week 11-16: Nuxt Dashboard (UI, auth, billing) β
β Week 17-20: PHP Cloud SDK (phonycloud/phony-cloud) β
β β
β YEAR 2: PYTHON ECOSYSTEM β
β βββββββββββββββββββββββββ β
β Q1-Q2: Python Generation Library (pip install phony) β
β βββ Load .phony models β
β βββ N-gram generation (native Python) β
β βββ FastAPI/Django integrations β
β β
β Q3-Q4: Python Cloud SDK + Advanced Cloud Features β
β βββ pip install phony-cloud β
β βββ DB Sync advanced features β
β βββ Mock API stateful mode β
β β
β YEAR 3: TYPESCRIPT + SCALE β
β βββββββββββββββββββββββββ β
β Q1-Q2: TypeScript Generation (npm install @phonycloud/phony) β
β βββ Works in Node.js and browser β
β βββ TypeScript Cloud SDK β
β β
β Q3-Q4: Enterprise Features β
β βββ SSO, audit logs, on-premise option β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
VISUAL TIMELINE:
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3
βββββββΌββββββΌββββββΌββββββΌββββββΌββββββΌββββββΌββββββΌββββββΌββββββ€
YEAR 1 βRust β PHP β Cloud MVP β
β CLI β Gen ββββββββββββββββββββββ
βββββββββββββ β
β β β β
YEAR 2 β β Python Gen β Cloud Adv β
β βββββββββββββββββββββββββββββ
β β β β
YEAR 3 β β TypeScript β Enterprise β
β ββββββββββββββββββββββββββββ
β
π° β ββββ Revenue Starts ββββββββ Scale ββββLayer Details β
Layer 1: Nuxt (TypeScript + Vue) β
| Aspect | Detail |
|---|---|
| Purpose | Web dashboard, auth, billing UI |
| Why | Vue familiarity, TypeScript, easy deploy to Vercel |
| Tech | Nuxt 3, Vue 3, Auth.js, Stripe SDK |
Layer 2: Go Engine β
| Aspect | Detail |
|---|---|
| Purpose | DB sync, Mock API server, training orchestration |
| Why | Goroutines for concurrency, memory efficiency, fast HTTP |
| Tech | Go 1.22+, pgx, go-mysql, asynq |
Layer 3: Rust Core β
| Aspect | Detail |
|---|---|
| Purpose | N-gram train/generate/save/load |
| Why | Maximum performance for hot path (5M/sec) |
| Tech | Rust stable, serde_json + flate2 (gzip), FFI to Go |
Communication Flow β
Nuxt ββHTTPβββΊ Go Engine ββFFI (CGO)βββΊ Rust CoreAI-Assisted Development β
Development leverages AI agents for code generation with human review.
What AI Does Well β
- Writing isolated modules with clear interfaces
- Test generation
- Boilerplate and CRUD operations
- Documentation
- Code translation between languages
What Needs Human Expertise β
- Architectural decisions
- Performance optimization strategies
- Debugging complex issues
- Security review
- Production incident response
Language-Specific AI Effectiveness β
| Language | AI Code Quality | Review Difficulty |
|---|---|---|
| TypeScript | β β β β β | Easy |
| Go | β β β β | Medium (readable) |
| Rust | β β β β | Hard (lifetimes, borrowing) |
Key Insight: AI can write Rust well, but reviewing Rust for correctness requires understanding ownership/borrowing. Go is more forgiving for reviewers.