# verizhang/file-manager architecture

> Architecture diagram of the GitHub repository verizhang/file-manager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/verizhang/file-manager
- Repository: https://github.com/verizhang/file-manager

## Overview

File Manager supports simple and multipart direct-to-object-storage uploads, metadata and download/delete operations, and asynchronous virus scanning. The main path is client → API → service → storage/metadata; upload completion publishes an event consumed by the worker, which streams the object to a scanner and records the scan result. README and excerpts support the principal flows; some links involving unsampled modules are omitted where their call sites are not shown.

Main entry points: [`internal/service/file_service_impl.go`](https://github.com/verizhang/file-manager/blob/main/internal/service/file_service_impl.go) (File workflows), [`cmd/virusscannerworker/main.go`](https://github.com/verizhang/file-manager/blob/main/cmd/virusscannerworker/main.go) (Scanner worker), [`internal/handler/file_handler.go`](https://github.com/verizhang/file-manager/blob/main/internal/handler/file_handler.go) (File handler), [`cmd/api/main.go`](https://github.com/verizhang/file-manager/blob/main/cmd/api/main.go) (API composition)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API access"]
  node_gateway["HTTP gateway<br/>[gateway.go]"]
  node_grpc["gRPC server<br/>[grpc.go]"]
  node_handler["File handler<br/>[file_handler.go]"]
  node_validation["Request validation<br/>[file_validation.go]"]
  node_api_process["API composition<br/>[main.go]"]
  node_api_contract["File API contract<br/>[file.proto]"]
end

subgraph group_workflow["File workflows"]
  node_service["File workflows"]
  node_domain["File lifecycle<br/>[file.go]"]
end

subgraph group_persistence["Metadata persistence"]
  node_repository["MySQL repository<br/>[file_repository.go]"]
  node_mysql[("MySQL")]
end

subgraph group_scanning["Virus scanning"]
  node_worker_process["Scanner worker<br/>[main.go]"]
  node_consumer["Event consumer<br/>[consumer.go]"]
  node_scanner_adapter["ClamAV scanner<br/>[scanner.go]"]
end

subgraph group_integrations["External integrations"]
  node_storage_adapter["S3 storage adapter<br/>[storage.go]"]
  node_object_store[("S3-compatible storage")]
  node_messaging_adapter["RabbitMQ adapter<br/>[rabbitmq.go]"]
  node_rabbitmq["RabbitMQ"]
  node_clamav["ClamAV"]
end

node_client(("Client"))

node_client -->|"sends HTTP"| node_gateway
node_client -->|"calls gRPC"| node_grpc
node_gateway -->|"routes requests"| node_grpc
node_api_process -->|"starts"| node_gateway
node_api_process -->|"starts"| node_grpc
node_api_process -->|"constructs"| node_handler
node_grpc -->|"registers"| node_handler
node_handler -->|"validates with"| node_validation
node_handler -->|"calls"| node_service
node_handler -.->|"implements"| node_api_contract
node_service -->|"uses"| node_domain
node_service -->|"requests object operations"| node_storage_adapter
node_storage_adapter -->|"reads and writes"| node_object_store
node_service -->|"persists metadata"| node_repository
node_repository -->|"reads and writes"| node_mysql
node_api_process -->|"constructs"| node_repository
node_worker_process -->|"registers handler"| node_consumer
node_consumer -->|"calls scan"| node_service
node_worker_process -->|"constructs"| node_repository
node_worker_process -->|"constructs"| node_storage_adapter
node_worker_process -->|"constructs"| node_scanner_adapter
node_service -->|"publishes events"| node_messaging_adapter
node_messaging_adapter -->|"publishes and consumes"| node_rabbitmq
node_worker_process -->|"subscribes"| node_messaging_adapter
node_service -->|"streams object to scan"| node_scanner_adapter
node_scanner_adapter -->|"scans stream"| node_clamav

click node_gateway "https://github.com/verizhang/file-manager/blob/main/internal/server/gateway.go"
click node_grpc "https://github.com/verizhang/file-manager/blob/main/internal/server/grpc.go"
click node_handler "https://github.com/verizhang/file-manager/blob/main/internal/handler/file_handler.go"
click node_validation "https://github.com/verizhang/file-manager/blob/main/internal/handler/file_validation.go"
click node_api_process "https://github.com/verizhang/file-manager/blob/main/cmd/api/main.go"
click node_service "https://github.com/verizhang/file-manager/blob/main/internal/service/file_service_impl.go"
click node_domain "https://github.com/verizhang/file-manager/blob/main/internal/model/file.go"
click node_storage_adapter "https://github.com/verizhang/file-manager/blob/main/pkg/storage/s3/storage.go"
click node_repository "https://github.com/verizhang/file-manager/blob/main/internal/repository/mysql/file_repository.go"
click node_worker_process "https://github.com/verizhang/file-manager/blob/main/cmd/virusscannerworker/main.go"
click node_consumer "https://github.com/verizhang/file-manager/blob/main/internal/consumer/consumer.go"
click node_messaging_adapter "https://github.com/verizhang/file-manager/blob/main/pkg/messaging/rabbitmq/rabbitmq.go"
click node_scanner_adapter "https://github.com/verizhang/file-manager/blob/main/pkg/virusscanner/clamav/scanner.go"
click node_api_contract "https://github.com/verizhang/file-manager/blob/main/proto/file/v1/file.proto"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gateway,node_grpc,node_handler,node_validation,node_api_process,node_api_contract,node_client toneBlue
class node_service,node_domain toneAmber
class node_repository,node_mysql toneMint
class node_worker_process,node_consumer,node_scanner_adapter toneRose
class node_storage_adapter,node_object_store,node_messaging_adapter,node_rabbitmq,node_clamav toneIndigo
```

## Components

### API access

- [HTTP gateway](https://github.com/verizhang/file-manager/blob/main/internal/server/gateway.go): `internal/server/gateway.go`
- [gRPC server](https://github.com/verizhang/file-manager/blob/main/internal/server/grpc.go): `internal/server/grpc.go`
- [File handler](https://github.com/verizhang/file-manager/blob/main/internal/handler/file_handler.go): `internal/handler/file_handler.go`
- [Request validation](https://github.com/verizhang/file-manager/blob/main/internal/handler/file_validation.go): `internal/handler/file_validation.go`
- [API composition](https://github.com/verizhang/file-manager/blob/main/cmd/api/main.go): `cmd/api/main.go`
- [File API contract](https://github.com/verizhang/file-manager/blob/main/proto/file/v1/file.proto): `proto/file/v1/file.proto`

### File workflows

- [File workflows](https://github.com/verizhang/file-manager/blob/main/internal/service/file_service_impl.go): `internal/service/file_service_impl.go`
- [File lifecycle](https://github.com/verizhang/file-manager/blob/main/internal/model/file.go): `internal/model/file.go`

### Metadata persistence

- [MySQL repository](https://github.com/verizhang/file-manager/blob/main/internal/repository/mysql/file_repository.go): `internal/repository/mysql/file_repository.go`
- **MySQL**

### Virus scanning

- [Scanner worker](https://github.com/verizhang/file-manager/blob/main/cmd/virusscannerworker/main.go): `cmd/virusscannerworker/main.go`
- [Event consumer](https://github.com/verizhang/file-manager/blob/main/internal/consumer/consumer.go): `internal/consumer/consumer.go`
- [ClamAV scanner](https://github.com/verizhang/file-manager/blob/main/pkg/virusscanner/clamav/scanner.go): `pkg/virusscanner/clamav/scanner.go`

### External integrations

- [S3 storage adapter](https://github.com/verizhang/file-manager/blob/main/pkg/storage/s3/storage.go): `pkg/storage/s3/storage.go`
- **S3-compatible storage**
- [RabbitMQ adapter](https://github.com/verizhang/file-manager/blob/main/pkg/messaging/rabbitmq/rabbitmq.go): `pkg/messaging/rabbitmq/rabbitmq.go`
- **RabbitMQ**
- **ClamAV**

### Other components

- **Client**

## Connections

- Client → HTTP gateway: sends HTTP (evidence: `README.md`)
- Client → gRPC server: calls gRPC (evidence: `README.md`)
- HTTP gateway → gRPC server: routes requests (evidence: `internal/server/gateway.go`)
- API composition → HTTP gateway: starts (evidence: `cmd/api/main.go`)
- API composition → gRPC server: starts (evidence: `cmd/api/main.go`)
- API composition → File handler: constructs (evidence: `cmd/api/main.go`)
- gRPC server → File handler: registers (evidence: `internal/server/grpc.go`)
- File handler → Request validation: validates with (evidence: `internal/handler/file_handler.go`)
- File handler → File workflows: calls (evidence: `internal/handler/file_handler.go`)
- File handler → File API contract: implements
- File workflows → File lifecycle: uses (evidence: `internal/service/file_service_impl.go`)
- File workflows → S3 storage adapter: requests object operations (evidence: `internal/service/file_service_impl.go`)
- S3 storage adapter → S3-compatible storage: reads and writes (evidence: `README.md`)
- File workflows → MySQL repository: persists metadata (evidence: `internal/service/file_service_impl.go`)
- MySQL repository → MySQL: reads and writes (evidence: `README.md`)
- API composition → MySQL repository: constructs (evidence: `cmd/api/main.go`)
- Scanner worker → Event consumer: registers handler (evidence: `cmd/virusscannerworker/main.go`)
- Event consumer → File workflows: calls scan (evidence: `internal/consumer/consumer.go`)
- Scanner worker → MySQL repository: constructs (evidence: `cmd/virusscannerworker/main.go`)
- Scanner worker → S3 storage adapter: constructs (evidence: `cmd/virusscannerworker/main.go`)
- Scanner worker → ClamAV scanner: constructs (evidence: `cmd/virusscannerworker/main.go`)
- File workflows → RabbitMQ adapter: publishes events (evidence: `internal/service/file_service_impl.go`)
- RabbitMQ adapter → RabbitMQ: publishes and consumes (evidence: `pkg/messaging/rabbitmq/rabbitmq.go`)
- Scanner worker → RabbitMQ adapter: subscribes (evidence: `cmd/virusscannerworker/main.go`)
- File workflows → ClamAV scanner: streams object to scan (evidence: `internal/service/file_service_impl.go`)
- ClamAV scanner → ClamAV: scans stream (evidence: `README.md`)
