StockPal

StockPal’s Developer Guide

Acknowledgements

Third-party libraries:


Design

:bulb: Tip: The .puml files used to create diagrams in this document are in the docs/diagrams folder. Refer to the PlantUML Tutorial at se-edu/guides to learn how to create and edit diagrams.

Architecture

Architecture Diagram

The Architecture Diagram given above explains the high-level design of the App.

Given below is a quick overview of main components and how they interact with each other.

Main components of the architecture

StockPal is in charge of the app launch and shut down.

The bulk of the app’s work is done by the following five components:

Commons represents a collection of classes used by multiple components above. Exceptions represents a collection of exceptions used by multiple components above.

How the architecture components interact with each other

The Sequence Diagram below shows how the components interact with each other for the scenario where the user issues the command delete 1.

Architecture Sequence Diagram

The sections below give more details of each component.

UI component

The API of this component is specified in Ui.java.

Structure of the UI Component

The UI component,

Parser component

API : Parser.java

Structure of the Parser Component

How the Parser component works:

  1. When user inputs, the input is passed to the Parser.
  2. Parser first extracts the command.
  3. Using the extracted command, Parser will perform different validation checks on the arguments supplied in the input, iteratively.

    For example, edit 1 n/newName q/100 will be checked in the order: Command name: edit, PID: 1, Name: newName, Quantity: 100, Price: null, and lastly Description: null.

  4. Arguments (mainly the pid, name, quantity, price, description, amount fields) are validated. Exceptions are thrown when the fields do not pass their respective type checks.
  5. Once validation passes, Parser uses the validated arguments to creates an instance of that particular command. For example, a delete command will cause Parser to create a new instance of DeleteCommand(pid).
  6. The created command object is returned back to main function for further processing.

Command component

**API ** : Command.java

Structure of the Command Component

How the Command component works:

  1. Parser first creates the respective Command after parsing user input. Then, the Command is passed to StockPal, awaiting execution.
  2. StockPal then executes the respective Command.
  3. After execution, be it successful or unsuccessful, Command calls on the UI component to output the results to screen.

Data component

API : Data

The following is a class diagram of the Data component.

Structure of the Data Component

The Data component,

Storage component

API : Storage

Structure of the Storage Component

The Storage component,

In addition to saving products, the Storage component has a subcomponent TransactionStorage, which

Common Classes

Classes used by multiple components are in the seedu.stockpal.common package. The common package consists of 2 useful utility classes that are mainly used for printing of output to screen, as well as containing the output messages.

Exception Classes

Exception classes used by multiple components are in the seedu.stockpal.exceptions package.


Implementation

This section describes some noteworthy details on how certain features are implemented.

Command Feature

The following sequence diagram summarizes what happens when a user inputs a valid command.

images/CommandSequenceDiagram.png

Validation of the user input is done in Parser, hence XYZCommand assumes that all fields provided upon creation of a XYZCommand object are properly formatted.

The execute() method of each command will be elaborated further with the introduction of each of the features below.

Help Feature

Implementation

The help command is used to display the help page for either all or individual commands.

The help feature is facilitated by HelpCommand which extends Command.

Details for individual commands are stored within the individual classes as static variables. The details are stored as 5 variables as follows.

Variable What it represents Example
COMMAND_KEYWORD The keyword used to identify the command. “inflow”
COMMAND_DESCRIPTION Description of the command. “Increases the quantity of a product from the existing amount.”
COMMAND_USAGE The format of the command. “inflow PID a/INCREMENT_AMOUNT”
COMMAND_FLAGS Placeholder value used to denote command arguments. {“PID”, “INCREMENT_AMOUNT”}
COMMAND_FLAG_DESCRIPTIONS Description of what the placeholder value represents. {“Product ID of product”, “Quantity of product to add”}

FormatUtils#formatCommandDetails() takes in these 5 variables as arguments and produces a formatted version of the details.

Example of formatted version of details based on the 5 example variables above:

====================================================================================
Command: inflow

Description: Increases the quantity of a product from the existing amount.

Usage: inflow PID a/INCREMENT_AMOUNT

Options:
PID                   Product ID of product
INCREMENT_AMOUNT      Quantity of product to add
====================================================================================

Each command has a public static commandDetails() method that will return the formatted version of its command details.

Design Considerations

Aspect: Where to store the individual command details.

New Product Feature

The new command is responsible for adding a new product to the inventory in the StockPal application.

The new product feature is facilitated by NewCommand which extends ListActionCommand.

Specific validations are still carried out within NewCommand.

  1. Checking if the new product name is the same as an existing product name.

Once all validation is completed, adding of product is done by calling ProductList#newProduct().

The following sequence diagram details how NewCommand#execute() functions.

AddCommandExecuteSequenceDiagram.png

Edit Product Feature

Implementation

The edit command is used to edit product details such as name, quantity, price and description.

The edit product feature is facilitated by EditCommand which extends ListActionCommand.

Specific validations are still carried out when updating the product details.

  1. Checking if at least 1 field (name, quantity, price or description) is provided.
  2. Checking if the product ID (PID) belongs to an existing product.
  3. Checking if the edited product name is the same as an existing product name.

Updating of product details is done by calling ProductList#updateProduct().

The following sequence diagram details how EditCommand#execute() functions.

EditCommandExecuteSequenceDiagram.png

List Feature

The list command is responsible for sorting and printing out the products in the list.

The list feature is facilitated by ListCommand which extends ListActionCommand.

Attributes

Methods

The following sequence diagram illustrates how ListCommand#execute() functions.

ListCommandExecuteSequenceDiagram.png

InflowCommand Feature

The inflow command is used to increase the quantity of a specific product in the inventory. This could represent scenarios like receiving new stock and updating inventory with new quantities.

Implementation

The inflow product feature is facilitated by InflowCommand which extends TransactionActionCommand.

Specific validations are still carried out within the InflowCommand.

  1. Checking if the product ID (PID) belongs to an existing product.
  2. Checking if the addition of inflow quantity and existing quantity will result in an integer overflow.

Once all validations are completed, increasing a product quantity is done by calling ProductList#increaseAmountCaller().

The following sequence diagram shows how the InflowCommand works.

InflowCommand Class

OutflowCommand Feature

The outflow command is used to decrease the quantity of a specific product in the inventory. This could represent scenarios like selling products and updating inventory with new updated quantities.

Implementation

The outflow product feature is facilitated by OutflowCommand which extends TransactionActionCommand.

Specific validations are still carried out within the OutflowCommand.

  1. Checking if the product ID (PID) belongs to an existing product.
  2. Checking if the outflow quantity is larger than the existing quantity.

Once all validations are completed, decreasing a product quantity is done by calling ProductList#decreaseAmountCaller().

The following sequence diagram shows how the InflowCommand works.

OutflowCommand Class

Delete product feature

The delete command is used to delete a product of the specified PID in the inventory.

Implementation

The delete product feature is mainly facilitated by DeleteCommand which extends TransactionActionCommand.

Attributes

PID The unique Product ID for the product to be deleted from the StockPal inventory productList.

Methods

Given below is an example usage scenario and how the delete function behaves at each step. The scenario assumes that the user has a Product with PID of 2 in StockPal’s productList.

Step 1. The user executes delete 2 command to delete a specific Product with PID of 2. Step 2. The product is successfully deleted from the inventory list.

Possible Exceptions that can be thrown

The following sequence diagram shows how DeleteCommand#execute() functions. The sequence diagram assumes that PID provided is valid.

DeleteCommandSequenceDiagram

Find product feature

The find command is responsible for finding a particular keyword in a product’s name in the StockPal application.

The find product feature is facilitated by FindCommand which extends ListActionCommand.

Finding of keyword of product is done by calling ProductList#FindKeyword().

The following sequence diagram details how FindCommand#execute() functions.

FindCommandExecuteSequenceDiagram.png

History product feature

The history command is responsible for finding any inflows or outflows for a particular PID in the StockPal application.

The history product feature is facilitated by HistoryCommand which extends TransactionActionCommand.

Finding of transactions is done by calling ProductList#FindTransactions().

The following sequence diagram details how HistoryCommand#execute() functions.

HistoryCommandExecuteSequenceDiagram.png


Appendix: Requirements

Product scope

Target user profile:

Value proposition:
Traditional inventory management methods often involve manual data entry, spreadsheets, and paper-based tracking systems. These processes are time-consuming, error-prone, and lack real-time visibility into inventory status. StockPal allows users to quickly update, track, and monitor inventory data through intuitive command-line commands, saving time and improving efficiency.

User Stories

Version As a … I want to … So that I can …
v1.0 beginner user have a small manual page aware of the commands that I can enter
v1.0 forgetful user of StockPal see usage instructions refer to them when I forget how to use the application
v1.0 small business owner add details of products easily track my products’ stock
v1.0 user that makes mistakes be able to edit details of the products easily easily change the name / price / quantity /description of the products, if there is an error
v1.0 continuous user of StockPal have my entered data to be saved track all the products that I have entered from past uses of the app
v2.0 business owner view at past inflow/outflows of a product keep track of sales data of the product and know which products are of higher demand
v2.0 user that owns a lot of products find products’ name that contain the keyword find my product, or want to get the product’s PID in a long list of products
v2.0 business owner doing a sales analysis find my products’ past transactions keep track of the changes in my products’ quantity
v2.0 business owner that is forgetful have a warning when my products have low quantity restock them before they go out of stock.

Non-Functional Requirements

Glossary


Appendix: Instructions for manual testing

Viewing Help page

  1. No prerequisites needed.

  2. Test case 1: help inflow
    Expected: Help page for inflow command will be printed out.

    Test case 2: help bleh
    Expected: Invalid command. For more information on the commands, use `help`. will be printed out as bleh in an invalid command keyword.

Adding a Product

  1. No prerequisites needed.

  2. Test case 1: new n/Drinking Cup q/20
    Expected: The product will be added. Name of the product is Drinking Cup, Quantity of chocolate Milk stock is 20 units.

    Test case 2: new n/Chocolate Milk q/100 p/2.00 d/Marigold HL Milk
    Expected: The product will be added. Name of the product is Chocolate Milk, Quantity of chocolate Milk stock is 100 units, Price of each unit is $2.00, Description of the Chocolate Milk product is Marigold HL Milk, which is the brand.

Editing Product Details

  1. Prerequisites: List all products using list command. There should be at least 2 products in the list.

  2. Test case 1: edit 1 n/Updated name d/Updated description
    Expected: The name and description of the product with Product ID (PID) 1 will be changed to Updated name and Updated description respectively.

    Test case 2: edit 1 q/100 p/0.99
    Expected: The quantity and price of the product with Product ID (PID) 1 will be changed to 100 and 0.99 respectively.

Increase Product Quantity

  1. Prerequisites: List all products using list command. There should be a particular product with PID 1 and PID 2.
    The product with PID 1 should have quantity 30 and PID 2 should have quantity 100.

  2. Test case 1 : inflow 1 a/20
    Expected: The quantity of the product with Product ID (PID) 1 will increase by 20.

    • Do note that the amount to increase must be less than INT_MAX.

    Test case 2: inflow 1 a/2147483650
    Expected: Integer input exceeds largest integer allowed. Max integer is 2147483647 will be printed out.

Decrease Product Quantity

  1. Prerequisites: List all products using list command. There should be a particular product with PID 1 and PID 2. The product with PID 1 should have quantity 30 and PID 2 should have quantity 100.

  2. Test case 1 : outflow 1 a/20
    Expected: Warning! This product is low in quantity. Quantity updated. Quantity: 10

    Test case 2: outflow 2 a/20
    Expected: Quantity updated. Quantity: 80 will be printed out.

Deleting a product

  1. Prerequisites: List all products using list command. There should be a particular product with PID of 1 and no product with PID of 2.

  2. Test case 1: delete 1
    Expected: product with pid of 1 is deleted from the list. "Product has been deleted" is printed to the user.

    Test case 2: delete 2.
    Expected: "Product with pid: 2 not found"

Finding a keyword in the Product list

  1. No prerequisites needed.

  2. Test case: find Cor
    Expected: A list of products will be printed out if there is a match, otherwise No match found. will be printed out.

Finding all past transactions for a particular product in the Product list

  1. Prerequisites: List all products using list command. There should be at least multiple products in the list.

  2. Test case: history 1
    Expected: A list of transactions will be printed out if there is a match, otherwise No match found. will be printed out.