# bearcove/shapely architecture

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

- Interactive diagram: https://gitdiagram.com/bearcove/shapely
- Repository: https://github.com/bearcove/shapely

## Overview

##### Main Components
- Derive Macro Support (shapely-derive): Implements the procedural macro which users annotate on their structs/enums to generate the necessary code automatically.
- Code Generation Module (shapely-codegen): Likely responsible for generating additional boilerplate or helper code as part of the framework.
- Format-Specific Modules:
– shapely-json: Handles JSON serialization/deserialization routines.
– shapely-msgpack: Provides implementations for handling MessagePack formats.
– shapely-pretty: Offers pretty-printing utilities, likely for debugging or better output formatting.
– shapely-urlencoded: Supports URL-encoded data processing.
– shapely-yaml: Implements YAML-specific functionalities.
- Top-Level Public API (shapely): The primary crate that brings together all the functionalities from the specialized modules and exposes the public API.

##### Relationships and Interactions
- The “shapely” crate acts as an aggregator that exposes APIs and interacts with the lower-level internal libraries (shapely-core, shapely-derive, and the various format-specific crates).
- “shapely-derive” uses “shapely-core” and possibly other helper utilities to generate code at compile-time by leveraging the Rust procedural macro system.
- The format crates (json, msgpack, etc.) likely depend on “shapely-core” for the base reflection and introspection logic and might be used by the “shapely” crate to extend support for different data formats.
- “shapely-codegen” might integrate with both the derive macros and core to facilitate the generation of optimized code or enhance functionality.

##### Architectural Patterns and Design Principles
- Modularization: Each functionality (such as JSON support, pretty printing, or code generation) is encapsulated in its own crate. This encourages clear separation of concerns and ease of maintenance.
- Dependency Inversion: The top-level API (“shapely”) depends on abstracted, format-specific modules, which in turn are built on a shared core library.
- Procedural Macros: The use of “shapely-derive” embodies Rust’s compile-time code-generation capabilities, which is a key design principle in modern Rust frameworks.
- Extensibility: By providing separate libraries for each supported format, the system is designed to be easily extensible when adding or updating support for additional data formats.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Entity
    UC("User Code"):::external

    %% Core Layer
    subgraph "Core Layer"
        SC["shapely-core: Reflection & Introspection"]:::core
    end

    %% Macros & Code Generation Layer
    subgraph "Macros & Codegen Layer"
        SD["shapely-derive: Procedural Macros"]:::macro
        SCG["shapely-codegen: Code Generation"]:::macro
    end

    %% Format-Specific Modules Layer
    subgraph "Format-Specific Modules"
        SJSON["shapely-json: JSON Support"]:::format
        SMSG["shapely-msgpack: MessagePack Support"]:::format
        SPRETTY["shapely-pretty: Pretty Printing"]:::format
        SURL["shapely-urlencoded: URL-Encoding"]:::format
        SYAML["shapely-yaml: YAML Support"]:::format
    end

    %% Public API Layer
    subgraph "Public API Layer"
        SAPI["shapely: Public API Aggregator"]:::api
    end

    %% Relationships
    UC -->|"uses"| SAPI

    SAPI -->|"aggregates"| SC
    SAPI -->|"incorporates"| SD
    SAPI -->|"incorporates"| SCG
    SAPI -->|"integrates"| SJSON
    SAPI -->|"integrates"| SMSG
    SAPI -->|"integrates"| SPRETTY
    SAPI -->|"integrates"| SURL
    SAPI -->|"integrates"| SYAML

    SD -->|"utilizes"| SC
    SCG -->|"integrates_with"| SD
    SCG -->|"integrates_with"| SC

    SJSON -->|"depends_on"| SC
    SMSG -->|"depends_on"| SC
    SPRETTY -->|"depends_on"| SC
    SURL -->|"depends_on"| SC
    SYAML -->|"depends_on"| SC

    %% Styles
    classDef core fill:#fde2e4,stroke:#d62828,stroke-width:2px;
    classDef macro fill:#e0fbfc,stroke:#118ab2,stroke-width:2px;
    classDef format fill:#e7f9a9,stroke:#40916c,stroke-width:2px;
    classDef api fill:#fefae0,stroke:#f4a261,stroke-width:2px;
    classDef external fill:#f0efeb,stroke:#6d6875,stroke-width:2px;

    %% Click Events
    click SC "https://github.com/bearcove/shapely/tree/main/shapely-core/"
    click SD "https://github.com/bearcove/shapely/tree/main/shapely-derive/"
    click SCG "https://github.com/bearcove/shapely/tree/main/shapely-codegen/"
    click SJSON "https://github.com/bearcove/shapely/tree/main/shapely-json/"
    click SMSG "https://github.com/bearcove/shapely/tree/main/shapely-msgpack/"
    click SPRETTY "https://github.com/bearcove/shapely/tree/main/shapely-pretty/"
    click SURL "https://github.com/bearcove/shapely/tree/main/shapely-urlencoded/"
    click SYAML "https://github.com/bearcove/shapely/tree/main/shapely-yaml/"
    click SAPI "https://github.com/bearcove/shapely/tree/main/shapely/"
```
