Tech Stack β
π PGDL Architecture: This page covers the technical implementation stack. For the data generation architecture (PGDL, 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.ngram β β
β β $ phony train data.csv --column name -o model.ngram β β
β β $ phony info model.ngram # Show model metadata β β
β β $ phony generate gen.json -n 1000 --seed 42 # Local generation β β
β β β β
β β 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 # Bulk/scale generation (5M/s) β β
β β β β
β β WHY UNIFIED CLI: β β
β β β’ Offline-first (train + generate locally, free, no auth) β β
β β β’ 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 .ngram models (GENERATION ONLY) β β
β β APPROACH: Pure native implementation per language β β
β β DEVELOPMENT: AI-assisted (AI writes, human reviews) β β
β β FORMAT: Reads .ngram 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 .ngram 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 β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ β
β β β β
β β FREE EVERYWHERE (OSS, MIT): β β
β β βββ Training: CLI + files, full speed, unlimited β β
β β βββ Generation: CLI + libraries, unlimited β never metered β β
β β (generation is the adoption funnel, not the moat) β β
β β β β
β β MONETIZATION (Cloud, priced per connected data source): β β
β β βββ Tiers: $0 / $49 / $199 / $599 / Enterprise β β
β β βββ Database sync & anonymization (local-first data plane) β β
β β βββ Mock API hosting, snapshots, scheduled jobs β β
β β βββ Team collaboration, compliance β β
β β β β
β β KEY INSIGHT: β β
β β The moat is the prod-data platform (connect DB β detect PII β β β
β β safe, referentially-intact copy) β not generation speed. β β
β β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββGeneration is free and unlimited everywhere; Cloud pricing is per connected data source β see Pricing.
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 |
Binary .ngram format | One documented byte layout; compact, deterministic across runtimes |
The .ngram Model Format β
Models are saved as .ngram files β a portable binary format (magic PHNYNG03 + gzip-compressed body) defined normatively in FORMAT.md in the phony-core repository.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β .NGRAM FILE FORMAT β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β FILE STRUCTURE: β
β βββββββββββββββ β
β .ngram file = 8-byte magic ("PHNYNG03") + gzip-compressed binary body β
β β
β Body (single n-gram order): β
β βββ order, token_type, tokenizer config, metadata β
β βββ interned vocab (sorted; index = u32 id) β
β βββ opener + transition distributions (LEB128 varint id/weight) β
β βββ word/sentence/paragraph length distributions β
β βββ deduped originals (unique item + count) β
β β
β INSPECT: β
β $ phony info model.ngram # metadata β
β $ phony validate model.ngram # format + integrity β
β $ phony stats model.ngram # statistics β
β β
β WHY THIS FORMAT: β
β ββββββββββββββββ β
β β One documented byte layout β readable with plain integer reads β
β (LEB128 varints + UTF-8 strings); no schema library, no reflection β
β β Compact: interned vocab + varint weights + gzip β
β β Deterministic: normative edge ordering β identical sampling β
β across runtimes β
β β Fast load: the on-disk layout mirrors the in-memory CSR graph β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββDetailed specification: the normative byte layout lives in
FORMAT.mdin thephony-corerepository. For the modelling concepts, see N-gram Models Architecture.
Format Versioning β
The version is carried in the magic string (PHNYNG03). The project is pre-release: readers reject anything not starting with the current magic, and there is no legacy format to support.
Reading Models β
.ngram files are not ad-hoc JSON β they are read through the ngram-core reader, which parses the binary layout (per FORMAT.md) directly into the in-memory graph:
use ngram_core::NgramModel;
let model = NgramModel::load("tr_TR/names.ngram")?; // validates magic + layout
let names = model.generate_many(/* seed */ 42, /* count */ 10, /* max_len */ 32);Planned language libraries (PHP first, then JS/Python) will ship the same reader: the fixed byte layout is what makes a dependency-free port possible β plain integer reads, no external dependencies.
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, generate, info, validate, stats β
β βββ .ngram format (portable binary, zero dependencies) β
β βββ Pre-train bundled models (tr_TR, en_US, etc.) β
β β
β Week 5-10: PHP Generation Library (phonycloud/phony-php) β
β βββ Load .ngram 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 .ngram 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, binary .ngram model I/O (gzip via flate2), 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.