# ilich956/s3_clone architecture

> Architecture diagram of the GitHub repository ilich956/s3_clone, 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/ilich956/s3_clone
- Repository: https://github.com/ilich956/s3_clone

## Overview

##### Main Components

A. API Layer
- HTTP Server (main.go)
- Request Handlers (internal/handler)
- Input Validation (internal/utils/validation)
- Response Formatting (internal/utils/response)

B. Storage Layer
- Bucket Management (internal/storage/bucket.go)
- Object Management (internal/storage/object.go)
- CSV Utilities (pkg/csvutil)

C. File System Storage
- Physical storage for buckets and objects
- Metadata storage (CSV files)

**[Client Requests]**
- ↓
**[HTTP Server Layer]**
- ↓
**[Handler Layer] ←→ [Validation Layer]**
- ↓
**[Storage Layer] ←→ [CSV Utilities]**
- ↓
**[File System]**

##### Component Details

a. Client Interface:
- Supported HTTP methods (GET, PUT, DELETE)
- Main endpoints (/, /{bucket}, /{bucket}/{object})

b. Handler Layer:
- Request routing and processing
- Error handling
- Response formatting

c. Storage Layer:
- Bucket operations (Create, List, Delete)
- Object operations (Upload, Download, Delete)
- Metadata management

d. File System Layer:
- Physical storage structure
- Metadata storage (CSV files)

##### Important Details to Highlight

a. API Structure:
- RESTful endpoints
- HTTP methods mapping
- Response codes

b. Validation Rules:
- Bucket naming conventions
- Object key validation
- Existence checks

c. Storage Organization:
- Bucket/object hierarchy
- Metadata structure
- CSV file usage

##### Implementation Notes

- Clean separation of concerns (handlers, storage, utils)
- RESTful API design
- File system interaction
- Metadata management through CSV files
- Validation and error handling flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        C[Client Requests]:::client
    end

    subgraph "API Layer"
        S[HTTP Server]:::server
        H[Request Handlers]:::handler
        V[Input Validation]:::validation
        R[Response Formatting]:::response
    end

    subgraph "Storage Layer"
        BM[Bucket Management]:::storage
        OM[Object Management]:::storage
        CSV[CSV Utilities]:::util
    end

    subgraph "File System Layer"
        FS[Physical Storage]:::filesystem
        MS[Metadata Storage]:::filesystem
    end

    %% Client to API Layer
    C -->|HTTP Requests| S
    S -->|Route Request| H
    H <-->|Validate| V
    H <-->|Format Response| R

    %% API to Storage Layer
    H <--> BM
    H <--> OM
    BM <--> CSV
    OM <--> CSV

    %% Storage to File System
    BM --> FS
    OM --> FS
    CSV --> MS

    %% Click Events
    click S "https://github.com/ilich956/s3_clone/blob/main/main.go"
    click H "https://github.com/ilich956/s3_clone/blob/main/internal/handler/handler.go"
    click V "https://github.com/ilich956/s3_clone/blob/main/internal/utils/validation/validation.go"
    click R "https://github.com/ilich956/s3_clone/blob/main/internal/utils/response/response.go"
    click BM "https://github.com/ilich956/s3_clone/blob/main/internal/storage/bucket.go"
    click OM "https://github.com/ilich956/s3_clone/blob/main/internal/storage/object.go"
    click CSV "https://github.com/ilich956/s3_clone/blob/main/pkg/csvutil/csv.go"

    %% Styles
    classDef client fill:#6C8EBF,stroke:#333,stroke-width:2px
    classDef server fill:#82B366,stroke:#333,stroke-width:2px
    classDef handler fill:#9673A6,stroke:#333,stroke-width:2px
    classDef validation fill:#D6B656,stroke:#333,stroke-width:2px
    classDef response fill:#B85450,stroke:#333,stroke-width:2px
    classDef storage fill:#D79B00,stroke:#333,stroke-width:2px
    classDef util fill:#A9C4EB,stroke:#333,stroke-width:2px
    classDef filesystem fill:#666666,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Client Interface]:::client
        L2[Server Component]:::server
        L3[Handler Component]:::handler
        L4[Validation Component]:::validation
        L5[Response Component]:::response
        L6[Storage Component]:::storage
        L7[Utility Component]:::util
        L8[File System Component]:::filesystem
    end
```
