Extending lammps by calling as shared lib

I want to build a code where lammps is called as a shared library. Here I would like to pull lammps from github to use latest version automatically and build it as shared lib every time I build my own code.

When one wants to add new fix into the lammps, one can put those relevant .h and .cpp files within lammps/src/ directory and build it from makefile.

My difficulty comes when I plan to implement a new custom fix in my own code as if it is part of the lammps itself i.e. by not keeping those fix files in lammps/src/ but in our own code/ directory. The new fix name should get accepted from the input script as if it is part of default lammps. I am aware that this is not appropriate coding method for this but I just want to know the best possible way to keep my changes totally separate from lammps main code when using all possible internal lammps functions/variables.

To do what you describe, you need to build your custom fix as a plugin.
Please see:

For examples of plugins that are external to LAMMPS, please see: GitHub - lammps/lammps-plugins: Collection of LAMMPS plugins