Skip to content

std-input/nocloud

Repository files navigation

NoCloud

Sistema de almacenamiento cloud con microservicios en Go. Subida con chunking (4MB), compresion gzip, cifrado AES-256-GCM por usuario, autenticacion JWT y API Gateway unificado.

Arquitectura

                   ┌──────────────┐
                   │  API Gateway  │ :8080
                   └────┬────┬────┘
                        │    │
              ┌─────────┤    ├──────────┐
              │         │    │          │
         ┌────▼──┐ ┌───▼──┐ ┌▼────┐    │
         │ Upload│ │ Read │ │Auth │    │
         │ :3001 │ │:3002 │ │:3300│    │
         └───┬───┘ └──┬───┘ └─────┘    │
             │        │                 │
         ┌───▼────────▼───┐             │
         │  Storage       │◄────────────┘
         │  :3003         │  (internal)
         └────────────────┘
Servicio Puerto Autenticacion Rol
API Gateway 8080 JWT / None Entry point unico
Upload Service 3001 JWT Subida con chunking + crypto
Read Service 3002 JWT Descarga y listado
Auth Service 3300 JWT / Google OAuth Login y gestion de usuarios
Storage Service 3003 API Key (internal) Abstraccion de FS

Stack

  • Go 1.26 + Fiber v3
  • PostgreSQL — metadatos de archivos y chunks
  • JWT (golang-jwt/v5) — autenticacion
  • AES-256-GCM + gzip — cifrado y compresion por usuario
  • Chunking 4MB — archivos divididos en fragmentos

Requisitos

  • Go 1.26+
  • Docker (para PostgreSQL)
  • Credenciales de OAuth2 de Google (opcional, para login con Google)

Quick Start

1. PostgreSQL

docker compose up -d

2. Configurar servicios

Cada servicio tiene un example.env. Copiarlo a .env y ajustar si es necesario:

cp auth_service/example.env auth_service/.env
cp api_gateway/example.env api_gateway/.env
cp upload_service/example.env upload_service/.env
cp read_service/example.env read_service/.env
cp storage_service/example.env storage_service/.env

3. Generar token JWT (para pruebas)

go run ./auth_service/cmd/gentoken -user testuser123

4. Iniciar servicios

# Terminal 1 — Storage (interno)
cd storage_service && go run .

# Terminal 2 — Upload
cd upload_service && go run .

# Terminal 3 — Read
cd read_service && go run .

# Terminal 4 — Auth
cd auth_service && go run .

# Terminal 5 — API Gateway
cd api_gateway && go run .

5. Probar

TOKEN="eyJ..."

# Subir archivo
curl -X POST http://localhost:8080/api/upload/init \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"path":"fotos/vacaciones.jpg","size":10485760,"mime_type":"image/jpeg"}'

# Listar
curl http://localhost:8080/api/read/list?prefix=fotos/ \
  -H "Authorization: Bearer $TOKEN"

# Descargar
curl -o descarga.jpg http://localhost:8080/api/read/files/fotos/vacaciones.jpg \
  -H "Authorization: Bearer $TOKEN"

API

Todas las rutas pasan por el API Gateway (http://localhost:8080).

Publicas (sin JWT)

Metodo Ruta Descripcion
GET /health Health check
GET /api/auth Iniciar sesion con Google
GET /api/auth/google/callback Callback OAuth
POST /api/refresh Refrescar token JWT
GET /api/user/:id Obtener perfil publico

Protegidas (JWT requerido)

Upload Service

Metodo Ruta Descripcion
POST /api/upload/init Iniciar subida (path, size, mime_type)
PUT /api/upload/:id/chunks/:index Subir chunk (body raw)
GET /api/upload/:id/status Estado de la subida
POST /api/upload/:id/complete Finalizar subida
DELETE /api/upload/:id Cancelar subida
GET /api/upload/files?prefix= Listar archivos subidos
DELETE /api/upload/dir?prefix= Eliminar directorio

Read Service

Metodo Ruta Descripcion
GET /api/read/files/* Descargar archivo (streaming)
GET /api/read/list?prefix= Listar archivos disponibles

Auth Service

Metodo Ruta Descripcion
DELETE /api/user Eliminar cuenta
PUT /api/user Actualizar perfil

Bloqueadas

Metodo Ruta Descripcion
* /api/storage/* 403 Forbidden — solo uso interno

Seguridad

  • Chunking: archivos divididos en fragmentos de 4MB
  • Compresion: gzip por chunk antes de cifrar
  • Cifrado: AES-256-GCM con clave derivada por usuario (HMAC(ENCRYPTION_KEY, user_id))
  • JWT: tokens HS256 con 24h de expiracion
  • Aislamiento: Storage Service no expuesto al exterior, solo accesible con API Key interna

Estructura del proyecto

├── api_gateway/         # API Gateway (Fiber, CORS, rate limiting, JWT edge)
├── auth_service/        # Autenticacion (Google OAuth, JWT, usuarios)
│   └── cmd/gentoken/    # CLI para generar tokens de prueba
├── read_service/        # Lectura (descarga con streaming + crypto)
├── storage_service/     # Almacenamiento (FS抽象, API Key interna)
├── upload_service/      # Subida (chunking, crypto, metadata)
├── docker-compose.yml   # PostgreSQL
└── README.md

TO-DO

  • Validacion de chunk size en Complete — verificar que el tamano declarado en Init coincida con la suma real de los chunks
  • Compartir archivos — links publicos con expiracion
  • Parallel chunk upload — el backend ya lo soporta (no requiere orden), el frontend deberia aprovecharlo
  • Dockerizar servicios — Dockerfile para cada microservicio

Licencia

MIT

About

Sistema de almacenamiento cloud con microservicios en Go + Fiber v3. Subida con chunking de 4MB, compresión gzip, cifrado AES-256-GCM por usuario, autenticación JWT y API Gateway unificado.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages