MortezaBashsiz / nipovpn

Powerfull http proxy
GNU General Public License v3.0
183 stars 11 forks source link

Suggestions for Code Improvement and Project Structure #59

Open missixs opened 3 months ago

missixs commented 3 months ago

Hi,

After reviewing the codebase, I've identified some areas for improvement that could enhance readability, maintainability, and performance. These suggestions aim to make the code more accessible to potential contributors and improve overall project quality.

Architecture

  1. SOLID Principles: Implementing SOLID principles could significantly improve code readability and testability. For a concise introduction, I recommend this video. A key benefit would be improved testability, allowing for more accurate benchmarking without network delays by enabling the use of mock objects.

  2. Decoupling: The current dependency of tcpConnection on runMode (Agent or Server Mode) seems unnecessary. Consider refactoring to reduce coupling between these components.

  3. CMake Integration: Adopting CMake could greatly facilitate cross-platform deployment, especially for Windows.

  4. Project Structure: Consider dividing the monorepo into three smaller projects:

    • Core library (TCP and HTTP functionality)
    • Agent repository
    • Server repository Use the core library as a submodule in both the agent and server repositories.

Readability

  1. String Formatting: Utilize the C++20 format library for more readable string operations, e.g., fmt::print("hello {} from {}", "John", "Joe");.

  2. Reduce Nesting: Eliminate deep nesting of if/else statements. For reference, see this article on early returns.

Performance

  1. String Operations: Minimize unnecessary string conversions. Consider replacing the BoolStr struct with std::expected from C++23 where appropriate.

  2. Concurrency: Review the current multi-threading implementation. If performance is critical, consider lock-free programming techniques after establishing a measurable baseline.

Additional Suggestions

  1. Use GitHub Releases instead of pushing binaries to the repository.
  2. Adopt std::jthread (C++20) to leverage RAII and eliminate explicit join() calls.
  3. Add a .clang-format file for consistent code styling.
  4. Implement a .clang-tidy file for static analysis to catch common mistakes.

I also have a question, why is a custom HTTP library used instead of Boost.Beast?

I'm available to assist with implementation after late September.

MortezaBashsiz commented 3 months ago

@missixs Thank you so much for your hints I will try to consider them, and I am looking forward to your contribution Will inform here