rps-royale/docs/ARCHITECTURE.md
Ubuntu 1224ea28a6
Some checks are pending
Deploy to VPS / deploy (push) Waiting to run
feat: integrate blockchain commit-reveal + on-chain match creation
- Update RPSArena.sol: move bet payment to commit() instead of createMatch()
- Fix Hardhat tests to match new contract API (7/7 passing)
- Deploy updated contract to local Hardhat node (0xe7f1725...)
- Add blockchain service (server) listening to contract events
- Create matches on-chain from server matchmaking handler
- Frontend calls contract directly for commit/reveal via MetaMask
- Add Prisma DB persistence for match results and player stats
- Copy ABI to shared package for frontend/server consumption
- Update deployment docs and architecture docs

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 03:27:51 +00:00

47 lines
2 KiB
Markdown

# Architecture — The Arena RPS Royale
## Vue d'ensemble
Le projet est un monorepo organisé en trois applications et un package partagé, orchestré par Docker Compose.
```
rps-royale/
├── apps/
│ ├── web/ # Next.js 15 + Phaser 3 (frontend jeu)
│ ├── server/ # Node.js + Socket.io + Express (backend temps réel)
│ └── contracts/ # Hardhat + Solidity (smart contract commit-reveal)
├── packages/
│ └── shared/ # Types et constantes TypeScript partagés
└── docker-compose.yml
```
## Flux de données
1. Le joueur ouvre `jeu.cosmolan.fr` (Next.js + Phaser)
2. Il se connecte via Socket.io à `api.jeu.cosmolan.fr` (Node.js)
3. Le matchmaking place deux joueurs dans une "room"
4. Le serveur crée le match sur la blockchain (`createMatch`) et retourne le `matchId` on-chain
5. Chaque joueur appelle directement `commit(matchId, hash)` sur le contrat `RPSArena.sol` en payant la mise
6. Le serveur écoute les événements `Committed` on-chain et déclenche la phase **Suspense**
7. Chaque joueur appelle `reveal(matchId, choice, nonce)` sur le contrat
8. Le smart contract vérifie les hashes, détermine le gagnant et distribue automatiquement le pot (moins 3% de frais plateforme)
## Réseau Docker
Tous les services partagent le réseau `npm_default` (géré par Nginx Proxy Manager).
| Service | Port conteneur | Port hôte | Exposé via NPM |
|---------|----------------|-----------|----------------|
| rps-web | 3000 | 127.0.0.1:3050 | `jeu.cosmolan.fr` |
| rps-server | 3001 | 127.0.0.1:3051 | `api.jeu.cosmolan.fr` |
| rps-db | 5432 | 127.0.0.1:3052 | Interne |
| rps-redis | 6379 | 127.0.0.1:3053 | Interne |
| hardhat-node | 8545 | 127.0.0.1:3054 | Interne |
## Technologies clés
- **Phaser 3** : moteur 2D pour les animations, particules et scènes de jeu
- **Socket.io** : communication temps réel multijoueur
- **Hardhat** : environnement de développement Ethereum avec tests automatiques
- **Prisma ORM** : accès typé à PostgreSQL
- **Commit-Reveal** : pattern blockchain anti-triche