The patella is a bone within a tendon - the tendon of the long quadriceps muscle that spans the region from the hip to the shinbone. The illustration on the right shows one part of the quadriceps muscle (the rectus femoris part) and you can see the patella within its tendon just at the knee joint. The muscle attaches above to the pelvis and the top of the femur (thighbone), and below to the tibia (shinbone) at an important lumpy spot about 1.5 inches below the bottom of the patella - the 'tibial tubercle'.
This image on the left (an MRI scan with reverse contrast) is looking at the knee from the side. One can see the patella as part of the tendon, and the point where the tendon attaches to the tibia bone at the tibial tubercle. The bit of tendon below the patella is called the patellar tendon, and the bit above it is called the quads tendon (or quadriceps tendon). Note also the relationship of the fat pad to the patella - this is a wad of fatty tissue that fills the space below and behind the patella.
When talking about the mechanics of the patella, doctors often refer to the 'extensor mechanism' - meaning the whole muscle/tendon/bone structure of which the patella is a part. ['Extension' means 'straightening', and the extensor mechanism is comprised of the bones, muscles and tendons which act to straighten (extend) the knee, the main extensor muscle being the quadriceps muscle.]
The capsular structures of the knee (the internal casing of the joint) play a local role in maintaining patellar alignment. On the lateral (outer side) is a tight area called the 'lateral retinaculum' and it tends to restrain the patella on the outer side, usually counteracted on the medial side by the medial patellofemoral ligament and a strong quads muscle, especially that portion of it known as the VMO. The medial capsular structures are less tight, so if the VMO becomes weak there may be a tendency for the patella to be pulled to the lateral side. The medial patellofemoral ligament (MPFL) is an important restraint that becomes damages after patellar dislocation.
Anatomical conditions affecting the extensor mechanism and tending to pull the patella to the outer side include a twisted femur (femoral torsion) or a tibial tubercle which is too far over to the outer side. A measure of the likely stress on the patella is the 'Q-angle' 'quads' angle. The bigger this angle, the greater the force trying to pull the patella to the outer side, and the restraints and the trochlear groove are not always sufficient to keep the patella where it should be.
Normally, when the knee is straight (extension) the kneecap sits at the shallow section of the trochlea. As the knee flexes ('bends'), it is pulled into the deeper part of the trochlea at about 30 degrees of flexion, then runs centrally in the trochlear groove during the rest of bending. Should the walls of the groove be defective ('trochlear dysplasia') or the patella sit too high on the femur ('patella alta'), then the patella may sometimes come out of the groove, partially ('subluxation') or fully ('dislocation').