The electronic and optical properties of Boron (B) and Beryllium (Be)-doped graphene were determined using the ab initio approach based on the generalized gradient approximations within the Full potential linearized Augmented Plane wave formalism (FP-LAPW). Our findings demonstrated that doping at the edges of graphene is notably stable. In both systems, Be- doped graphene proves more efficient in manipulating the band gap of graphene. Both B and Be, induce P-type doping in graphene. B-doped graphene exhibits a negligible magnetic moment of 0.000742, suggesting its suitability for catalytic semiconductor devices. Conversely, Be-doped graphene displays a large magnetic moment of 1.045 μB, indicating its potential in spintronics. Additionally, this study elucidates the influence of the dopant atoms on the optical properties of graphene. These findings underscore a stable and controllable method for modelling graphene at its edges with B and Be atoms, opening new avenues in the design of these devices.