# vadosware/pg_idkit architecture

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

- Interactive diagram: https://gitdiagram.com/vadosware/pg_idkit
- Repository: https://github.com/vadosware/pg_idkit

## Overview

##### Main Components and Architecture

a) Core Extension Layer:
- Main PostgreSQL extension interface
- Extension registration and initialization process
- Control file (pg_idkit.control) integration

b) ID Generation Modules:
Create distinct modules for each ID type:
- UUID (v6, v7)
- KSUID
- ULID
- Timeflake
- PushID
- XID
- CUID/CUID2
- NanoID

c) Integration Layer:
- PostgreSQL function interfaces
- Type conversion handlers
- Timestamp extraction capabilities

**[PostgreSQL Database]**
- ↑

**[pg_idkit Extension Interface]**
- ↑

**[Core Function Registry]**
- ↑
- ______|______

**[ID Generators] [Type Converters] [Timestamp Extractors]**

##### Implementation Details to Highlight

a) Extension Structure:
- Relationship between src/lib.rs and individual generator modules
- Pgrx framework integration
- Configuration management (pg_idkit.control)

b) ID Generation Flow:
- Demonstrate how each ID generator module interfaces with PostgreSQL
- Type conversion process for different ID formats
- Timestamp extraction capabilities

##### Component Relationships

**[Client Application]**
- ↓
**[PostgreSQL Database]**
- ↓
**[pg_idkit Extension]**

- [UUID Generators (v6, v7)]
- [KSUID Generator]
- [ULID Generator]
- [Timeflake Generator]
- [PushID Generator]
- [XID Generator]
- [CUID/CUID2 Generator]
- [NanoID Generator]

- [Timestamp Extractors]
- [Type Converters]

##### Additional Elements

- Version compatibility matrix
- Supported PostgreSQL versions
- Platform support (currently amd64)
- Build and packaging workflow

This design captures the essence of pg_idkit as a PostgreSQL extension while showing its modular approach to supporting multiple ID generation schemes and its integration with the broader PostgreSQL ecosystem.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph PostgreSQL
        PG[PostgreSQL Database]
    end

    subgraph Extension
        EI[Extension Interface]:::core
        CR[Core Function Registry]:::core
    end

    subgraph "ID Generators"
        UUIDv6[UUID v6]:::generator
        UUIDv7[UUID v7]:::generator
        KSUID[KSUID]:::generator
        KSUIDMS[KSUID MS]:::generator
        ULID[ULID]:::generator
        Timeflake[Timeflake]:::generator
        PushID[PushID]:::generator
        XID[XID]:::generator
        CUID[CUID]:::generator
        CUID2[CUID2]:::generator
        NanoID[NanoID]:::generator
    end

    subgraph "Utility Functions"
        TC[Type Converters]:::utility
        TE[Timestamp Extractors]:::utility
    end

    subgraph "Build & Deploy"
        Docker[Docker Container]:::deploy
        RPM[RPM Package]:::deploy
        CI[CI/CD Pipeline]:::deploy
    end

    PG --> EI
    EI --> CR
    CR --> UUIDv6
    CR --> UUIDv7
    CR --> KSUID
    CR --> KSUIDMS
    CR --> ULID
    CR --> Timeflake
    CR --> PushID
    CR --> XID
    CR --> CUID
    CR --> CUID2
    CR --> NanoID
    CR --> TC
    CR --> TE

    classDef core fill:#f9f,stroke:#333
    classDef generator fill:#bfb,stroke:#333
    classDef utility fill:#fbf,stroke:#333
    classDef deploy fill:#fbb,stroke:#333

    click EI "https://github.com/VADOSWARE/pg_idkit/blob/main/src/lib.rs"
    click UUIDv6 "https://github.com/VADOSWARE/pg_idkit/blob/main/src/uuid_v6.rs"
    click UUIDv7 "https://github.com/VADOSWARE/pg_idkit/blob/main/src/uuid_v7.rs"
    click KSUID "https://github.com/VADOSWARE/pg_idkit/blob/main/src/ksuid.rs"
    click KSUIDMS "https://github.com/VADOSWARE/pg_idkit/blob/main/src/ksuid_ms.rs"
    click ULID "https://github.com/VADOSWARE/pg_idkit/blob/main/src/ulid.rs"
    click Timeflake "https://github.com/VADOSWARE/pg_idkit/blob/main/src/timeflake.rs"
    click PushID "https://github.com/VADOSWARE/pg_idkit/blob/main/src/pushid.rs"
    click XID "https://github.com/VADOSWARE/pg_idkit/blob/main/src/xid.rs"
    click CUID "https://github.com/VADOSWARE/pg_idkit/blob/main/src/cuid.rs"
    click CUID2 "https://github.com/VADOSWARE/pg_idkit/blob/main/src/cuid2.rs"
    click NanoID "https://github.com/VADOSWARE/pg_idkit/blob/main/src/nanoid.rs"
    click Docker "https://github.com/VADOSWARE/pg_idkit/tree/main/infra/docker/"
    click CI "https://github.com/VADOSWARE/pg_idkit/tree/main/.github/workflows/"
```
