All three terms refer to textiles in different phases of production and development; from basic raw material to finished product. They are all the same thing, but they are nothing like each other. The three terms are not interchangeable.
Fabric is the finished product. It's sold on rolls, cut and sewn into articles of wearing apparel, curtains and bedding, etc. Fabric can be either knitted or woven. The knitting or weaving is done with the yarn.
Yarn is the basic component of weaving or knitting textiles. Yarns can be so fine as to be measured in micrometers, or it can be as thick as bulky knitting yarn. The word "yarn and "thread" can be used interchangeably, although there is a semantic difference which will be mentioned later. In textile manufacturing. The yarns/threads are set up on a loom and woven or knitted on large knitting machines.
Yarns and threads are spun from fibers. Fibers can be natural, such as cotton bolls, wool fleece, polyester rovings, rayon linters, all are merely bunches of fluff with little substance. On their own, fibers have little tensile strength and can't be used for anything other than stuffing a pillow. But when fibers are spun they become stronger. A large machine will draw out the fibers and spin them into long fine strands. When several strands of spun fibers are twisted together they form thread/yarn. Then the yarn goes to the mill where it is woven or knitted into fabric.
Fiber-yarn-fabric. Fabrics are made from yarn/thread, yarn/thread is made from fiber. So you will be making whatever it is you want to make from fabric. In addition, yarn is often used to refer to thicker spun fibers, such as you find in knitting yarn. As the spun fibers become finer, it becomes known as thread, such as what you find on spools of sewing thread.