This is a backend application for a Point of Sales system built with TypeScript, Node.js, and Fastify. It includes functionalities for user authentication, product management, upsell product management, and sales transactions. Sequelize is used as the ORM for MySQL database interactions.
- Getting Started
- Environment Variables
- Running the Application
- Running Tests
- API Descriptions
- Future Enhancements
- Node.js (>= 14.x)
- npm (>= 6.x)
- MySQL
- Clone the repository:
git clone repository_url cd repository_name - Install dependencies:
npm install - Install MySQL:
Windows: Download the MySQL Installer from the official MySQL website and follow the installation instructions.
- Set up the database:
CREATE DATABASE pos_db; - Create a
.envfile in the root directory and add your database configuration:DB_HOST=localhost DB_USER=root DB_PASSWORD=yourpassword DB_NAME=pos_db JWT_SECRET=your_jwt_secret
Ensure the following environment variables are set in your .env file:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=pos_db
JWT_SECRET=your_jwt_secret
PORT=3000
To start the server:
npm start
The server will start on http://localhost:3000.
To run the unit tests:
npm test
This will run all the test suites in the tests directory.
- Sign Up: This endpoint creates a new user account. It accepts an email and password, hashes the password for security, and generates a JWT token for authentication.
- Login: This endpoint logs in an existing user. It verifies the user's credentials, checks the hashed password, and generates a JWT token for authentication.
- Create Product: This endpoint creates a new product. It accepts details like name, price, description, and quantity of the product and stores it in the database.
- Retrieve All Products: This endpoint retrieves all products from the database. It returns a list of products with their details.
- Update Product: This endpoint updates an existing product. It accepts the product ID and updated details, and then updates the product in the database.
- Delete Product: This endpoint deletes an existing product. It accepts the product ID and removes the product from the database.
- Create Transaction: This endpoint creates a new transaction with details of products sold and their quantities. It checks the availability of the products, reduces their quantities accordingly, and adds the transaction details to the database. If the product quantity is insufficient, it returns an error.
- Retrieve All Transactions: This endpoint retrieves all transactions. It returns a list of transactions with their details, including the associated products and upsell products.
- Retrieve Specific Transaction: This endpoint retrieves a specific transaction by ID along with the associated products and upsell products. It provides detailed information about the transaction.
- Link Upsell Product: This endpoint links an upsell product to an existing product. It accepts the IDs of the main product and the upsell product, and creates a link between them in the database.
- Retrieve Upsell Products: This endpoint retrieves all upsell products linked to a specific product. It returns a list of upsell products associated with the given product ID.
To ensure the system can be easily expanded in the future, several potential enhancements have been considered:
- Discount Management: Implementing a system to manage discounts and promotions that can be applied to transactions.
- Inventory Management: Adding features for managing inventory, including automated stock replenishment alerts and detailed inventory reports.
- Customer Management: Introducing a customer relationship management (CRM) module to track customer details, purchase history, and preferences.
- Reporting and Analytics: Developing advanced reporting and analytics tools to provide insights into sales performance, customer behavior, and product trends.
- Multi-language Support: Expanding the system to support multiple languages for a more inclusive user experience.
The current architecture, using Fastify and Sequelize, is designed to be modular and scalable, making it easier to integrate these additional features in the future.