This document outlines the software architecture of a desktop Chess application. The system is a self-contained program that provides a graphical user interface (GUI) for playing chess, complete with user authentication, game state persistence, and move history tracking.
The primary problem solved is the creation of a complete, playable chess game that encapsulates game logic, user interaction, and data management within a single, executable application. The system is designed as a standalone desktop experience, not as a client-server or web-based application.
The system is implemented using a Monolithic Architecture. All core components—including the user interface, game logic, and data persistence layers—are tightly integrated and run within a single process. This design choice is appropriate for a small-scale, standalone desktop application, as it simplifies development and deployment.
The internal design leverages the Observer Pattern to decouple components. GameObserver instances (GUIObserver, HistoryObserver, JsonLogObserver) are notified of state changes within the Game object. This allows for concerns like UI updates, logging, and history tracking to be handled independently of the core move validation and execution logic.
- User Interaction: The user interacts with the GUI, which is constructed using components from the
GUI_Componentspackage (e.g.,LoginAndRegisterWindow,GameFrame). - Event Handling: UI events (e.g., button clicks, piece movements) are captured by listeners within the GUI components.
- Logic Execution: These events trigger method calls into the core
game_logicpackage, primarily interacting with theGameandBoardclasses. - State Change: The
Gameobject updates its state (e.g., piece positions, turn). - Notification: The
Gameobject notifies all registeredGameObserverinstances of the state change. - Component Updates: Each observer responds accordingly:
GUIObserver: Updates the visual representation of the chess board.HistoryObserver: Records the move.PointsObserver: Recalculates and displays scores.JsonLogObserver: Appends game events to a JSON log.
- Data Persistence: User and game data are persisted to the local filesystem using utility classes (
JsonReaderUtil,JsonWriterUtil) that read from and write to JSON files (input/accounts.json,input/games.json).
main_package: Contains the application entry point (Main.java), responsible for initializing and launching the application.GUI_Components: Manages all aspects of the user interface. It includes frames, buttons, and custom Swing components for rendering the game.game_logic: Encapsulates the core rules and state management of the chess game.Board.javamaintains the state of the pieces, andGame.javaorchestrates the gameplay.pieces_details: Defines the chess pieces and their valid movements. It employs a Strategy Pattern, where each piece type has an associatedMoveStrategythat defines its movement logic.Interfaces: A set of Java interfaces (ChessPiece,GameObserver,MoveStrategy) that define the primary contracts between components, promoting a degree of loose coupling.user_details: Contains data models forUserandPlayer.misc: A collection of utility classes, including for JSON serialization/deserialization.errors: Defines custom, domain-specific exceptions for handling invalid operations.
This project intentionally minimizes external dependencies, opting for a standard, self-contained toolchain.
-
Language: Java
- Justification: Java is a mature, object-oriented language with strong typing, which is beneficial for a logic-intensive application like chess. Its robust standard library and platform independence make it a reliable choice for desktop applications.
-
GUI Framework: Java Swing
- Justification: The use of
javax.swingcomponents is inferred from theGUI_Componentspackage. Swing is part of the standard Java SE Development Kit (JDK), requiring no external libraries. This simplifies the build process and ensures that the application can run on any machine with a compatible Java Runtime Environment (JRE). For a standalone desktop application of this scope, it is a practical and sufficient choice.
- Justification: The use of
-
Data Storage: JSON Files (via
json-simple)- Justification: Persistence is handled by serializing game and user data to local JSON files. The
json-simplelibrary is included directly in thelib/directory. This approach avoids the operational overhead of a database system (e.g., PostgreSQL, MongoDB), which would be excessive for the project's requirements. File-based storage is adequate for managing a limited amount of data for a single-user application.
- Justification: Persistence is handled by serializing game and user data to local JSON files. The
-
Dependency Management: Manual (JAR in
/lib)- Justification: The project eschews a formal dependency management tool like Maven or Gradle. Instead, the single external dependency (
json-simple-1.1.1.jar) is stored directly in the repository. This is a pragmatic decision for a project with a minimal number of dependencies, as it removes the need for additional configuration and tooling.
- Justification: The project eschews a formal dependency management tool like Maven or Gradle. Instead, the single external dependency (
The project's source code is organized using a package-by-feature approach, which promotes a clear separation of concerns.
GUI_Components/vs.game_logic/: This is the most critical separation, isolating the presentation layer from the business logic. It allows developers to work on the UI and the core game engine independently.pieces_details/: Grouping all piece-related classes and their movement strategies into a single package aligns with Domain-Driven Design principles, where a core concept of the domain (the chess piece) is encapsulated in its own module.Interfaces/: Centralizing the application's key interfaces makes the system's contracts explicit and easy to locate.input/: This directory serves as a simple database, storing the application's state in a clear and accessible location.
This structure enhances modularity and maintainability within the context of a monolithic application.
- A Java Development Kit (JDK), version 8 or later.
- An IDE such as IntelliJ IDEA or Eclipse is recommended for ease of compilation and execution (the project contains
.ideaand.imlfiles).
As there is no pom.xml or build.gradle file, the project is intended to be compiled and run using standard Java commands or directly from an IDE.
From the Command Line:
- Navigate to the
PROIECT/directory. - Compile the source code, including the
json-simplelibrary in the classpath:javac -d out -cp "lib/json-simple-1.1.1.jar" src/**/*.java
- Run the application by specifying the main class:
java -cp "out;lib/json-simple-1.1.1.jar" main_package.Main
Running Tests:
The project includes a test runner that can be executed similarly:
java -cp "out;lib/json-simple-1.1.1.jar" Testare.ChessTestRunnerThe architecture reflects a series of deliberate trade-offs that prioritize simplicity and rapid development over other concerns.
- Simplicity vs. Scalability: The monolithic architecture and file-based data storage are simple to implement but do not scale. The application is fundamentally designed for a single user on a single machine and cannot be extended to a multi-user, client-server model without a complete architectural refactor.
- Coupling: The
game_logicis tightly coupled to the Swing-based GUI via theGUIObserver. While the Observer pattern provides a layer of abstraction, replacing the UI with a different technology (e.g., a web interface or JavaFX) would still require significant rework. - Data Integrity: Using raw JSON files for persistence lacks the ACID guarantees of a true database system. There is a risk of data corruption if the application terminates unexpectedly during a file-write operation. This trade-off sacrifices robustness for simplicity.