# onsonr/sonr architecture

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

- Interactive diagram: https://gitdiagram.com/onsonr/sonr
- Repository: https://github.com/onsonr/sonr

## Overview

##### Main Components (Top Level)

- `sonrd` (Chain Node Service)
- `hway` (Gateway Service)
- `motr` (Vault Service)
- `DWN` (Decentralized Web Node)

- IPFS
- WebAuthn
- Cosmos SDK
- Database Systems

a) User Interactions:
- WebAuthn Authentication → Gateway
- Identity Management → DID Module
- Asset Management → Vault
- Service Requests → DWN

b) Internal Communications:
- Chain State Updates
- Cross-Module Messages
- Event Propagation

- Cryptographic Services (/internal/crypto/)
- Authentication Flow
- Authorization Systems
- Key Management

##### Specific Implementation Details

a) Module Structure (Show as nested components):
- x/
- did/
- dwn/
- svc/

b) Core Services (Show as interconnected services):
- cmd/
- sonrd/
- hway/
- motr/

Design Guidelines:

##### Critical paths
- User authentication flow
- Transaction processing
- Identity management
- Asset operations

Remember to:
- Technical details but avoid overwhelming complexity
- Clear boundaries between components
- Security and cryptographic flows
- Document interface points between services

## Diagram (Mermaid)

```mermaid
graph BT
    %% Protocol Layer
    subgraph Protocol["Protocol Layer"]
        CRYPTO[Crypto Primitives]
        DIDM[DID Implementation]
        SVCM[Service Management]
        DWNM[DWN Implementation]
    end

    %% External Dependencies
    subgraph External["External Systems"]
        IPFS[IPFS]
        COSMOS[Cosmos SDK]
        DB[(Databases)]
    end

    %% Security Components
    subgraph Security["Security Layer"]
        AUTH[Authentication Flow]
        KEYS[Key Management]
        AUTHZ[Authorization Systems]
    end

    %% Core Services
    subgraph Core["Core Services"]
        SONRD[Chain Node Service]
        HWAY[Gateway Service]
        MOTR[Vault Service]
        DWN[Decentralized Web Node]
    end

    %% API Layer
    subgraph APILayer["API Layer"]
        GRPC[gRPC Services]
        REST[REST Endpoints]
        QUERY[Query Handlers]
        TX[Transaction Handlers]
    end

    %% Application Layer
    subgraph App["Application Layer"]
        GWAY_UI[Gateway UI]
        VAULT_UI[Vault UI]
        CHAIN[Chain Logic]
    end

    %% Public Interface
    WAUTHN[WebAuthn]

    %% Relationships
    WAUTHN --> HWAY
    HWAY --> AUTH
    AUTH --> KEYS
    KEYS --> CRYPTO
    MOTR --> DB
    SONRD --> COSMOS
    DWN --> IPFS
    GWAY_UI --> GRPC
    VAULT_UI --> REST
    GRPC --> QUERY
    REST --> TX
    TX --> CHAIN
    CHAIN --> DIDM
    CHAIN --> SVCM
    CHAIN --> DWNM

    %% Click Events
    click SONRD "https://github.com/onsonr/sonr/tree/main/cmd/sonrd/"
    click HWAY "https://github.com/onsonr/sonr/tree/main/cmd/hway/"
    click MOTR "https://github.com/onsonr/sonr/tree/main/cmd/motr/"
    click DWNM "https://github.com/onsonr/sonr/tree/main/x/dwn/"
    click DIDM "https://github.com/onsonr/sonr/tree/main/x/did/"
    click SVCM "https://github.com/onsonr/sonr/tree/main/x/svc/"
    click CRYPTO "https://github.com/onsonr/sonr/tree/main/internal/crypto/"
    click GWAY_UI "https://github.com/onsonr/sonr/tree/main/gateway/"
    click VAULT_UI "https://github.com/onsonr/sonr/tree/main/vault/"
    click CHAIN "https://github.com/onsonr/sonr/tree/main/app/"
    click GRPC "https://github.com/onsonr/sonr/tree/main/api/"
    click AUTH "https://github.com/onsonr/sonr/blob/main/gateway/handlers/login.go"
    click KEYS "https://github.com/onsonr/sonr/tree/main/internal/crypto/keys/"
    click DB "https://github.com/onsonr/sonr/tree/main/internal/database/"

    %% Styling
    classDef core fill:#a8d1ff
    classDef external fill:#c2f0c2
    classDef security fill:#ffe599
    classDef protocol fill:#d9d9d9
    classDef api fill:#fff2cc
    classDef app fill:#e6e6e6

    class SONRD,HWAY,MOTR,DWN core
    class IPFS,WAUTHN,COSMOS,DB external
    class AUTH,KEYS,AUTHZ security
    class CRYPTO,DIDM,SVCM,DWNM protocol
    class GRPC,REST,QUERY,TX api
    class GWAY_UI,VAULT_UI,CHAIN app
```
