CritterCraft Universe ‐ Codebase Architecture Guide - BigBossBoolingB/CritterCraftUniverse GitHub Wiki

CritterCraft Universe - Codebase Architecture Guide Welcome to CritterCraft Universe! This is a comprehensive architecture overview to help you understand this AI-powered blockchain pet simulation platform. Let me walk you through the key components and how they work together.

🏗️ High-Level Architecture Overview CritterCraft is a multi-layered application that combines:

Frontend: React-based web interface with 3D graphics

Backend: Python-based pet simulation engine with AI integration

Blockchain: Custom Substrate-based blockchain (CritterChain) for NFTs and governance

AI Engine: Personality and behavior systems for digital companions

📁 Project Structure AIPet3/ ├── 📱 Frontend (React/TypeScript) │ ├── src/ │ │ ├── components/ │ │ ├── App.jsx │ │ └── crittercraft_api.js │ └── package.json │ ├── 🐍 Core Pet Engine (Python) │ ├── main.py # Main game loop & CLI interface │ ├── pet_core.py # Core Pet class & logic │ ├── Config.py # Game constants & configuration │ └── pet/ # Additional pet modules │ ├── ⛓️ Blockchain Layer (Substrate) │ ├── BlockChain/ │ │ ├── pallets/ # Modular blockchain components │ │ ├── critter-craft/ # Main blockchain runtime │ │ └── node/ # Blockchain node implementation │ └── 📚 Documentation ├── README.md ├── ARCHITECTURE_PRINCIPLES.md └── Various specification docs 🎯 Core Components Deep Dive

  1. Pet Simulation Engine (pet_core.py) Purpose: The heart of the digital companion system

Key Classes:

Pet: Main pet entity with stats, personality, and behavior

InteractionRecord: Tracks all interactions for AI learning

Core Features:

Vital Stats: Hunger, happiness, energy (0-100 scale)

Personality Traits: AI-driven characteristics that evolve

Time-based Decay: Pets require care or stats decline

Interaction History: Persistent memory of all player actions

Data Flow:

Player Action → Pet.feed()/play() → Update Stats → AI Personality Analysis → Save State 2. Game Loop & Persistence (main.py) Purpose: Main application entry point and user interface

Key Functions:

CLI-based interaction system

Local JSON persistence for pet state

Migration readiness assessment for blockchain

Time-based progression simulation

User Journey:

Start → Load/Create Pet → Main Menu → Actions (Feed/Play/Status) → Save State → Exit 3. Frontend Interface (frontend/) Technology Stack:

React 18 with TypeScript

Vite for build tooling

Three.js for 3D pet visualization

Material UI for components

Polkadot.js for blockchain integration

Key Dependencies:

@polkadot/api: Blockchain connectivity

three: 3D graphics rendering

zustand: State management

react-query: Data fetching

  1. Blockchain Layer (BlockChain/) Architecture: Modular pallet-based design using Substrate framework

Core Pallets:

pallet-critter-nfts: Pet NFT management and ownership

pallet-marketplace: Trading and commerce

pallet-battles: Strategic combat system

pallet-breeding: Genetic breeding mechanics

pallet-items: Equipment and consumables

pallet-quests: Adventure and progression

Key Principles:

Modularity: Each pallet handles specific functionality

Trait-based Interfaces: Clean separation between components

Governance: Community-driven decision making

Security: Rigorous validation and audit processes

🔄 Data Flow & Interactions Pet Lifecycle:

  1. Creation → Generate unique DNA hash → Set base stats
  2. Interaction → Update stats → Record history → AI analysis
  3. Evolution → Personality changes → Blockchain migration readiness
  4. Migration → Export to blockchain as NFT Cross-System Communication: Frontend ↔ API Layer ↔ Pet Engine ↔ Blockchain ↓ ↓ ↓ ↓ UI/UX REST/WebSocket Python Substrate 🧠 AI Integration Strategy Current State: Conceptual framework with placeholder traits

Future Vision:

LangChain integration for natural language processing

Personality evolution based on interaction patterns

AI-generated responses and behaviors

Machine learning for pet behavior prediction

🔧 Technology Stack Summary | Layer | Technologies |

|-------|-------------|

| Frontend | React, TypeScript, Vite, Three.js, Material UI |

| Backend | Python 3.11, Flask/FastAPI, SQLAlchemy |

| Blockchain | Substrate, Polkadot, Rust |

| AI/ML | TensorFlow/PyTorch, LangChain (planned) |

| Infrastructure | Docker, PostgreSQL, Redis, Nginx |

🚀 Getting Started as a Developer

  1. Local Development Setup:

Clone and setup

git clone https://github.com/BigBossBooling/AIPet3.git cd AIPet3

Run Python pet engine

python main.py

Run frontend (separate terminal)

cd frontend npm install npm run start 2. Key Entry Points: Pet Simulation: main.py - Start here for core game logic

Frontend: frontend/src/App.jsx - Main React application

Blockchain: BlockChain/critter-craft/src/main.py - Substrate runtime

  1. Configuration: Game Settings: Config.py - Adjust stats, decay rates, thresholds

Frontend Config: frontend/package.json - Dependencies and scripts

Blockchain Config: Various Cargo.toml files in pallet directories

🎨 Design Philosophy The codebase follows "The Architect's" KISS Principles:

Keep it Clear: Modular, well-separated concerns

Iterate Intelligently: MVP-first approach with planned complexity

Secure the Solution: Security-first blockchain design

Stimulate Engagement: Focus on meaningful player interactions

🔮 Future Architecture Evolution Planned Enhancements:

AI Personality Engine: Advanced behavioral modeling

Cross-chain Interoperability: Multi-blockchain support

Advanced Breeding: Complex genetic algorithms

Social Features: Multi-player interactions

Mobile Apps: Native iOS/Android applications

This architecture provides a solid foundation for building a sophisticated, engaging, and technically robust digital companion platform. The modular design allows for incremental development while maintaining system integrity and user experience quality.

Happy coding! 🚀