The famous teaching of
וּכְשֶׁבָּרָא הַקָּדוֹשׁ בָּרוּךְ הוּא אֶת עוֹלָמוֹ נִתְיָעֵץ
בַּתּוֹרָה
When Hashem created His world, He consulted the Torah
is a core teaching in Torah. It is so foundational and primary that it is the very first teaching in both Midrash Rabbah and Midrash Tanchuma. The Midrash Tanchuma declares the point that every word and letter is perfect and purposeful:
מַהוּ קְוֻצּוֹתָיו תַּלְתַּלִּים? עַל כָּל קוֹץ וָקוֹץ. תִּלֵּי
תִלִּים שֶׁל הֲלָכוֹת
What is meant by "His locks are curled" [Shir Hashirim 5:11]? It means
that each crowned stroke on the letters of the Torah contains heaps
and heaps of law. (Midrash Tanhuma-Yelammedenu, trans. Samuel A. Berman)
This is the source for the concept.
It then proceeds to give numerous examples of how if a single letter were changed, the world (which was created from the Torah) would be destroyed. Notably, it brings examples from Torah, Neviim and Ketuvim:
Torah
It is written in the Torah: Profane not My Holy Name (Lev. 22:2); but
if you should change the chet in the word yechallelu (“profane”) into a
heh, the word would read “praise,” and you would thereby destroy the
world.
Neviim
"They have lied against the Lord" (Jer. 5:12), if you should change the
preposition bet (“against”) into the preposition kaf (“like”), you
would thereby destroy the world.
Ketuvim
"Let everything that hath breath praise the Lord" (Ps. 150:6), if you
should alter the heh in the word tehallel (“praise”) into a het,
the word would read “profane,” and you would thereby destroy the
world.
The Midrash finishes the point by saying:
וְאִם אוֹת אַחַת כָּךְ, כָּל שֶׁכֵּן הַתֵּבָה כֻלָּהּ, לְכָךְ נֶאֱמַר:
קְוֻצּוֹתָיו תַּלְתַּלִּים
If a slight change in a single letter can produce such drastic
consequences, how much more so the alteration of a complete word.
and then proceeds to demonstrate how the world is constructed according to the blueprints of the Torah, and notably gives examples from Neviim and Ketuvim:
It [the world] was with the assistance of the Torah that God stretched
out the heavens and established the earth, as it is said: "If My
covenant be not with day and night, if I have not appointed the
ordinances of heaven and earth" (Jer. 33:25). With it, He bound up the
sea lest it should go forth and overflow the world, as it is said:
"Fear ye not Me? saith the Lord; nor will ye not tremble at My
presence who have placed the sand for the bound of the sea" (ibid.
5:22). With it, also, He locked up the deep so that it might not
inundate the world, as is written: "When He set a circle on the face
of the deep" (Prov. 8:27). Similarly, He fashioned with it the sun and
the moon, as is said: "The Lord giveth the sun to light the day, the
ordinances of the moon and the stars to light the night. Who stirreth
up the sea, that the waves thereof roar, the Lord of hosts is His
name" (Jer. 31:35). Hence, you learn that the world was founded upon
the Torah.