How capitansec/portpilot works
Main Components
• API Component (Directory: Api):
– Built with FastAPI, this is the core backend service.
– It contains configuration files (for database, Elasticsearch, Redis), HTTP routes (for scan and user-related endpoints), middleware for authentication, and various providers for logging, cryptography, environment handling, and interfacing with RabbitMQ queues.
– The API acts as the entry point: it accepts scan requests, validates user credentials, and forwards scan jobs into the messaging middleware.
• Frontend/Panel Component (Directory: Panel):
– A React-based web UI (as indicated by the package.json and various React source files).
– Provides dashboards, login and registration forms, and components like scan viewers and tables.
– It consumes API endpoints from the backend and offers real-time visualizations (supported by Grafana for scan results visualization).
• Worker Component (Directory: Worker):
– Implements the scanning agents. The Worker retrieves scan tasks from a RabbitMQ queue (configured via QueueContext and QueueConsume) and executes scanning routines (located in Worker/Scanner).
– Once a scan is executed, the results are sent to Elasticsearch (handled via ElasticContext) for further storage and analysis.
External and Integrated Services
• Messaging Middleware: RabbitMQ – Acts as the central job queue where scan requests are published by the API and consumed by multiple Worker agents.
• Data Stores:
– Elasticsearch – Stores and indexes scan results.
– Database(s) – Likely PostgreSQL (and possibly MongoDB based on the badges mentioned in the README) are used for storing user data and application metadata.
– Redis – Used for caching or session management, as configured in the API.
• Other Tools:
– Jenkins (see Jenkinsfile) for CI/CD integration.
– Docker and Docker Compose (multiple Dockerfiles and docker-compose files) for containerized deployments.
– Grafana – For visualizing and monitoring the scan results analysis.
Architectural Patterns and Relationships
• The API acts as the intermediary, receiving requests (both from the Panel UI and external API calls) and orchestrating scan processes.
• The messaging pattern is central: API submits tasks to RabbitMQ, the distributed Worker agents compete to pop and process these tasks, and finally results get stored in Elasticsearch.
• The system follows a distributed microservices style, with clear separation between the user interface (Panel), the API (as an orchestrator/service layer), and backend processing (Worker).