# Network Scanner - Full Stack Quick Start Guide This guide helps you get both backend and frontend running together. ## ๐Ÿš€ Quick Start (5 minutes) ### Step 1: Start Backend ```bash # From project root cd /home/rwiegand/Nextcloud/entwicklung/Werkzeuge/teamleader_test # Start backend server ./start.sh # OR python main.py ``` The backend will be available at: `http://localhost:8000` ### Step 2: Install Frontend Dependencies ```bash # Open new terminal cd /home/rwiegand/Nextcloud/entwicklung/Werkzeuge/teamleader_test/frontend # Run setup ./setup.sh # OR npm install ``` ### Step 3: Start Frontend ```bash # From frontend directory ./start.sh # OR npm run dev ``` The frontend will be available at: `http://localhost:3000` ### Step 4: Use the Application 1. Open browser to `http://localhost:3000` 2. You'll see the Dashboard 3. Enter a network range (e.g., `192.168.1.0/24`) 4. Click "Start Scan" 5. Watch real-time progress 6. Explore the Network Map, Hosts, and Scans pages ## ๐Ÿ“Š Architecture Overview ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ USER BROWSER โ”‚ โ”‚ http://localhost:3000 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ HTTP/WebSocket โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ VITE DEV SERVER (3000) โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ React TypeScript Frontend โ”‚ โ”‚ โ”‚ โ”‚ โ€ข Dashboard โ€ข Network Map โ€ข Hosts โ€ข Scans โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ Proxy: /api/* โ†’ http://localhost:8000/api/* โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ REST API + WebSocket โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ FASTAPI BACKEND (8000) โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ REST API Endpoints โ”‚ โ”‚ โ”‚ โ”‚ โ€ข /api/scans/* โ€ข /api/hosts/* โ€ข /api/topology/* โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ WebSocket Endpoint โ”‚ โ”‚ โ”‚ โ”‚ โ€ข /api/ws (real-time updates) โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ Network Scanner Engine โ”‚ โ”‚ โ”‚ โ”‚ โ€ข Port scanning โ€ข Service detection โ”‚ โ”‚ โ”‚ โ”‚ โ€ข Topology analysis โ€ข Database storage โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ Database: SQLite (scanner.db) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` ## ๐Ÿ”Œ API Integration Details ### REST API Flow ``` Frontend Component โ†“ Custom Hook (useHosts, useScans, etc.) โ†“ API Service (services/api.ts) โ†“ Axios HTTP Request โ†“ Vite Dev Proxy (/api โ†’ :8000/api) โ†“ FastAPI Backend โ†“ Database / Scanner โ†“ JSON Response โ†“ React State Update โ†“ UI Re-render ``` ### WebSocket Flow ``` Frontend App Start โ†“ useWebSocket Hook โ†“ WebSocket Client (services/websocket.ts) โ†“ WS Connection: ws://localhost:8000/api/ws โ†“ Backend WebSocket Manager โ†“ Scan Events (progress, complete, host_discovered) โ†“ Message Handler in Hook โ†“ State Update โ†“ UI Re-render (real-time) ``` ## ๐Ÿงช Testing the Integration ### 1. Test Backend Alone ```bash # Check health curl http://localhost:8000/health # List hosts curl http://localhost:8000/api/hosts # Start scan (from CLI) python cli.py scan 127.0.0.1 ``` ### 2. Test Frontend-Backend Integration 1. **Start both servers** 2. **Open browser console** (F12) 3. **Go to Network tab** 4. **Trigger actions and verify**: - API calls show in Network tab - WebSocket connection established - Real-time updates received ### 3. Test WebSocket 1. Start a scan from frontend 2. Open browser console 3. Watch for WebSocket messages: ```javascript // You should see: { type: 'scan_progress', data: { ... } } { type: 'host_discovered', data: { ... } } { type: 'scan_complete', data: { ... } } ``` ## ๐Ÿ› Troubleshooting ### Backend Issues **Port 8000 already in use** ```bash # Find process lsof -i :8000 # Kill it kill -9 ``` **Permission denied (for nmap)** ```bash # Run without nmap or with sudo python main.py ``` **Database locked** ```bash # Stop all backend instances pkill -f "python main.py" # Remove lock rm scanner.db-journal ``` ### Frontend Issues **Port 3000 already in use** ```bash # Vite will automatically try 3001, 3002, etc. # Or kill the process: lsof -i :3000 kill -9 ``` **Cannot connect to backend** - Verify backend is running: `curl http://localhost:8000/health` - Check `.env` file has correct URLs - Check browser console for CORS errors **WebSocket not connecting** - Backend CORS must allow WebSocket - Check WebSocket URL in `.env` - Backend must support WebSocket upgrade ### Integration Issues **CORS Errors** Backend should have: ```python app.add_middleware( CORSMiddleware, allow_origins=["http://localhost:3000"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) ``` **Proxy Not Working** Check `frontend/vite.config.ts`: ```typescript proxy: { '/api': { target: 'http://localhost:8000', changeOrigin: true, }, } ``` ## ๐Ÿ“ Development Workflow ### Typical Development Session ```bash # Terminal 1: Backend cd ~/Nextcloud/entwicklung/Werkzeuge/teamleader_test python main.py # Terminal 2: Frontend cd ~/Nextcloud/entwicklung/Werkzeuge/teamleader_test/frontend npm run dev # Terminal 3: Testing cd ~/Nextcloud/entwicklung/Werkzeuge/teamleader_test python cli.py scan 192.168.1.0/24 ``` ### Making Changes **Backend Changes** 1. Edit Python files 2. Backend auto-reloads (if uvicorn reload enabled) 3. Frontend automatically uses new API **Frontend Changes** 1. Edit React/TypeScript files 2. Vite hot-reloads automatically 3. Browser updates instantly ## ๐Ÿšข Production Deployment ### Backend ```bash # Option 1: Direct uvicorn app.main:app --host 0.0.0.0 --port 8000 # Option 2: Gunicorn gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker # Option 3: Docker docker build -t network-scanner-backend . docker run -p 8000:8000 network-scanner-backend ``` ### Frontend ```bash cd frontend npm run build # Output in: frontend/dist/ ``` Deploy `dist/` to: - Nginx - Apache - Netlify - Vercel - AWS S3 + CloudFront ### Full Stack (Docker Compose) Create `docker-compose.yml`: ```yaml version: '3.8' services: backend: build: . ports: - "8000:8000" volumes: - ./data:/app/data frontend: build: ./frontend ports: - "80:80" depends_on: - backend environment: - VITE_API_URL=http://localhost:8000 - VITE_WS_URL=ws://localhost:8000 ``` Run: ```bash docker-compose up -d ``` ## ๐Ÿ”’ Security Considerations ### Development - Backend and frontend on localhost only - CORS restricted to localhost:3000 - No authentication (internal use) ### Production Must add: 1. **Authentication**: JWT, OAuth, or API keys 2. **HTTPS**: TLS certificates required 3. **CORS**: Restrict to production domain 4. **Rate Limiting**: Prevent abuse 5. **Input Validation**: Already implemented 6. **Network Scanning**: Ensure authorized networks only ## ๐Ÿ“Š Monitoring ### Backend Logs ```bash # Follow logs tail -f logs/network_scanner.log # Check for errors grep ERROR logs/network_scanner.log ``` ### Frontend Logs - Browser console (F12) - Network tab for API calls - React DevTools for component inspection ## ๐ŸŽฏ Common Use Cases ### 1. Scan Local Network ``` 1. Go to Dashboard 2. Enter: 192.168.1.0/24 3. Select: Quick scan 4. Click: Start Scan 5. Monitor progress 6. View results in Network Map ``` ### 2. Investigate Specific Host ``` 1. Go to Hosts page 2. Search for IP or hostname 3. Click on host 4. View services and details 5. Check last seen time ``` ### 3. Monitor Scan Progress ``` 1. Start scan from Dashboard 2. Go to Scans page 3. Watch real-time progress bar 4. View hosts scanned count 5. Cancel if needed ``` ### 4. Explore Network Topology ``` 1. Complete at least one scan 2. Go to Network Map 3. Pan/zoom to explore 4. Click nodes for details 5. Observe connections ``` ## ๐Ÿ“š Additional Resources ### Backend Documentation - [README.md](../README.md) - [QUICKSTART.md](../QUICKSTART.md) - [ARCHITECTURE.md](../ARCHITECTURE.md) ### Frontend Documentation - [README.md](./README.md) - [DEVELOPMENT.md](./DEVELOPMENT.md) - [FRONTEND_SUMMARY.md](./FRONTEND_SUMMARY.md) ### API Documentation - Swagger UI: http://localhost:8000/docs - ReDoc: http://localhost:8000/redoc ## โœ… Verification Checklist After setup, verify: - [ ] Backend running on port 8000 - [ ] Frontend running on port 3000 - [ ] Can access http://localhost:3000 - [ ] Dashboard loads successfully - [ ] Can start a scan - [ ] Real-time updates working - [ ] Network map displays - [ ] Hosts table populated - [ ] WebSocket connected (check console) - [ ] No errors in browser console - [ ] No errors in backend logs ## ๐ŸŽ‰ You're Ready! Both backend and frontend are now running and integrated. Start scanning your network! --- **Need Help?** - Check browser console for frontend errors - Check `logs/network_scanner.log` for backend errors - Ensure both servers are running - Verify network connectivity **Happy Scanning! ๐Ÿ”**