# loveholidays/excalidraw-decrypt architecture

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

- Interactive diagram: https://gitdiagram.com/loveholidays/excalidraw-decrypt
- Repository: https://github.com/loveholidays/excalidraw-decrypt

## Overview

##### Project Type and Purpose
- This is primarily a CLI application (cmd/excalidraw-decrypt) with a reusable Go library (pkg/excalidrawdecrypt) that:
- Decrypts it using a key supplied in the shareable link

##### File Structure
- Top‐level artifacts:
- cmd/excalidraw-decrypt – the CLI’s `main()` entrypoint
- pkg/excalidrawdecrypt – core library broken into subpackages:
– fetch: HTTP client for Excalidraw API
– crypto: decryption routines
– buffers: in-memory data buffering and I/O helpers
- Config & CI: Dockerfile, Makefile, GitHub workflows, goreleaser
- Tests and mocks under pkg/excalidrawdecrypt confirm clear separation of concerns.

##### README Insights
- Architecture is layered:
- Presentation: CLI
- Application logic: Library interfaces (CreateShareableExcalidrawDecrypter(), Decrypt())
- Infrastructure: HTTP fetch + crypto algorithms
- External dependency: public Excalidraw API (https://json.excalidraw.com/api/v2/documentID)

##### Main Components
a. User / CLI (cmd/excalidraw-decrypt)
b. Library API (pkg/excalidrawdecrypt)
– Fetch module (HTTP client)
– Crypto module (decryption)
– Buffers module (I/O helpers)
c. External Service: Excalidraw Public API
d. Output: stdout or file

##### Relationships and Data Flows
- User invokes CLI → CLI parses args → calls Library.Decrypt()
- Library.Fetch retrieves encrypted payload from Excalidraw API
- Library.Crypto decrypts payload using key from args
- Library.Buffers formats plaintext JSON
- CLI writes output to stdout or file

##### Highlighted Architectural Patterns
- Layered architecture (presentation → application → infrastructure)
- Separation of concerns: each pkg subdirectory focuses on one responsibility
- Dependency injection (in tests via mocks/fetch)

##### Relevant Technologies & Frameworks
- Go modules (go.mod)
- HTTP client (net/http)
- AES/GCM decryption (crypto/cipher)
- JSON unmarshalling (encoding/json)
- Cobra/flag (CLI parsing, if used)
- Testing/mocks (Go testing, autogenerated mocks)

- Clear, consistent component labels (e.g., “pkg/excalidrawdecrypt/crypto”)
- Annotations for protocols (HTTPS) and data formats (JSON)
- Optional: CI/CD pipeline overview (GitHub Actions → Docker/Goreleaser)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Actors and Presentation
    User("User"):::actor
    CLI["cmd/excalidraw-decrypt\n(Presentation Layer)"]:::cli

    %% Library Layers
    subgraph "Library (Application & Infrastructure)"
        Decrypt["decrypt.go\n(Application Layer)"]:::lib
        subgraph "Fetch Module"
            Fetch["fetch.go\n(HTTP Client)"]:::infra
        end
        subgraph "Crypto Module"
            Crypto["crypto.go\n(Decryption Routines)"]:::infra
        end
        subgraph "Buffers Module"
            Buffers["buffers.go\n(I/O Helpers)"]:::infra
        end
        subgraph "Tests & Mocks"
            TestDecrypt["decrypt_test.go"]:::test
            TestBuffers["buffers_test.go"]:::test
            MockFetch["mock_fetch.go"]:::test
        end
    end

    %% External Service and Output
    ExcalidrawAPI["Excalidraw Public API\n(cylinder)"]:::external
    Output["Output\n(stdout/file)"]:::output

    %% CI/CD & Config
    subgraph "CI/CD & Config"
        Dockerfile["Dockerfile"]:::config
        WorkflowDocker["docker.yaml"]:::config
        WorkflowGoreleaser["goreleaser.yaml"]:::config
        GoreleaserConfig[".goreleaser.yaml"]:::config
        Makefile["Makefile"]:::config
        GoMod["go.mod"]:::config
        GoSum["go.sum"]:::config
        Readme["README.md"]:::config
    end

    %% Data Flows
    User -->|"invoke CLI"| CLI
    CLI -->|"calls Decrypt()"| Decrypt
    Decrypt -->|"Fetch() → encrypted JSON"| Fetch
    Fetch -->|"encrypted JSON"| Decrypt
    Decrypt -->|"Decrypt() → decrypted JSON"| Crypto
    Crypto -->|"decrypted JSON"| Buffers
    Buffers -->|"formatted JSON"| CLI
    CLI -->|"writes plaintext diagram"| Output
    Output -->|"display/consume"| User
    Fetch -->|"HTTPS request"| ExcalidrawAPI
    ExcalidrawAPI -->|"encrypted JSON"| Fetch

    %% Click Events
    click CLI "https://github.com/loveholidays/excalidraw-decrypt/blob/main/cmd/excalidraw-decrypt/excalidraw-decrypt.go"
    click Decrypt "https://github.com/loveholidays/excalidraw-decrypt/blob/main/pkg/excalidrawdecrypt/decrypt.go"
    click Fetch "https://github.com/loveholidays/excalidraw-decrypt/blob/main/pkg/excalidrawdecrypt/fetch/fetch.go"
    click Crypto "https://github.com/loveholidays/excalidraw-decrypt/blob/main/pkg/excalidrawdecrypt/crypto/crypto.go"
    click Buffers "https://github.com/loveholidays/excalidraw-decrypt/blob/main/pkg/excalidrawdecrypt/buffers/buffers.go"
    click TestDecrypt "https://github.com/loveholidays/excalidraw-decrypt/blob/main/pkg/excalidrawdecrypt/decrypt_test.go"
    click TestBuffers "https://github.com/loveholidays/excalidraw-decrypt/blob/main/pkg/excalidrawdecrypt/buffers/buffers_test.go"
    click MockFetch "https://github.com/loveholidays/excalidraw-decrypt/blob/main/pkg/excalidrawdecrypt/mocks/fetch/mock_fetch.go"
    click Dockerfile "https://github.com/loveholidays/excalidraw-decrypt/tree/main/Dockerfile"
    click WorkflowDocker "https://github.com/loveholidays/excalidraw-decrypt/blob/main/.github/workflows/docker.yaml"
    click WorkflowGoreleaser "https://github.com/loveholidays/excalidraw-decrypt/blob/main/.github/workflows/goreleaser.yaml"
    click GoreleaserConfig "https://github.com/loveholidays/excalidraw-decrypt/blob/main/.goreleaser.yaml"
    click Makefile "https://github.com/loveholidays/excalidraw-decrypt/tree/main/Makefile"
    click GoMod "https://github.com/loveholidays/excalidraw-decrypt/blob/main/go.mod"
    click GoSum "https://github.com/loveholidays/excalidraw-decrypt/blob/main/go.sum"
    click Readme "https://github.com/loveholidays/excalidraw-decrypt/blob/main/README.md"

    %% Styles
    classDef actor fill:#D3D3D3,stroke:#333,stroke-width:1px;
    classDef cli fill:#90CAF9,stroke:#333,stroke-width:1px;
    classDef lib fill:#BBDEFB,stroke:#333,stroke-width:1px;
    classDef infra fill:#C8E6C9,stroke:#333,stroke-width:1px;
    classDef external fill:#A5D6A7,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5;
    classDef output fill:#FFE082,stroke:#333,stroke-width:1px;
    classDef test fill:#E1BEE7,stroke:#333,stroke-width:1px;
    classDef config fill:#CFD8DC,stroke:#333,stroke-width:1px;
```
