# dimo-network/dimo-identity architecture

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

- Interactive diagram: https://gitdiagram.com/dimo-network/dimo-identity
- Repository: https://github.com/dimo-network/dimo-identity

## Overview

##### Main Components

a) Core Registry Layer:

b) NFT Module Layer:
- NFT-related contracts (AftermarketDeviceId, IntegrationId, ManufacturerId, VehicleId, SyntheticDeviceId)
- Inheritance from Base/MultiPrivilege

c) Implementation Modules Layer:
- By implementation types:
- Charging implementations
- Node implementations
- Streamr implementations
- Tableland implementations
- AdLicenseValidator

d) Access Control Layer:
- DimoAccessControl components
- Relationship with other components

e) External Integrations:
- Streamr integration
- Tableland integration

##### Specific Elements

a) Smart Contract Infrastructure:
- Upgrade proxy pattern implementation
- Libraries and utilities as supporting components
- EIP-712 implementation for structured data signing

b) Development Tools:
- Testing framework integration
- Deployment scripts relationship
- ABI generation flow

##### Technical Details to Emphasize

- Relationship between different node types
- Access control flows
- External integration points

##### Additional Elements

- Version information
- Network deployment options (Polygon, Mumbai testnet)
- Important configuration flows

##### Metadata Section

- Important environment variables
- Dependencies

Key Considerations:
- Proxy-based upgrade pattern
- How the NFT system integrates with the core functionality
- Role of external services (Streamr, Tableland)
- Demonstrate the access control flow through the system

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External
        StreamrService[Streamr Service]
        TablelandService[Tableland Service]
    end

    subgraph Core
        DimoRegistry["DimoRegistry"]:::core
        click DimoRegistry "https://github.com/DIMO-Network/dimo-identity/blob/main/abis/DimoRegistry.json"
    end

    subgraph "Access Control"
        AccessControl["DimoAccessControl"]:::security
        AccessControlConst["Access Control Constants"]:::security
        click AccessControl "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/access"
        click AccessControlConst "https://github.com/DIMO-Network/dimo-identity/blob/main/utils/constants/AccessControl.ts"
    end

    subgraph "NFT Layer"
        direction TB
        BaseNFT["MultiPrivilege Base"]:::nft
        AftermarketNFT["AftermarketDeviceId"]:::nft
        IntegrationNFT["IntegrationId"]:::nft
        ManufacturerNFT["ManufacturerId"]:::nft
        VehicleNFT["VehicleId"]:::nft
        SyntheticNFT["SyntheticDeviceId"]:::nft
        click BaseNFT "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/NFTs/Base/MultiPrivilege"
        click AftermarketNFT "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/NFTs"
        click IntegrationNFT "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/NFTs"
        click ManufacturerNFT "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/NFTs"
        click VehicleNFT "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/NFTs"
        click SyntheticNFT "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/NFTs"
    end

    subgraph "Implementation Layer"
        direction TB
        ChargingImpl["Charging Implementation"]:::impl
        NodeImpl["Node Implementation"]:::impl
        StreamrImpl["Streamr Implementation"]:::impl
        TablelandImpl["Tableland Implementation"]:::impl
        AdLicenseImpl["AdLicense Validator"]:::impl
        click ChargingImpl "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/implementations/charging"
        click NodeImpl "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/implementations/nodes"
        click StreamrImpl "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/implementations/streamr"
        click TablelandImpl "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/implementations/tableland"
        click AdLicenseImpl "https://github.com/DIMO-Network/dimo-identity/tree/main/contracts/implementations/AdLicenseValidator"
    end

    subgraph "Development Tools"
        direction TB
        DeployScripts["Deployment Scripts"]:::dev
        ABIGen["ABI Generator"]:::dev
        TestFramework["Testing Framework"]:::dev
        click DeployScripts "https://github.com/DIMO-Network/dimo-identity/blob/main/scripts/deploy.ts"
        click ABIGen "https://github.com/DIMO-Network/dimo-identity/blob/main/scripts/abiGenerator.ts"
        click TestFramework "https://github.com/DIMO-Network/dimo-identity/tree/main/test/"
    end

    subgraph "Utilities"
        direction TB
        Constants["Constants"]:::util
        Helpers["Helpers"]:::util
        Types["Types"]:::util
        click Constants "https://github.com/DIMO-Network/dimo-identity/tree/main/utils/constants"
        click Helpers "https://github.com/DIMO-Network/dimo-identity/blob/main/utils/helpers.ts"
        click Types "https://github.com/DIMO-Network/dimo-identity/blob/main/utils/types.ts"
    end

    %% Relationships
    StreamrService --> StreamrImpl
    TablelandService --> TablelandImpl
    
    DimoRegistry --> AccessControl
    AccessControl --> AccessControlConst
    
    BaseNFT --> |inherits| AftermarketNFT
    BaseNFT --> |inherits| IntegrationNFT
    BaseNFT --> |inherits| ManufacturerNFT
    BaseNFT --> |inherits| VehicleNFT
    BaseNFT --> |inherits| SyntheticNFT
    
    DimoRegistry --> ChargingImpl
    DimoRegistry --> NodeImpl
    DimoRegistry --> StreamrImpl
    DimoRegistry --> TablelandImpl
    DimoRegistry --> AdLicenseImpl
    
    DeployScripts --> DimoRegistry
    ABIGen --> DimoRegistry
    TestFramework --> DimoRegistry

    %% Styling
    classDef core fill:#2d4059,color:white
    classDef security fill:#ea5455,color:white
    classDef nft fill:#28b485,color:white
    classDef impl fill:#ff9f43,color:white
    classDef dev fill:#a55eea,color:white
    classDef util fill:#778ca3,color:white
    
    %% Legend
    subgraph Legend
        L1["Core System"]:::core
        L2["Security Components"]:::security
        L3["NFT Contracts"]:::nft
        L4["Implementations"]:::impl
        L5["Development Tools"]:::dev
        L6["Utilities"]:::util
    end
```
