Skip to content

Project Setup For Development

Sirin Puenggun edited this page Oct 17, 2024 · 3 revisions

Overview

Here is the overview of the steps to install and run this project locally.

Backend

  1. Install Python
  2. Install NodeJS and pnpm via npm
  3. Install PostgreSQL via docker or installer
  4. Setup Google Google Cloud Project, Oauth Consent, and get Google API Client ID and Secret
  5. Set up Amazon S3 Bucket and get Amazon S3 Access Key and Secret
  6. Setup Django Project, and development environment

Frontend

  1. Run pnpm to install dependencies in /frontend
pnpm install
  1. Start React app
pnpm dev

If you've already installed Pythonand NodeJS, you can skip to Install PostgreSQL


Install Python and NodeJS

Install python

  1. Download Python installer and follow the guide on Python website

  2. Check Python installation

python --version

Install NodeJS and pnpm

You can follow these methods

Then install pnpm, look at this guide or run

npm install -g pnpm

Install PostgreSQL

Install via docker

  1. First of all download and install docker desktop that contains the docker engine, docker CLI, etc.

  2. Pull docker postgres Image

docker pull postgres
  1. Create a Docker container for PostgreSQL. Adjust these variables in the command below
  • YOUR_CONTAINER_NAME
  • YOUR_POSTGRE_USERNAME
  • YOUR_POSTGRE_PASSWORD
docker run --name YOUR_CONTAINER_NAME -e POSTGRES_USER=YOUR_POSTGRE_USERNAME -e POSTGRES_PASSWORD=YOUR_POSTGRE_PASSWORD -p 5432:5432 -d postgres
  1. Wait for the container to start. You can check the logs with
docker logs YOUR_CONTAINER_NAME

Extra: you can download pgadmin4 via docker which is a tool for managing Postgres database. Click here For more information

Host: localhost Port: 5432 (or the port you specified) Database: postgres Database User: YOUR_POSTGRE_USERNAME Password: YOUR_POSTGRE_PASSWORD

Install PostgreSQL via Installer

We recommend to install postgres with pgadmin4

After installing of postgres and pgadmin4 you must

  1. Create a new database.
  2. Specify username, password, and host as you desire.

Usually, Hostname will be localhost, the port will be 5432, and the default postgres database user is postgres


Setup Google Google Cloud Project, Oauth Consent and, get Google API Client ID and Secret

You can visit here for more information

Here is the overview

  1. Create Google cloud project
  2. Setup OAuth Consent
  3. You need to provide these scopes below in Page Usage Agreements of your Google Cloud Project
  https://www.googleapis.com/auth/userinfo.email
  https://www.googleapis.com/auth/userinfo.profile
  https://www.googleapis.com/auth/calendar.acls.readonly
  https://www.googleapis.com/auth/calendar.events.readonly
  1. In Credentials tab, you will see OAuth 2.0 Client IDs, look for Client ID and Secret their and keep it secret from others.

If you're still confusing about Credentials creation for Client ID, please visit here.


Set up Amazon S3 Bucket and get Amazon S3 Access Key and Secret

Please follow instruction in Amazon S3 Website


Setup Django Project and environment

  1. Clone this repository
git clone https://github.com/Sosokker/Inventory-Management-System
cd Inventory-Management-System
  1. Create virtual environment and use it to install require packages
python -m venv venv

(Optional: You can use venv instead)Install virtualenv via pip

python -m pip install --user virtualenv
python -m virtualenv venv
# Access virtual environment using
# Windows
.\venv\Scripts\activate
# Linux or MacOS
source venv/bin/activate
  1. Install require module.
pip install -r requirements.txt

Setup Django

  1. Create file .env to provide environment varible for Django You can look at sample.env for more information and others environment variables to set.
SECRET_KEY=your_secret_key
DEBUG=False
ALLOWED_HOSTS=*.ku.th, localhost, 127.0.0.1, ::1
DB_NAME=your_DB_NAME
DB_USER=your_DB_USER
DB_PASSWORD=your_DB_PASSWORD
DB_HOST=your_DB_HOST
DB_PORT=your_DB_PORT
GOOGLE_CLIENT_ID=your_GOOGLE_CLIENT_ID
GOOGLE_CLIENT_SECRET=your_GOOGLE_CLIENT_SECRET
BUCKET_NAME=your_BUCKET_NAME
AMAZON_S3_ACCESS_KEY=YOUR_S3_ACCESS_KEY
AMAZON_S3_SECRET_ACCESS_KEY=YOUR_S3_SECRET

Generate Secret key from Djecrety

Don't forget to change your_secret_key to your secret key (without quote)

  1. Migrate database then runserver
python manage.py migrate
python manage.py createcachetable {DB_NAME}_cache // DB_NAME is same same as name of your created database
python manage.py runserver

You can now access webpage via http://127.0.0.1:8000/ or you can change port by

python manage.py runserver <PORT>

Clone this wiki locally