Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/team3-10-child-therapy-database.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 74 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Spring 2025 CS 3200 Project Template Repository

This repo is a template for your semester project. It includes most of the infrastructure setup (containers), sample databases, and example UI pages. Explore it fully and ask questions!
This repo is a template for your semester project. It includes most of the infrastructure setup (containers), sample
databases, and example UI pages. Explore it fully and ask questions!

## Overview

Our project is a Child Therapist Database built around our five personas: a therapist, an art therapist specialist, a child, a guardian, and an art therapist specialist. We incorporated numerous attributes with these entities, including phone numbers, emails, names, and unique identifiers. Our database's purpose is to assist matching virtual children with therapists based on their individual art preferences, chronic conditions, personality traits, and context-aware replies.

## Prerequisites

Expand All @@ -19,67 +24,107 @@ Currently, there are three major components that will each run in their own Dock

## Suggestion for Learning the Project Code Base

If you are not familiar with web app development, this code base might be confusing. But don't worry, it's not that bad. Here are some suggestions for learning the code base:
If you are not familiar with web app development, this code base might be confusing. But don't worry, it's not that bad.
Here are some suggestions for learning the code base:

1. Have two versions of the template repo - one for you to individually explore and lear and another for the team's project implementation.
1. Start by exploring the `./app` directory. This is where the Streamlit app is located. The Streamlit app is a Python-based web app that is used to interact with the user. It's a great way to build a simple web app without having to learn a lot of web development.
1. Next, explore the `./api` directory. This is where the Flask REST API is located. The REST API is used to interact with the database and perform other server-side tasks.
1. Finally, explore the `./database-files` directory. This is where the SQL scripts are located that will be used to initialize the MySQL database.
1. Have two versions of the template repo - one for you to individually explore and lear and another for the team's
project implementation.
1. Start by exploring the `./app` directory. This is where the Streamlit app is located. The Streamlit app is a
Python-based web app that is used to interact with the user. It's a great way to build a simple web app without
having to learn a lot of web development.
1. Next, explore the `./api` directory. This is where the Flask REST API is located. The REST API is used to interact
with the database and perform other server-side tasks.
1. Finally, explore the `./database-files` directory. This is where the SQL scripts are located that will be used to
initialize the MySQL database.

### Setting Up Your Personal Repo

1. In GitHub, click the **fork** button in the upper right corner of the repo screen.
1. When prompted, give the new repo a unique name, perhaps including your last name and the word 'personal'.
1. Once the fork has been created, clone YOUR forked version of the repo to your computer.
1. Set up the `.env` file in the `api` folder based on the `.env.template` file.
1. For running the testing containers (for your personal repo), you will tell `docker compose` to use a different configuration file named `docker-compose-testing.yaml`.
1. `docker compose -f docker-compose-testing.yaml up -d` to start all the containers in the background
1. `docker compose -f docker-compose-testing.yaml down` to shutdown and delete the containers
1. `docker compose -f docker-compose-testing.yaml up db -d` only start the database container (replace db with api or app for the other two services as needed)
1. `docker compose -f docker-compose-testing.yaml stop` to "turn off" the containers but not delete them.
1. For running the testing containers (for your personal repo), you will tell `docker compose` to use a different
configuration file named `docker-compose-testing.yaml`.
1. `docker compose -f docker-compose-testing.yaml up -d` to start all the containers in the background
1. `docker compose -f docker-compose-testing.yaml down` to shutdown and delete the containers
1. `docker compose -f docker-compose-testing.yaml up db -d` only start the database container (replace db with api
or app for the other two services as needed)
1. `docker compose -f docker-compose-testing.yaml stop` to "turn off" the containers but not delete them.

### Setting Up Your Team's Repo

**Before you start**: As a team, one person needs to assume the role of _Team Project Repo Owner_.

1. The Team Project Repo Owner needs to fork this template repo into their own GitHub account **and give the repo a name consistent with your project's name**. If you're worried that the repo is public, don't. Every team is doing a different project.
1. In the newly forked team repo, the Team Project Repo Owner should go to the **Settings** tab, choose **Collaborators and Teams** on the left-side panel. Add each of your team members to the repository with Write access.
1. The Team Project Repo Owner needs to fork this template repo into their own GitHub account **and give the repo a name
consistent with your project's name**. If you're worried that the repo is public, don't. Every team is doing a
different project.
1. In the newly forked team repo, the Team Project Repo Owner should go to the **Settings** tab, choose **Collaborators
and Teams** on the left-side panel. Add each of your team members to the repository with Write access.

**Remaining Team Members**

1. Each of the other team members will receive an invitation to join. Obviously accept the invite.
1. Once that process is complete, each team member, including the repo owner, should clone the Team's Repo to their local machines (in a different location your Personal Project Repo).
1. Once that process is complete, each team member, including the repo owner, should clone the Team's Repo to their
local machines (in a different location your Personal Project Repo).
1. Set up the `.env` file in the `api` folder based on the `.env.template` file.
1. For running the testing containers (for your team's repo):
1. `docker compose up -d` to start all the containers in the background
1. `docker compose down` to shutdown and delete the containers
1. `docker compose up db -d` only start the database container (replace db with api or app for the other two services as needed)
1. `docker compose stop` to "turn off" the containers but not delete them.
1. `docker compose up -d` to start all the containers in the background
1. `docker compose down` to shutdown and delete the containers
1. `docker compose up db -d` only start the database container (replace db with api or app for the other two
services as needed)
1. `docker compose stop` to "turn off" the containers but not delete them.

**Note:** You can also use the Docker Desktop GUI to start and stop the containers after the first initial run.

## Handling User Role Access and Control

In most applications, when a user logs in, they assume a particular role. For instance, when one logs in to a stock price prediction app, they may be a single investor, a portfolio manager, or a corporate executive (of a publicly traded company). Each of those _roles_ will likely present some similar features as well as some different features when compared to the other roles. So, how do you accomplish this in Streamlit? This is sometimes called Role-based Access Control, or **RBAC** for short.
In most applications, when a user logs in, they assume a particular role. For instance, when one logs in to a stock
price prediction app, they may be a single investor, a portfolio manager, or a corporate executive (of a publicly traded
company). Each of those _roles_ will likely present some similar features as well as some different features when
compared to the other roles. So, how do you accomplish this in Streamlit? This is sometimes called Role-based Access
Control, or **RBAC** for short.

The code in this project demonstrates how to implement a simple RBAC system in Streamlit but without actually using user authentication (usernames and passwords). The Streamlit pages from the original template repo are split up among 3 roles - Political Strategist, USAID Worker, and a System Administrator role (this is used for any sort of system tasks such as re-training ML model, etc.). It also demonstrates how to deploy an ML model.
The code in this project demonstrates how to implement a simple RBAC system in Streamlit but without actually using user
authentication (usernames and passwords). The Streamlit pages from the original template repo are split up among 3
roles - Political Strategist, USAID Worker, and a System Administrator role (this is used for any sort of system tasks
such as re-training ML model, etc.). It also demonstrates how to deploy an ML model.

Wrapping your head around this will take a little time and exploration of this code base. Some highlights are below.

### Getting Started with the RBAC

1. We need to turn off the standard panel of links on the left side of the Streamlit app. This is done through the `app/src/.streamlit/config.toml` file. So check that out. We are turning it off so we can control directly what links are shown.
1. Then I created a new python module in `app/src/modules/nav.py`. When you look at the file, you will se that there are functions for basically each page of the application. The `st.sidebar.page_link(...)` adds a single link to the sidebar. We have a separate function for each page so that we can organize the links/pages by role.
1. Next, check out the `app/src/Home.py` file. Notice that there are 3 buttons added to the page and when one is clicked, it redirects via `st.switch_page(...)` to that Roles Home page in `app/src/pages`. But before the redirect, I set a few different variables in the Streamlit `session_state` object to track role, first name of the user, and that the user is now authenticated.
1. Notice near the top of `app/src/Home.py` and all other pages, there is a call to `SideBarLinks(...)` from the `app/src/nav.py` module. This is the function that will use the role set in `session_state` to determine what links to show the user in the sidebar.
1. The pages are organized by Role. Pages that start with a `0` are related to the _Political Strategist_ role. Pages that start with a `1` are related to the _USAID worker_ role. And, pages that start with a `2` are related to The _System Administrator_ role.
1. We need to turn off the standard panel of links on the left side of the Streamlit app. This is done through the
`app/src/.streamlit/config.toml` file. So check that out. We are turning it off so we can control directly what links
are shown.
1. Then I created a new python module in `app/src/modules/nav.py`. When you look at the file, you will se that there are
functions for basically each page of the application. The `st.sidebar.page_link(...)` adds a single link to the
sidebar. We have a separate function for each page so that we can organize the links/pages by role.
1. Next, check out the `app/src/Home.py` file. Notice that there are 3 buttons added to the page and when one is
clicked, it redirects via `st.switch_page(...)` to that Roles Home page in `app/src/pages`. But before the redirect,
I set a few different variables in the Streamlit `session_state` object to track role, first name of the user, and
that the user is now authenticated.
1. Notice near the top of `app/src/Home.py` and all other pages, there is a call to `SideBarLinks(...)` from the
`app/src/nav.py` module. This is the function that will use the role set in `session_state` to determine what links
to show the user in the sidebar.
1. The pages are organized by Role. Pages that start with a `0` are related to the _Political Strategist_ role. Pages
that start with a `1` are related to the _USAID worker_ role. And, pages that start with a `2` are related to The
_System Administrator_ role.

## (VERY Optional) Adding an ML Model to your App

_Note_: This project only contains the infrastructure for a hypothetical ML model.

1. Build, train, and test your ML model in a Jupyter Notebook.
1. Once you're happy with the model's performance, convert your Jupyter Notebook code for the ML model to a pure python script. You can include the `training` and `testing` functionality as well as the `prediction` functionality. You may or may not need to include data cleaning, though.
1. Check out the `api/backend/ml_models` module. In this folder, I've put a sample (read _fake_) ML model in `model01.py`. The `predict` function will be called by the Flask REST API to perform '_real-time_' prediction based on model parameter values that are stored in the database. **Important**: you would never want to hard code the model parameter weights directly in the prediction function. tl;dr - take some time to look over the code in `model01.py`.
1. The prediction route for the REST API is in `api/backend/customers/customer_routes.py`. Basically, it accepts two URL parameters and passes them to the `prediction` function in the `ml_models` module. The `prediction` route/function packages up the value(s) it receives from the model's `predict` function and send its back to Streamlit as JSON.
1. Back in streamlit, check out `app/src/pages/11_Prediction.py`. Here, I create two numeric input fields. When the button is pressed, it makes a request to the REST API URL `/c/prediction/.../...` function and passes the values from the two inputs as URL parameters. It gets back the results from the route and displays them. Nothing fancy here.
1. Once you're happy with the model's performance, convert your Jupyter Notebook code for the ML model to a pure python
script. You can include the `training` and `testing` functionality as well as the `prediction` functionality. You may
or may not need to include data cleaning, though.
1. Check out the `api/backend/ml_models` module. In this folder, I've put a sample (read _fake_) ML model in
`model01.py`. The `predict` function will be called by the Flask REST API to perform '_real-time_' prediction based
on model parameter values that are stored in the database. **Important**: you would never want to hard code the model
parameter weights directly in the prediction function. tl;dr - take some time to look over the code in `model01.py`.
1. The prediction route for the REST API is in `api/backend/customers/customer_routes.py`. Basically, it accepts two URL
parameters and passes them to the `prediction` function in the `ml_models` module. The `prediction` route/function
packages up the value(s) it receives from the model's `predict` function and send its back to Streamlit as JSON.
1. Back in streamlit, check out `app/src/pages/11_Prediction.py`. Here, I create two numeric input fields. When the
button is pressed, it makes a request to the REST API URL `/c/prediction/.../...` function and passes the values from
the two inputs as URL parameters. It gets back the results from the route and displays them. Nothing fancy here.
File renamed without changes.
14 changes: 14 additions & 0 deletions api/backend/rest_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
import os
from dotenv import load_dotenv

from backend.therapy.trainingSupervisor_routes import supervisors
from backend.therapy.therapist_routes import therapists
from backend.therapy.guardian_routes import guardians
from backend.therapy.specialist_routes import specialists
from backend.therapy.child_routes import children
from backend.therapy.artTherapy_routes import artTherapies

def create_app():
app = Flask(__name__)

Expand Down Expand Up @@ -43,6 +50,13 @@ def create_app():
app.register_blueprint(customers, url_prefix='/c')
app.register_blueprint(products, url_prefix='/p')

app.register_blueprint(supervisors)
app.register_blueprint(therapists)
app.register_blueprint(guardians)
app.register_blueprint(specialists)
app.register_blueprint(children)
app.register_blueprint(artTherapies)

# Don't forget to return the app object
return app

Loading