# Elofun Architectures
[TOC]
## Architecture

## Languages
Server: Typescript + NodeJS
Client: Typescript + ReactJS
Deployment: Docker
## DiscoveryService
Connection: HTTPS
Location: AWS
- Maintain client load balance registry
- Keepalive GameService and update registry
## GameService
General logic
Connection: Websocket
Location: AWS
Modules:
- Auth
- GameProfile
- Shop
- User Notification (Mail box)
- User Activities and analytic
- Leaderboard, Championship
- Game server
Database:
- DB: Store user data
- CacheDb: PubSub, Memorycache
## GameServer
host multiple GameRoom. spawn and manage by GameService
Connection: Websocket
Locations: Local Region(optimize ping)
Life circle:
1. GameService matching => Request create a game room
```
roomId
bundleGameServerSourceCDN
bundleBotSourceCDN
```
2. GameServer download `bundleGameServerSourceCDN` and create new instance
3. Client connect
4. Match start
5. End match => Update result to GameService
6. Kill instance
## Client
ReactJS hosted on CDN
Life circle:
1. Connect DiscoveryService to lookup GameService(version=x)
2. Connect to GameService
3. User request a matching
4. Server response GameServer url + RoomInfo
5. Download `bundleGameClientSourceCDN`
6. Connect to GameServer via ws and play game
## Game
Build base on EloGameSDK. (allow develop game base on Nodejs, CocosCreator)
Webpack bundles source => upload s3
```
gameId
gameVersion
bundleGameServerSourceCDN
bundleGameClientSourceCDN
bundleBotSourceCDN
```
## Trackings
Third party analytic services
## Proposal - Event sourcing approach
User activities store inside DB under Actions and Events
- Actions: User action (openaccount, connect, buyitem, requestmatch, winmatch, losematch....)
- Events: trigger by action (dailyRewardReceived, matchRewardReceived, friendOpenAccountWithRefCode, ....)
**Biz logic building base on action and events**
Example:
- Action connect after x days => send welcomeback gift
- friendOpenAccountWithRefCode 3 times => send friend invited gift
Ref:
- https://martinfowler.com/eaaDev/EventSourcing.html
- https://microservices.io/patterns/data/event-sourcing.html
---

###### tags: `Elofun` `Architecture`