How sabarishr-dev/arena works
Purpose and Runtime
Arena is a browser-based office gaming platform: users authenticate, discover games, launch Unity WebGL or HTML builds, and participate in progress/leaderboard-oriented play. It is a Next.js application using both App Router UI/API routes and legacy Pages Router API routes. Root composition begins at app/layout.tsx and the landing route is app/page.tsx.
Identity and Session Boundary
Authentication is handled by NextAuth with Azure Entra ID/OpenID, exposed through the Pages Router catch-all auth endpoint at pages/api/auth/[...nextauth].ts. Client session access is provided by components/auth/SessionProvider.tsx; sign-in UI is in components/auth/SignIn.tsx. This boundary supplies user identity to profile, gameplay, and platform-service actions.
Game Catalog and Local Persistence
The catalog is backed by a local SQLite database (data/games.db at runtime), initialized by scripts/init-db.ts and accessed through lib/db.ts. It stores game metadata, categories, and build type (unity or html). Catalog CRUD/read flows are exposed through App Router endpoints:
• app/api/arena/games/route.ts
• app/api/arena/games/[id]/route.ts
• app/api/profile/my-games/route.ts
Player-Facing Navigation
The principal user journeys are catalog discovery, game detail, game launch, dashboard/profile, and leaderboard views. The Arena routes are app/arena/page.tsx, app/arena/[id]/page.tsx, and app/arena/play-game/page.tsx; account-oriented views are app/dashboard/page.tsx, app/profile/page.tsx, and app/leaderboard/page.tsx. components/sidebar/SideBar.tsx provides shared application navigation.
Game Launch and Rendering
components/game/GameLoader.tsx is the game-type dispatch boundary. Unity builds are embedded through components/unity/game-view.tsx, while non-Unity/browser content is rendered through components/html/html-game-view.tsx. Unity WebGL is the gameplay runtime; Photon Fusion 2 supplies multiplayer behavior within Unity builds rather than as a visible Next.js server subsystem.
Gameplay Session and Time Validation
Play duration and session state are held client-side through context/PlayTimeContext.tsx and components/timer/PlayTimer.tsx; Unity-specific session coordination is in context/UnitySessionContext.tsx. The client validates playtime through app/api/playtime/validate/route.ts, creating a server boundary for accepting or rejecting duration-related actions.
External Platform Services and Rewards
PlayFab integration is centralized in lib/playfab/playfab.ts and supports player progress, achievements, leaderboards, and virtual currency. Coupon/reward delivery crosses into email via app/api/send-coupon-mail/route.ts; redemption UI is at app/coupon/redeem/page.tsx. Ticket-related logic resides in lib/ticket/ticket.ts, likely supporting reward or access workflows.
Publishing Flow
Contributors use app/contribute/page.tsx and app/contribute/publish/page.tsx to supply game content. File/folder selection components (components/publish/File.tsx, components/publish/Folder.tsx) feed the legacy upload/publish endpoint pages/api/publish.ts. Published metadata then enters the SQLite-backed catalog, from which Arena discovery and launch routes consume it.
Main entry points: arena/page.tsx Arena catalog & detail · play-game/page.tsx Game launch route · GameLoader.tsx Game loader · PlayTimeContext.tsx Playtime & Unity session
Components 20
Next.js web app
App Router views and API routes.
- Root layout
app/layout.tsx - Landing page
app/page.tsx - Shared sidebar
components/sidebar/SideBar.tsx - Arena catalog & detail · Discovery and game-detail views.
app/arena/page.tsx - Dashboard, profile & leaderboard · Account-oriented player views.
app/dashboard/page.tsx
Gameplay runtime
Client-side launch and session handling.
- Game launch route
app/arena/play-game/page.tsx - Game loader · Selects Unity or HTML rendering by game type.
components/game/GameLoader.tsx - Unity WebGL view · Unity builds use Photon Fusion 2 for multiplayer.
components/unity/game-view.tsx - HTML game view
components/html/html-game-view.tsx - Playtime & Unity session · Tracks duration and Unity-specific session state.
context/PlayTimeContext.tsx - Playtime validation · Accepts or rejects duration-related actions.
app/api/playtime/validate/route.ts
Platform services
Identity, catalog, progress, and rewards.
- NextAuth Entra endpoint
pages/api/auth/[...nextauth].ts - Session provider
components/auth/SessionProvider.tsx - Catalog APIs · Games and player-game catalog access.
app/api/arena/games/route.ts - Games SQLite database · Runtime database at data/games.db.
- Database access
lib/db.ts - PlayFab · Progress, achievements, leaderboards, and currency.
lib/playfab/playfab.ts - Coupon rewards · Redemption UI and coupon email delivery.
app/coupon/redeem/page.tsx
Publishing
Contributor upload flow.
- Contributor publishing UI · Game contribution and publish workflow.
app/contribute/publish/page.tsx - Legacy publish endpoint · Receives selected game files and metadata.
pages/api/publish.ts
Connections 20
- Root layout → Landing page: composes
- Root layout → Session provider: provides session
- Shared sidebar → Arena catalog & detail: navigates
- Shared sidebar → Dashboard, profile & leaderboard: navigates
- Session provider → NextAuth Entra endpoint: authenticates via
- Session provider → Dashboard, profile & leaderboard: supplies identity
- Arena catalog & detail → Catalog APIs: reads catalog
- Catalog APIs → Database access: uses
- Database access → Games SQLite database: reads and writes
- Arena catalog & detail → Game launch route: launches game
- Game launch route → Game loader: renders through
- Game loader → Unity WebGL view: Unity build
- Game loader → HTML game view: HTML build
- Game launch route → Playtime & Unity session: tracks session
- Playtime & Unity session → Playtime validation: validates duration
- Dashboard, profile & leaderboard → PlayFab: loads progress and rankings
- Playtime & Unity session → PlayFab: updates gameplay progress
- PlayFab → Coupon rewards: drives rewards
- Contributor publishing UI → Legacy publish endpoint: uploads content
- Legacy publish endpoint → Database access: publishes metadata