# crawlic-stud/go-hybrid-storage architecture

> Architecture diagram of the GitHub repository crawlic-stud/go-hybrid-storage, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/crawlic-stud/go-hybrid-storage
- Repository: https://github.com/crawlic-stud/go-hybrid-storage

## Overview

##### Project Overview
- Project Type & Purpose: This is a hybrid storage system written in Go. It supports storing data via different backend systems – the filesystem, SQLite, PostgreSQL, and MongoDB – as indicated in both the README and the handler implementations. The project also includes load testing scripts using k6, indicating performance testing is a key concern.
- Key Identifiers: The README clearly specifies how to run the application with different storage backends and how to start load tests. The file structure (particularly the “handlers/backends” directory) shows that different storage methods are implemented in separate files.

##### Analyzing the File Structure
- Top-Level Files and Directories:
- main.go – The application entry point.
- handlers – Houses the logic for servicing requests; within it, the “backends” directory holds separate implementations for each storage backend (filesystem, SQL-based, MongoDB).
- models – Probably contains data models and response formats used across the application.
- utils – Utility functions such as file handling, JSON support, and SQL interactions.
- load_tests – Contains k6 scripts and related configurations for performance testing.
- index.html – Likely an entry point for a simple UI or documentation.
- Architectural Implications: The segmentation of code (handlers, models, utilities) suggests a modular design where the application’s core functionality is separated from backend specific implementations. The clear separation in the “handlers/backends” folder evidences the use of a Strategy-like pattern where the storage mechanism is chosen at runtime.

##### Key Components and Their Relationships
- Main Entry Point (main.go): Initializes the service and selects the appropriate storage backend based on command-line arguments.
- Handlers: Manage incoming requests and delegate storage operations to the appropriate backend implementation.
- Backends (filesystem_backend.go, sql_backend.go, mongodb_backend.go): Interface implementations that encapsulate the details of respective storage methods.
- Models: Define the structure of data transferred between components (files, responses, etc.).
- Utilities: Provide supporting functions like file operations and JSON management, abstracting common tasks.
- Load Tests: External scripts and configuration files used to test the performance and reliability of the system. These modules simulate real load scenarios and interact with the main API endpoints.

##### Architectural Patterns & Technologies
- Modular Design: The separation of concerns into handlers, models, and utilities ensures that each module’s responsibility is clearly defined.
- Strategy Pattern: The same interface is implemented by different storage backends, allowing swapping of backend storage at runtime.
- Integration with External Tools: The k6 load testing scripts indicate an emphasis on validating performance and scalability.
- Technologies/Frameworks: Written in Go, using standard Go modules (go.mod, go.sum), and external testing via k6 (with test scripts in JavaScript).

## Diagram (Mermaid)

```mermaid
graph TD
    A["Main Entry (main.go)"]:::app
    H1["handlers.go"]:::app
    H2["root.go"]:::app
    I1["Storage Backend Interface (interface.go)"]:::storage
    FS["Filesystem Storage"]:::storage
    SQL["SQL Storage"]:::storage
    MDB["MongoDB Storage"]:::storage
    M1["files.go"]:::support
    M2["responses.go"]:::support
    U1["file_util.go"]:::support
    U2["json_util.go"]:::support
    U3["read_chunks.go"]:::support
    U4["sql.go"]:::support
    LT["Load Testing (k6 Scripts)"]:::external
    DB[(Database System)]:::external
    FSys[(File System)]:::external

    %% Data Flow
    A -->|"initiates"| H1
    A -->|"initiates"| H2
    H1 -->|"calls"| I1
    H2 -->|"calls"| I1
    I1 -->|"strategy:fs"| FS
    I1 -->|"strategy:sql"| SQL
    I1 -->|"strategy:mongodb"| MDB
    FS -->|"stores to"| FSys
    SQL -->|"stores to"| DB
    MDB -->|"stores to"| DB
    H1 -->|"uses-model"| M1
    H1 -->|"uses-model"| M2
    H1 -->|"utilizes"| U1
    H1 -->|"utilizes"| U2
    H1 -->|"utilizes"| U3
    H1 -->|"utilizes"| U4
    LT -->|"tests-API"| H1

    %% Click Events
    click A "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/main.go"
    click H1 "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/handlers/handlers.go"
    click H2 "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/handlers/root.go"
    click I1 "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/handlers/backends/interface.go"
    click FS "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/handlers/backends/filesystem_backend.go"
    click SQL "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/handlers/backends/sql_backend.go"
    click MDB "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/handlers/backends/mongodb_backend.go"
    click M1 "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/models/files.go"
    click M2 "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/models/responses.go"
    click U1 "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/utils/file_util.go"
    click U2 "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/utils/json_util.go"
    click U3 "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/utils/read_chunks.go"
    click U4 "https://github.com/crawlic-stud/go-hybrid-storage/blob/main/utils/sql.go"
    click LT "https://github.com/crawlic-stud/go-hybrid-storage/tree/main/load_tests"

    %% Styles
    classDef app fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef storage fill:#D6EAF8,stroke:#2471A3,stroke-width:2px;
    classDef support fill:#D5F5E3,stroke:#2E86C1,stroke-width:2px;
    classDef external fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
```
