How pkmn/ps works
Main Components
• Simulator Component (@pkmn/sim):
– This package is an extraction of the Pokémon Showdown simulator portion and forms the core engine for battles.
• Data and Dex Components (@pkmn/dex and @pkmn/data):
– The “dex” package unifies data from both server and client codebases, while “data” is a higher-level wrapper API.
– Show these components as being tightly coupled; the “Data API” draws information from the “Dex” (data unification) source.
• Mods (@pkmn/mods):
– Provides support for non-standard modifications to both sim and dex.
– Represent this as an “Extension/Modification” layer that plugs into the simulator and data components.
• Sets (@pkmn/sets):
– This handles importing/exporting Pokémon Showdown’s team/set specifications.
• Types (@pkmn/types):
– Provides shared TypeScript definitions, which are used throughout the system.
• Protocol (@pkmn/protocol):
– Contains parsing logic for the Pokémon Showdown protocols. It is used by other components (for example, the client component).
• Client (@pkmn/client):
– A fork of the Pokémon Showdown client battle engine that builds on top of the protocol.
• View (@pkmn/view):
– Its purpose is to build UIs for the client side.
• Img (@pkmn/img):
• Login (@pkmn/login):
– Manages authentication logic.
• Randoms (@pkmn/randoms):
– Implements random team generation for Random Battle formats.
• Streams (@pkmn/streams):
– Extracts the streams library from Pokémon Showdown.
• Integration and Other Supporting Folders:
– “integration”, “login”, and other directories contain testing frameworks, integration tests and additional scripts for building or simulating parts of the system.
Relationships & Data Flow
• Most packages depend on each other in a layered fashion. For example, the Client component uses the Protocol package to communicate, while the Simulator (sim) may pull in data from Dex and be modified by Mods.
• The Data component is a central API that wraps around and integrates both the simulator and dex functionalities.
• The Types package is a foundational library that all other components reference.
• UI-related components (Client and View) depend on Protocol, which in turn interacts with the underlying simulation logic from “sim”.
• Testing and integration directories that validate individual components and their interactions.
Architectural Patterns and Design Principles
• Separation of Concerns: Each package has a clearly defined role (e.g., simulation, data processing, rendering, authentication).
• Layered Architecture: Emphasize how the lower-level simulation and data models are abstracted by higher-level components (like the client and view).