# mattosaurus/pgpcore architecture

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

- Interactive diagram: https://gitdiagram.com/mattosaurus/pgpcore
- Repository: https://github.com/mattosaurus/pgpcore

## Overview

##### Main Components
- Core Library – The heart of the PgpCore library. It includes all the implementations of PGP operations (e.g., PGP.EncryptAsync, PGP.DecryptAsync, PGP.SignAsync, etc.).
- Abstraction Layer – Found in the “PgpCore/Abstractions” directory; this layer defines interfaces like IPGP, IPGP.EncryptSync, etc., that formalize the contract for the various operations.
- Domain Models – Under “PgpCore/Models”, these classes (e.g., EncryptionKeys, PGPInspectResult, VerificationResult) encapsulate data used in PGP operations.
- Helper and Utility Components – As seen in the “PgpCore/Helpers”, “PgpCore/Extensions”, and “PgpCore/Enums” directories. They provide supporting functions (e.g., stream and string extensions, disposable patterns, etc.) and enumeration values for various algorithms.
- Unit Testing – Represented in the “PgpCore.Tests” project. This shows how operations (encrypt, decrypt, sign, verify) are validated, ensuring the core functionality remains reliable.
- External Dependency – The Portable.BouncyCastle library; an external block which the core library depends on for cryptographic operations.

##### Relationships and Data Flow
- The Application Developer or consumer of the library calls into the core APIs exposed by the PgpCore classes.
- The PgpCore class uses interfaces (from the Abstractions) as contracts. Its implementations use utility classes and models to process the input data (files, streams, or strings).
- Depending on the chosen operation (e.g., encryption vs. signing), the appropriate method is called, following a typical “Facade” pattern granting a simple interface to the sophisticated underlying implementations.
- Input and output data (like file paths, streams, or plain strings) flow from the consumer to the method implementation, then through helper methods for transformations (e.g., converting strings to streams) and finally to the Portable.BouncyCastle library for the cryptographic processing.
- There is clear separation between operations: key generation, encryption/signing, decryption/verifying, and the “inspection” operations.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each sub-directory (Abstractions, Enums, Helpers, Models) isolates a specific responsibility.
- Facade Pattern: The PGP class provides a simplified interface for the complex PGP operations.
- Dependency Management: The core library depends on Portable.BouncyCastle, but the rest of the operations are decoupled via the use of interfaces.
- Test Driven Structure: The presence of an extensive “PgpCore.Tests” project indicates that behavior is validated through well-isolated unit tests.

##### Elements
- Clear Labels: Each component (e.g., “Core Library (PGP class)”, “Abstraction Interfaces”, “Encryption Operations”, “Decryption Operations”, “Key Management”, “Utilities”, “Tests”, “External: Portable.BouncyCastle”).
- External dependency block with a unique style to denote that it is a third-party library.
- Notes or Annotations: Brief commentary next to each component detailing its responsibility (for example, note that the “Abstractions” layer defines contracts like IPGP, while the “Models” encapsulate the data structures used in operations).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "API Consumer"
        D("Developer"):::consumer
    end

    subgraph "Core Library & Internal Components"
        PGP("Core Library (PGP)"):::core
        subgraph "Abstractions"
            A("Abstraction Interfaces"):::abstractions
        end
        subgraph "Models andUtilities"
            M("Domain Models"):::models
            H("Helpers"):::utilities
            E("Extensions"):::utilities
            EN("Enums"):::utilities
        end
        B("Portable.BouncyCastle"):::external
    end

    subgraph "Testing"
        T("Unit Testing"):::tests
    end

    D -->|"callsAPI"| PGP
    PGP -->|"implements"| A
    PGP -->|"uses"| M
    PGP -->|"utilizes"| H
    PGP -->|"utilizes"| E
    PGP -->|"utilizes"| EN
    PGP -->|"callsCrypto"| B
    T -->|"validates"| PGP

    click PGP "https://github.com/mattosaurus/pgpcore/blob/master/PgpCore/PGP.cs"
    click A "https://github.com/mattosaurus/pgpcore/tree/master/PgpCore/Abstractions"
    click M "https://github.com/mattosaurus/pgpcore/tree/master/PgpCore/Models"
    click H "https://github.com/mattosaurus/pgpcore/tree/master/PgpCore/Helpers"
    click E "https://github.com/mattosaurus/pgpcore/tree/master/PgpCore/Extensions"
    click EN "https://github.com/mattosaurus/pgpcore/tree/master/PgpCore/Enums"
    click T "https://github.com/mattosaurus/pgpcore/blob/master/PgpCore.Tests"

    classDef consumer fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef core fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef abstractions fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef models fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef utilities fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef tests fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef external fill:#fefefe,stroke:#333,stroke-dasharray: 5,5,stroke-width:2px;
```
