NES-Style Game Console with AI-Powered Game Generation
flowchart TB
subgraph Client["🎮 Client Layer"]
UI["UI Components
(Panels, Controls)"]
Engine["X9000Engine
(Main Controller)"]
Canvas["Game Canvas
(256x256 NES Screen)"]
end
subgraph Core["⚙️ Core Systems"]
GameLib["GameLibrary
(Local Storage)"]
Sound["SoundEngine
(MML Audio)"]
Debug["DebugUI
(Developer Tools)"]
Sharing["SharingManager
(Cloud Sync)"]
end
subgraph External["🌐 External Services"]
Pollinations["Pollinations AI"]
Grok["Grok API"]
OpenRouter["OpenRouter API"]
BerrryAPI["berrry.app API"]
end
UI --> Engine
Engine --> Canvas
Engine --> GameLib
Engine --> Sound
Engine --> Debug
Engine --> Sharing
Sharing --> BerrryAPI
Engine -.->|"Generate Games"| Pollinations
Engine -.->|"Generate Games"| Grok
Engine -.->|"Generate Games"| OpenRouter
flowchart LR
subgraph Storage["💾 Storage Layer"]
LS["localStorage"]
Cloud["berrry.app API"]
end
subgraph Data["📦 Data Structures"]
GameIDs["Game IDs List
x9000-game-ids"]
Games["Individual Games
x9000-game-{id}"]
SharedIDs["Shared Game IDs
x9000-shared-game-ids"]
Settings["User Settings"]
end
subgraph CloudData["☁️ Cloud Data"]
SharedGames["Public Games
/api/data/game-{id}"]
Scores["Leaderboards
/api/data/score-{userId}-{gameId}"]
end
LS --> GameIDs
LS --> Games
LS --> SharedIDs
LS --> Settings
Cloud --> SharedGames
Cloud --> Scores
Games -.->|"Share"| SharedGames
SharedGames -.->|"Play"| Scores
x9000-game-ids → Array of game IDs (ordered, newest first)x9000-game-{id} → Individual game object with code, prompt, versionsx9000-shared-game-ids → Array of IDs for games user has sharedx9000-highscore → Local high scorex9000-settings → Prompt template, max tokens, etc.
sequenceDiagram
participant User
participant Engine as X9000Engine
participant API as AI API
participant Parser as Code Parser
participant Runtime as Game Runtime
User->>Engine: Enter prompt + click Generate
Engine->>Engine: Build prompt with template
Engine->>API: Stream request (SSE)
loop Streaming Response
API-->>Engine: Code chunks
Engine-->>User: Show progress
end
Engine->>Parser: Parse generated code
Parser->>Parser: new Function(code)
Parser-->>Engine: GAME object
Engine->>Runtime: loadGame(GAME, code)
Runtime->>Runtime: Build tileset atlas
Runtime->>Runtime: Initialize game state
Runtime-->>User: Game starts playing
Engine->>Engine: Save to GameLibrary
flowchart TB
subgraph Input["🎮 Input Processing"]
KB["Keyboard"]
Touch["Touch Controls"]
GP["Gamepad"]
end
subgraph Update["🔄 Game Loop (60fps)"]
GetInput["Read Input State"]
RunUpdate["Run game.update()"]
GetGraphics["Get Graphics State (G)"]
end
subgraph Render["🖼️ Render Layers"]
Clear["Clear Canvas
(Background Color)"]
Tiles["Render Tile Layers
(Scrolling Backgrounds)"]
Sprites["Render Sprites
(Dynamic Objects)"]
Text["Render Text Layer
(ASCII Overlay)"]
UI["Render UI
(Game Over, Score)"]
end
KB --> GetInput
Touch --> GetInput
GP --> GetInput
GetInput --> RunUpdate
RunUpdate --> GetGraphics
GetGraphics --> Clear
Clear --> Tiles
Tiles --> Sprites
Sprites --> Text
Text --> UI
flowchart BT
subgraph Modules["📁 JavaScript Modules"]
SampleGame["sample-game.js
Game templates & factory"]
EngineCore["engine.js
Constants & palette"]
Sound["sound.js
Audio synthesis"]
Debug["debug.js
Developer tools"]
App["app.js
Main application"]
end
subgraph Exports["🔗 Window Exports"]
WSample["X9000SampleGame"]
WEngine["X9000Engine"]
WSound["X9000Sound"]
WDebug["X9000Debug"]
end
SampleGame --> WSample
EngineCore --> WEngine
Sound --> WSound
Debug --> WDebug
WSample --> App
WEngine --> App
WSound --> App
WDebug --> App
sample-game.js → Exports SAMPLE_GAME_CODE, FLAPPY_BIRD, JUMPERengine.js → Exports SCREEN_SIZE (256), NES_PALETTEsound.js → Exports SoundEngine classdebug.js → Exports DebugUI classapp.js → Main entry point, creates X9000Engine instance/api/auth/* → User authentication/api/data/* → Private data storage/api/public-data/* → Public game discovery
sequenceDiagram
participant A as User A (Author)
participant API as berrry.app API
participant B as User B (Player)
Note over A: Creates game locally
A->>API: POST /api/data/game-{id}?visibility=public
API-->>A: Share URL generated
A->>B: Shares URL: ?play={userId}/{gameId}
B->>API: GET /api/public-data/{userId}/game-{gameId}
API-->>B: Game code + metadata
B->>B: Plays game locally
Note over B: Achieves high score
B->>API: POST /api/data/score-{userId}-{gameId}
API-->>B: Score saved
B->>API: GET /api/public-data/users/score-{userId}-{gameId}
API-->>B: Global leaderboard