# pinojs/pino architecture

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

- Interactive diagram: https://gitdiagram.com/pinojs/pino
- Repository: https://github.com/pinojs/pino

## Overview

##### Main Components

a. Core Logger Components:
- Main Logger Instance
- Child Logger System
- Level Management System
- Transport System
- Serialization Layer
- Time Management

b. Transport Layer:
- Worker Thread Transport System
- Stream Management
- Asynchronous Pipeline

##### Architectural Patterns to Highlight

- Worker Thread Architecture for Transport
- Plugin System for Formatters
- Streaming Architecture
- Child Logger Hierarchy

##### Specific Implementation Details

**┌─ Logger Core ─────────────────────┐**
- ┌─────────────┐    ┌────────────┐ │
- Level System │    │Time System │ │
- ┘    └────────────┘ │
- ┌─────────────┐    ┌────────────┐ │
- Serializers  │    │Redaction   │ │
- ┘    └────────────┘ │
- ┬───────────────────┘

**┌───────────────▼───────────────────┐**
- Transport Layer                 │
- ┌─────────────────────────────────┤
- Worker Thread Transport          │
- ┌─────────────┐ ┌────────────┐ │
- Stream Mgmt  │ │Async Queue │ │
- ┘ └────────────┘ │
- ┬─┘

**┌─────────────────────────────────▼─┐**
- Output Destinations        │
- ┌─────────────┐    ┌────────────┐ │
- File System  │    │Stdout      │ │
- ┘    └────────────┘ │
- ┬─┘

##### Important Flows

- Log message flow from creation to output
- Child logger creation and inheritance
- Transport worker thread communication
- Asynchronous operations

##### Technical Details

- Node.js Worker Threads
- Stream API
- JSON serialization
- Level management system

##### Integration Points

Integration with:
- Web frameworks (Express, Fastify, etc.)
- External transport systems
- Pretty printing capabilities
- Browser support

Remember to:
- Keep the main logging flow clear and central
- Separation between synchronous and asynchronous operations
- Performance-critical paths
- Notes about key performance characteristics

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core["Logger Core"]
        direction TB
        MainLogger["Main Logger Instance"]
        LevelSys["Level System"]
        TimeSys["Time System"]
        Serial["Serializers"]
        Redact["Redaction"]
        Proto["Core Protocol/Child Logger"]
        Meta["Metadata Handler"]
        Caller["Caller ID"]
        Constants["Constants & Symbols"]
    end

    subgraph Transport["Transport Layer"]
        direction TB
        WorkerT["Worker Thread Transport"]
        StreamMgmt["Stream Management"]
        AsyncQ["Async Queue"]
        MultiStream["Multistream System"]
        TransportStream["Transport Stream Pipeline"]
    end

    subgraph Output["Output Destinations"]
        direction TB
        FileSystem["File System"]
        Stdout["Stdout"]
        Browser["Browser Support"]
    end

    MainLogger --> Proto
    Proto --> Transport
    Transport --> Output

    LevelSys --> MainLogger
    TimeSys --> MainLogger
    Serial --> MainLogger
    Redact --> MainLogger
    Meta --> MainLogger
    Caller --> MainLogger
    Constants --> MainLogger

    WorkerT --> StreamMgmt
    StreamMgmt --> AsyncQ
    MultiStream --> TransportStream
    
    classDef core fill:#2374ab
    classDef transport fill:#2a9d8f
    classDef output fill:#e76f51
    
    class MainLogger,LevelSys,TimeSys,Serial,Redact,Proto,Meta,Caller,Constants core
    class WorkerT,StreamMgmt,AsyncQ,MultiStream,TransportStream transport
    class FileSystem,Stdout,Browser output

    click MainLogger "https://github.com/pinojs/pino/blob/main/pino.js"
    click LevelSys "https://github.com/pinojs/pino/blob/main/lib/levels.js"
    click TimeSys "https://github.com/pinojs/pino/blob/main/lib/time.js"
    click WorkerT "https://github.com/pinojs/pino/blob/main/lib/worker.js"
    click StreamMgmt "https://github.com/pinojs/pino/blob/main/lib/transport-stream.js"
    click Redact "https://github.com/pinojs/pino/blob/main/lib/redaction.js"
    click MultiStream "https://github.com/pinojs/pino/blob/main/lib/multistream.js"
    click Proto "https://github.com/pinojs/pino/blob/main/lib/proto.js"
    click Constants "https://github.com/pinojs/pino/blob/main/lib/constants.js"
    click Browser "https://github.com/pinojs/pino/blob/main/browser.js"
    click TransportStream "https://github.com/pinojs/pino/blob/main/lib/transport-stream.js"
    click Meta "https://github.com/pinojs/pino/blob/main/lib/meta.js"
    click Caller "https://github.com/pinojs/pino/blob/main/lib/caller.js"
```
