# nuts-foundation/nuts-node architecture

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

- Interactive diagram: https://gitdiagram.com/nuts-foundation/nuts-node
- Repository: https://github.com/nuts-foundation/nuts-node

## Overview

##### Main Components Identification

The system consists of several core modules that should be represented as primary components:

a) Core Services:
- Authentication (auth/)
- Cryptography (crypto/)
- DID Management (vdr/)
- Verifiable Credentials (vcr/)
- Network Communication (network/)
- Discovery Service (discovery/)
- Storage Layer (storage/)

b) API Layer:
- HTTP APIs
- gRPC APIs
- OpenID Connect/OAuth2 endpoints

- External Systems                                      |
- (Other Nuts Nodes, Identity Providers, Credential Issuers, Service Consumers)          |

- ↕

- API Gateway Layer                                     |
- HTTP/REST APIs                                                                       |
- gRPC Endpoints                                                                       |
- OpenID Connect/OAuth2                                                                |

- ↕

- Core Services Layer                                    |

- Auth     |  |    VDR     |  |    VCR    |  | Discovery  |  |     Network     |     |
- (OAuth/OIDC)|  | (DID Mgmt) |  | (Creds)   |  | (Services) |  | (P2P Comms)     |     |

- Crypto    |  |   Events   |  |  Policy   |                                       |
- (Key Mgmt)  |  | (NATS)     |  | (Rules)   |                                       |

- ↕

- Storage Layer                                          |

- SQL Database  |  |  Redis Cache  |  |   Memcached   |  |  File System      |         |

##### Additional Details

Important elements:
- Security boundaries
- Authentication flows
- DID resolution paths
- Credential issuance/verification flows
- Network communication paths

##### Technical Specifications

Technical details:
- Supported DID methods (web, nuts)
- Credential formats
- Storage backends
- Authentication mechanisms
- Network protocols

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Systems Layer
    subgraph External["External Systems"]
        direction TB
        ES1["Other Nuts Nodes"]
        ES2["Identity Providers"]
        ES3["Credential Issuers"]
        ES4["Service Consumers"]
    end

    %% API Gateway Layer
    subgraph Gateway["API Gateway Layer"]
        direction TB
        API1["HTTP/REST APIs"]:::api
        API2["gRPC Endpoints"]:::api
        API3["OpenID Connect/OAuth2"]:::api
    end

    %% Core Services Layer
    subgraph Core["Core Services Layer"]
        direction TB
        subgraph AuthService["Authentication Service"]
            Auth["OAuth/OIDC"]:::auth
            IAM["IAM Services"]:::auth
        end

        subgraph CryptoService["Cryptography Service"]
            Crypto["Key Management"]:::security
            JWT["JWT Handling"]:::security
            Hash["Hash Functions"]:::security
        end

        subgraph VDRService["DID Management"]
            DIDNuts["DID Nuts"]:::vdr
            DIDWeb["DID Web"]:::vdr
            DIDResolver["DID Resolver"]:::vdr
        end

        subgraph VCRService["Verifiable Credentials"]
            VCStore["Credential Store"]:::vcr
            Issuer["Issuer"]:::vcr
            Holder["Holder"]:::vcr
            Verifier["Verifier"]:::vcr
            OIDVC["OpenID4VCI"]:::vcr
        end

        subgraph NetworkService["Network Communication"]
            DAG["DAG Implementation"]:::network
            Transport["Transport Layer"]:::network
            GRPC["gRPC Protocol"]:::network
        end

        subgraph DiscoveryService["Discovery Service"]
            Discovery["Service Discovery"]:::discovery
            DiscStore["Service Store"]:::discovery
        end

        subgraph EventSystem["Events System"]
            EventHandler["Event Handler"]:::events
            EventTypes["Event Types"]:::events
        end
    end

    %% Storage Layer
    subgraph Storage["Storage Layer"]
        direction TB
        SQL["SQL Database"]:::storage
        Redis["Redis Cache"]:::storage
        Memcached["Memcached"]:::storage
        BBolt["BBolt File System"]:::storage
    end

    %% Relationships
    External <--> Gateway
    Gateway --> Core
    Core --> Storage

    %% Click Events
    click Auth "https://github.com/nuts-foundation/nuts-node/tree/master/auth/oauth"
    click IAM "https://github.com/nuts-foundation/nuts-node/tree/master/auth/api/iam"
    click Crypto "https://github.com/nuts-foundation/nuts-node/tree/master/crypto/storage"
    click JWT "https://github.com/nuts-foundation/nuts-node/tree/master/crypto/jwx"
    click Hash "https://github.com/nuts-foundation/nuts-node/tree/master/crypto/hash"
    click DIDNuts "https://github.com/nuts-foundation/nuts-node/tree/master/vdr/didnuts"
    click DIDWeb "https://github.com/nuts-foundation/nuts-node/tree/master/vdr/didweb"
    click DIDResolver "https://github.com/nuts-foundation/nuts-node/tree/master/vdr/resolver"
    click VCStore "https://github.com/nuts-foundation/nuts-node/tree/master/vcr/credential/store"
    click Issuer "https://github.com/nuts-foundation/nuts-node/tree/master/vcr/issuer"
    click Holder "https://github.com/nuts-foundation/nuts-node/tree/master/vcr/holder"
    click Verifier "https://github.com/nuts-foundation/nuts-node/tree/master/vcr/verifier"
    click OIDVC "https://github.com/nuts-foundation/nuts-node/tree/master/vcr/openid4vci"
    click DAG "https://github.com/nuts-foundation/nuts-node/tree/master/network/dag"
    click Transport "https://github.com/nuts-foundation/nuts-node/tree/master/network/transport"
    click GRPC "https://github.com/nuts-foundation/nuts-node/tree/master/network/transport/grpc"
    click Discovery "https://github.com/nuts-foundation/nuts-node/tree/master/discovery/api"
    click DiscStore "https://github.com/nuts-foundation/nuts-node/tree/master/discovery/store"
    click SQL "https://github.com/nuts-foundation/nuts-node/tree/master/storage/sql_migrations"
    click Redis "https://github.com/nuts-foundation/nuts-node/blob/master/storage/redis.go"
    click Memcached "https://github.com/nuts-foundation/nuts-node/blob/master/storage/memcached.go"
    click BBolt "https://github.com/nuts-foundation/nuts-node/blob/master/storage/bbolt.go"
    click EventHandler "https://github.com/nuts-foundation/nuts-node/blob/master/events/stream.go"
    click EventTypes "https://github.com/nuts-foundation/nuts-node/blob/master/events/types.go"

    %% Styling
    classDef api fill:#87CEEB
    classDef auth fill:#FF9999
    classDef security fill:#FF0000
    classDef vdr fill:#98FB98
    classDef vcr fill:#DDA0DD
    classDef network fill:#F0E68C
    classDef discovery fill:#87CEFA
    classDef events fill:#FFA07A
    classDef storage fill:#FFD700
```
