Functionally competent immune system includes a functionally competent T-cell repertoire that is reactive to foreign antigens but is tolerant to self-antigens. The repertoire of T cells is primarily formed in the thymus through positive and negative selection of developing thymocytes. Immature thymocytes that undergo V(D)J recombination of T-cell antigen receptor (TCR) genes and that express the virgin repertoire of TCRs are generated in thymic cortex. The recent discovery of thymoproteasomes, a molecular complex specifically expressed in cortical thymic epithelial cells (cTEC), has revealed a unique role of cTEC in cuing the further development of immature thymocytes in thymic cortex, possibly by displaying unique self-peptides that induce positive selection. Cortical thymocytes that receive TCR-mediated positive selection signals are destined to survive for further differentiation and are induced to express CCR7, a chemokine receptor. Being attracted to CCR7 ligands expressed by medullary thymic epithelial cells (mTEC), CCR7-expressing positively selected thymocytes relocate to thymic medulla. The medullary microenvironment displays another set of unique self-peptides for trimming positively selected T-cell repertoire to establish self-tolerance, via promiscuous expression of tissue-specific antigens by mTEC and efficient antigen presentation by dendritic cells. Recent results demonstrate that tumor necrosis factor (TNF) superfamily ligands, including receptor activating NF-kappaB ligand (RANKL), CD40L, and lymphotoxin, are produced by positively selected thymocytes and pivotally regulate mTEC development and thymic medulla formation.