PageTalk (Backend)
Welcome to the backend of the PageTalk project. PageTalk allows users to upload PDFs and receive summaries, along with query-based responses.
Tech Stack:
- ExpressJS
- TypeScript
- Docker
- Firebase Cloud Storage
Technologies Used:
- JWT: For secure header authentication and verification
- bcrypt: For password storage and retrieval
- body-parser and url-encoded: Middleware for parsing request bodies
Tables:
- Users
- Query
- PDF
- Admin
- Collection
- Interaction
Routes:
- User:
/user/login
(POST: Login User)
/user/:username
(POST: Create User, GET: Retrieve User, PATCH: Update User)
- Query:
/query/:pdfID
(POST: Create Query, GET: Retrieve Query by Username and PDF)
/query/:queryID
(GET: Retrieve Query by ID, PATCH: Update Query by ID, DELETE: Delete Query by ID)
- PDF:
/pdf/
(POST: Create PDF)
/pdf/:pdfID
(GET: Retrieve PDF by ID)
Try it yourself:
- Clone the repository:
git clone https://github.com/PageTalk/Backend.git
- Configure your environment variables as in the
.env.example
file
- Configure the docker-compose file on your end
- Open a terminal, CD to this folder, and run
docker-compose up -d
- Start the docker container, then create the tables as mentioned in the
database/init.sql
file.
- Run
npm start
- Your application is now running.
Database Diagram:
Starting
Start the docker container, then run
docker exec -it pagetalk-mysql-container bash
To start a MySQL server, run
mysql -u root -p
Enter password: 1234
Troubleshooting
In case of SQL Connection error
Run the following command in the MySQL server
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '1234';
Note: Server is running on port 3306 so add the port to the dbconfig while creating a connection.
If connection still fails
If the connection still fails, go into the MySQL Container files, look for etc/my.cnf
config file, and set port to 3306.
// my.cnf
---- previous code
port=3306
---- rest of the code
How JWT Works
How JWT is used
Credits: GeeksForGeeks
How to use JWT
- User sends a POST request to the server with username and password
- Server checks if the username and password are correct
- If correct, the server creates a JWT token and sends it back to the user
- User stores the JWT token in the local storage
- User sends the JWT token in the header of every request
- Server checks if the JWT token is valid
- If valid, the server sends the response back to the user