LevelUP Coder is a gamified coding education platform that transforms programming practice into an engaging RPG experience. The system combines real-time coding tracking, achievement systems, and interactive challenges with immersive 2D pixel art aesthetics.
- Framework: FastAPI (Python 3.13+)
- Database: SQLite with SQLAlchemy ORM
- Authentication: JWT-based authentication
- WebSocket: Real-time communication for live updates
- API Documentation: Auto-generated OpenAPI/Swagger
- Framework: React 19 with Vite
- State Management: Zustand
- Routing: React Router v6
- Styling: Tailwind CSS with custom pixel art components
- 3D Graphics: Three.js with React Three Fiber
- Animations: GSAP and Framer Motion
- Internationalization: i18next (KO, EN, JA, ZH)
- Real-time: Socket.io client
Flow: User Registration → JWT Token Generation → Protected Routes
- User Model: Stores credentials and basic info
- JWT Tokens: 24-hour expiration with HS256 algorithm
- Password Security: Bcrypt hashing
- Session Management: Token refresh on activity
- Base XP Calculation: 1 XP per line of code
- Multipliers: Language-specific bonuses
- Level Progression: Exponential curve (level^2 * 100)
- Coins: Earned through coding and quests
- Gems: Premium currency for special items
- Exchange Rate: 100 coins = 1 gem
WebSocket Architecture:
Client → WS Connection → ConnectionManager → Event Handlers
- Connection Management: User-specific channels
- Event Types:
coding_update: Track real-time coding progressxp_update: Notify XP gainsachievement_unlocked: Instant achievement notificationsbattle_update: Dungeon battle state changes
users
├── id (PK)
├── username (unique)
├── email (unique)
├── hashed_password
└── created_at
user_profiles
├── id (PK)
├── user_id (FK → users)
├── level
├── experience
├── coins
├── gems
├── coding_streak
├── avatar_data (JSON)
└── statistics (JSON)
coding_sessions
├── id (PK)
├── user_id (FK → users)
├── start_time
├── end_time
├── lines_written
├── xp_earned
└── project_namedungeons
├── id (PK)
├── name
├── difficulty
├── required_level
├── enemies (JSON)
└── rewards (JSON)
challenges
├── id (PK)
├── type (CTF, BUG_BOUNTY, SYSTEM_DESIGN)
├── difficulty
├── xp_reward
├── coin_reward
└── solution_hash
quests
├── id (PK)
├── type (DAILY, WEEKLY)
├── requirements (JSON)
├── rewards (JSON)
└── expiry_dateEntry → Authentication → Dashboard → Game Modes → Progress Tracking
-
Registration/Login
- Form validation
- API authentication
- Token storage
- Profile initialization
-
Dashboard Access
- Load user profile
- Fetch active quests
- Display statistics
- Initialize WebSocket
-
Game Mode Selection
- Coding Mode: Real-time XP tracking
- Dungeons: Turn-based battles
- Challenges: CTF, Bug Bounty, System Design
- Quests: Daily/Weekly objectives
Start Session → Track Activity → Calculate XP → Update Profile → End Session-
Session Initialization
POST /api/game/coding/start → Create session record → Return session_id
-
Real-time Tracking
WebSocket: coding_update event → Lines of code counter → Character tracking → File modification count
-
Session Completion
POST /api/game/coding/end → Calculate total XP → Update user level → Check achievements → Return rewards
Select Dungeon → Initialize Battle → Turn-based Combat → Victory/Defeat → Rewards
-
Battle Initialization
- Load enemy data
- Set player stats
- Initialize turn order
-
Combat Loop
while not battle_ended: player_action = await get_player_action() execute_action(player_action) enemy_action = calculate_enemy_action() execute_action(enemy_action) check_battle_status()
-
Damage Calculation
damage = base_damage * type_multiplier * critical_modifier # Type advantages: Fire > Grass > Water > Fire
POST /api/auth/register - User registration
POST /api/auth/login - User login
GET /api/auth/me - Current user info
POST /api/auth/refresh - Token refresh
GET /api/game/profile - User game profile
POST /api/game/coding/start - Start coding session
POST /api/game/coding/end - End coding session
GET /api/game/dungeons - Available dungeons
POST /api/game/dungeons/battle - Dungeon battle action
GET /api/game/challenges - Available challenges
POST /api/game/challenges/submit - Submit challenge solution
GET /api/game/quests - Active quests
POST /api/game/quests/complete - Complete quest
GET /api/game/shop - Shop inventory
POST /api/game/shop/purchase - Purchase item
GET /api/game/inventory - User inventory
POST /api/game/inventory/equip - Equip/unequip item
GET /api/game/leaderboard - Global rankings
App
├── AuthProvider (Context)
│ └── Router
│ ├── Public Routes
│ │ ├── Login
│ │ └── Register
│ └── Protected Routes
│ └── PixelLayout
│ ├── Header (Stats Bar)
│ ├── Navigation
│ └── Page Components
│ ├── Dashboard
│ ├── CodingMode
│ ├── Dungeons
│ ├── Challenges
│ ├── Quests
│ ├── Shop
│ ├── Inventory
│ ├── Leaderboard
│ └── Profile
// Zustand Store Structure
gameStore
├── user
│ ├── profile
│ ├── stats
│ └── preferences
├── session
│ ├── currentSession
│ ├── sessionHistory
│ └── realTimeStats
├── game
│ ├── dungeons
│ ├── challenges
│ ├── quests
│ └── inventory
└── ui
├── notifications
├── modals
└── loading-
Pixel Art Components
// Consistent pixel art styling const PixelButton = ({ children, onClick }) => ( <button className="pixel-button" onClick={onClick}> {children} </button> );
-
Real-time Updates
useEffect(() => { const ws = new WebSocket(WS_URL); ws.onmessage = (event) => { const data = JSON.parse(event.data); updateGameState(data); }; return () => ws.close(); }, []);
-
Lazy Loading
const Dungeons = lazy(() => import('./pages/Dungeons'));
- Database Indexing: Indexed columns for frequent queries
- Connection Pooling: SQLAlchemy connection pool
- Async Operations: FastAPI async endpoints
- Caching: In-memory caching for static game data
- Code Splitting: Route-based lazy loading
- Memoization: React.memo for expensive components
- Virtual Scrolling: For leaderboard and inventory lists
- Asset Optimization: Compressed images and lazy loading
- JWT Token Security: Short expiration, secure storage
- Password Policy: Minimum 8 characters, bcrypt hashing
- Rate Limiting: API endpoint throttling
- CORS Configuration: Whitelisted origins only
- Input Sanitization: Pydantic models for request validation
- SQL Injection Prevention: SQLAlchemy ORM parameterized queries
- XSS Protection: React's automatic escaping
Backend: http://localhost:8000
Frontend: http://localhost:5176
Database: SQLite (local file)
Backend: HTTPS with SSL certificate
Frontend: CDN deployment (Vercel/Netlify)
Database: PostgreSQL with replication
Cache: Redis for session management
Monitor: Logging and error tracking
- User Engagement: Daily active users, session duration
- Game Metrics: XP earned, levels gained, items purchased
- Performance: API response times, error rates
- System Health: CPU usage, memory consumption, database queries
try:
# Game logic
except GameException as e:
log_error(e)
return error_response(e.message)
except Exception as e:
log_critical(e)
return generic_error_response()API Gateway
├── Auth Service
├── Game Service
├── Battle Service
├── Achievement Service
└── Analytics Service
- User data sharding by user_id
- Game content replication
- Read replicas for leaderboards
- WebSocket server clustering
- Redis pub/sub for inter-server communication
- Load balancing with sticky sessions
# Backend
cd backend
pip install -r requirements.txt
python -m app.main
# Frontend
cd frontend
npm install
npm run dev- Unit Tests: Individual function testing
- Integration Tests: API endpoint testing
- E2E Tests: User journey testing
- Performance Tests: Load testing with multiple users
Pipeline:
- Lint & Format
- Run Tests
- Build Application
- Deploy to Staging
- Run E2E Tests
- Deploy to ProductionLevelUP Coder demonstrates a robust architecture combining modern web technologies with gamification principles. The system's modular design allows for easy feature additions and scaling while maintaining code quality and performance standards.