This is a Next.js project bootstrapped with create-next-app.
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.
This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.
Welcome to the Secure Health Record Encryption System, a final-year Computer Science BSc project designed to provide a secure platform for encrypting and decrypting health records using the AES-256 algorithm. This application is tailored for small clinics to manage sensitive patient data securely. This README provides a step-by-step guide to set up, run, and understand the project.
- Project Overview
- Prerequisites
- Environment Setup
- Dependencies Installation
- Database Installation and Connection
- Running the Project
- Testing the Application
- How Uploads Work
- Project Workflow
- Troubleshooting
- Contributing
- License
This project is a web-based application built with Next.js (frontend) and FastAPI (backend) to:
- Encrypt health records using AES-256 encryption.
- Store encrypted files in a MySQL database.
- Allow users to decrypt and download files in .docx or .pdf format.
- Provide a user-friendly dashboard with educational content and activity tracking.
The system is designed for clinic staff, ensuring data confidentiality and usability. It includes features like user authentication, file upload/decryption, and a modern UI.
Before setting up the project, ensure you have the following installed on your system:
- Node.js (v18 or later) - Download
- Python (v3.9 or later) - Download
- MySQL Server (v8.0 or later) - Download
- Git - Download
- A code editor (e.g., VS Code)
- Basic knowledge of command-line operations
- Clone the Repository:
git clone https://github.com/your-username/health-record-encryption.git cd health-record-encryption
Create a Virtual Environment (Python):On Windows:
python -m venv venv venv\Scripts\activate
Install Frontend and Backend Dependencies (see below).
Navigate to the backend directory:
- cd backend
Install required Python packages:
- pip install -r requirements.txt
If requirements.txt doesn’t exist, create it with the following content and run the install command:
- fastapi
- uvicorn
- sqlalchemy
- mysql-connector-python
- python-jose[cryptography]
- python-multipart
- pycryptodome
- python-docx
- reportlab
- Navigate to the frontend directory:
- cd frontend
- Install required Node.js packages:
- npm install
Ensure the following dependencies are included (add to package.json if missing):
- react-slick
- slick-carousel
- @radix-ui/react-tabs
- @shadcn/ui (install via npx shadcn-ui@latest add [component])
Install MySQL
- Install MySQL Server and set up a database.
- Create a database named health_records:
- CREATE DATABASE health_records;
- Open backend/app/database.py.
- Update the database URL with your MySQL credentials:
- SQLALCHEMY_DATABASE_URL = "mysql+mysqlconnector://:@localhost:3306/health_records"
Replace and with your MySQL username and password (e.g., root and your password). 3. Ensure the database tables are created automatically when the backend starts (handled by SQLAlchemy).
- Start the Backend: Activate the virtual environment (if not already active). Navigate to the backend directory and run:
- uvicorn app.main:app --host 127.0.0.1 --port 8000 --reload
The backend will be available at http://127.0.0.1:8000.
- Start the Frontend:
Navigate to the frontend directory and run:
- npm run dev
The frontend will be available at http://localhost:3000.
- Access the Application: Open your browser and go to http://localhost:3000.
Register a new user (e.g., username: devintel, password: devintel, role: admin) or log in with existing credentials.
-
Registration and Login: Navigate to http://localhost:3000/register, create a user, and log in at http://localhost:3000/login.
-
File Upload: Go to the “Encrypt Files” tab on the dashboard.
Upload a small .txt or .docx file (e.g., test.txt).
Check the sidebar for an activity log entry (e.g., “Uploaded file: test.txt”).
- File Listing and Decryption: Navigate to the “Decrypt Files” tab. Verify the uploaded file appears in the list. Click “Decrypt” and download as .docx or .pdf.
Large File Upload: Test with a larger .docx file (e.g., 1MB) to ensure the LONGBLOB storage works. Error Handling: Try uploading an invalid file type or accessing the dashboard without logging in (should redirect to /login).
- Process: Users select a file (e.g., .txt, .docx) via the “Encrypt Files” tab.
The frontend sends the file to the /files/upload endpoint using a POST request with multipart/form-data.
Reads the file content. Generates a random AES-256 key and IV (initialization vector). Encrypts the file using AES in CBC mode. Stores the encrypted data, IV, and key in the files table of the MySQL database.
-
Storage: Encrypted data is stored as a LONGBLOB to handle large files. The filename, user ID, IV, and encryption key are also saved for decryption.
-
Security: Encryption ensures data confidentiality. User authentication restricts access to authorized users only.