# giahuy910/aura-farm-battle architecture

> Architecture diagram of the GitHub repository giahuy910/aura-farm-battle, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/giahuy910/aura-farm-battle
- Repository: https://github.com/giahuy910/aura-farm-battle

## Overview

Aura Farm Battle is a browser game for registering, claiming giftcodes, collecting gacha items, and challenging friends in turn-based matches. Its client separates authenticated pages and account state, REST API access, room/battle interaction, and battle presentation. The README documents a Haskell/Servant backend and MongoDB, but no server source is in the supplied tree; those are shown as external dependencies. Some client-page wiring is unsampled, so those links are marked unverified rather than asserted as inspected.

Main entry points: [`client/components/battle/BattleScreen.tsx`](https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/BattleScreen.tsx) (Battle screen), [`client/app/(authenticated)/gacha/page.tsx`](https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/gacha/page.tsx) (Gacha and history), [`client/contexts/auth/AuthProvider.tsx`](https://github.com/giahuy910/aura-farm-battle/blob/main/client/contexts/auth/AuthProvider.tsx) (Auth provider), [`client/websocket/useRoomSocket.tsx`](https://github.com/giahuy910/aura-farm-battle/blob/main/client/websocket/useRoomSocket.tsx) (Room socket state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pages["Game pages"]
  node_authenticated["Authenticated shell<br/>[layout.tsx]"]
  node_home["Game home<br/>[page.tsx]"]
  node_gacha["Gacha and history<br/>[page.tsx]"]
  node_roomslist["Room listing<br/>[page.tsx]"]
  node_roompage["Room match page<br/>[page.tsx]"]
  node_userpage["User inventory<br/>[page.tsx]"]
end

subgraph group_account["Account state"]
  node_authprovider["Auth provider<br/>[AuthProvider.tsx]"]
  node_authcontext["Auth context<br/>[AuthContext.tsx]"]
  node_login["Login and registration<br/>[LogIn.tsx]"]
  node_settings["Settings and giftcodes<br/>[SettingManager.tsx]"]
end

subgraph group_api["REST access"]
  node_authapi["Authentication API<br/>[auth.ts]"]
  node_giftapi["Giftcode API<br/>[giftcode.ts]"]
  node_gachaapi["Gacha API<br/>[pool.ts]"]
  node_historyapi["Gacha history API<br/>[gachaHistory.ts]"]
  node_roomapi["Room API<br/>[rooms.ts]"]
  node_userapi["User API<br/>[user.ts]"]
end

subgraph group_rooms["Rooms and battle"]
  node_wsstate["Room socket state<br/>[useRoomSocket.tsx]"]
  node_battletypes["Battle protocol types<br/>[battleTypes.ts]"]
end

subgraph group_presentation["Battle presentation"]
  node_battleui["Battle screen<br/>[BattleScreen.tsx]"]
  node_effects["Effect playback<br/>[EffectOverlay.tsx]"]
  node_sprites["Effect sprites<br/>[SpriteEffect.tsx]"]
  node_assets["Battle assets<br/>[battleAssets.ts]"]
  node_rewards["Reward selection<br/>[RewardPannel.tsx]"]
  node_results["Match results<br/>[ResultScreen.tsx]"]
end

node_player(("Player"))
node_backend{{"Game backend"}}
node_database[("MongoDB")]

node_player -->|"uses"| node_authenticated
node_authenticated -.->|"opens"| node_home
node_player -.->|"registers"| node_login
node_login -.->|"authenticates through"| node_authprovider
node_authprovider -->|"calls"| node_authapi
node_authprovider -->|"provides"| node_authcontext
node_player -.->|"claims code"| node_settings
node_settings -.->|"redeems through"| node_giftapi
node_player -->|"opens"| node_gacha
node_gacha -.->|"loads pools"| node_gachaapi
node_gacha -.->|"loads history"| node_historyapi
node_player -.->|"finds matches"| node_roomslist
node_roomslist -.->|"uses"| node_roomapi
node_roompage -.->|"uses"| node_wsstate
node_wsstate -->|"uses types"| node_battletypes
node_wsstate -.->|"exchanges room events"| node_backend
node_roompage -.->|"presents match"| node_battleui
node_battleui -.->|"shows round effects"| node_effects
node_effects -->|"renders"| node_sprites
node_effects -->|"uses"| node_assets
node_battleui -.->|"shows rewards"| node_rewards
node_battleui -.->|"shows outcome"| node_results
node_player -.->|"manages inventory"| node_userpage
node_userpage -.->|"loads account data"| node_userapi
node_backend -.->|"persists game data"| node_database

click node_authenticated "https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/layout.tsx"
click node_home "https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/page.tsx"
click node_gacha "https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/gacha/page.tsx"
click node_roomslist "https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/rooms/page.tsx"
click node_roompage "https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/rooms/%5Bid%5D/page.tsx"
click node_userpage "https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/user/page.tsx"
click node_authprovider "https://github.com/giahuy910/aura-farm-battle/blob/main/client/contexts/auth/AuthProvider.tsx"
click node_authcontext "https://github.com/giahuy910/aura-farm-battle/blob/main/client/contexts/auth/AuthContext.tsx"
click node_login "https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/LogIn.tsx"
click node_settings "https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/SettingManager.tsx"
click node_authapi "https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/auth.ts"
click node_giftapi "https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/giftcode.ts"
click node_gachaapi "https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/pool.ts"
click node_historyapi "https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/gachaHistory.ts"
click node_roomapi "https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/rooms.ts"
click node_userapi "https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/user.ts"
click node_wsstate "https://github.com/giahuy910/aura-farm-battle/blob/main/client/websocket/useRoomSocket.tsx"
click node_battletypes "https://github.com/giahuy910/aura-farm-battle/blob/main/client/websocket/battleTypes.ts"
click node_battleui "https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/BattleScreen.tsx"
click node_effects "https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/EffectOverlay.tsx"
click node_sprites "https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/SpriteEffect.tsx"
click node_assets "https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/battleAssets.ts"
click node_rewards "https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/RewardPannel.tsx"
click node_results "https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/ResultScreen.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_authenticated,node_home,node_gacha,node_roomslist,node_roompage,node_userpage toneBlue
class node_authprovider,node_authcontext,node_login,node_settings,node_database toneAmber
class node_authapi,node_giftapi,node_gachaapi,node_historyapi,node_roomapi,node_userapi toneMint
class node_wsstate,node_battletypes toneRose
class node_battleui,node_effects,node_sprites,node_assets,node_rewards,node_results,node_player,node_backend toneIndigo
```

## Components

### Game pages

- [Authenticated shell](https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/layout.tsx): `client/app/(authenticated)/layout.tsx`
- [Game home](https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/page.tsx): `client/app/(authenticated)/page.tsx`
- [Gacha and history](https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/gacha/page.tsx): `client/app/(authenticated)/gacha/page.tsx`
- [Room listing](https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/rooms/page.tsx): `client/app/(authenticated)/rooms/page.tsx`
- [Room match page](https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/rooms/%5Bid%5D/page.tsx): `client/app/(authenticated)/rooms/[id]/page.tsx`
- [User inventory](https://github.com/giahuy910/aura-farm-battle/blob/main/client/app/(authenticated)/user/page.tsx): `client/app/(authenticated)/user/page.tsx`

### Account state

- [Auth provider](https://github.com/giahuy910/aura-farm-battle/blob/main/client/contexts/auth/AuthProvider.tsx): `client/contexts/auth/AuthProvider.tsx`
- [Auth context](https://github.com/giahuy910/aura-farm-battle/blob/main/client/contexts/auth/AuthContext.tsx): `client/contexts/auth/AuthContext.tsx`
- [Login and registration](https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/LogIn.tsx): `client/components/LogIn.tsx`
- [Settings and giftcodes](https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/SettingManager.tsx): `client/components/SettingManager.tsx`

### REST access

- [Authentication API](https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/auth.ts): `client/api/auth.ts`
- [Giftcode API](https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/giftcode.ts): `client/api/giftcode.ts`
- [Gacha API](https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/pool.ts): `client/api/pool.ts`
- [Gacha history API](https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/gachaHistory.ts): `client/api/gachaHistory.ts`
- [Room API](https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/rooms.ts): `client/api/rooms.ts`
- [User API](https://github.com/giahuy910/aura-farm-battle/blob/main/client/api/user.ts): `client/api/user.ts`

### Rooms and battle

- [Room socket state](https://github.com/giahuy910/aura-farm-battle/blob/main/client/websocket/useRoomSocket.tsx): `client/websocket/useRoomSocket.tsx`
- [Battle protocol types](https://github.com/giahuy910/aura-farm-battle/blob/main/client/websocket/battleTypes.ts): `client/websocket/battleTypes.ts`

### Battle presentation

- [Battle screen](https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/BattleScreen.tsx): `client/components/battle/BattleScreen.tsx`
- [Effect playback](https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/EffectOverlay.tsx): `client/components/battle/EffectOverlay.tsx`
- [Effect sprites](https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/SpriteEffect.tsx): `client/components/battle/SpriteEffect.tsx`
- [Battle assets](https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/battleAssets.ts): `client/components/battle/battleAssets.ts`
- [Reward selection](https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/RewardPannel.tsx): `client/components/battle/RewardPannel.tsx`
- [Match results](https://github.com/giahuy910/aura-farm-battle/blob/main/client/components/battle/ResultScreen.tsx): `client/components/battle/ResultScreen.tsx`

### Other components

- **Player**
- **Game backend**
- **MongoDB**

## Connections

- Player → Authenticated shell: uses (evidence: `README.md`)
- Authenticated shell → Game home: opens
- Player → Login and registration: registers
- Login and registration → Auth provider: authenticates through
- Auth provider → Authentication API: calls (evidence: `client/contexts/auth/AuthProvider.tsx`)
- Auth provider → Auth context: provides (evidence: `client/contexts/auth/AuthProvider.tsx`)
- Player → Settings and giftcodes: claims code
- Settings and giftcodes → Giftcode API: redeems through
- Player → Gacha and history: opens (evidence: `README.md`)
- Gacha and history → Gacha API: loads pools
- Gacha and history → Gacha history API: loads history
- Player → Room listing: finds matches
- Room listing → Room API: uses
- Room match page → Room socket state: uses
- Room socket state → Battle protocol types: uses types (evidence: `client/websocket/useRoomSocket.tsx`)
- Room socket state → Game backend: exchanges room events
- Room match page → Battle screen: presents match
- Battle screen → Effect playback: shows round effects
- Effect playback → Effect sprites: renders (evidence: `client/components/battle/EffectOverlay.tsx`)
- Effect playback → Battle assets: uses (evidence: `client/components/battle/EffectOverlay.tsx`)
- Battle screen → Reward selection: shows rewards
- Battle screen → Match results: shows outcome
- Player → User inventory: manages inventory
- User inventory → User API: loads account data
- Game backend → MongoDB: persists game data
