Law and Grace form a cycle in the bible. Law drives us to Grace. We know we need grace because of law.
Grace teaches us to love and follow law. We cannot separate the two.
Law without grace is legalism. In fact law increases sin. It is only grace which gives the power to keep the law.
The bible mainly bases law on grace although sometimes the direction is law which drives us to grace.
The power to follow the law is grace. The law has no ability apart from grace.
We must first trust in Christ’s righteousness and then only then try to follow the works the bible has for us to do.