# falcosecurity/falco architecture

> Architecture diagram of the GitHub repository falcosecurity/falco, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/falcosecurity/falco
- Repository: https://github.com/falcosecurity/falco

## Overview

##### Project type and purpose
- Falco is a C++-based, cloud-native Linux runtime security tool that monitors kernel events (syscalls) and container metadata, applies user-defined rules, and emits alerts in real time.
- It comprises a kernel-space component (drivers/BPF), a userspace engine (event capture, filtering, rule evaluation), and a userspace daemon/CLI (`falco`) providing gRPC/HTTP interfaces and various output plugins.

##### File structure
- Top-level build orchestration: `CMakeLists.txt`, `cmake/` modules, `Makefile`, Docker and CI workflows (`.github/workflows/`, `docker/`).
- Core libraries (event capture, rule engine) live under `userspace/engine/`.
- The Falco daemon/application (CLI, servers, output plugins) lives under `userspace/falco/`.
- Configuration and default rule files in `config/`.
- Packaging scripts under `scripts/`.
- Demo and containerized environment in `docker/docker-compose/`.

##### README insights
- Falco uses backends for driver loading (kernel module or modern BPF) provided via `libs` submodule.
- Outputs can be to stdout, file, syslog, HTTP, gRPC or via plugins (Falco Plugin SDK).
- Offers a gRPC server and embedded HTTP server for remote control and event streaming.
- Demo environment includes Falco, Falcosidekick (event shipper), Redis, and UI.

##### Main components & their interactions
a. Kernel-space probes (legacy kmod or eBPF):
- Raw syscall/container events
- Built via CMake modules (`cmake/modules/bpf.cmake`, `driver.cmake`)
b. Event Capture Library (`libscap` in `userspace/engine/`):
- Reads events from kernel probe
- Normalizes, buffers, and hands off to engine
c. Falco Engine (`userspace/engine/`):
- Applies filter rules, resolves macros, tracks stats
- Generates alerts and enriches events with metadata (e.g., Kubernetes)
d. Falco Daemon/CLI (`userspace/falco/app/`):
- Loads engine, handles CLI commands (`run`, `list`, `start_grpc_server`, etc.)
- Manages lifecycle, signal handling, config parsing
e. Output Plugins & Servers (`userspace/falco/outputs*`, `grpc_server`, `webserver`):
- Formats and dispatches alerts to stdout, files, syslog, HTTP POST, gRPC streams
- Embedded HTTP/gRPC servers to stream events to clients or orchestration tools
f. External Components:
- Container runtime/Kubernetes API for metadata enrichment
- SIEM/Data Lake or Falcosidekick (via Docker Compose) as downstream consumers

##### Architectural patterns & design principles
- Layered architecture: kernel probe → capture library → engine → output layer
- Modular CMake organization for drivers, third-party libs, static analysis
- Plugin-style outputs and server interfaces for extensibility
- Single-process, single-thread execution model in Falco daemon for deterministic behavior

##### Detailed and comprehensive capture
- Low-level build and packaging modules (`cmake/`, `scripts/`) as supporting elements
- Submodules (e.g., `falcosecurity-libs`, `falcosecurity-rules`) as external dependencies

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Kernel-space Probes Layer
    subgraph "Kernel-space Probes" 
        direction TB
        KM["driver.cmake"]:::cmake
        KB["bpf.cmake"]:::cmake
    end

    %% Userspace Engine & Capture Layer
    subgraph "Userspace Engine & Capture" 
        direction TB
        SCAP["libscap\n(userspace/engine/)"]:::engine
        FE["Falco Engine"]:::engine
    end

    %% Falco Daemon & CLI Layer
    subgraph "Falco Daemon & CLI" 
        direction TB
        APP["Falco Daemon/CLI"]:::daemon
        GRPC_SRV["gRPC Server\n(port: 5060)"]:::daemon
        HTTP_SRV["HTTP Server\n(port: 8765)"]:::daemon
    end

    %% Output Plugins & External Consumers Layer
    subgraph "Output Plugins & External Consumers"
        direction TB
        OUT_STD["Stdout"]:::output
        OUT_FILE["File"]:::output
        OUT_SYS["Syslog"]:::output
        OUT_HTTP["HTTP POST"]:::output
        OUT_GRPC["gRPC Streams"]:::output
        subgraph "External Services" 
            direction TB
            SIEM["SIEM/Data Lake"]:::external
            FSK["Falcosidekick"]:::external
            UI["UI"]:::external
            REDIS["Redis"]:::external
        end
    end

    %% Packaging & Deployment Scripts
    subgraph "Packaging & Deployment Scripts"
        direction TB
        S1["CMakeLists.txt"]:::scripts
        S2["falco-modern-bpf.service"]:::scripts
        S3["postinst.in"]:::scripts
        S4["publish-deb"]:::scripts
    end

    %% Configuration Files
    CFG["config/"]:::support

    %% Docker Compose Demo Environment
    DC["docker-compose.yaml"]:::support
    HTTP_CFG["http_output.yml"]:::support
    DOCKERFILE["Falco Dockerfile"]:::support

    %% Data Flow
    KM --> SCAP
    KB --> SCAP
    SCAP --> FE
    FE --> APP
    APP --> GRPC_SRV
    APP --> HTTP_SRV
    APP --> OUT_STD
    APP --> OUT_FILE
    APP --> OUT_SYS
    APP --> OUT_HTTP
    APP --> OUT_GRPC
    GRPC_SRV --> UI
    GRPC_SRV --> SIEM
    HTTP_SRV --> UI
    OUT_HTTP --> SIEM
    OUT_GRPC --> FSK
    DC --> FSK
    DC --> REDIS
    DC --> UI

    %% Click Events
    click KM "https://github.com/falcosecurity/falco/blob/master/cmake/modules/driver.cmake"
    click KB "https://github.com/falcosecurity/falco/blob/master/cmake/modules/bpf.cmake"
    click SCAP "https://github.com/falcosecurity/falco/tree/master/userspace/engine/"
    click FE "https://github.com/falcosecurity/falco/blob/master/userspace/engine/falco_engine.cpp"
    click APP "https://github.com/falcosecurity/falco/blob/master/userspace/falco/app/app.cpp"
    click S1 "https://github.com/falcosecurity/falco/blob/master/scripts/CMakeLists.txt"
    click S2 "https://github.com/falcosecurity/falco/blob/master/scripts/systemd/falco-modern-bpf.service"
    click S3 "https://github.com/falcosecurity/falco/blob/master/scripts/debian/postinst.in"
    click S4 "https://github.com/falcosecurity/falco/tree/master/scripts/publish-deb"
    click CFG "https://github.com/falcosecurity/falco/tree/master/config/"
    click DC "https://github.com/falcosecurity/falco/blob/master/docker/docker-compose/docker-compose.yaml"
    click HTTP_CFG "https://github.com/falcosecurity/falco/blob/master/docker/docker-compose/config/http_output.yml"
    click DOCKERFILE "https://github.com/falcosecurity/falco/tree/master/docker/falco/Dockerfile"

    %% Styles
    classDef cmake fill:#FFA500,stroke:#333,stroke-width:1px
    classDef engine fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef daemon fill:#90EE90,stroke:#333,stroke-width:1px
    classDef output fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef external fill:#E6E6FA,stroke:#333,stroke-width:1px
    classDef support fill:#F5F5F5,stroke:#333,stroke-width:1px
    classDef scripts fill:#EEE8AA,stroke:#333,stroke-width:1px
```
