Skip to content

Game data#73

Draft
jmtth wants to merge 9 commits intocodastream:mainfrom
jmtth:game-data
Draft

Game data#73
jmtth wants to merge 9 commits intocodastream:mainfrom
jmtth:game-data

Conversation

@jmtth
Copy link
Collaborator

@jmtth jmtth commented Feb 13, 2026

PR Draft sur la gestion des donnees du Game

Je fais une PR Draft pour vous tenir au courant de l'avancee de la base de donnee du Game

Important

Cette PR concerne :

  • lien frontend backend (creation des routes , controller et requetes sql)

Schema de la base dans game-service

rappel nous sommes en design pattern Database per service + Data replication

erDiagram

    TOURNAMENT {
        INTEGER id PK
        INTEGER creator_id
        TEXT status
        INTEGER created_at
    }

    MATCH {
        INTEGER id PK
        INTEGER tournament_id
        INTEGER player1
        INTEGER player2
        INTEGER score_player1
        INTEGER score_player2
        INTEGER winner_id
        TEXT round
        INTEGER created_at
    }

    TOURNAMENT_PLAYER {
        INTEGER tournament_id PK
        INTEGER player_id PK
        INTEGER final_position
    }
    
    PLAYER {
        INTEGER id PK
        TEXT username
        INTEGER updated_at
    }

 
    TOURNAMENT ||--o{ MATCH : contains
    TOURNAMENT ||--o{ TOURNAMENT_PLAYER : has_players
    TOURNAMENT }o--|| PLAYER : is
    MATCH }o--|| PLAYER : is
    TOURNAMENT_PLAYER }o--|| PLAYER : is 

Loading

Navigation dans le Tournoi

flowchart TD

%% Entry
A[Home / TournamentMenuPage.tsx]

A -->|Participate| B[TournamentsListPage.tsx]
A -->|Create| C[TournamentCreatePage.tsx]

C -->|POST /game/create-tournament| D[(Create tournament in DB)]
D -->|return tournamentId| E[TournamentPage.tsx]

B -->|Join| E

%% Tournament structure
E --> F{4 players ready?}

F -->|Yes| SF1[Semi-Final 1]
F -->|Yes| SF2[Semi-Final 2]

%% Semi Final 1
SF1 --> G1{Both players Start?}
G1 -->|Yes| M1[Play Match 1]
M1 -->|Save score in game.db| R1[Determine Winner/Loser 1]

%% Semi Final 2
SF2 --> G2{Both players Start?}
G2 -->|Yes| M2[Play Match 2]
M2 -->|Save score in game.db| R2[Determine Winner/Loser 2]

%% Propagation
R1 -->|Winner → Final P1| FP1[Final Slot P1]
R1 -->|Loser → Small Final P1| SP1[Small Final Slot P1]

R2 -->|Winner → Final P2| FP2[Final Slot P2]
R2 -->|Loser → Small Final P2| SP2[Small Final Slot P2]

%% Final
FP1 --> FINAL{Both players Start?}
FP2 --> FINAL

FINAL -->|Yes| FM[Play Final]
FM -->|Save score in game.db| FW[Determine Champion]

%% Small Final
SP1 --> SMALL{Both players Start?}
SP2 --> SMALL

SMALL -->|Yes| SM[Play Small Final]
SM -->|Save score in game.db| SW[Determine 3rd place]

%% Tournament completion
FW --> UPDATE[Update Tournament_player positions]
SW --> UPDATE

UPDATE --> END[Tournament Completed]

Loading

Services Game

Ajout du plugin custom Authplugin

  • permet de récupérer les informations du user

Ajout du plugin ioredis

permet decouplage des services et de ne pas faire une requette http pour avoir le username de chaque user

  • permet de récupérer le username et de mettre à jour la table player.
  • ajout d'un message dans le stream user-events dans le service user au moment de la création du profile.
await req.server.redis.xadd(
      'user.events',
      '*',
      'data',
      JSON.stringify({
        type: UserEventType.CREATED,
        id: profile.id,
        username: profile.username,
        timestamp: Date.now(),
      }),
    );
  • ajout d'un consumer dans le service game
await redis.xgroup('CREATE', STREAM, GROUP, '0', 'MKSTREAM');
const streams = await redis.xreadgroup(
        'GROUP',
        GROUP,
        CONSUMER,
        'BLOCK',
        5000,
        'COUNT',
        1,
        'STREAMS',
        STREAM,
        '>',
      );
const [[, messages]] = streams;
      for (const [id, fields] of messages) {
        await processMessage(app, redis, id, fields);
      }
  • il faut penser à ajouter ce consumer au hook Onready de Fastify.
fastify.addHook('onReady', async () => {
  startGameConsumer(fastify);
});

Modifications de certains composants

  • Input : ajout toggle button pour afficher masquer le password.

Routes Front(React) - Back(Fastify) du tournoi

info Front Back base de donnees
menu du tournoi /tournaments
liste des tournois /tournaments/list GET api/game/tournaments listTournament()
création d'un tournoi /tournaments/create POST api/game/create-tournament CreateTrounement()
un tournoi en particulier /tournaments/:id

Caution

Changement route dans Game

  • /:sessionId -> /ws/:sessionId

BREAKING_CHANGES: add three table in game.db match, tournament,
tournament_player
add request for adding and udating database
next: add route and controller to interact with database

package-lock.json
srcs/.env.game.example
srcs/game/package.json
srcs/game/src/controllers/game.controller.ts
srcs/game/src/core/game.database.ts
srcs/game/src/routes/game.routes.ts
srcs/game/src/types/game.dto.ts
newTournament: create a Tournament and send his id to the frontend
FastifyJWT: new interface for prehandler request
update(front): fakeCreateTournament -> CreatingTournament
Input: addc toggle button to sho/hide the password

package-lock.json
srcs/.env.game.example
srcs/game/package.json
srcs/game/src/controllers/game.controller.ts
srcs/game/src/core/game.database.ts
srcs/game/src/pulgins/auth.plugin.ts
srcs/game/src/routes/game.routes.ts
srcs/game/src/server.ts
srcs/game/src/types/fastify.d.ts
srcs/nginx/src/components/atoms/Input.tsx
srcs/nginx/src/pages/TournamentCreatePage.tsx
feat(game-database): add new table player to have username
add sql request for listing tournaments

srcs/game/src/controllers/game.controller.ts
srcs/game/src/core/game.database.ts
srcs/users/src/app.ts
srcs/users/src/config/env.ts
srcs/users/src/plugins/ioredis.plugins.ts
jhervoch and others added 6 commits February 17, 2026 16:06


add to type in user.schema.ts
feat(game-redis): add ioredis plugins, consumer
fastify hook onReady StartGameConsumer
feat(game-db): add sql request for upsert user and deleted
feat(user-redis): add data to stream user.events in controller
feat(game): add envalid to config env

package-lock.json
srcs/docker-compose.yml
srcs/game/package.json
srcs/game/src/config/env.ts
srcs/game/src/core/game.consumer.ts
srcs/game/src/core/game.database.ts
srcs/game/src/plugins/auth.plugin.ts
srcs/game/src/plugins/ioredis.plugin.ts
srcs/game/src/server.ts
srcs/game/src/types/fastify.d.ts
srcs/game/tsconfig.json
srcs/shared/core/src/index.ts
srcs/shared/core/src/schemas/user.schema.ts
srcs/users/src/app.ts
srcs/users/src/controllers/profiles.controller.ts
srcs/users/src/types/fastify.d.ts
srcs/users/tsconfig.json
feat(game-tournament): add Tournament List page
add sql request for list tournament
fix(game): root route :sessionId intercept all get routes
change to ws/:sessionId

package-lock.json
srcs/game/src/controllers/game.controller.ts
srcs/game/src/core/game.database.ts
srcs/game/src/routes/game.routes.ts
srcs/gateway/src/controllers/game.controller.ts
srcs/nginx/src/pages/TournamentsListPage.tsx
srcs/shared/core/src/index.ts
srcs/shared/core/src/schemas/game.schema.ts
feat(user-events): add event bus insteaed of calling redis.xadd directly
in controller
fix(gane-data): add player(creator) when creating a tournament

package-lock.json
srcs/game/src/core/game.consumer.ts
srcs/game/src/core/game.database.ts
srcs/shared/core/src/index.ts
srcs/shared/core/src/schemas/user.schema.ts
srcs/users/src/app.ts
srcs/users/src/controllers/profiles.controller.ts
srcs/users/src/events/redis.subscriber.ts
srcs/users/src/events/user.bus.ts
srcs/users/test/profiles.controller.test.ts
srcs/users/vite.config.mjs
srcs/users/src/plugins/ioredis.plugins.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments