Getting Started - shleen/threadline GitHub Wiki

How to build and run threadline

threadline is an iOS app, with a Django backend. So, we do all of our development on a Macbook and assume the same of you, dear reader.

For all three of the following sections, you'll need a copy of the repo. Clone it using git clone [email protected]:shleen/threadline.git. The following steps will assume that your current directory is in ./threadline/

Frontend

  1. If you do not have Xcode installed yet, install it.
  2. Clone the repo git clone [email protected]:shleen/threadline.git
  3. Open the folder threadline/app in Xcode
  4. Run in your chosen simulator or device by clicking the play button or using Cmd + R

Backend

  1. cd into the backend directory cd threadline/backend
  2. Create a virtual environment, ensure the virtual environment activation file is executable, and activate the virtual environment.
    python -m venv venv
    chmod +x ./venv/bin/activate
    
    # for bash and zsh, see https://docs.python.org/3/library/venv.html#how-venvs-work for other shells
    source venv/bin/activate
  3. Install requirements pip install -r requirements.txt
  4. Run the server python manage.py runserver
  5. [Optional] Configure systemd service
    [Unit]
    Description=Threadline Backend
    Requires=postgresql.service
    After=network.target
    StartLimitIntervalSec=0
    
    [Service]
    Type=simple
    Restart=on-failure
    RestartSec=1
    User=<YOUR_USER>
    Group=<YOUR_GROUP>
    WorkingDirectory=<BACKEND_DIR>
    ExecStart=<BACKEND_DIR>/venv/bin/python <BACKEND_DIR>/manage.py runserver
    
    [Install]
    WantedBy=multi-user.target
    

Tips!

  1. Once you're running the backend, you can test the endpoints using HTTPie or Postman, or cURL. For example, you can send a POST request to /clothing/create using HTTPie with http -f POST http://127.0.0.1:8000/clothing/create username=sheline type=shirt fit=loose occasion=casual winter=0 image@~/Desktop/shirt.png

Cloudflare R2 (File storage)

  1. Sign up for a Cloudflare account

  2. Navigate to the R2 dashboard, and create a bucket called threadline-clothing.

  3. From the 'Overview' page, click on this API button

    image
  4. Click 'Manage API tokens' and create an API Token with 'Object Read & Write' permission.

  5. Take note of the ACCESS_KEY_ID and the SECRET_ACCESS_KEY

  6. Paste these two values into threadline/backend/blank.env

  7. Rename blank.env to .env. Gitignore should already take care of this, but remember to not commit this file to Github.

  8. Navigate back to your R2 bucket. Navigate to the Settings page, and copy the value in S3 API.

  9. In threadline/backend/apps/core/images.py, replace the endpoint_url parameter with the value you copied below. Remove everything after the / in the URL.

PostgreSQL Database

  1. cd into the backend directory cd threadline/backend
  2. Install PostgreSQL if you do not have it installed. Recommended to use the interactive installer from this page
  3. If you've already created a virtual environment, activate it source venv/bin/activate.
    If not, create and activate a virtual environment by following the steps in step 2 of the above Backend section
  4. Install Psycopg, a PostgreSQL adapter for Python pip install "psycopg[binary]"
  5. Create a database called threadline_db
    1. You can do this by either opening pgAdmin, logging in, and right clicking on 'Databases' in the left sidebar menu, then 'Create'
    2. or through the cli using
      /Library/PostgreSQL/17/scripts/runpsql.sh
      create database threadline_db;
      exit;
  6. Create a .pg_service.conf file to tell Django how to look for the database. Replace USER and PASSWORD with your PostgreSQL user and password.
    cat << EOF >> ~/.pg_service.conf
    [db_service]
    host=localhost
    dbname=threadline_db
    user=USER
    password=PASSWORD
    port=5432
    EOF
  7. Run migrations for the database
    python manage.py makemigrations
    python manage.py migrate
  8. [Optional] Seed data! If you want to populate the db with dummy data that you can actually use, run python manage.py seed_data

3rd-party tools, libraries, SDKs, and APIs used

Libraries:

APIs:

⚠️ **GitHub.com Fallback** ⚠️