How hash2004/nettrafficmonitor_cpp_js_flask works
Main Components
• C++ Network Monitor:
• File: src/network_monitor.cpp
• Function: Uses libpcap (and pthread) to capture network traffic.
• Deployment: Compiled using g++ and run with root privileges.
• Python FastAPI Backend:
• Files: main.py, requirements.txt.
• Function: Exposes API endpoints (hosted via uvicorn) to serve network data, likely reading from generated data assets.
• Frontend:
• Files: frontend/app.js, frontend/index.html, frontend/styles.css.
• Data Storage:
• Directory: data (contains CSV files such as connections.csv, protocol_counts.csv, total_packets.csv).
• Function: Stores the output (or processed result) of the network monitoring operations.
Relationships and Data Flow
• The C++ component is responsible for capturing network traffic and saving the results as CSV files in the “data” folder.
• The Python FastAPI backend (launched with uvicorn as per README instructions) acts as an intermediary: reading the CSV files and providing an API for the frontend.
• The frontend then consumes this API to display network monitoring statistics to the user.
• “Network Monitor (C++)” → “Data Storage” (CSV files updated with traffic data).
• “Data Storage” → “FastAPI Backend” (reads/serves data).
• “FastAPI Backend” → “Frontend” (serves API responses).
Architectural Patterns and Design Principles
• Separation of Concerns: Each component is built using a language suited for its purpose (fast low-level monitoring in C++, efficient API/backend in Python, responsive UI in JavaScript/HTML/CSS).
• Loose Coupling: The components interact via well-defined data storage (CSV files) and API endpoints.
• Modularity: Components are separated into different directories (src for C++ code, frontend for UI, data for persistence), making it easy to modify one part of the system with minimal impact on others.