Tropicode-Guam / gymjim

Gym Class 2-Sided App: Members and Admin
0 stars 0 forks source link

Prereqs

  1. Setup a domain for your server
    • Purchase a domain.
    • Ensure your server has a static IP
    • Create an A record mapping the ip to the domain
  2. Setup network and server
    • Ensure ports 80 and 443 are open to the internet
  3. Install prereqs
  4. Setup repository
    • Clone this repo
      • navigate to the desired project location in your server via your terminal
      • run git clone https://github.com/Tropicode-Guam/gymjim
    • Create settings files
      • Create a .env file
        • copy .env.sample and name it .env
        • fill in all the environment variables
      • in the frontend/settings folder, create general.json and insurances.json files matching their example formats: general.sample.json and insurances.sample.json (read more about settings below)

Deployment

docker compose up -d --build

* note: this docker-compose.yml was made with docker rootless mode in mind. If you are running this in root mode (the default), you might need to start it by first unsetting the XDG_RUNTIME_DIR environment variable like so: unset XDG_RUNTIME_DIR && docker-compose up -d --build

Development

docker compose -f docker-compose.dev.yml up --build

Architecture

graph TD
    linkStyle default interpolate basis
    user((user))---|internet:443|nginx
    letsencrypt---|internet:80|nginx
    subgraph server [your server: www.example.com]
      subgraph docker [docker containers]
        subgraph network [nginx: proxy-network]
          nginx---frontend
          nginx---api
          nginx---certbot
          frontend[Frontend]
          certbot[[Certbot]]
          api[Backend API]
        end
        subgraph db [db network: db]
          mongo[(mongodb<br>gym_classes_db)]
          api[Backend API]---|shared db network|mongo
        end
        certbot---certs([gymjim_certs])
        nginx---certs
      end
      frontend---settings{{frontend/settings}}
      mongo---data{{db/data}}
    end

Settings & Configs

.env file

color_palette.json file

This file adjusts the colors of the class cards. You can add as many colors as you'd like in the format of hexidecimal colors. If you'd like to stick with the defaults, you can just copy paste the color_palette.sample.json file into this one.

general.json file

The Fee Message setting replaces all occurances of {FEE} with the fee for that particular class. For example if the setting was Pay {FEE} dollars at the gate., then the message would be Pay 5.00 dollars at the gate. assuming the class has a fee of 5.00.

insurances.json file

This file is broken into 2 sections, the Insurances section and the Sponsors section.

Insurances section

The options listed here will show up on the signup form in the insurance dropdown list. Selecting an insurance other than Other/None will cause a new field to appear. This field will by default say Insurance Member ID. If you would like to change what that field says for a particular insurance option, change the option to this format:

{
  "name": "Insurance Name",
  "id_name": "Appeared Field Name"
}

name should be the insurance name and id_name should be the text you want to replace Insurance Member ID with.

Sponsors section

The options listed here will show up on the Sponsors dropdown in the admin menu when creating a new class. If a class is sponsored by the same insurance that the user signing up chooses as their insurance, they can take the class for free. Note that the insurance names in the Insurances list and the Sponsors list need to be exactly the same for this to be the case.

If you want a particular sponsor to make multiple insurances choices free for the user, use the following format:

{
  "name": "Insurance Name",
  "also_free_for": "Other Insurance Name"
},

name should be the sponsor name and also_free_for should be the name of the other insurance that will be free if chosen by the user. Note that this allows you to have more control in what shows up as the sponsor, for example you could make the name be TakeCare and Triple J and make also_free_for be TakeCare, allowing users of TakeCare to sign up for free.

also_free_for can also be a list of other insurance names like so:

{
  "name": "Paradise Fitness",
  "also_free_for": [
    "TakeCare", 
    "Calvo's SelectCare"
  ]
}

If a class is sponsored by this sponsor, users of any of these insurances get in free.

Finally, also_free_for can also be the special value all. A class doesn't need to be sponsored by this insurance for users to get into any class by choosing this insurance. This can be used in conjunction with the Insurances list to for example make all Hotel Guest "insurances" free. Here is an example configuration showing how to do so:

{
    "Insurances": [
        ...
        {
            "name": "Hotel Guest",
            "id_name": "Room Number"
        }
    ],
    "Sponsors": [
        ...
        {
            "name": "Hotel Guest",
            "also_free_for": "all"
        }
    ]
}

Logs & Troubleshooting

Logs

You can access the logs by using the command docker compose logs (check out the docs for more detailed options)

If you suspect a problem with a certain portion of the app, you can use docker compose logs followed by one of the short service names below:

frontend
backend
db
nginx
certbot

Database

The Database is stored in the db/data folder, so if you'd like to make backups, do so by copying that directory.

If you'd like to execute queries on the database, you can open a shell to it using the following command for production (deployment):

source .env && docker exec -it gym_classes_db mongosh -u $DB_USER -p $DB_PASSWORD production

or this command for development:

source .env && docker exec -it gym_classes_db mongosh -u $DB_USER -p $DB_PASSWORD development

The database used is MongoDB version 7.0.3. You can find docs for the mongosh shell here.