How to realize on-site small-scale production and sustainable consumption of H2O2 is the focus of attention of this study. Photocatalysis technology can just meet this demand, and gC3N4 is one of the most popular catalysts employed. However, the numerous defects in the g-C3N4 nanostructure seriously inhibit its catalytic activity, which act as recombination centers of photo generated carriers. Herein, we propose an anti-defect engineering strategy to tailor a highly crystalline g-C3N4 nanostructure for efficient photocatalytic in situ H2O2 production, which can be further cascaded to wastewater remediation. High-resolution transmission electron microscopy and electron spin-resonance spectroscopy results demonstrate that highly crystalline g-C3N4 is successfully fabricated with extremely low defect concentrations. Transient surface photovoltage data shows that highly crystalline g-C3N4 exhibits rapid charge separation and transfer with slow decay. Therefore, the photocatalytic activity of g-C3N4 can be significantly promoted by eliminating its defects to construct a highly crystalline structure. Especially, the crystalline g-C3N4 prepared by thiourea (CNT) exhibits the maximum H2O2 production of 2.48 mmol g-1 h-1 with an apparent quantum efficiency of 22% (lambda = 400 nm), along with an excellent cascade tetracycline removal effect. This work provides an anti-defect engineering strategy to regulate the crystal structure of the catalyst for its enhanced photocatalytic activity.