any one know where moodle define the class that we take $CFG from it
It's read from the mdl_config table on startup (and/or if you change any settings).
Is that what you are asking?
EDIT...
config.php (which creates $CFG) calls..
lib/setup.php calls...
moodlelib.php function get_config()
Is that what you are asking?
EDIT...
config.php (which creates $CFG) calls..
lib/setup.php calls...
moodlelib.php function get_config()