How forta-network/forta-node works
Main Components
• CLI & Orchestration Layer: Represented mainly by the cmd folder (e.g., cmd/cli.go, cmd/run.go, etc.) and the main.go file. This is the entry point from which administrators initialize (“forta init”) and run (“forta run”) the node. It interacts with the underlying service manager.
• Container Management: The project uses Docker extensively (multiple Dockerfiles, docker-compose configurations, and related scripts). This component acts as the runtime environment for the different services and agents.
• Service Modules: These are implemented in the services folder. They include specialized components such as:
• Detection and scanning (services/scanner)
• API gateway and JSON-RPC communication (services/json-rpc, services/public-api)
• JWT-based authentication (services/jwt-provider)
• Supervisory components (services/supervisor) that monitor and manage agent logs and health
• Miscellaneous supporting services like storage management (services/storage), update mechanisms (services/updater), and metric collections (services/components/metrics, services/components/prometheus)
• Detection Agents and Bots: Although deployed as Dockerized containers, the agents are developed in various parts of the project (see directories like tests/e2e/agents and clients/agentgrpc). They represent the detection bots that monitor blockchain events.
• External Integrations and Clients: Various client packages (e.g., clients/alertapi, clients/docker, clients/ipfsclient, clients/redis) provide interfaces to external systems (such as alert platforms, container runtimes, IPFS, and Redis) and are used across different services.
• Continuous Integration/Deployment & Build Tools: The .github directory, Makefile, and release scripts indicate robust build, test, and deployment pipelines; include these components as ancillary but important parts of the system that ensure automation and consistency.
Relationships and Interactions
• The CLI (user interface) triggers container orchestration actions using Docker. In turn, it deploys various services that work independently but coordinate through inter-service APIs (e.g., via JSON-RPC or public API endpoints).
• The service modules interact with detection agents running in containers—supervisors track the agents, while messaging and alert components handle result propagation.
• Build and release pipelines (represented in the .github workflows and release directories) are part of the development environment and ensure that container images (CLI and service containers) are built and pushed appropriately.
• Client libraries encapsulate calls to external services (like IPFS or Redis) while also abstracting internal inter-service communications.
Architectural Patterns and Design Principles
• Modularity: The project is organized into multiple small components (e.g., services/components, clients, store, config) that interact through well-defined interfaces.
• Containerization: With Docker at its core, each service and agent is isolated into its own container for scalability and ease of deployment.
• Microservices/Lite Service Decomposition: While not strictly split into separate microservices, the diverse services (scanner, jwt-provider, supervisor, etc.) resemble a microservices architecture within a container ecosystem.
• Clear Separation of Concerns: Each module (CLI, service orchestration, blockchain detection, logging, monitoring) is implemented in its own area, easing maintenance and future expansion.