This guide will help you start up the project and test the relationship features I just implemented.
Before starting, ensure you have:
- ✅ Node.js >= 18.0.0
- ✅ MongoDB running (local or Docker)
- ✅ Git repository cloned
# In the root directory
cd C:\Drip\muse-fullstack-dapp
# Install all dependencies
npm install
# Install backend dependencies
cd apps\backend
npm installOption A: Using Docker (Recommended)
# Start MongoDB in Docker
docker run -d -p 27017:27017 --name muse-mongo mongo:6
# Verify it's running
docker psOption B: Check if MongoDB is already running
# Check if MongoDB process is running
Get-Process | Where-Object {$_.Name -like "*mongo*"}
# Or try to connect
mongosh --eval "db.version()"Option C: Install MongoDB locally
- Download from: https://www.mongodb.com/try/download/community
- Install and start the MongoDB service
# In backend directory
cd C:\Drip\muse-fullstack-dapp\apps\backend
# Create .env file for development
@"
# Server
PORT=3001
NODE_ENV=development
# Database
MONGODB_URI=mongodb://localhost:27017/muse
# Authentication (use any 32+ char string for testing)
JWT_SECRET=test_secret_key_for_development_min_32_chars_12345
# Blockchain (optional for testing relationships)
STELLAR_NETWORK=testnet
STELLAR_RPC_URL=https://soroban-testnet.stellar.org
# AI Services (optional for testing relationships)
OPENAI_API_KEY=sk-test
STABILITY_API_KEY=sk-test
"@ | Out-File -FilePath .env -Encoding utf8
# Create .env.test file for testing
@"
# Test Database
MONGODB_URI_TEST=mongodb://localhost:27017/muse-test
# Test Settings
NODE_ENV=test
PORT=5001
JWT_SECRET=test_secret_key_for_testing_min_32_chars_12345
"@ | Out-File -FilePath .env.test -Encoding utf8Just check for TypeScript/syntax errors:
cd C:\Drip\muse-fullstack-dapp\apps\backend
# Check for compilation errors
npm run buildIf this succeeds with no errors, the code is valid! ✨
Run the comprehensive test suite I created:
cd C:\Drip\muse-fullstack-dapp\apps\backend
# Run all tests including the new relationship tests
npm test
# Or run only the relationship tests
npm test -- relationships.test.tsExpected output:
PASS src/tests/relationships.test.ts
Relationship Helpers
Virtual Relationships
✓ should populate user created artworks (XX ms)
toggleLike
✓ should add like when not exists (XX ms)
✓ should remove like when exists (XX ms)
toggleFavorite
✓ should add favorite and update user stats (XX ms)
✓ should remove favorite and update user stats (XX ms)
toggleFollow
✓ should create follow relationship and update stats (XX ms)
✓ should remove follow relationship and update stats (XX ms)
Artwork Cascade Delete
✓ should delete all related data when artwork is deleted (XX ms)
Query Helpers
✓ should get user created artworks with pagination (XX ms)
✓ should get artwork with all relationships (XX ms)
Relationship Status Checks
✓ should check if user liked artwork (XX ms)
✓ should check if user is following another user (XX ms)
Test Suites: 1 passed, 1 total
Tests: 12 passed, 12 total
This validates existing data and updates statistics:
cd C:\Drip\muse-fullstack-dapp\apps\backend
# Run the migration
npm run migrateExpected output:
Starting relationship support migration...
Validating artwork references in transactions...
Found 0 transactions with invalid artwork references
Validating artwork references in bids...
Found 0 bids with invalid artwork references
...
Relationship support migration completed successfully!
# Terminal 1 - Start Backend
cd C:\Drip\muse-fullstack-dapp\apps\backend
npm run dev
# You should see:
# Server is running on port 3001
# Connected to MongoDB
# Environment: developmentTest the API manually:
# In a new terminal, test the health endpoint
curl http://localhost:3001/health
# Or in PowerShell:
Invoke-WebRequest -Uri http://localhost:3001/health# Check User model has virtual relationships
Select-String -Path "apps\backend\src\models\User.ts" -Pattern "virtual\("
# Check Artwork model has cascade delete
Select-String -Path "apps\backend\src\models\Artwork.ts" -Pattern "pre\('deleteOne'"
# Check relationship helpers exist
Test-Path "apps\backend\src\utils\relationshipHelpers.ts"
# Check migration exists
Test-Path "apps\backend\src\migrations\003_add_relationship_support.ts"# Open files to review changes
code apps\backend\src\models\User.ts
code apps\backend\src\models\Artwork.ts
code apps\backend\src\utils\relationshipHelpers.ts
code apps\backend\src\migrations\003_add_relationship_support.ts- User.ts - Added 13 virtual relationships
- Artwork.ts - Added 6 virtual relationships + cascade delete
- Transaction.ts - Enabled virtual serialization
- Bid.ts - Enabled virtual serialization
- Collection.ts - Enabled virtual serialization
- Like.ts - Enabled virtual serialization
- Favorite.ts - Enabled virtual serialization
- Follow.ts - Enabled virtual serialization
- Notification.ts - Enabled virtual serialization
- relationshipHelpers.ts - NEW: 20+ helper functions
- 003_add_relationship_support.ts - NEW: Migration script
- relationships.test.ts - NEW: Comprehensive test suite
- ✓ Virtual relationships (populate)
- ✓ Toggle like (add/remove)
- ✓ Toggle favorite (add/remove with stats)
- ✓ Toggle follow (add/remove with stats)
- ✓ Cascade delete (cleanup related data)
- ✓ Query helpers (pagination, filtering)
- ✓ Status checks (hasLiked, isFollowing)
- ✓ Activity feeds
Run through this checklist to fully verify:
- TypeScript Compilation:
npm run buildsucceeds - No Syntax Errors: Code compiles without errors
- MongoDB Connection: Can connect to MongoDB
- Unit Tests Pass: All 12 tests pass
- Migration Runs: Migration completes successfully
- Server Starts: Backend starts without errors
- API Responds: Health check endpoint works
Error: connect ECONNREFUSED ::1:27017
Solution: Make sure MongoDB is running
# Check if MongoDB is running
docker ps | Select-String mongo
# Or start it
docker start muse-mongoMongoServerError: Authentication failed
Solution: Use connection string without auth for local testing
MONGODB_URI_TEST=mongodb://localhost:27017/muse-testCannot find module '../utils/relationshipHelpers'
Solution: Rebuild the project
npm run buildError: listen EADDRINUSE: address already in use :::3001
Solution: Kill the process using that port
# Find process on port 3001
Get-NetTCPConnection -LocalPort 3001 | Select-Object -Property OwningProcess
# Kill it (replace XXXX with process ID)
Stop-Process -Id XXXX -ForceAfter verifying everything works:
- Review the documentation: Check ISSUE_49_RESOLUTION.md
- Explore the API: Import relationship helpers in controllers
- Test in real app: Try the features in the frontend
- Run full test suite:
npm testto ensure nothing broke
You've successfully tested the implementation if:
- ✅ All TypeScript files compile without errors
- ✅ All unit tests pass (12/12)
- ✅ Migration runs successfully
- ✅ Backend starts and connects to MongoDB
- ✅ No console errors or warnings
Don't want to set up MongoDB? Just run this:
cd C:\Drip\muse-fullstack-dapp\apps\backend
npm run buildIf you see:
Successfully compiled TypeScript
Then the implementation is syntactically correct and ready to use! 🎊
Questions? Check the main documentation in ISSUE_49_RESOLUTION.md