IntroductionThe capacity to reliably provide ecosystems, productivity, livelihoods, and health with an adequate water supply has elevated freshwater to a critical human resource1. The increased use of chemical fertilizers, pesticides, and herbicides in farming, industrial pollution, and fast population growth have resulted in sewage that seriously threatens freshwater supplies2. Wastewater treatment plants (WWTPs) should be a priority for public health initiatives that aim to maintain clean urban water systems. Water collected from various sources (rainwater, sewage, industrial drainage) is subjected to a complicated mechanical-physical chemical-biological process known as wastewater treatment to eliminate contaminants and produce potable water. For this same reason, WWTPs are designed to filter out contaminants in wastewater3,4. Because each individual produces an average of 0.15 m3/day of wastewater, WWTP treatment capacities may vary from hundreds of thousands of m3/day in smaller towns and cities to millions of m3/day in larger cities, metropolises, conurbations, or megalopolises5. This requires comprehensive plant management and control systems and accurate capacity planning. Automating key functionalities dealing with fluctuations in inlet wastewater flow, administering chemical and biological reagents, managing resources, performing maintenance and optimising are specific issues and challenges in WWTP management6. Information and communication technologies (ICT) provide a strong basis for WWTP automation, while different approaches are used at different levels of automation7. Many manufacturing operations sometimes release large amounts of water into the public sewage system, which is a common occurrence. It is common for sewage treatment plant operators to lack or be unable to regulate the amount of effluent released into the sewer8. If the anticipated water consumption rates differ, hydraulic overload in the purification plant might occur. Since verifying the network status upstream of the plant is not feasible, a workable alternative would be to continually monitor the intake and outflow of the purification facilities9. This would allow for immediate alarms to be triggered to authorities or data to be used for plant functionality analysis or to identify plants with unusual inlet effluents in specific weather conditions10.The optimal sites for WWTPs inside a city’s centralized wastewater management system have been the subject of several research investigations11. Researchers use geographical approaches to determine where wastewater comes from and how much runoff from individual buildings ends in the sewage system12. Measure the parameters of the wastewater before and after treatment, paying specific attention to the nutritional components. Gathering sensor data or taking wastewater samples and analyzing the plant’s influent/effluent flow to determine the raw waste’s characteristics are the steps the operator has to do to get the required data13. Several health problems may arise from introducing untreated wastewater, a source of nutrients, into bodies of water, including groundwater systems14. However, there has been a significant drop in the amount of nutrients emitted by WWTPs due to facility upgrades that enhance the removal of nutrient contaminants15. One branch of artificial intelligence is machine learning (ML), which involves finding patterns in data to make predictions or categorizations. Since AI can handle real-world issues with sewage treatment, river quality monitoring, and water resource management, its usage in environmental phenomenon modelling and forecasting has skyrocketed in the last few years16. Pattern recognition and computational learning theories give rise to machine learning algorithms, which have strong ties to computational statistics. More water engineering problems have been solved with their help in recent years17.Motivation Since many cities rely on wastewater management as their main water supply, managing this resource is an important concern in urban areas. Agricultural runoff, landfilling, and industrial waste dumping are a few human activities that compromise wastewater quality. Because of this, keeping an eye on and accurately predicting water quality is becoming an increasingly pressing issue, as is the viability of wastewater. The main contribution of the research has the following,AquaFlowNet analyzes real-time data using machine learning to forecast changes in flow and improve wastewater treatment procedures on the fly.Regression Tree models have handled complex wastewater engineering issues including energy loss, water depth, retention of air in a maintenance hole for a drop, and sideflow via a low-crested weir.Particle swarm optimization and Support vector machine used to identify the water quality, reduce energy use, improve treatment performance, and prevent overflows are all ways the system tackles the inefficiencies of old approaches.AquaFlowNet enhances wastewater treatment sustainability by reducing environmental consequences and improving regulatory compliance.Literature surveyWastewater treatment and flow management have been the focus of numerous studies that leverage machine learning (ML), deep learning, and emerging technologies such as blockchain and IoT. This section reviews key advancements in the field, highlighting their methodologies, contributions, and limitations.Machine learning-based wastewater forecastingWWTP forecasting has been significantly enhanced by deep learning models. A novel hybrid deep learning model, TCN-LSTM, was developed to improve wastewater treatment plant (WWTP) predictions18. When tested at a WWTP in Jiangsu Province, China, this model outperformed traditional ML models in terms of prediction accuracy. The model utilized the Shapley Additive Explanation (SHAP) technique to identify the most influential parameters affecting water quality. While effective in prediction accuracy, this method lacks real-time adaptability, limiting its application in dynamic wastewater management systems.Similarly, a Machine Learning–CEEMDAN-TSTF model was proposed for the real-time prediction of reclaimed water volumes21. By integrating ML with Complete Ensemble Empirical Mode Decomposition with Adaptive Noise (CEEMDAN) and Time-Aware Outlier-Sensitive Transformers (TSTF), the approach improved forecasting accuracy over conventional models. However, while decomposition enhances precision, it increases computational overhead, making it less suitable for real-time applications with high-frequency data streams.Risk prediction and flood managementFlood risk management and wastewater flow optimization have also been studied extensively. The Evaluation and Risk Prediction using Effects Analysis and Probability Forecasting (EAPF) model analyzed five years of data on rainfall, inundation, and waterlogging19. By integrating structural equation modeling (SEM) with drainage capacity simulations, this approach effectively predicted flood risks. However, its reliance on historical data limits adaptability to rapidly changing climate conditions.A reliable blockage detection system (RBDS) was developed using low-power sensors integrated with 4G telemetry for real-time sewer monitoring23. The system differentiates between normal flow conditions and blockages using time series analysis and decision criteria. While this approach offers a computationally efficient solution for real-time monitoring, its dependency on predefined decision rules restricts its ability to adapt to novel obstruction patterns.Blockchain and IoT in water managementRecent research has explored the integration of blockchain and IoT for improving wastewater monitoring. A Blockchain-based Water Management Architecture (BC-WMA) proposed an IoT-enabled real-time data authentication system to track water distribution and leakage detection20. This system enhances transparency and accountability, reducing inefficiencies. However, blockchain implementation introduces significant computational costs, and network scalability remains a challenge in large-scale wastewater management.The Python-based Stormwater Management Model (PySWMM) extends the EPA’s SWMM for intelligent management of combined sewer systems24. By embedding SWMM within Python’s scientific computing framework, researchers developed real-time Combined Sewer Overflow (CSO) management applications, reducing overflow incidents. While PySWMM provides a powerful simulation tool, its reliance on predefined models limits adaptability to unforeseen environmental changes.Wastewater management assessment and decision supportA Novel Assessment Framework (NAF) was developed to evaluate wastewater management (WWM) practices by assessing data quality, performance indicators, and areas for improvement22. The framework employs five key matrices—CSAS, PAAS, TARGET, TOOL, and MASS—to quantify system efficiency. While this model provides a structured evaluation approach, it does not directly integrate real-time data, making it more suited for periodic assessments rather than continuous optimization.This literature review highlights various approaches to wastewater treatment and flow management, each with distinct advantages and limitations. While deep learning models like TCN-LSTM and ML-CEEMDAN-TSTF improve forecasting accuracy, they often require significant computational resources and lack real-time adaptability. Risk prediction models, such as EAPF, provide valuable insights but are constrained by historical data reliance. IoT and blockchain-based solutions, like BC-WMA, enhance monitoring but pose scalability and cost challenges.AquaFlowNet builds upon these prior works by integrating real-time wastewater flow prediction, optimization, and adaptive resource management using machine learning. Unlike existing solutions, it focuses on dynamic adaptability, minimizing energy consumption, optimizing chemical treatment processes, and preventing overflows in a computationally efficient manner. By addressing the limitations of traditional models, AquaFlowNet provides a more resilient and scalable solution for wastewater management.Research gap and novelty of AquaFlowNetDespite these advancements, several critical limitations remain:1.Lack of real-time adaptability: Most ML-based wastewater forecasting models, such as TCN-LSTM and CEEMDAN-TSTF, focus on accuracy but lack the ability to dynamically adjust to real-time changes in wastewater flow.2.Computational inefficiency: Many existing models require high computational resources, making them impractical for real-time wastewater treatment optimization.3.Limited integration of intelligent control strategies: Most studies rely on historical data or predefined rules, limiting their ability to proactively adjust treatment processes in response to real-time conditions.4.Scalability challenges: IoT and blockchain-based solutions offer improved monitoring, but their high computational cost and network scalability issues restrict their deployment in large-scale wastewater management systems.5.Absence of an integrated approach: Current models often focus on either prediction, monitoring, or assessment, but fail to integrate all aspects into a single, real-time decision-making framework.How AquaFlowNet addresses these gapsAquaFlowNet builds upon existing research by integrating real-time wastewater flow prediction, optimization, and adaptive resource management using machine learning. Unlike previous methods, it offers:Real-time adaptability: The system continuously analyzes wastewater flow patterns and dynamically adjusts treatment processes, ensuring instantaneous optimization.Computational efficiency: AquaFlowNet leverages lightweight ML models and particle swarm optimization to enhance predictive accuracy while minimizing processing overhead.Proactive control strategies: By combining regression trees, SVM, and particle swarm optimization, AquaFlowNet proactively prevents overflows, reduces energy consumption, and optimizes chemical treatment.Scalable architecture: Unlike blockchain-based solutions that face scalability constraints, AquaFlowNet employs distributed processing techniques to handle large-scale wastewater systems efficiently.End-to-end integration: AquaFlowNet offers a unified framework for prediction, optimization, and compliance monitoring, making it a comprehensive solution for wastewater management.Table 1 presents a thorough examination of the current body of researchTable 1 Comprehensive analysis.Full size tableProposed methodologyThe control of wastewater and the monitoring of water quality in metropolitan areas are problematic. Combining machine learning methods allows for development of a model that reliably forecasts urban water quality. Hence, multiple intricate wastewater engineering problems have been tackled using the Regression Tree model, SVM and PSO. These issues include air entrainment in drop maintenance holes, pool depth, and lateral outflow in low-crested side weirs. Use pH, chemical concentration, and temperature readings from monitoring wells to predict water quality. It is possible to optimize the machine learning model’s parameters using the particle optimization approach to get very accurate results when forecasting water quality. We expect these machine-learning methods will prove their worth by being applied to previously investigated experimental challenges.Fig. 1Proposed Methodology.Full size imageThe wastewater management system begins with data collection, as depicted in Fig. 1. Flow meters and IoT devices deployed at monitoring sites gather real-time data on critical parameters such as temperature, chemical concentrations, pH levels, and wastewater flow rates. This data is sourced from treatment facilities, pipelines, and groundwater systems to ensure comprehensive monitoring.In the preprocessing stage, the collected data undergoes noise removal, missing value imputation, and standardization to improve its quality. Techniques like outlier detection and data normalization ensure consistency, which is crucial for reliable machine learning predictions.Once preprocessed, the data is analyzed using the Least Squares Support Vector Machine (LS-SVM) to assess groundwater quality. The LS-SVM model performs classification and regression to evaluate key metrics such as dissolved oxygen (DO), pH levels, and pollution indicators. However, due to the complex and nonlinear nature of wastewater data, Particle Swarm Optimization (PSO) is employed to fine-tune the LS-SVM model’s parameters, including kernel coefficients and feature weights. This optimization improves both accuracy and adaptability to dynamic environmental conditions.For wastewater flow prediction, Regression Tree Models are utilized. These models incorporate historical and real-time data to provide accurate estimations of wastewater flow rates under different scenarios. This enables proactive management of wastewater systems, facilitating early detection of anomalies and improved operational control.The model’s performance is evaluated using metrics such as Mean Square Error (MSE), Mean Absolute Error (MAE), and overall accuracy. These measures validate the effectiveness of the proposed approach compared to baseline methods. The integration of this optimized model into a decision support system allows wastewater treatment facility operators to leverage real-time monitoring and data-driven insights for efficient resource allocation and compliance with environmental standards.Additionally, wastewater output prediction begins with building population estimation, a key factor in demand forecasting. A two-stage approach is used for greater accuracy:1.Estimating population density based on building area, which is effective for most urban settings but challenging in densely packed slum areas.2.Averaging population density across sub-districts to refine predictions in areas with irregular housing patternsBy integrating machine learning models, optimization techniques, and real-time monitoring, this comprehensive system ensures accurate forecasting, adaptive parameter tuning, and practical insights for sustainable wastewater management.Wastewater output prediction begins with determining building population. A two-stage method improves accuracy: first, population density is estimated from building areas, though this poses challenges in slums due to small, densely packed structures. To address this, the second approach averages population density across a sub-district. The final estimate combines both methods. Pre-processing, essential for wastewater quality prediction, includes data cleansing and optimization.Fig. 2Wastewater Treatment Process.Full size imageThis investigation focused on an urban nutrient removal data set from the municipal treatment plant. A daily average capacity of 22,000 tons is designed for this WWTP. The wastewater treatment plant has a clarifier, anaerobic/aerobic reactors, and a sedimentation tank. The wastewater treatment plant (WWTP) has a grit chamber, aerobic, anaerobic, pretreatment tanks, and an active sludge system (Fig. 2). After the biological treatment system, the final effluent was treated using flocculation, sedimentation, sand filtration, disinfection, and a secondary clarifier.Fig. 3Feature Selection.Full size imageFigure 3 examines the feature selection. An information set for training purposes that includes hourly readings of the following parameters: dissolved oxygen (DO), influent flowrate (Qin), effluent flowrate (Qeff), return flowrate (RAS), waste flowrate (WAS), mixed liquor suspended solids (MLSS), total phosphorus (TP), and total suspended solids (TSS). Input and effluent waste quality statistics from WWTPs. A total of 14.08 mg/L of COD, 2793.07 mg/L of MLSS, 3.66 mg/L of TSS, 7.13 mg/L of TN, and 0.55 mg/L of TP were measured in the influent. With a data collection frequency of 1 h, the operation data were acquired in real-time. In addition, standardizing the dataset and removing superfluous datasets are crucial steps in producing an adequate model. Finding the best sensors and operational parameters in a dataset is the primary objective of feature selection. In reality, feature reduction is challenging and often requires extensive testing. Many methods exist in the machine learning community to determine which attributes to use as predictors of future outcomes or as nonpredictors.Recursive feature removal aims to shorten training time and speed learning by removing nonpredictive features from a model without increasing its error. Consequently, employing data that may be predicted using a regression and a decision-tree-based classifier is essential to improve a detection system to extract relevant attributes. The research lends credibility to the idea that regression-based feature selection may improve classifier performance and identify important characteristics of influent and effluent water quality indicators. Here, we can see the steps to generate data extracted from the SCADA database before it is preprocessed. Finally, water parameters are eliminated using RFE and a decision tree model. Feature selection occurs at time step \(\:S\), and the procedure continues until completion by predicting the effluent at time \(\:S\).Equation (1a) was used to estimate the population in this study. In this context, \(\:Building\:Production\:\left(Pb\right)\)represents building occupancy rate, Building area represents building size, \(\:\sum\:building\:area\)measures the sum of all building areas in a region, population represents the region’s population, and \(\:\sum\:building\)represents the region’s total number of buildings. This approach determines Bandung City sub-district regions. The term “population estimate” refers to studies that monitor demographic characteristics such as birth and death rates, migration trends, and population growth and composition. The research also included two methods for estimating construction wastewater production. The original method estimated home and business trash output. This computational technique uses the rural factor (RF) variable to account for the reality that not all inhabitants work from home and create wastewater at home. Finding out what proportion of the population works in each sub-district showed that a lower RF value indicates a greater workforce.$$\:Building\:Production\:\left(Pb\right)=\frac{\left(\frac{building\:area}{\sum\:building\:area}\times\:population\right)+\left(\frac{population}{\sum\:building}\right)}{2}$$(1a)$$\:Residential\:Building = Residents \times \:\frac{{93L}}{{resident}}/c \times \:RA$$(1b)$$\:Commercial\:Building = Building\:Area \times \:\frac{{2.4L}}{{m^{2} }}/d$$(1c)Residential and commercial waste generation formulae are in Eq. 1(a-c). The daily water consumption of residential and commercial buildings is \(\:Residential\:Building\) and \(\:Commercial\:Building\) respectively. Hospitals and places of worship were regularly computed at 1600 and 2400 L/d, respectively. The final wastewater output estimate was the average of techniques one and two, determined for each building.Based on two possible outcomes—one with a river and the other without—this analysis calculated the possible access to an existing centralized wastewater system. Because rivers are sometimes the only means of disposing of untreated wastewater in places lacking sanitation, access to river parameters is an important consideration. In this study, we look at the possibility of future construction connections to the sewage system. The river’s proximity is important for extending the wastewater treatment infrastructure’s sewage system. Combining the index created without considering each parameter’s weight with the percentage of sub-district sanitation access yielded the final output.$$\:Santiation\:access={\sum\:}_{j=0}^{m}K{d}_{j}+T{J}_{j}+C{O}_{j}+C{Z}_{j}+C{R}_{j}$$(2)Potential sanitation access \(\:Santiation\:access\) formula shown in Eq. (2). Here, \(\:m\) is the number of buildings processed in the research area, \(\:j\) is the building parameter, \(\:K{d}_{j}\) is the land cover parameter, \(\:T{J}_{j}\)is the slope parameter, \(\:C{O}_{j}\) is the road distance, \(\:C{Z}_{j}\) is the water source distance, \(\:C{R}_{j}\) is the river distance, and so on. The next step in establishing new sanitary networks was ranking buildings by importance. This priority index combines waste production estimates with sanitation network accessibility. Structures with plenty of trash and no sanitation were prioritized. To effectively treat wastewater while reducing negative impacts on the ecosystem, decision-makers should consider river conditions. Therefore, it is recommended that a WWTP be constructed at a considerable distance from the river, according to a comprehensive assessment of these elements. The best spot to put a WWTP is the one with the greatest combined value of the normalized and integrated parameters.$$\:Suitabilty\:Index=\sum\:_{j=0}^{n}K{d}_{j}+T{J}_{j}+C{O}_{j}+C{Z}_{j}+C{R}_{j}$$(3)As stated in Eq. (3), the technique for calculating the suitability index of WWTP candidates \(\:Suitabilty\:Index\) makes use of the following parameters: \(\:K{d}_{j}\) is the distance from the road \(\:C{O}_{j}\) is the slope \(\:T{J}_{j},\)the water source \(\:C{Z}_{j}\), and the river \(\:C{R}_{j}\), as well as the value of each parameter (\(\:j\)). In the case of a centralized WWTP, there are m GOF objectives, and these goals are used as a criterion for each WWTP.Random Forest (RF) is a popular machine learning method for response variables \(\:Y\). The RF method uses a set of randomly dispersed, independently distributed data vectors called parameters to build prediction models according to the decision trees. The classification model of the approach is based on a decision tree regression. In RF’s computation, the basic mathematical formula is \(\:{\widehat{G}}_{i}\), where \(\:i\) is a sample with a constant classification level, \(\:i\) is the prediction model’s value and \(\:argma{x}_{x}\) is the sample representation. Equation (6) shows this is a commonly used machine learning technique for determining which class has the greatest predictive probability. Here, \(\:y\) are the predictors and \(\:x\) shown in Eq. (4).$$\:E\left(y\right)=argma{x}_{x}{\sum\:}_{i=1}^{i}I\left({\widehat{G}}_{i}\left(y\right)=x\right)$$(4)This work uses Gradient Tree Boosting (GTB) to enhance error function-based classification and regression. Decision trees and other low-predictive models help GBT develop more accurate prediction models. GBT largely reduces residual yield from the previous prediction model using gradient-wise methods. By using the negative gradient of the residues\(\:\:{E}_{n-1}\) in conjunction with the \(\:learning\:rate\), the outcomes of the regression tree \(\:{\phi\:}_{n}\), and the loss function \(\:{h}_{n}\), the goal of the GBT prediction model, as demonstrated in Eq. (5), is to reduce residues and overfitting.$$\:{E}_{n}\left(y\right)={E}_{n-1}\left(y-1\right)+learning\:rate*{\phi\:}_{n}{h}_{n}\left(\vartheta\:\right)$$(5)In addition, the likelihood of a flood catastrophe is estimated by implementing an overfitting solution based on the two machine learning algorithms. This solution is derived from Eq. (6), where \(\:{J}_{ML}\) is an index of the chance of a flood disaster, and the new index results from integrating RF and GBT.$$\:{J}_{ML}={\sum\:}_{j=0}^{m}{E}_{n}\left(y\right)+\widehat{E}\left(y\right)$$(6)A correlation test was also run to assess the model, which included making a correlation matrix of the study variables and analyzing the ones that impact the conditions of the flood susceptibility index. After determining the sample size (\(\:m\)), we used Eq. (7), where \(\:x\:and\:y\) are the criteria for determining the correlation coefficient, which are the variables that are independent and dependent, respectively (\(\:o\)). Coefficients of correlation (\(\:o\)) show how strongly two variables\(\:,\:x\:and\:y\), are related to one another.$$\:Correlation\:Coefficient=\frac{\sum\:yx-\frac{\sum\:x\sum\:y}{m}}{\sqrt{\left(\sum\:{y}^{2}-\frac{{\left(\sum\:y\right)}^{2}}{m}\right)\left(\sum\:{x}^{2}-\frac{{\left(\sum\:x\right)}^{2}}{m}\right)}}$$(7)Details are entered from a variety of water sources. This information has been compiled in many forms. The normalizing procedure can only be used for data that is homogenous. To normalize anything, you need to start with the min-max technique. It is located between the intervals [− 2, 2].$$\:O=-2