Welcome to the CryptEdu platform! This document is a complete, beginner-friendly guide to running, updating, and deploying the CryptEdu application.
The project is split into two main parts:
- Frontend: The user interface (React/TypeScript).
- Backend: The server and API (Python/FastAPI).
If you just want to test the app on your computer, follow these steps.
- Open a terminal (Command Prompt, PowerShell, or VS Code terminal).
- Navigate to the backend folder:
cd admin_and_end_user_apps/backend - Install the required Python packages (you only need to do this once):
pip install -r requirements.txt
- Start the server:
The backend is now running at
python main.py
http://localhost:8000.
- Open a new, separate terminal window.
- Navigate to the frontend folder:
cd admin_and_end_user_apps/frontend - Install the required Node packages (you only need to do this once):
npm install
- Start the development server:
The terminal will show a local link (usually
npm run dev
http://localhost:5173). Click it to open the app in your browser!
When you make changes to the React code in frontend/src and want the world to see them, you must deploy the frontend to your AWS S3 bucket.
- In your terminal, go to the frontend folder:
cd admin_and_end_user_apps/frontend - Build the production-ready code:
This creates a
npm run build
distfolder containing the compiled website. - Upload the
distfolder to your AWS S3 bucket using the AWS CLI:(Replaceaws s3 sync dist/ s3://<your-bucket-name> --delete
<your-bucket-name>with the actual name of your S3 bucket).
- Run
npm run buildin thefrontendfolder to generate thedistfolder. - Log in to the AWS Management Console.
- Search for S3 and open the S3 dashboard.
- Click on your bucket name.
- Click Upload, then drag and drop all the files and folders from inside your local
distfolder into the AWS window. - Click Upload at the bottom.
When you update your Python code in the backend/ folder, you need to package it up and upload it to AWS Lambda.
- Open a terminal and navigate to the backend folder:
cd admin_and_end_user_apps/backend - Create a temporary folder to package the dependencies:
mkdir package pip install -r requirements.txt --target ./package
- Zip everything together (this requires
zipto be installed on your system, or you can use a PowerShell equivalent):cd package zip -r ../lambda_function.zip . cd .. zip -g lambda_function.zip main.py config.py seed.py zip -r -g lambda_function.zip engines/ data/
- Upload the zip file to your AWS Lambda function using the AWS CLI:
(Replace
aws lambda update-function-code --function-name <your-lambda-function-name> --zip-file fileb://lambda_function.zip
<your-lambda-function-name>with the actual name of your Lambda function).
AWS Lambda has a strict limit: your unzipped code and libraries cannot exceed 250MB. Because your app uses heavy AI and Data libraries (scikit-learn, numpy, openai-whisper, PyMuPDF), the unzipped size easily exceeds 500MB.
The Solution: AWS Lambda allows you to upload Docker Container Images up to 10GB! I have already created a Dockerfile for you in the backend/ folder. Here is how to use it:
- Install Docker: Download and install Docker Desktop on your computer and make sure it is running.
- Log in to AWS ECR: Open your terminal and log into Amazon Elastic Container Registry (ECR). Replace
<region>and<account-id>with yours:aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com
- Create a Repository in AWS:
aws ecr create-repository --repository-name cryptedu-backend --region <region>
- Build the Docker Image: Run this inside your
admin_and_end_user_apps/backendfolder:docker build -t cryptedu-backend . - Tag the Image for AWS:
docker tag cryptedu-backend:latest <account-id>.dkr.ecr.<region>.amazonaws.com/cryptedu-backend:latest
- Push the Image to AWS:
docker push <account-id>.dkr.ecr.<region>.amazonaws.com/cryptedu-backend:latest
- Create the Lambda Function:
- Go to the AWS Lambda Console.
- Click Create function.
- Select Container image (instead of "Author from scratch").
- Name the function
CryptEdu-Backend. - Under Container Image URI, click Browse images, select your
cryptedu-backendrepository, and pick thelatestimage. - Click Create function.
From here, proceed to Step C and Step D below to expose the URL and set environment variables!
If you have already hosted your frontend on S3 but need to point it to your new AWS Lambda backend, you need your API URL:
- Open the AWS Lambda Console and click on your function.
- In the Configuration tab, click Function URL on the left menu.
- If you haven't created one, click Create function URL (Choose "NONE" for Auth type, and check "Configure cross-origin resource sharing (CORS)").
- Copy the Function URL (it looks like
https://xyz.lambda-url.us-east-1.on.aws/). - Open your
frontend/.env.productionfile and set it:VITE_API_URL=https://xyz.lambda-url.us-east-1.on.aws
- Re-run
npm run buildin your frontend and upload the newdist/folder to your S3 bucket!
By default, the backend uses a local SQLite database (cryptedu.db). When running on AWS Lambda, local files are deleted after execution, meaning your database will reset constantly.
To fix this while keeping the same encryption/login logic and retaining the mocked roshi user, you should use Supabase (a cloud PostgreSQL database with a generous free tier) or AWS DynamoDB.
The CryptEdu backend is already wired to sync data to Supabase!
- Go to Supabase and create a free project.
- Get your Project URL and API Key.
- In your AWS Lambda console, go to Configuration > Environment variables.
- Add these variables:
SUPABASE_URL: (Your Supabase URL)SUPABASE_KEY: (Your Supabase anon key)SUPABASE_ENABLED:True
- How it works: The backend will automatically write to Supabase when hosted. For local development, it will continue using SQLite if those environment variables are absent.
If you must strictly keep the SQLite file and stay 100% within AWS:
- Create an AWS EFS file system.
- Attach it to your Lambda function (in Configuration > File systems).
- Set the Local mount path to
/mnt/efs. - Add an Environment Variable in Lambda:
DB_PATH=/mnt/efs/cryptedu.db. - How it works: Lambda will use the persistent EFS drive to store your SQLite file. The encryption and login logic remains identical, and it requires zero changes to the application code.
To save your code online so you don't lose it, you push it to GitHub.
- Open a terminal in the root folder of your project (where this README is located).
- Add all your changes to the staging area:
git add . - Save (commit) your changes with a descriptive message:
git commit -m "Describe what you changed here" - Push the changes to GitHub:
(If your main branch is called
git push origin main
master, usegit push origin masterinstead).
- Open VS Code and click on the Source Control icon on the left sidebar (it looks like a branch with circles).
- You will see a list of files you changed. Hover over the word Changes and click the
+icon to stage all changes. - In the text box at the top, type a message describing what you did (e.g., "Updated README and Help Page").
- Click the Commit button.
- Finally, click the Sync Changes button (or "Push") that appears to send your code to GitHub.
If you are an admin or end-user of the application, please refer to the Help page within the application itself for a detailed breakdown of how to use every feature in the platform!