This is a Flask-based API for managing therapy client cases in a mental health institute. The API includes features for user authentication, role management, and case management using JWT tokenization for secure authentication. SQLite is used for storing user credentials and case data. The backend is deployed publicly and is testable via Postman.
- User Authentication
- POST /auth/register: Register a clinician with a username and password (Role: Junior by default).
- POST /auth/login: Authenticate a clinician and return a JWT token for session management.
- Role Management
- POST /auth/promote: Promote a clinician from "Junior" to "Senior" with a valid username and password.
- POST /auth/demote: Demote a clinician from "Senior" to "Junior".
- Therapy Case Management
- GET /cases/cases: Fetch the list of all therapy cases.
- POST /cases/case: Add a new therapy case.
- DELETE /cases/case/ :Delete the therapy case by added user
- JWT Authentication
- app.py: The main entry point of the application, initializes the Flask app, sets up the blueprints, and starts the app.
- routes/: Contains the blueprints for authentication and case management, each in their respective files.
- db.py: Handles database connection and setup. This file contains the logic for connecting to the SQLite3 database and initializing the tables using SQL queries from setup_db.sql.
- models.py: Contains classes that represent database models (User and Case), with methods for interacting with the database (e.g., adding users or retrieving cases).
- jwt_util.py: Provides functions for generating and decoding JWT tokens and retrieving the user ids of current login users.
- wrapper.py: Defines the token_required decorator, ensuring that routes requiring authentication are protected.
- build.sh /vercel.json:Use for the deployment using vercel.
- .env : use to define secret key that used for authentication
- Clone the Repository
git clone https://github.com/pathu11/Therapy-Management-System.git
cd Therapy-Management-System
- Install Dependencies
python3 -m venv venvvenv\Scripts\activate # on windowspip install -r requirements.txt- Generate the Secret Key
Before running the application, you need to generate a secret key for JWT token signing.
- Navigate to the project directory and run config.py .
python config.py- Copy that generated key from terminal and create .env file like below.
SECRET_KEY=your_generated_secret_key- Or you can create a SECRET_KEY manually .
- Modify app.py to work locally (replace 'app = create_app()' with this code segment )
# Local development environment condition
if __name__ == '__main__':
app = create_app()
app.run(debug=True) # Will run on http://127.0.0.1:5000- Adjust database file location:For Deployment, Database file (mental_health.db) located in /tmp Location .But for the local development, you can change that location to be relatively in the models/db.py function.
- Running Locally: For local development, users will run
python app.py, and the application will be accessible athttp://127.0.0.1:5000.
python app.pyThe server will start running, typically on http://127.0.0.1:5000
- Deployment on Vercel: For deployment, Vercel takes care of the serverless deployment, so you don't need the
if __name__ == '__main__':block in your deployed version. This block is just for local development.
- Register a New User:
- Method: POST
- URL: http://127.0.0.1:5000/auth/register
- Body:
{
"fullname":"new user name".
"username": "newuser",
"password": "newpassword"
}- Login as already registered user:
- Method: POST
- URL: http://127.0.0.1:5000/auth/login
- Body:
{
"username": "user name",
"password": "user's password"
}- Response(success):
{
"token": "your_jwt_token_here"
}- Promote an user from Senior to Junior:
- Method: POST
- URL: http://127.0.0.1:5000/auth/promote
- Body:
{
"username": "user name",
"password": "user's password"
}- Headers: Authorization: Bearer your_jwt_token_here
- Demote an user from Junior to Senior:
- Method: POST
- URL: http://127.0.0.1:5000/auth/demote
- Body:
{
"username": "user name",
"password": "user's password"
}- Headers: Authorization: Bearer your_jwt_token_here
- Get All Therapy Cases:
- Method: GET
- URL: http://127.0.0.1:5000/cases/cases
- Headers: Authorization: Bearer your_jwt_token_here
- Add a New Case:
- Method: POST
- URL: http://127.0.0.1:5000/cases/case
- Body:
{
"name": "John Doe",
"description": "A 35-year-old man with depression and difficulty focusing at work."
}
- Headers: Authorization: Bearer your_jwt_token_here
- Delete the case by added user(It can be deleted only by added user):
- Method: DELETE
- URL: http://127.0.0.1:5000/cases/case/<case_id>
- Headers: Authorization: Bearer your_jwt_token_here
- Make sure you have linked your project to GitHub.
- Go to the Vercel Dashboard, create a new project, and
- link it to your GitHub repository.
- Vercel will automatically detect the Flask app and deploy it as a serverless function.
- After deployment, you'll get a public URL for the API, which you can share with others for testing.
GitHub Pages is designed for hosting static websites and cannot run server-side code like Flask. In contrast, Vercel is built for deploying dynamic, serverless applications, including Flask APIs. Vercel handles server setup, scaling, and deployment, making it the ideal choice for hosting a Flask API with full backend support.
This backend has been deployed using Vercel. You can access and test the API using the following link: Mental Health Therapy API on Vercel
Thank you for reviewing this API. If you have any questions or feedback, feel free to reach out:
- Email : pathuahinsa2001@gmail.com