# frida/frida-core architecture

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

- Interactive diagram: https://gitdiagram.com/frida/frida-core
- Repository: https://github.com/frida/frida-core

## Overview

##### Main Components

a. Core Components:
- Injection System (inject/ directory)
- Agent System (lib/agent/)
- Payload System (lib/payload/)
- Communication Layer (lib/pipe/)
- Platform-specific Backends (src/darwin/, src/linux/, src/windows/, etc.)

b. Supporting Systems:
- Compiler Service (src/compiler/)
- Host Session Service (src/host-session-service.vala)
- Portal Service (portal/)
- Server Component (server/)

##### Architectural Layers (from bottom to top)

Layer 1 - Platform Layer:
- Native APIs and system interfaces

Layer 2 - Core Services:
- Process manipulation services
- Memory management systems

Layer 3 - Communication:
- Pipe system for IPC
- Socket communication
- P2P capabilities (lib/base/p2p.vala)

Layer 4 - Runtime:
- Script engine
- Agent container
- Compiler services

Layer 5 - API Layer:
- Language binding interfaces
- Public APIs
- Service interfaces

##### Component Details

For each major component, include:
- Component name
- Primary responsibilities
- Key interfaces
- Dependencies

##### Additional Elements

- External integration points
- Version information
- Extension points
- Resource management systems

- The modular nature of the system
- Cross-platform compatibility
- Security boundaries
- Communication channels
- Injection mechanisms
- Script execution flow

Keep the abstraction level high enough to be understandable but detailed enough to show the sophisticated nature of the system. Use a hierarchical layout to show the relationship between components, with platform-specific implementations grouped together but clearly separated.

Remember to highlight the core feature of code injection and instrumentation, showing how it flows from the API layer through to the platform-specific implementations.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef platform fill:#e6f3ff,stroke:#4a90e2
    classDef core fill:#f5e6ff,stroke:#9b51e0
    classDef communication fill:#e6ffe6,stroke:#2ecc71
    classDef security fill:#ffe6e6,stroke:#e74c3c
    classDef service fill:#fff5e6,stroke:#f1c40f
    classDef api fill:#f0f0f0,stroke:#95a5a6

    %% Legend
    subgraph Legend
        P[Platform Component]:::platform
        C[Core Component]:::core
        COM[Communication Component]:::communication
        SEC[Security Component]:::security
        SER[Service Component]:::service
        API[API Component]:::api
    end

    %% API Layer
    subgraph API
        PublicAPI[Public API Interface]:::api
        LanguageBindings[Language Bindings]:::api
    end

    %% Core Services Layer
    subgraph CoreServices
        HostSession[Host Session Service]:::service
        Portal[Portal Service]:::service
        Server[Server Component]:::service
        ScriptEngine[Script Engine]:::core
        ProcessMgmt[Process Management]:::core
    end

    %% Communication Layer
    subgraph Communication
        Pipe[Pipe System]:::communication
        P2P[P2P Communication]:::communication
        Socket[Socket Communication]:::communication
        RPC[RPC System]:::communication
    end

    %% Security Layer
    subgraph Security
        SELinux[SELinux Integration]:::security
    end

    %% Platform-specific Layer
    subgraph PlatformLayer
        Darwin[Darwin Backend]:::platform
        Linux[Linux Backend]:::platform
        Windows[Windows Backend]:::platform
        FreeBSD[FreeBSD Backend]:::platform
        QNX[QNX Backend]:::platform
    end

    %% Core Components
    subgraph CoreComponents
        Injection[Injection System]:::core
        Agent[Agent System]:::core
        Payload[Payload System]:::core
        Compiler[Compiler Service]:::core
    end

    %% Relationships
    PublicAPI --> HostSession
    HostSession --> Injection
    Injection --> Agent
    Agent --> Payload
    Payload --> ProcessMgmt
    ProcessMgmt --> PlatformLayer
    Communication --> CoreComponents
    SELinux --> PlatformLayer
    Portal --> Server
    Server --> Communication
    ScriptEngine --> Payload

    %% Click Events
    click Injection "https://github.com/frida/frida-core/tree/main/inject/"
    click Agent "https://github.com/frida/frida-core/tree/main/lib/agent/"
    click Payload "https://github.com/frida/frida-core/tree/main/lib/payload/"
    click Pipe "https://github.com/frida/frida-core/tree/main/lib/pipe/"
    click Darwin "https://github.com/frida/frida-core/tree/main/src/darwin/"
    click Linux "https://github.com/frida/frida-core/tree/main/src/linux/"
    click Windows "https://github.com/frida/frida-core/tree/main/src/windows/"
    click FreeBSD "https://github.com/frida/frida-core/tree/main/src/freebsd/"
    click QNX "https://github.com/frida/frida-core/tree/main/src/qnx/"
    click Compiler "https://github.com/frida/frida-core/tree/main/src/compiler/"
    click HostSession "https://github.com/frida/frida-core/blob/main/src/host-session-service.vala"
    click Portal "https://github.com/frida/frida-core/tree/main/portal/"
    click Server "https://github.com/frida/frida-core/tree/main/server/"
    click SELinux "https://github.com/frida/frida-core/tree/main/lib/selinux/"
    click P2P "https://github.com/frida/frida-core/blob/main/lib/base/p2p.vala"
    click Socket "https://github.com/frida/frida-core/blob/main/lib/base/socket.vala"
    click RPC "https://github.com/frida/frida-core/blob/main/lib/base/rpc.vala"
    click ScriptEngine "https://github.com/frida/frida-core/blob/main/lib/payload/script-engine.vala"
    click ProcessMgmt "https://github.com/frida/frida-core/blob/main/lib/payload/process.vala"
```
