rustdrivesync 1.1.0

Production-ready CLI tool for one-way file synchronization with Google Drive. Features: dependency injection, rate limiting, retry with backoff, parallel uploads, and comprehensive documentation.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# RustDriveSync

![Rust](https://img.shields.io/badge/rust-1.70%2B-orange)
![License](https://img.shields.io/badge/license-MIT-blue)
![Status](https://img.shields.io/badge/status-production--ready-brightgreen)
![Version](https://img.shields.io/badge/version-1.1.0-blue)
![Tests](https://img.shields.io/badge/tests-118%20passing-brightgreen)
![Coverage](https://img.shields.io/badge/coverage-36.46%25-yellow)

**Sincronização unidirecional de arquivos com Google Drive**

RustDriveSync é uma ferramenta CLI desenvolvida em Rust para sincronização eficiente e confiável de arquivos locais com o Google Drive. Projetada para ser leve, rápida e segura.

## 🎯 Características

### Core Features (V1.0)
- **Dependency Injection** - Abstrações via traits para múltiplos backends
-**Rate Limiting** - Proteção automática contra limites da API (800 req/100s)
-**Retry com Backoff** - Recuperação automática de falhas (exponential backoff)
-**Uploads Paralelos** - Até 10x mais rápido (configurável)
-**Thread-Safe** - Arquitetura async/await com Tokio
-**Sincronização unidirecional** (local → Google Drive)
-**Modo único ou monitoramento contínuo** (watch mode)
-**Upload com streaming** - memória constante para arquivos grandes
-**Autenticação OAuth2** segura
-**Configuração via arquivo TOML**
-**Logs detalhados** com níveis configuráveis
-**Detecção de mudanças** por hash MD5 incremental
-**Detecção automática de MIME types** - suporte a 800+ formatos
-**Preservação de estrutura de pastas** - mantém hierarquia de diretórios

### Qualidade e Arquitetura
- **118 testes** (36.46% cobertura total, >70% em módulos críticos)
-**Documentação completa** - ADRs, C4 diagrams, security docs
-**SOLID principles** - Clean architecture
-**Zero breaking changes** - Código legado continua funcionando

## 📋 Pré-requisitos

- Rust 1.70 ou superior
- Credenciais OAuth2 do Google Cloud Console

## 🚀 Instalação

### Via Cargo

```bash
cargo install rustdrivesync
```

### Build manual

```bash
git clone https://github.com/usuario/rustdrivesync
cd rustdrivesync
cargo build --release
```

O binário estará em `target/release/rustdrivesync`

## 🔧 Configuração Inicial

### 1. Obter Credenciais do Google Cloud Console

Para usar o RustDriveSync, você precisa de credenciais OAuth 2.0 do Google. Siga este guia passo a passo:

#### Passo 1: Criar um Projeto no Google Cloud

1. **Acesse o Google Cloud Console**
   - URL: https://console.cloud.google.com
   - Faça login com sua conta Google

2. **Criar Novo Projeto**
   - Clique no seletor de projeto no topo (ao lado de "Google Cloud")
   - Clique em **"New Project"** (Novo Projeto)
   - Digite um nome: ex: "RustDriveSync" ou "My Drive Backup"
   - Clique em **"Create"** (Criar)
   - Aguarde alguns segundos até o projeto ser criado
   - Selecione o projeto criado no seletor de projetos

#### Passo 2: Habilitar a Google Drive API

1. **Acessar a API Library**
   - No menu lateral (☰), vá em: **"APIs & Services"****"Library"**
   - Ou acesse diretamente: https://console.cloud.google.com/apis/library

2. **Buscar e Habilitar**
   - Na barra de busca, digite: `Google Drive API`
   - Clique em **"Google Drive API"** nos resultados
   - Clique no botão azul **"Enable"** (Habilitar)
   - Aguarde a ativação (geralmente instantânea)

#### Passo 3: Configurar Tela de Consentimento OAuth

⚠️ **Obrigatório antes de criar credenciais**

1. **Acessar OAuth Consent Screen**
   - No menu lateral: **"APIs & Services"****"OAuth consent screen"**
   - Ou: https://console.cloud.google.com/apis/credentials/consent

2. **Configurar Tipo de Usuário**
   - Selecione **"External"** (para uso pessoal)
   - Clique em **"Create"** (Criar)

3. **Preencher Informações Obrigatórias**
   - **App name**: "RustDriveSync" (ou seu nome preferido)
   - **User support email**: Seu email
   - **Developer contact email**: Seu email
   - Clique em **"Save and Continue"** (Salvar e Continuar)

4. **Escopos (Scopes)**
   - Clique em **"Add or Remove Scopes"**
   - Busque e selecione: `https://www.googleapis.com/auth/drive.file`
   - Clique em **"Update"** e depois **"Save and Continue"**

5. **Test Users (Usuários de Teste)**
   - Clique em **"Add Users"**
   - Adicione seu email (o que você usará para sincronizar)
   - Clique em **"Add"** e depois **"Save and Continue"**

6. **Revisar e Confirmar**
   - Clique em **"Back to Dashboard"**

#### Passo 4: Criar Credenciais OAuth 2.0

1. **Acessar Credentials**
   - No menu lateral: **"APIs & Services"****"Credentials"**
   - Ou: https://console.cloud.google.com/apis/credentials

2. **Criar Nova Credencial**
   - Clique no botão **"+ Create Credentials"** no topo
   - Selecione **"OAuth client ID"**

3. **Configurar Tipo de Aplicação**
   - **Application type**: Selecione **"Desktop app"**
   - **Name**: "RustDriveSync CLI" (ou qualquer nome)
   - Clique em **"Create"**

4. **Baixar Credenciais**
   - Uma janela popup aparecerá com "OAuth client created"
   - Clique em **"Download JSON"** (ícone de download ⬇️)
   - O arquivo será baixado como `client_secret_XXXXX.json`
   - **Renomeie** este arquivo para `credentials.json`
   - **Mova** para uma pasta segura (ex: `~/.config/rustdrivesync/`)

#### Passo 5: Proteger Suas Credenciais

```bash
# Linux/macOS
mkdir -p ~/.config/rustdrivesync
mv ~/Downloads/client_secret_*.json ~/.config/rustdrivesync/credentials.json
chmod 600 ~/.config/rustdrivesync/credentials.json

# Windows (PowerShell)
New-Item -Path "$env:APPDATA\rustdrivesync" -ItemType Directory -Force
Move-Item "$env:USERPROFILE\Downloads\client_secret_*.json" "$env:APPDATA\rustdrivesync\credentials.json"
```

✅ **Pronto!** Você agora tem o arquivo `credentials.json` necessário.

---

### ⚠️ Troubleshooting

**Erro: "Access blocked: This app's request is invalid"**
- Certifique-se de configurar a OAuth Consent Screen (Passo 3)
- Adicione seu email como Test User

**Erro: "The OAuth client was not found"**
- Verifique se criou credenciais do tipo "Desktop app"
- Não use "Web application" ou "Service account"

**Arquivo credentials.json não baixa**
- Vá em Credentials → Clique no nome da credencial criada
- Clique no ícone de download (⬇️) no lado direito

---

### 2. Criar Configuração

```bash
rustdrivesync config --init
```

Isso criará um arquivo `config.example.toml`. Copie-o para `config.toml` e edite:

```bash
cp config.example.toml config.toml
vim config.toml
```

Configure pelo menos:
- `source.path`: pasta local a sincronizar
- `google_drive.credentials_file`: caminho para credentials.json
- `google_drive.target_folder_id` ou `target_folder_name`

### 3. Autenticar

```bash
rustdrivesync auth
```

Isso abrirá seu navegador para autorizar o aplicativo.

## 📖 Uso

### Sincronização Única

```bash
rustdrivesync sync --once
```

### Monitoramento Contínuo

```bash
rustdrivesync sync --watch
```

### Simular (Dry Run)

```bash
rustdrivesync sync --dry-run
```

### Verificar Status

```bash
rustdrivesync status
```

### Listar Arquivos

```bash
# Arquivos pendentes
rustdrivesync list

# Arquivos no Google Drive
rustdrivesync list --remote

# Diferenças local vs remoto
rustdrivesync list --diff
```

## 📂 Preservação de Estrutura de Pastas

Por padrão, o RustDriveSync preserva a estrutura de diretórios local no Google Drive.

### Comportamento

**Com `preserve_folder_structure = true` (padrão):**

```
LOCAL                           GOOGLE DRIVE
/home/user/Documentos/          RustDriveSync/
├── projeto/                    ├── projeto/
│   ├── arquivo1.txt       →    │   ├── arquivo1.txt
│   └── src/                    │   └── src/
│       └── main.rs        →    │       └── main.rs
└── fotos/                      └── fotos/
    └── foto.jpg           →        └── foto.jpg
```

**Com `preserve_folder_structure = false` (modo legado):**

```
LOCAL                           GOOGLE DRIVE
/home/user/Documentos/          RustDriveSync/
├── projeto/                    ├── arquivo1.txt
│   ├── arquivo1.txt       →    ├── main.rs
│   └── src/                    └── foto.jpg
│       └── main.rs        →
└── fotos/
    └── foto.jpg           →
```

### Configuração

No arquivo `config.toml`:

```toml
[sync]
preserve_folder_structure = true  # Padrão: true
```

### Performance

- **Cache inteligente**: Pastas criadas são armazenadas em cache para evitar chamadas redundantes à API
- **Criação recursiva**: Toda a hierarquia é criada automaticamente quando necessário
- **Thread-safe**: Cache compartilhado com segurança entre uploads paralelos

## 📚 Documentação

### Para Usuários
- **[Guia de Uso Completo]GUIA_DE_USO.md** - Tutorial passo a passo em Português
  - Instalação e configuração inicial
  - Comandos básicos e avançados
  - Exemplos práticos de uso
  - Solução de problemas comuns
  - Dicas de segurança

### Para Desenvolvedores
- **[Sumário de Arquitetura]docs/ARCHITECTURE_SUMMARY.md** - Visão executiva da arquitetura
- **[Documentação Completa de Arquitetura]docs/architecture/README.md** - Índice central
  - **[ADRs - Architecture Decision Records]docs/architecture/adr/**
    - [0001: Dependency Injection com Traits]docs/architecture/adr/0001-dependency-injection-with-traits.md
    - [0002: Rate Limiting para Google Drive API]docs/architecture/adr/0002-rate-limiting-google-drive-api.md
    - [0003: Retry com Exponential Backoff]docs/architecture/adr/0003-retry-with-exponential-backoff.md
    - [0004: Uploads Paralelos]docs/architecture/adr/0004-parallel-uploads.md
  - **[Diagramas C4]docs/architecture/diagrams/**
    - [Context Diagram]docs/architecture/diagrams/c4-context.md - Visão de sistema
    - [Container Diagram]docs/architecture/diagrams/c4-container.md - Componentes internos
    - [Data Flow]docs/architecture/diagrams/data-flow.md - Fluxo de dados
  - **[Atributos de Qualidade]docs/architecture/quality-attributes.md** - Performance, Segurança, Confiabilidade
  - **[Arquitetura de Segurança]docs/architecture/security-architecture.md** - Modelo de ameaças e compliance

### API Documentation
```bash
# Gerar documentação Rust
cargo doc --open
```

## ⚙️ Configuração

Exemplo de `config.toml`:

```toml
[general]
log_level = "info"

[source]
path = "/home/usuario/documentos"
recursive = true
ignore_hidden = true
ignore_patterns = ["*.tmp", "node_modules/", ".git/"]

[google_drive]
credentials_file = "./credentials.json"
token_file = "./token.json"
target_folder_id = "1ABC123xyz"

[sync]
mode = "watch"
interval_seconds = 300
conflict_resolution = "overwrite"
max_file_size_mb = 100
chunk_size_mb = 5
preserve_folder_structure = true  # Mantém hierarquia de pastas (true = preserva, false = todos os arquivos na raiz)
```

Veja `config.example.toml` para todas as opções disponíveis.

## 🏗️ Arquitetura

```
┌─────────────────────────────────────────────────┐
│                  RustDriveSync                  │
├─────────────────────────────────────────────────┤
│                                                 │
│  CLI (clap) → Config → Core Engine              │
│                         │                       │
│                         ├─ File Scanner         │
│                         ├─ Sync Engine          │
│                         └─ State Manager        │
│                         │                       │
│                         ▼                       │
│               Google Drive Client               │
│               (OAuth2 + Upload)                 │
│                                                 │
└─────────────────────────────────────────────────┘
```

## 🧪 Desenvolvimento

### Build

```bash
cargo build
```

### Testes

```bash
cargo test
```

### Linting

```bash
cargo clippy
```

### Formatação

```bash
cargo fmt
```

## 📝 Roadmap

### ✅ V1.0 - Production Ready (CONCLUÍDO)

**Fundação**:
- [x] Estrutura base e CLI ✅
- [x] Sistema de configuração ✅
- [x] Integração com Google Drive ✅
- [x] Sync engine completo ✅
- [x] File watcher (modo watch) ✅
- [x] Streaming de uploads ✅

**Qualidade e Performance**:
- [x] Dependency Injection com traits ✅
- [x] Rate limiting automático (800 req/100s) ✅
- [x] Retry com exponential backoff ✅
- [x] Uploads paralelos (5-10x speedup) ✅
- [x] 113 testes (>70% cobertura em módulos críticos) ✅
- [x] Documentação completa (ADRs, C4, Security) ✅

### 🚀 Próximos Passos

**V1.1 (Q1 2026)** - Melhorias de Segurança e Observabilidade:
- [ ] OS Keychain integration (macOS Keychain, Windows Credential Manager, Linux Secret Service)
- [ ] Jitter em retry para prevenir thundering herd
- [ ] Structured logging (JSON format)
- [ ] Prometheus metrics endpoint
- [ ] E2E tests com Docker

**V1.2 (Q2 2026)** - Múltiplos Backends:
- [ ] Backend S3 (AWS S3, MinIO, Wasabi)
- [ ] Backend Dropbox
- [ ] SQLite state (substituir JSON)
- [ ] Progress bar melhorado (multi-file)
- [ ] Cobertura de testes >50%

**V2.0 (Q3-Q4 2026)** - Sincronização Avançada:
- [ ] Sincronização bidirecional (Drive → Local)
- [ ] Resolução automática de conflitos
- [ ] End-to-end encryption opcional
- [ ] Web dashboard (status, métricas, logs)
- [ ] Multi-user support

**V3.0 (2027)** - Enterprise Features:
- [ ] Webhooks para notificações
- [ ] API REST para integração
- [ ] Suporte a múltiplos clouds simultâneos
- [ ] Versionamento de arquivos
- [ ] Rollback de mudanças

📋 Veja [ROADMAP.md](ROADMAP.md) para detalhes completos sobre features planejadas, sprints, e debt técnica.
📄 Veja [CHANGELOG.md](CHANGELOG.md) para histórico detalhado de mudanças.

## 🤝 Contribuindo

Contribuições são bem-vindas! Por favor:

1. Fork o projeto
2. Crie uma branch para sua feature (`git checkout -b feature/AmazingFeature`)
3. Commit suas mudanças (`git commit -m 'Add some AmazingFeature'`)
4. Push para a branch (`git push origin feature/AmazingFeature`)
5. Abra um Pull Request

## 📄 Licença

Este projeto está licenciado sob a Licença MIT - veja o arquivo [LICENSE](LICENSE) para detalhes.

## 🔗 Links Úteis

- [Documentação da Google Drive API]https://developers.google.com/drive/api
- [OAuth 2.0 para Desktop Apps]https://developers.google.com/identity/protocols/oauth2/native-app
- [Documentação Rust]https://doc.rust-lang.org/

## 🙏 Agradecimentos

- Comunidade Rust
- Mantenedores das crates utilizadas (clap, tokio, yup-oauth2, etc.)
- Contribuidores do projeto

---

**Desenvolvido com ❤️ em Rust**