# identinet/did-web-server architecture

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

- Interactive diagram: https://gitdiagram.com/identinet/did-web-server
- Repository: https://github.com/identinet/did-web-server

## Overview

##### Main Components

a) Core Server Components:
- HTTP Server Layer (Rocket Framework)
- DID Management Module
- Storage Layer (with multiple implementations)
- Resolver Module
- Authentication/Verification Layer

b) External Interfaces:
- HTTP/HTTPS Endpoints
- DNS System Integration
- File System Interface

##### Key Architectural Aspects to Highlight

a) Modular Storage Design:
- Both File-based and In-Memory storage implementations
- Storage interface/trait that allows for extensibility

b) Authentication Flow:
- Use of DIDs, Verifiable Credentials, and Verifiable Presentations
- Verification process flow

##### Specific Implementation Details

**┌─ Client Layer ─────────────────────────┐**
- HTTP/HTTPS Clients                     │
- ┬─────────────────────┘
- ↓
**┌─ API Layer ──────────────────────────────────────────┐**
- Rocket Web Framework                                 │
- DID Registration                                   │
- DID Resolution                                     │
- DID Update                                         │
- DID Deactivation                                  │
- ┬────────────────────────────────────┘
- ↓
**┌─ Core Services Layer ──────────────────────────────┐**
- ┌─ DID Management ─┐ ┌─ Resolver ─┐ ┌─ Auth ─┐    │
- Creation      │ │ - DNS      │ │ - VC    │    │
- Updates       │ │ - HTTP     │ │ - VP    │    │
- Validation    │ └───────────┘ └────────┘     │
- ┘                               │
- ┬─────────────────────────────────┘
- ↓
**┌─ Storage Layer ────────────────────────────────────┐**
- ┌─ Storage Interface ─┐                            │
- ┌─ File Store ─┐   │                           │

- ┘   │                           │
- ┌─ Memory Store ┐  │                           │

- ┘  │                           │
- ┘                            │
- ┘

##### Important Elements

- Relationship between the DID document storage and the HTTP server
- Verification flow for DID operations
- Integration with DNS for did:web resolution
- Separation between authentication and DID management

##### Technical Details to Note

- Rocket framework as the web server implementation
- SSI library integration from Spruce Systems
- Storage abstraction that allows for different backends
- Test fixtures and their relationship to the testing infrastructure

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph CL[Client Layer]
        Client[HTTP/HTTPS Clients]:::client
    end

    %% API Layer
    subgraph AL[API Layer]
        Server["HTTP Server (Rocket)"]:::server
        click Server "https://github.com/identinet/did-web-server/blob/main/src/main.rs"
        
        DIDOps["DID Operations API"]:::api
        subgraph Operations
            Register["Registration"]:::operation
            click Register "https://github.com/identinet/did-web-server/blob/main/docs/src/content/docs/did-management/register-did.md"
            Resolve["Resolution"]:::operation
            click Resolve "https://github.com/identinet/did-web-server/blob/main/docs/src/content/docs/did-management/resolve-did.md"
            Update["Update"]:::operation
            click Update "https://github.com/identinet/did-web-server/blob/main/docs/src/content/docs/did-management/update-did.md"
            Deactivate["Deactivation"]:::operation
            click Deactivate "https://github.com/identinet/did-web-server/blob/main/docs/src/content/docs/did-management/deactivate-did.md"
        end
    end

    %% Core Services Layer
    subgraph CSL[Core Services Layer]
        DIDMgmt["DID Management"]:::core
        click DIDMgmt "https://github.com/identinet/did-web-server/blob/main/src/did.rs"
        
        Resolver["Resolver Module"]:::core
        click Resolver "https://github.com/identinet/did-web-server/blob/main/src/resolver.rs"
        
        Auth["Authentication"]:::security
        
        Config["Configuration"]:::util
        click Config "https://github.com/identinet/did-web-server/blob/main/src/config.rs"
        
        ErrorHandler["Error Handling"]:::util
        click ErrorHandler "https://github.com/identinet/did-web-server/blob/main/src/error.rs"
        
        ContentTypes["Content Types"]:::util
        click ContentTypes "https://github.com/identinet/did-web-server/blob/main/src/content_types.rs"
    end

    %% Storage Layer
    subgraph SL[Storage Layer]
        StorageInterface["Storage Interface"]:::storage
        click StorageInterface "https://github.com/identinet/did-web-server/blob/main/src/store/mod.rs"
        
        FileStore["File Storage"]:::storage
        click FileStore "https://github.com/identinet/did-web-server/blob/main/src/store/file.rs"
        
        MemStore["Memory Storage"]:::storage
        click MemStore "https://github.com/identinet/did-web-server/blob/main/src/store/mem.rs"
    end

    %% Test Components
    subgraph TC[Test Components]
        TestFixtures["Test Fixtures"]:::test
        click TestFixtures "https://github.com/identinet/did-web-server/tree/main/src/__fixtures__"
        
        DIDExamples["DID Examples"]:::test
        click DIDExamples "https://github.com/identinet/did-web-server/blob/main/src/__fixtures__/valid-did.json"
        
        KeyMaterials["Key Materials"]:::test
        click KeyMaterials "https://github.com/identinet/did-web-server/blob/main/src/__fixtures__/owner.jwk"
        
        UpdateOps["Update Operations"]:::test
        click UpdateOps "https://github.com/identinet/did-web-server/blob/main/src/__fixtures__/valid-did_update.json"
    end

    %% Relationships
    Client --> Server
    Server --> DIDOps
    DIDOps --> Register & Resolve & Update & Deactivate
    Register & Resolve & Update & Deactivate --> DIDMgmt
    DIDMgmt --> Resolver
    DIDMgmt --> Auth
    DIDMgmt --> StorageInterface
    StorageInterface --> FileStore & MemStore
    DIDMgmt --> ErrorHandler
    DIDMgmt --> ContentTypes
    DIDMgmt --> Config

    %% Styles
    classDef client fill:#B3E5FC,stroke:#0288D1
    classDef server fill:#C8E6C9,stroke:#388E3C
    classDef api fill:#DCEDC8,stroke:#689F38
    classDef operation fill:#F0F4C3,stroke:#AFB42B
    classDef core fill:#C5CAE9,stroke:#303F9F
    classDef security fill:#FFCDD2,stroke:#D32F2F
    classDef storage fill:#FFE0B2,stroke:#F57C00
    classDef util fill:#E1BEE7,stroke:#7B1FA2
    classDef test fill:#CFD8DC,stroke:#455A64
```
