# openwallet-foundation/credo-ts architecture

> Architecture diagram of the GitHub repository openwallet-foundation/credo-ts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openwallet-foundation/credo-ts
- Repository: https://github.com/openwallet-foundation/credo-ts

## Overview

##### Project Type and Purpose
- This is a large TypeScript monorepo (managed with pnpm) providing a modular framework for building decentralized-identity solutions.
- It exposes a core “Agent” abstraction plus pluggable packages for DIDComm messaging, credential issuance/presentation (AnonCreds, W3C VCs, SD-JWT), ledger integrations (Indy-VDR, Cheqd), OpenID4VC flows, multi-tenant support, transports (HTTP/WS), storage layers (Askar, in-memory, filesystem), and platform runtimes (Node, React Native).

##### High-Level Architecture Components
a. Runtime Environments
- Node.js (@credo-ts/node)
- React Native (@credo-ts/react-native)
b. Application Layer
- Consumer application instantiates one or more Agents via `@credo-ts/core` (BaseAgent, AgentConfig, AgentModules).
- Optional multi-tenant layer (`@credo-ts/tenants`) coordinates multiple logical Agent contexts.
c. Core Agent
- Event bus and dependency manager
- Module registry (didcomm, credentials, proofs, connections, cache, generic-records, mdoc, sd-jwt-vc, vc, x509, question-answer, action-menu, drpc, etc.)
- Transport orchestration (inbound/outbound HTTP & WebSocket)
d. Protocol Modules
- DIDComm (message envelope, decorators, dispatcher, handlers)
- Connections (DID exchange state machine)
- Credentials & Proofs (formats, protocols v1/v2, handlers, services)
- OpenID4VC (issuer, holder, verifier modules, express routers)
- AnonCreds (Rust core via FFI, holder/issuer/verifier services)
- Ledger integrations (Indy-VDR, Cheqd registry services)
e. Crypto Layer
- JWS, JOSE key management, hashing, multibase/varint encoders
- Native/subtle implementations (CredoWebCrypto, CredoSubtle)
- BBS+ signature suites, SD-JWT
f. Storage Layer
- Askar wallet & storage module (supports SQLite, Postgres, in-memory)
- Generic repository API (records, migrations)
- Single-context LRU cache
g. Transports
- HTTP/WS outbound/inbound transports
- pluggable custom transports
h. External Systems
- DID registries & resolvers (did:web, did:key, did:jwk, did:peer, did:sov, did:indy, did:cheqd)
- Ledger pools (Indy-VDR, Cheqd nodes)
- OpenID4VC endpoints (oauth2/token, credential, metadata)

##### How Components Interact (Data Flows)
- Consumer invokes Agent API → Agent routes call to specific Module Service
- Module constructs a protocol message → Crypto layer signs/encrypts → Transport layer sends over HTTP/WS
- Inbound transport receives message → Agent dispatches via DIDComm dispatcher → Protocol handler updates state in repository → Emits events back to consumer
- Credential issuance: Agent + AnonCreds & Indy-VDR modules coordinate ledger writes, tails file service, key-correctness proofs
- OpenID4VC issuance: Express router → OpenID4VC module services → storage & crypto → responses

##### Architectural Patterns & Principles
- Modular plugin architecture: each feature is a self-contained npm package that registers with the core Agent via a dependency manager.
- Dependency inversion: core defines interfaces, modules implement them.
- Event-driven: modules emit/consume events via central EventEmitter.
- Repository pattern + migrations for storage.
- Strategy pattern for transports, signature suites, credential/proof formats.
- Adapter pattern for ledger integrations and crypto backends.

##### Technologies & Frameworks
- TypeScript & Node.js / React Native
- pnpm workspaces
- jest for testing
- express (for OpenID4VC REST endpoints)
- indy-vdr / indy-sdk-to-askar migration
- asark-ffi wallet backends

##### Essential Elements
- Clear component names matching npm packages or class names
- Annotations for key patterns (e.g., “EventEmitter publishes ‘message-received’”)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Top Layer: Consumer Applications
    subgraph "Consumer Applications" 
        direction TB
        DemoApp["Demo App\n(BaseAgent.ts)"]:::app
        DemoOpenIDHolder["Demo OpenID Holder\n(Holder.ts)"]:::app
    end

    %% Runtime Environments
    subgraph "Runtime Environments"
        direction TB
        NodeRuntime["Node.js Runtime"]:::runtime
        RNRuntime["React Native Runtime"]:::runtime
    end

    %% Tenant & Agent Instantiation
    subgraph "Application Layer"
        direction TB
        TenantModule["TenantsModule"]:::core
        TenantContext["TenantAgentContextProvider"]:::core
        BaseAgent["BaseAgent"]:::core
        AgentConfig["AgentConfig"]:::core
    end

    %% Core Agent & Plugin Infrastructure
    subgraph "Core Agent"
        direction TB
        EventBus["EventEmitter"]:::core
        DependencyMgr["DependencyManager"]:::core
    end

    %% Protocol & Feature Modules
    subgraph "Protocol Modules" 
        direction TB
        DidCommModule["DidCommModule"]:::module
        Dispatcher["Dispatcher"]:::module
        Connections["DidExchangeStateMachine"]:::module
        CredentialsMod["CredentialsModule"]:::module
        ProofsMod["ProofsModule"]:::module
        AnonCreds["AnonCredsModule"]:::module
        OpenID4VC["OpenId4VcIssuerModule"]:::module
        IndyVDR["IndyVdrModule"]:::module
        Cheqd["CheqdModule"]:::module
        DIDs["DidsModule"]:::module
        GenericRec["GenericRecordsModule"]:::module
        SDJWT["SdJwtVcModule"]:::module
        X509["X509Module"]:::module
        DRPC["DrpcModule"]:::module
        Migration["IndySdkToAskarMigrationUpdater"]:::module
    end

    %% Crypto & Signature Suites
    subgraph "Crypto Layer"
        direction TB
        JWS["JwsService"]:::crypto
        WebCrypto["CredoWebCrypto"]:::crypto
        BBS["BbsModule"]:::crypto
    end

    %% Storage Layer
    subgraph "Storage Layer"
        direction TB
        Askar["AskarModule"]:::storage
        Cache["InMemoryLruCache"]:::storage
        Repo["Repository"]:::storage
    end

    %% Transports & External Systems
    subgraph "Transports & External"
        direction TB
        TransportService["TransportService"]:::transport
        HttpOut["HttpOutboundTransport"]:::transport
        HttpIn["HttpInboundTransport"]:::transport
        ExternalLedgers["Ledger Pools\n(Indy-VDR, Cheqd)"]:::external
        ExternalDIDs["DID Registries & Resolvers"]:::external
        OpenIDEndpoints["OpenID4VC Endpoints"]:::external
    end

    %% Connections
    DemoApp -->|"instantiate"| BaseAgent
    DemoOpenIDHolder -->|"instantiate"| BaseAgent
    DemoApp --> NodeRuntime
    DemoApp --> RNRuntime
    DemoOpenIDHolder --> NodeRuntime

    BaseAgent --> TenantModule
    TenantModule --> TenantContext
    BaseAgent --> EventBus
    BaseAgent --> DependencyMgr

    DependencyMgr --> DidCommModule
    DependencyMgr --> CredentialsMod
    DependencyMgr --> ProofsMod
    DependencyMgr --> Connections
    DependencyMgr --> AnonCreds
    DependencyMgr --> OpenID4VC
    DependencyMgr --> IndyVDR
    DependencyMgr --> Cheqd
    DependencyMgr --> DIDs
    DependencyMgr --> GenericRec
    DependencyMgr --> SDJWT
    DependencyMgr --> X509
    DependencyMgr --> DRPC
    DependencyMgr --> Migration

    DidCommModule --> Dispatcher
    Dispatcher --> Connections
    CredentialsMod -->|v1/v2| ProofsMod

    CredentialsMod --> CryptoFlow
    ProofsMod --> CryptoFlow
    AnonCreds --> CryptoFlow
    OpenID4VC --> CryptoFlow

    subgraph CryptoFlow [ ]
        JWS --> WebCrypto
        WebCrypto --> BBS
    end

    CryptoFlow --> TransportService
    TransportService --> HttpOut
    TransportService --> HttpIn

    HttpOut --> ExternalDIDs
    HttpOut --> ExternalLedgers
    HttpOut --> OpenIDEndpoints

    HttpIn -->|"message"| Dispatcher
    Dispatcher --> Repo
    Repo --> Askar
    Repo --> Cache

    %% Click events
    click NodeRuntime "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/node/src/index.ts"
    click RNRuntime "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/react-native/src/index.ts"
    click DemoApp "https://github.com/openwallet-foundation/credo-ts/blob/main/demo/src/BaseAgent.ts"
    click DemoOpenIDHolder "https://github.com/openwallet-foundation/credo-ts/blob/main/demo-openid/src/Holder.ts"
    click TenantModule "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/tenants/src/TenantsModule.ts"
    click TenantContext "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/tenants/src/context/TenantAgentContextProvider.ts"
    click BaseAgent "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/core/src/agent/BaseAgent.ts"
    click AgentConfig "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/core/src/agent/AgentConfig.ts"
    click EventBus "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/core/src/agent/EventEmitter.ts"
    click DependencyMgr "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/core/src/plugins/DependencyManager.ts"
    click TransportService "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/didcomm/src/TransportService.ts"
    click DidCommModule "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/didcomm/src/DidCommModule.ts"
    click Dispatcher "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/didcomm/src/Dispatcher.ts"
    click Connections "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/didcomm/src/modules/connections/DidExchangeStateMachine.ts"
    click CredentialsMod "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/didcomm/src/modules/credentials/CredentialsModule.ts"
    click ProofsMod "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/didcomm/src/modules/proofs/ProofsModule.ts"
    click AnonCreds "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/anoncreds/src/AnonCredsModule.ts"
    click OpenID4VC "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/openid4vc/src/openid4vc-issuer/OpenId4VcIssuerModule.ts"
    click IndyVDR "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/indy-vdr/src/IndyVdrModule.ts"
    click Cheqd "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/cheqd/src/CheqdModule.ts"
    click JWS "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/core/src/crypto/JwsService.ts"
    click WebCrypto "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/core/src/crypto/webcrypto/CredoWebCrypto.ts"
    click BBS "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/bbs-signatures/src/BbsModule.ts"
    click Askar "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/askar/src/AskarModule.ts"
    click Cache "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/core/src/modules/cache/InMemoryLruCache.ts"
    click Repo "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/core/src/storage/Repository.ts"
    click HttpOut "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/didcomm/src/transport/HttpOutboundTransport.ts"
    click HttpIn "https://github.com/openwallet-foundation/credo-ts/blob/main/packages/node/src/transport/HttpInboundTransport.ts"

    %% Styles
    classDef app fill:#f9f,stroke:#333,stroke-width:1px
    classDef runtime fill:#ffeb99,stroke:#333,stroke-width:1px
    classDef core fill:#bbdefb,stroke:#333,stroke-width:1px
    classDef module fill:#c8e6c9,stroke:#333,stroke-width:1px
    classDef crypto fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef storage fill:#e0e0e0,stroke:#333,stroke-width:1px
    classDef transport fill:#d1c4e9,stroke:#333,stroke-width:1px
    classDef external fill:#ffcdd2,stroke:#333,stroke-width:1px
```
