Inventory Management System

Overview

A full-stack inventory management system that allows users to track products, manage stock, and generate reports. The project consists of a client built with Next.js and a server using Node.js and Prisma.

Features

  • Product management
  • Stock tracking
  • Automated reporting
  • User authentication

Technologies Used

  • Client: Next.js, React, TailwindCSS
  • Server: Node.js, Prisma, PostgreSQL
  • Database: PostgreSQL
  • Production : AWS, EC2, S3, RDS ,Amplify

DataModelling

Schema Relations

AWS Architecture

Diagram

Installation Steps

  1. Clone the repository:

    git clone [git-url]
    cd inventory-management
  2. Install dependencies for both client and server:

    # Client setup
    cd client
    npm i
    cd ..
    
    # Server setup
    cd server
    npm i
  3. Set up the database:

    npx prisma generate
    npx prisma migrate dev --name init
    npm run seed
  4. Configure environment variables:

    • For server settings, configure the .env file:
      PORT=your-port
      DATABASE_URL=your-database-url
      
    • For client settings, configure the .env.local file:
      NEXT_PUBLIC_API_BASE_URL=your-api-base-url
      
  5. Run the project:

    npm run dev

EC2 Setup Instructions

  1. Connect to EC2 Instance:

    • Use EC2 Instance Connect from your AWS Console to access your instance.
  2. Install Node Version Manager (nvm) and Node.js:

    • Switch to superuser:
      sudo su -
    • Install nvm:
      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    • Activate nvm:
      . ~/.nvm/nvm.sh
    • Install the latest version of Node.js:
      nvm install node
    • Verify installation:
      node -v
      npm -v
  3. Install Git:

    • Update system and install Git:
      sudo yum update -y
      sudo yum install git -y
    • Check Git version:
      git --version
    • Clone your repository:
      git clone [your-github-link]
      cd inventory-management
      npm i
  4. Create Env File and Start the Application:

    • Set the server to use port 80:
      echo "PORT=80" > .env
    • Start the application:
      npm start
  5. Install pm2 (Production Process Manager for Node.js):

    • Install pm2 globally:
      npm i pm2 -g
    • Create a pm2 ecosystem configuration file (inside the server directory):
      module.exports = {
        apps: [{
          name: 'inventory-management',
          script: 'npm',
          args: 'run dev',
          env: {
            NODE_ENV: 'development',
            ENV_VAR1: 'environment-variable',
          }
        }],
      };
    • Modify the ecosystem file if necessary:
      nano ecosystem.config.js
    • Set pm2 to restart on reboot:
      sudo env PATH=$PATH:$(which node) $(which pm2) startup systemd -u $USER --hp $(eval echo ~$USER)
    • Start the application with pm2:
      pm2 start ecosystem.config.js

Useful pm2 Commands:

  • Stop all processes:

    pm2 stop all
  • Delete all processes:

    pm2 delete all
  • status of processes:

    pm2 status
  • Monitor processes:

    pm2 monit

RDS PostgreSQL

To connect to your RDS PostgreSQL database, you will need to set up a connection string in your environment variables. The connection string format is as follows:

DATABASE_URL="postgresql://<username>:<password>@<hostname>:<port>/<database_name>?schema=<schema>"

remember to set the password only in alphanumeric format otherwise exceptions may occur

S3 Bucket Policy

To allow public read access to the objects in your S3 bucket, you can use the following bucket policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "[bucket-arn]/*"
        }
    ]
}