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.