# soheilpro/sherlock-web architecture

> Architecture diagram of the GitHub repository soheilpro/sherlock-web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/soheilpro/sherlock-web
- Repository: https://github.com/soheilpro/sherlock-web

## Overview

##### Main System Components

A. Frontend Layer (UI)
- React Components (src/scripts/ui/components)
- UI Contexts (src/scripts/ui/contexts)
- UI Hooks (src/scripts/ui/hooks)

B. Core Layer (Application Logic)
- Core Managers (src/scripts/core)
- Database Management (src/scripts/database)
- Crypto Management (src/scripts/managers/crypto.ts)

C. Storage Layer
- Multiple Storage Providers:
- Local Storage
- Google Drive
- File System
- Test Storage

##### Component Relationships

**[UI Layer] → [Core Layer] → [Storage Layer]**
- ↑          ↓               ↓
- ┴───────────────┘
- (Event-based communication)

##### Detailed Component Breakdown

- Main App Container
- Database Management UI
- Folder Management
- Item Management
- Search Functionality
- Storage Management

B. Core Layer Components:
- Database Manager
- Storage Manager
- Crypto Manager
- Event Management System

C. Storage Layer Components:
- Storage Provider Interface
- Individual Storage Implementations

##### Key Design Elements

Use the following visual elements:
- Rounded rectangles for UI components
- Hexagons for managers/controllers

##### Important Architectural Patterns to Highlight

- PWA Architecture (as mentioned in README)
- React Component Hierarchy
- Storage Provider Pattern
- Event-Driven Communication
- Crypto Management Integration

##### Implementation Details

- Database structure (folders, items, sequences)
- Storage provider interfaces
- Security layer integration
- UI state management flow
- Data synchronization paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef storage fill:#f1c40f,stroke:#f39c12,color:black
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef utility fill:#95a5a6,stroke:#7f8c8d,color:white

    %% UI Layer
    subgraph UI
        AppContainer["Main App Container"]
        DBManagementUI["Database Management UI"]
        FolderManagement["Folder Management"]
        ItemManagement["Item Management"]
        SearchFunc["Search Functionality"]
        StorageManagementUI["Storage Management"]
        
        UIContexts["UI Contexts"]
        UIHooks["UI Hooks"]
        
        EditContext["Edit Context"]
        PasteboardContext["Pasteboard Context"]
        ScreenSizeHook["Screen Size Hook"]
    end

    %% Core Layer
    subgraph Core
        DBManager["Database Manager"]
        StorageManager["Storage Manager"]
        CryptoManager["Crypto Manager"]
        CoreDB["Core Database"]
        CoreStorage["Core Storage"]
        EventEmitter["Event Management"]
    end

    %% Storage Layer
    subgraph Storage
        GoogleDrive["Google Drive Storage"]
        LocalStorage["Local Storage"]
        FileSystem["File System Storage"]
        TestStorage["Test Storage"]
    end

    %% Database Components
    subgraph Database
        DBCore["Database Core"]
        FolderDB["Folder Management"]
        ItemDB["Item Management"]
        SequenceDB["Sequence Management"]
    end

    %% PWA Components
    subgraph PWA
        ServiceWorker["Service Worker"]
        PWAConfig["PWA Configuration"]
    end

    %% Relationships
    AppContainer --> DBManagementUI
    AppContainer --> FolderManagement
    AppContainer --> ItemManagement
    AppContainer --> SearchFunc
    AppContainer --> StorageManagementUI

    DBManagementUI --> DBManager
    FolderManagement --> DBManager
    ItemManagement --> DBManager
    StorageManagementUI --> StorageManager

    DBManager --> CryptoManager
    DBManager --> CoreDB
    StorageManager --> CoreStorage
    
    CoreStorage --> GoogleDrive
    CoreStorage --> LocalStorage
    CoreStorage --> FileSystem
    CoreStorage --> TestStorage

    DBManager --> DBCore
    DBCore --> FolderDB
    DBCore --> ItemDB
    DBCore --> SequenceDB

    EventEmitter -.-> UI
    EventEmitter -.-> Core
    EventEmitter -.-> Storage

    %% Click events
    click AppContainer "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/ui/components/app/index.tsx"
    click DBManagementUI "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/ui/components/database/index.tsx"
    click FolderManagement "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/ui/components/folder-pane/index.tsx"
    click ItemManagement "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/ui/components/item/index.tsx"
    click SearchFunc "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/ui/components/search-input/index.tsx"
    click StorageManagementUI "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/ui/components/storage/index.tsx"
    click DBManager "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/managers/database-manager.ts"
    click StorageManager "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/managers/storage-manager.ts"
    click CryptoManager "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/managers/crypto.ts"
    click CoreDB "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/core/database.ts"
    click CoreStorage "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/core/storage.ts"
    click GoogleDrive "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/storage/google-drive/index.ts"
    click LocalStorage "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/storage/local/index.ts"
    click FileSystem "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/storage/file-system/index.ts"
    click TestStorage "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/storage/test/index.ts"
    click DBCore "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/database/database.ts"
    click FolderDB "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/database/folder.ts"
    click ItemDB "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/database/item.ts"
    click SequenceDB "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/database/sequence.ts"
    click EventEmitter "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/util/event-emitter.ts"
    click UIContexts "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/ui/contexts/index.ts"
    click UIHooks "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/ui/hooks/index.ts"
    click PWAConfig "https://github.com/soheilpro/Sherlock-Web/blob/master/src/manifest.webmanifest"
    click ServiceWorker "https://github.com/soheilpro/Sherlock-Web/blob/master/src/service-worker.ts"
    click EditContext "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/ui/contexts/edit.tsx"
    click PasteboardContext "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/ui/contexts/pasteboard.tsx"
    click ScreenSizeHook "https://github.com/soheilpro/Sherlock-Web/blob/master/src/scripts/ui/hooks/use-screen-size.ts"

    %% Style applications
    class AppContainer,DBManagementUI,FolderManagement,ItemManagement,SearchFunc,StorageManagementUI,UIContexts,UIHooks,EditContext,PasteboardContext,ScreenSizeHook ui
    class DBManager,StorageManager,CoreDB,CoreStorage,EventEmitter core
    class GoogleDrive,LocalStorage,FileSystem,TestStorage storage
    class CryptoManager security
    class ServiceWorker,PWAConfig utility
    class DBCore,FolderDB,ItemDB,SequenceDB core
```
