# jolocom/jolocom-lib architecture

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

- Interactive diagram: https://gitdiagram.com/jolocom/jolocom-lib
- Repository: https://github.com/jolocom/jolocom-lib

## Overview

##### And Isolate the Major Components
- Core Identity Modules: Look at the directories “js/identity” and “ts/identity” which include the construction and management of DID documents. Also note the “js/identityWallet” and “ts/identityWallet” folders for handling identity wallets.
- Credential Management: The “credentials” and “signedCredential” folders (found under both “js” and “ts”) handle the creation and operations on credentials and signed credentials.
- DID Methods: There are dedicated directories for “didMethods” with sub-folders for different DID method implementations (e.g., “jolo” and “local”). These modules encapsulate the logic for DID registration, recovery, and resolution.
- Interaction Tokens: Multiple folders (“js/interactionTokens” and “ts/interactionTokens”) contain modules for constructing and parsing various tokens such as authentication tokens, credential offer/response tokens, and credentials receive tokens, often built upon the JSON Web Token standard.
- Linked Data and Cryptographic Signatures: Directories like “js/linkedData”, “js/linkedDataSignature”, and their TypeScript equivalents provide functionality for linked data signatures and handling cryptographic signature suites.
- Utilities and Error Handling: The “js/utils” and “ts/utils” directories include functions for data validation, cryptographic helpers, and context management. The “js/errors” and “ts/errors” directories manage error definitions across the library.
- Testing: The “tests” directory (with subdirectories for each thematic area such as “credential”, “didMethods”, “identity”, “interactionTokens”, etc.) reflects an emphasis on unit and integration testing, ensuring that the interactions between these components are covered.

##### Understand Component Relationships and Data Flow
- The Identity and DID Document modules form the backbone, providing the core representation of identities.
- The DID Methods modules interact closely with identity functionality – they perform critical tasks like resolution, registration, and recovery which are necessary for managing decentralized identities.
- Credential modules (both issuance and verification of credentials and signed credentials) depend upon identity information and are often wrapped in interaction tokens.
- Interaction tokens serve as a communication layer, wrapping data (often using JSON Web Tokens) to support operations like authentication and credential exchange.
- Utility and helper methods support all core processes, and error handling is integrated across the system to ensure robustness.
- The library is designed to be modular; each component (identity, credentials, interaction tokens, DID methods, linked data) is separately maintained but interacts via well-defined interfaces.

##### Architectural Patterns and Design Principles
- Modularity and Separation of Concerns: The clear division into directories (credentials, didMethods, identity, interactionTokens) shows an architectural emphasis on loosely coupled modules.
- Interface and Type Definitions: With TypeScript’s heavy presence (evidenced by the “ts” and “js” folders containing type definition files), the design leverages strict typing and clearly defined interfaces for predictable interactions between modules.
- Extensibility: The separation between different DID methods (e.g., “jolo” versus “local”) indicates an architectural choice to support interchangeable implementations.
- Test-Driven Development: A comprehensive test suite indicates that unit and integration test components help validate interactions among modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Identity and Identity Wallet
    subgraph "Identity and Identity Wallet"
        idJ("Identity (JS)"):::identity
        walletJ("Identity Wallet (JS)"):::identity
        idTS("Identity (TS)"):::identity
        walletTS("Identity Wallet (TS)"):::identity
    end

    %% DID Methods
    subgraph "DID Methods"
        didJ("DID Methods (JS)"):::did
        didTS("DID Methods (TS)"):::did
    end

    %% Credential Management
    subgraph "Credential Management"
        credJ("Credentials (JS)"):::credential
        credTS("Credentials (TS)"):::credential
    end

    %% Interaction Tokens
    subgraph "Interaction Tokens"
        tokenJ("Interaction Tokens (JS)"):::token
        tokenTS("Interaction Tokens (TS)"):::token
    end

    %% Linked Data & Cryptographic Signatures
    subgraph "Linked Data & Signatures"
        ldJ("Linked Data (JS)"):::signature
        ldSigJ("Linked Data Signature (JS)"):::signature
        ldTS("Linked Data (TS)"):::signature
        ldSigTS("Linked Data Signature (TS)"):::signature
    end

    %% Utilities & Error Handling
    subgraph "Utilities & Error Handling"
        utilJ("Utilities (JS)"):::utils
        errJ("Errors (JS)"):::utils
        utilTS("Utilities (TS)"):::utils
        errTS("Errors (TS)"):::utils
    end

    %% Testing
    subgraph "Testing"
        tests("Tests Suite"):::test
    end

    %% Relationships
    %% DID Methods interacting with Identity
    didJ -->|"register/resolve"| idJ
    didTS -->|"register/resolve"| idTS

    %% Identity providing data to Credential Management
    idJ -->|"providesIdentity"| credJ
    idTS -->|"providesIdentity"| credTS
    walletJ -->|"supportsIdentity"| credJ
    walletTS -->|"supportsIdentity"| credTS

    %% Interaction Tokens wrapping Identity and Credentials
    tokenJ -->|"wrapsIdentity"| idJ
    tokenTS -->|"wrapsIdentity"| idTS
    tokenJ -->|"wrapsCredential"| credJ
    tokenTS -->|"wrapsCredential"| credTS

    %% Linked Data Signatures applied to Tokens and Credentials
    ldSigJ -->|"appliesSignature"| tokenJ
    ldSigTS -->|"appliesSignature"| tokenTS
    ldSigJ -->|"verifiesCredential"| credJ
    ldSigTS -->|"verifiesCredential"| credTS

    %% Utilities and Errors supporting core modules
    utilJ -.-> idJ
    utilTS -.-> idTS
    errJ -.-> credJ
    errTS -.-> credTS
    utilJ -.-> tokenJ
    utilTS -.-> tokenTS
    errJ -.-> tokenJ
    errTS -.-> tokenTS

    %% Testing suite covers core modules (dotted connections)
    tests -.-> idJ
    tests -.-> credJ
    tests -.-> didJ
    tests -.-> tokenJ
    tests -.-> ldSigJ

    %% Click Events for Component Mapping
    click idJ "https://github.com/jolocom/jolocom-lib/tree/develop/js/identity"
    click walletJ "https://github.com/jolocom/jolocom-lib/tree/develop/js/identityWallet"
    click idTS "https://github.com/jolocom/jolocom-lib/tree/develop/ts/identity"
    click walletTS "https://github.com/jolocom/jolocom-lib/tree/develop/ts/identityWallet"

    click credJ "https://github.com/jolocom/jolocom-lib/tree/develop/js/credentials"
    click credTS "https://github.com/jolocom/jolocom-lib/tree/develop/ts/credentials"

    click didJ "https://github.com/jolocom/jolocom-lib/tree/develop/js/didMethods"
    click didTS "https://github.com/jolocom/jolocom-lib/tree/develop/ts/didMethods"

    click tokenJ "https://github.com/jolocom/jolocom-lib/tree/develop/js/interactionTokens"
    click tokenTS "https://github.com/jolocom/jolocom-lib/tree/develop/ts/interactionTokens"

    click ldJ "https://github.com/jolocom/jolocom-lib/tree/develop/js/linkedData"
    click ldSigJ "https://github.com/jolocom/jolocom-lib/tree/develop/js/linkedDataSignature"
    click ldTS "https://github.com/jolocom/jolocom-lib/tree/develop/ts/linkedData"
    click ldSigTS "https://github.com/jolocom/jolocom-lib/tree/develop/ts/linkedDataSignature"

    click utilJ "https://github.com/jolocom/jolocom-lib/tree/develop/js/utils"
    click errJ "https://github.com/jolocom/jolocom-lib/tree/develop/js/errors"
    click utilTS "https://github.com/jolocom/jolocom-lib/tree/develop/ts/utils"
    click errTS "https://github.com/jolocom/jolocom-lib/tree/develop/ts/errors"

    click tests "https://github.com/jolocom/jolocom-lib/tree/develop/tests"

    %% Class Definitions for Colors and Styles
    classDef identity fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef credential fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef did fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef token fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef signature fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef utils fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef test fill:#fefefe,stroke:#818182,stroke-width:2px;
```
