# facebook/folly architecture

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

- Interactive diagram: https://gitdiagram.com/facebook/folly
- Repository: https://github.com/facebook/folly

## Overview

##### High-Level Architecture Components

a. Core Library Components
- Fundamental modules like Memory, Synchronization, Containers, etc.

b. Supporting Infrastructure
- Around the core components
- Build systems, testing framework, and documentation

##### Component Organization

Create these major groupings:

a. Foundation Layer (Bottom)
- Portability (/folly/portability/)
- Memory Management (/folly/memory/)
- System Utilities (/folly/system/)

b. Core Functionality Layer (Middle)
- Synchronization primitives (/folly/synchronization/)
- Containers (/folly/container/)
- String utilities (/folly/String.h, /folly/FBString.h)
- Futures & Promises (/folly/futures/)
- Executors (/folly/executors/)

c. Advanced Features Layer (Top)
- Fiber system (/folly/fibers/)
- Experimental features (/folly/experimental/)
- Logging system (/folly/logging/)
- IO utilities (/folly/io/)

##### External Dependencies

- Boost
- OpenSSL
- Google Test
- Format library
- Other external libraries

##### Component Details

For each major component, include:
- Name
- Key classes/features
- Thread safety guarantees
- Performance characteristics

##### Notes Section

A notes section indicating:
- Platform support (Linux, Windows, macOS)
- C++ version requirements (C++17)
- Build system requirements
- Performance considerations

##### Implementation Details

For critical components, show:
- Key algorithms used
- Memory layout
- Threading model
- Error handling approach

- The practical, performance-focused nature of the library
- The flat organizational structure
- The independence of components
- The extensive testing infrastructure
- The focus on modern C++ features

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef core fill:#b3d1ff,stroke:#333,stroke-width:2px
    classDef experimental fill:#ffe6b3,stroke:#333,stroke-width:2px
    classDef external fill:#d9d9d9,stroke:#333,stroke-width:2px
    classDef foundation fill:#c2f0c2,stroke:#333,stroke-width:2px
    classDef utility fill:#ffcccc,stroke:#333,stroke-width:2px

    %% External Dependencies
    subgraph External["External Dependencies"]
        Boost[Boost]:::external
        OpenSSL[OpenSSL]:::external
        GTest[Google Test]:::external
        Format[Format Library]:::external
    end

    %% Foundation Layer
    subgraph Foundation["Foundation Layer"]
        Port[Portability]:::foundation
        CoreF[Core Foundation]:::foundation
        MemMgmt[Memory Management]:::foundation
        SysUtil[System Utilities]:::foundation
    end

    %% Core Functionality Layer
    subgraph Core["Core Functionality Layer"]
        Sync[Synchronization]:::core
        Containers[Containers]:::core
        StringUtil[String Utilities]:::core
        FutProm[Futures & Promises]:::core
        Exec[Executors]:::core
    end

    %% Advanced Features Layer
    subgraph Advanced["Advanced Features Layer"]
        Fiber[Fiber System]:::core
        ExpFeatures[Experimental Features]:::experimental
        Logging[Logging System]:::utility
        IO[IO Utilities]:::utility
    end

    %% Relationships
    CoreF --> MemMgmt
    CoreF --> Port
    MemMgmt --> Containers
    MemMgmt --> Sync
    Sync --> FutProm
    Sync --> Exec
    Containers --> IO
    FutProm --> Fiber
    Exec --> Fiber
    Exec --> IO
    IO --> Logging
    Port --> ExpFeatures

    %% External Dependencies
    Boost --> CoreF
    OpenSSL --> IO
    GTest -.-> ExpFeatures
    Format --> StringUtil

    %% Click events
    click MemMgmt "https://github.com/facebook/folly/tree/main/folly/memory/"
    click Sync "https://github.com/facebook/folly/tree/main/folly/synchronization/"
    click Containers "https://github.com/facebook/folly/tree/main/folly/container/"
    click StringUtil "https://github.com/facebook/folly/blob/main/folly/String.h"
    click FutProm "https://github.com/facebook/folly/tree/main/folly/futures/"
    click Exec "https://github.com/facebook/folly/tree/main/folly/executors/"
    click Fiber "https://github.com/facebook/folly/tree/main/folly/fibers/"
    click Logging "https://github.com/facebook/folly/tree/main/folly/logging/"
    click IO "https://github.com/facebook/folly/tree/main/folly/io/"
    click Port "https://github.com/facebook/folly/tree/main/folly/portability/"
    click ExpFeatures "https://github.com/facebook/folly/tree/main/folly/experimental/"
    click CoreF "https://github.com/facebook/folly/tree/main/folly/lang/"

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Experimental]:::experimental
        L3[External]:::external
        L4[Foundation]:::foundation
        L5[Utilities]:::utility
    end
```
