-
Plan: https://docs.google.com/document/d/1HzEkPgcPmaZr2aXNdBmNr2lR0lxgDbRHEJrFaxJjstc/edit?usp=sharing
-
Documents folder: database and postman collection
- 1. What is this project used for?
- 2. What does this project can do?
- 3. 🚀 What technologies does this project use?
- 4. What is circular dependency?
- 5. How to run this project?
This project is a simple API for managing todo list.
- Create a new task
- Update a task
- Delete a task
- Get all tasks
- Get a task by id
- Get all parent tasks of a task
- Create / Delete a reference between tasks
- Detect a circular dependency in tasks
- Prevent circular dependency when adding new reference
- Periodically check tasks that are about to expire and send email notifications
- NodeJS
- ExpressJS
- MySQL
- Redis
- Nodemailer
- JWT
- Docker
-
Firstly, you can see the image below describe how task reference each other
-
Each task can have multiple parent tasks and multiple child tasks
-
Circular dependency
problem occurs whenTask 3
depends onTask 6
andTask 6
depends onTask 7
andTask 7
depends onTask 3
and... We have now got a circular dependency.😒😒
- Look at the image, we can see that like a graph, where each Node depends on other Nodes.
- So, how to detect it? The idea is when a Node is seen, but it is not resolved yet, we can say that we have a circular dependency.
- For example, we have a graph with path: 3 -> 6 -> 7 -> 3
- Task 3 in the end of path is seen at the top, but it is not resolved yet, because of Task 3 depends on Task 6 and so on.
This is how we can detect it by Pseudocode
function dep_resolve(node, visited, unFinished) {
unFinished.push(node);
for parentNode in node.parents {
if parentNode not in visited {
if parentNode in unFinished {
// we detected circular dependency here
}
dep_resolve(parentNode, visited, unFinished);
}
}
visited.push(node);
unFinished.remove(node);
}
// call function
type Node = {
id: number,
parents: Node[]
}
let firstNode : Node = {
id: ...,
parents: [ ... ]
}
dep_resolve(firstNode, [], []);
- Clone this project
- Create
.env
file in the root directory with following format
APP_PORT= 8000
DB_HOST= localhost (OPTIONAL)
DB_PORT= 3306 (OPTIONAL)
DB_USER= root (OPTIONAL)
DB_PASS= password (OPTIONAL)
DB_NAME= tododb (OPTIONAL)
REDIS_HOST= localhost (OPTIONAL)
REDIS_PORT= 5678 (OPTIONAL)
REDIS_PASSWORD= password (OPTIONAL)
JWT_SECRET_KEY=secret
ACCESS_TOKEN_EXPIRES_IN=1d
EMAIL_USER = your@gmail.com (OPTIONAL)
EMAIL_PASS = 'umtj jklmn mvtg wrnz' (OPTIONAL)
EMAIL_HOST = gmail (OPTIONAL)
- Run the following command:
docker-compose up --build
- Clone this project
- Create
.env
file in the root directory with following format
APP_PORT= 8000
DB_HOST= localhost
DB_PORT= 3306
DB_USER= root
DB_PASS= password
DB_NAME= tododb
REDIS_HOST= localhost
REDIS_PORT= 5678
REDIS_PASSWORD= password
JWT_SECRET_KEY=secret
ACCESS_TOKEN_EXPIRES_IN=1d
EMAIL_USER = your@gmail.com
EMAIL_PASS = 'umtj jklmn mvtg wrnz'
EMAIL_HOST = gmail
- Run the following command:
Step 1: Install dependencies
npm install
Step 2: Run project
Option 1:
npm run dev # for development
Option 2:
npm run build # for build
npm run start # for run bundle code