AbstractDiabetes mellitus is one of the most common diseases affecting patients of different ages. Diabetes can be controlled if diagnosed as early as possible. One of the serious complications of diabetes affecting the retina is diabetic retinopathy. If not diagnosed early, it can lead to blindness. Our purpose is to propose a novel framework, named $$D_MD_RDF$$ D M D R D F , for early and accurate diagnosis of diabetes and diabetic retinopathy. The framework consists of two phases, one for diabetes mellitus detection (DMD) and the other for diabetic retinopathy detection (DRD). The novelty of DMD phase is concerned in two contributions. Firstly, a novel feature selection approach called Advanced Aquila Optimizer Feature Selection ($$A^2OFS$$ A 2 O F S ) is introduced to choose the most promising features for diagnosing diabetes. This approach extracts the required features from the results of laboratory tests while ignoring the useless features. Secondly, a novel classification approach (CA) using five modified machine learning (ML) algorithms is used. This modification of the ML algorithms is proposed to automatically select the parameters of these algorithms using Grid Search (GS) algorithm. The novelty of DRD phase lies in the modification of 7 CNNs using Aquila Optimizer for the classification of diabetic retinopathy. The reported results concerning the DMD datasets shows that AO reports best performance metrics in the feature selection process with the help of modified ML classifiers. The best achieved accuracy is 98.65% with the GS-ERTC model and max-absolute scaling on the “Early Stage Diabetes Risk Prediction Dataset” dataset. Also, from the reported results concerning the DRD datasets, the AOMobileNet is considered a suitable model for this problem as it outperforms the other modified CNN models with accuracy of 95.80% on the “The SUSTech-SYSU dataset” dataset.