Seimurai

Seimurai - Backend Architecture
Seimurai is a Web3 tower-defense game built on the Sei Network, where players battle through waves of enemies, collect scrolls, build skill decks, and earn on-chain rewards. I designed and built the entire backend infrastructure powering the game.
Overview
The backend is a NestJS monorepo consisting of two core services — an API service handling all game logic and player data, and an AI service powering intelligent NPC agents. Together they support real-time gameplay, persistent progression, and trustless on-chain verification of game outcomes.
What I Built
Game Session Engine
A complete session lifecycle system managing game start, wave progression, pause/resume, gold tracking, and two distinct end-game flows (success vs. failure). Every session is tied to a player's wallet address and validated against on-chain events.
Wallet-Based Authentication
Players authenticate by signing a nonce-based message with their wallet. The backend verifies the signature, issues a JWT, and maps all game data to the player's on-chain identity — no emails, no passwords.
Inventory & Deck System
A scroll-based progression system where players acquire locked scrolls, unlock them into usable skills, level them up, and assemble a combat deck of up to 5 active skills. Supports bulk updates for seamless in-game flow.
Persistent Save Data
Full game state serialization — health, gold, wave index, action tiles with cooldown/damage/level stats, acquired actions, character selection, and timestamped level progression paths. Players can leave and pick up exactly where they left off.
On-Chain Verification
Integrated with the Sei Network smart contract to listen for GameStarted and GameEnded events. Game traces (wave count, gold earned, duration, character) are encoded and verified on-chain to prevent reward manipulation.
AI NPC Agents
Built an AI service powered by Groq LLMs featuring three distinct agent personalities — a Sensei for tutorials and guidance, a Dealer for in-game UI interactions, and an Enemy AI for dynamic combat behavior.
Architecture
The system follows a clean service-oriented architecture:
- API Service (Port 7001) — Game logic, player management, inventory, save data
- AI Service (Port 7000) — LLM-driven NPC agents via Groq
- MongoDB — Persistent storage for all game and player data
- Sei Network RPC — On-chain event listening and transaction verification
- Docker Compose — Orchestrated local and production deployments
Technical Highlights
- Wallet signature verification with ethers.js on the Sei EVM
- JWT-based session management mapped to blockchain addresses
- Mongoose schemas optimized for nested game state documents
- Swagger/OpenAPI documentation for all endpoints
- Shared package architecture for cross-service type safety and utilities
- Account abstraction support via Biconomy for gasless player transactions
Project Gallery




