# omurilo/shareless architecture

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

- Interactive diagram: https://gitdiagram.com/omurilo/shareless
- Repository: https://github.com/omurilo/shareless

## Overview

##### Main Components Identification

a) Web Layer
- Located in /web directory
- Handles HTML templates and user interface
- Entry point through web/main.go

b) API Layer
- Located in /api directory
- Handles REST endpoints for secret sharing
- Contains handler logic for share operations

c) Core Components
- Located in /internal and /pkg directories
- Database operations (Redis integration)
- Cipher operations for encryption/decryption
- HTTP server implementation

**[Client Layer]**

- ▼
**[Load Balancer/Reverse Proxy (Optional)]**

- ▼
**[Web Server Layer]**
- Template Engine
- Static Assets

- ▼
**[API Layer]**
- Share Handler
- Shared Handler

- ▼
**[Core Services]**
- Cipher Service
- Database Service

- ▼
**[Data Store]**
- Redis

##### Component Relationships

- Client → Web Server: HTTP/HTTPS requests
- Web Server → API Layer: Internal routing
- API Layer → Core Services: Business logic calls
- Core Services → Redis: Data persistence
- Cipher Service ←→ Share/Shared Handlers: Encryption/Decryption operations

##### Additional Elements

a) Security Layer:
- Encryption/decryption flow
- Token validation process
- Temporary storage mechanism

b) Data Flow:
- Secret submission path
- Secret retrieval path
- Expiration handling

##### Technical Details to Highlight

- Redis integration for temporary storage
- Token-based access control
- Configurable expiration mechanism
- Template-based web interface

##### Specific Implementation Notes

- The separation between web and API layers
- The central role of the cipher package
- The stateless nature of the application
- The temporary storage mechanism in Redis

##### Maintain clear boundaries between
- Presentation layer (web templates)
- Application layer (API handlers)
- Business logic layer (internal packages)
- Data layer (Redis)

##### Security flows
- Secret encryption/decryption paths
- Token generation and validation
- Expiration mechanism

##### Scalability potential
- Stateless design
- Redis as a centralized store
- Container-based deployment

##### Monitoring points
- Health checks
- Metrics collection
- Logging interfaces

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph WebLayer
        WebServer["Web Server"]:::webserver
        Templates["Template Engine"]:::templates
        StaticAssets["Static Assets"]
    end

    subgraph APILayer
        ShareHandler["Share Handler"]:::apihandler
        SharedHandler["Shared Handler"]:::apihandler
    end

    subgraph CoreServices
        CipherService["Cipher Service"]:::core
        DatabaseService["Database Service"]:::core
        HTTPServer["HTTP Server"]:::core
    end

    subgraph DataStore
        Redis[(Redis DB)]
    end

    %% Connections
    Browser --> WebServer
    WebServer --> Templates
    WebServer --> StaticAssets
    WebServer --> ShareHandler
    WebServer --> SharedHandler
    ShareHandler --> CipherService
    SharedHandler --> CipherService
    ShareHandler --> DatabaseService
    SharedHandler --> DatabaseService
    DatabaseService --> Redis
    HTTPServer --> WebServer

    %% Styling
    classDef webserver fill:#2374ab
    classDef templates fill:#2374ab
    classDef apihandler fill:#48a9a6
    classDef core fill:#4caf50
    classDef database fill:#ffd700

    %% Click events
    click WebServer "https://github.com/omurilo/shareless/blob/main/web/main.go"
    click Templates "https://github.com/omurilo/shareless/tree/main/web/templates"
    click ShareHandler "https://github.com/omurilo/shareless/blob/main/api/handler/share.go"
    click SharedHandler "https://github.com/omurilo/shareless/blob/main/api/handler/shared.go"
    click DatabaseService "https://github.com/omurilo/shareless/blob/main/internal/database/database.go"
    click HTTPServer "https://github.com/omurilo/shareless/blob/main/internal/http/server.go"
    click CipherService "https://github.com/omurilo/shareless/blob/main/pkg/cipher/cipher.go"

    %% Legend
    subgraph Legend
        WebUI["Web Interface"]:::webserver
        API["API Components"]:::apihandler
        Core["Core Services"]:::core
        DB["Database"]:::database
    end
```
