Skip to content

joshjms/ntusu-itc-backend

Repository files navigation

NTUSU ITC Backend

Overview

This is NTUSU ITC Backend repository created on December 2022. It is built using mainly Django REST Framework and a few other dependencies. The old 5 years old repository here (private repository, invitation is required to access) is about to be deprecated, as there are multiple compatibility issues and we want to shift to Single Page Application format where we separate the backend and frontend.

Table of Contents

  1. Development Environment
  2. Production Environment
  3. Applications Explanation

Development Environment

How To Run Development Server

  1. Install Docker Desktop based on your operating system (MAC / Windows / Linux) and launch the application

  2. Clone this repository and move into the project directory where docker-compose.yml file is located

  3. Install the server using Docker

        docker-compose up --build

    Stop using Ctrl+C. Re-run this command when you want to start the server again in your local development environment.

    Your server should be up at localhost:8888. If this is your first time running the development environment, please do step 4 as shown below. The application will not run properly if you do not perform database migration.

  4. Initialize database migration

    Using another terminal, execute the following command:

        docker exec -ti SUITC_Backend python manage.py migrate

    Note: you might need to add sudo if you're using MAC

    You should do this when it is your first time running the development environment, and anytime there are new database migrations.

Troubleshoot

This section is to document any problems that might occur when running the development environment along with its solution, as we all are using different devices which might have slightly different behaviour.

  • Note: For Macbook M1/M2, you must run this before doing all required steps below:
    softwareupdate --install-rosetta
    export DOCKER_DEFAULT_PLATFORM=linux/amd64

Executing Utility Commands

In order for you to execute other manage.py utility commands through Docker container, just add docker exec -ti SUITC_Backend (add sudo if you're using MAC) in front of your command. Please ensure that the server is indeed running, open another terminal if needed.

For example, to create new migrations you can run:

    docker exec -ti SUITC_Backend python manage.py makemigrations

Testing

Everytime you add new features, please create the appropriate test cases. You can run this command to run all the test cases:

    docker exec -ti SUITC_Backend python manage.py test

Automatic CI testing is enforced everytime a pull request or a push is done to the main branch.

Superuser & Sample Data

Sample data are generated using Django Fixtures. It is used to populate your database (stored in Docker Volumes) with some sample data so that every person do not have to do it on their own manually. You can load the data by opening another terminal and run the command:

    docker exec -ti SUITC_Backend python manage.py loaddata sample_user

Running this command will give you superuser access with the username superuser and password 123. Other sample data can be seen on the fixtures folder (password for other sample user: 1048576#).

Warning: running the command may overwrite some existing data

API Documentation

There are 2 types of documentation provided here:

  • Automatic Documentation using Swagger UI

  • Manual Documentation in the docs app by writing markdown files (stored locally in this repository) (NOTE: this is not available in the live environment yet)

See some of the manual documentations here:

Production Environment

The live server is deployed using AWS Elastic Beanstalk (environment name: Ntusuitcbackendprod-env) here using Python 3.8 running on Linux2 Ver 3.4.3 machine. Current database is stored using EC2 instance using MySQL (RDS is so expensive so we're not using this), static files are stored in S3 buckets. Database and S3 storage related configurations are set up through environment variables in the EB environment. SSL certificate issued through AWS certificate manager, dns using Route 53.

In order to manually type Django manage.py commands, you have to first download AWS EB CLI, then connect via ssh by typing eb ssh Ntusuitcbackendprod-env, enter secret key pair, and finally type these commands referenced here.

    eb ssh
    sudo su -
    export $(cat /opt/elasticbeanstalk/deployment/env | xargs)
    source /var/app/venv/*/bin/activate
    python3 /var/app/current/manage.py <command name>

Important note: every time there are new migrations, please connect via ssh to perform migration in the live server (later please try to automate this process!)

Applications Explanation

Portal

SSO

UFacility

Inventory

Event

Docs

StarsWar

ULocker

Workshop

Communication

Games

UShop

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 13