Skip to content

Latest commit

 

History

History
46 lines (25 loc) · 2.21 KB

ARCHITECTURE.md

File metadata and controls

46 lines (25 loc) · 2.21 KB

Pokemon Showdown architecture

At the highest level, PS is split into three parts:

  • Client
  • Login server
  • Game server

The game server is in this repository, smogon/pokemon-showdown, while the client and login server are in smogon/pokemon-showdown-client. All three communicate directly with each other.

Game server

The game server is written in TypeScript and runs on Node.js.

Its entry point is server/index.ts, which launches several major components:

  • server/sockets.ts sets up a SockJS (abstracted WebSocket) server to accept connections from clients

  • server/users.ts sets up Users, which wraps the SockJS connections in a system that handles users

  • server/rooms.ts sets up Rooms, which handles the individual chat rooms and battle rooms

  • server/chat.ts sets up Chat, which handles chat commands and messages coming in from users (all client-to-server commands are routed through there)

Rooms also includes support for battle rooms, which is where the game simulation itself is done. Game simulation code is in sim/.

Client

The client is built in a mix of TypeScript and JavaScript, with a mostly hand-rolled framework built on Backbone. There’s a rewrite to migrate it to Preact but it’s very stalled.

Its entry point is [index.template.html][https://github.com/smogon/pokemon-showdown-client/blob/master/index.template.html].

It was written long ago, so instead of a single JS entry point, it includes a lot of JS files. Everything important is launched from [js/client.js][https://github.com/smogon/pokemon-showdown-client/blob/master/js/client.js].

Login server

The client’s login server, which handles logins and most database interaction, is written in PHP, with a rewrite to TypeScript in progress. The backend is split between a MySQL InnoDB database and a Percona database, with a migration to Postgres planned.

Its entry point is [action.php][https://github.com/smogon/pokemon-showdown-client/blob/master/action.php].