Skip to content

dotlabshq/s3-browser

Repository files navigation

S3-Browser πŸš€

High-Performance, Secure File Management System built with Next.js 16, MinIO (S3), Redis, and ZITADEL authentication.

Features

  • πŸ“ S3-Compatible Storage - Multi-bucket architecture with MinIO
  • πŸ” YAML-based RBAC - Enterprise-grade access control with role-based permissions
  • ⚑ Redis Caching - Lightning-fast permission checks and file listings
  • πŸ”‘ ZITADEL Auth - OIDC authentication with Auth.js v5
  • πŸ“ Audit Logging - Complete operation tracking
  • 🎨 Modern UI - Built with Shadcn UI and Tailwind CSS v4
  • πŸ‘οΈ File Preview - In-browser preview for images and PDFs (no download required)
  • 🐳 Docker Ready - Multi-stage production Dockerfile included

Tech Stack

Category Technology
Framework Next.js 16.1.6 (App Router + Turbopack)
Runtime Node.js 22+
Auth Auth.js v5 (next-auth@5.0.0-beta.30) + ZITADEL OIDC
Storage MinIO (S3-compatible)
Cache Redis (ioredis)
UI Shadcn UI, Tailwind CSS v4, Lucide Icons
Language TypeScript 5

Quick Start

Prerequisites

  • Node.js 22+ (use nvm use with included .nvmrc)
  • Docker & Docker Compose
  • ZITADEL instance (for authentication)

1. Clone and Install

git clone <repo-url>
cd s3-browser
npm install

2. Setup Environment

cp .env.local.example .env.local
# Edit .env.local with your configuration

3. Start Services

# Start MinIO and Redis
npm run docker:up

# MinIO Console: http://localhost:9001
# Redis Commander: http://localhost:8081

4. Initialize

# Create S3 buckets
npm run init-buckets

# Sync permissions to Redis
npm run sync-permissions

5. Run Development Server

npm run dev
# Open http://localhost:3000

Project Structure

s3-browser/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                    # Next.js App Router
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/           # Auth.js v5 handlers
β”‚   β”‚   β”‚   β”œβ”€β”€ files/          # File operation endpoints
β”‚   β”‚   β”‚   └── permissions/    # Permission sync endpoint
β”‚   β”‚   β”œβ”€β”€ auth/               # Auth pages (signin, error)
β”‚   β”‚   └── (dashboard)/        # Protected routes
β”‚   β”‚       └── explorer/       # File explorer
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ explorer/           # File explorer components
β”‚   β”‚   β”‚   β”œβ”€β”€ FileExplorer.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ FileList.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ FileItem.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ FilePreview.tsx # Image/PDF preview modal
β”‚   β”‚   β”‚   β”œβ”€β”€ Breadcrumb.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ UploadZone.tsx
β”‚   β”‚   β”‚   └── PermissionBadge.tsx
β”‚   β”‚   └── ui/                 # Shadcn UI components
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ auth.ts             # Auth.js v5 configuration
β”‚   β”‚   β”œβ”€β”€ redis.ts            # Redis client
β”‚   β”‚   └── s3-client.ts        # S3/MinIO client
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ s3Service.ts        # S3 operations
β”‚   β”‚   β”œβ”€β”€ permissionService.ts # RBAC engine
β”‚   β”‚   β”œβ”€β”€ cacheService.ts     # Redis caching
β”‚   β”‚   β”œβ”€β”€ auditService.ts     # Audit logging
β”‚   β”‚   └── syncService.ts      # YAML sync
β”‚   β”œβ”€β”€ types/                  # TypeScript types
β”‚   └── proxy.ts                # Auth proxy (Next.js 16 pattern)
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ init-buckets.ts         # Bucket initialization
β”‚   └── sync-permissions.ts     # Permission sync CLI
β”œβ”€β”€ permissions.yaml            # Permission configuration
β”œβ”€β”€ Dockerfile                  # Multi-stage production build
β”œβ”€β”€ docker-compose.yml          # Development services
β”œβ”€β”€ .nvmrc                      # Node.js version (22)
└── .vscode/                    # VS Code debug configs

Permission System

Levels

  • OWNER - Full control (read, write, delete)
  • EDITOR - Read and write access
  • VIEWER - Read-only access

Configuration (permissions.yaml)

roles:
  admin:
    priority: 100
    permissions:
      - path: "*"
        level: OWNER

  engineering:
    priority: 50
    permissions:
      - path: "shared/engineering/*"
        level: EDITOR

users:
  john@company.com:
    priority: 80
    permissions:
      - path: "projects/secret/*"
        level: OWNER

defaults:
  authenticated:
    permissions:
      - path: "shared/public/*"
        level: VIEWER

Auto-granted Permissions

Every user automatically gets OWNER access to their home directory: home/${username}/*

API Endpoints

Endpoint Method Description
/api/files/list GET List files in a path
/api/files/upload-url POST Get presigned upload URL
/api/files/download-url POST Get presigned download URL
/api/files/preview-url POST Get presigned preview URL (images/PDF)
/api/files/create-folder POST Create a new folder
/api/files/rename POST Rename file/folder
/api/files/delete DELETE Delete file/folder
/api/permissions/sync POST Sync permissions to Redis

File Preview

The file explorer supports in-browser preview for:

File Type Features
Images (jpg, png, gif, webp, svg, bmp) Zoom in/out, Rotate
PDF Embedded iframe viewer

Click the πŸ‘οΈ (eye) icon on any previewable file to open the preview modal without downloading.

Environment Variables

# Auth.js v5
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-key
AUTH_TRUST_HOST=true

# ZITADEL
ZITADEL_ISSUER=https://your-instance.zitadel.cloud
ZITADEL_CLIENT_ID=your-client-id
ZITADEL_CLIENT_SECRET=your-client-secret

# MinIO
S3_ENDPOINT=http://localhost:9000
S3_REGION=us-east-1
S3_ACCESS_KEY_ID=minioadmin
S3_SECRET_ACCESS_KEY=minioadmin
S3_BUCKET_USER_FILES=user-files
S3_BUCKET_SHARED_FILES=shared-files
S3_BUCKET_TEMP_UPLOADS=temp-uploads

# Redis
REDIS_URL=redis://localhost:6379

# App Config
MAX_FILE_SIZE_MB=100
ALLOWED_FILE_TYPES=.pdf,.jpg,.png,.doc,.docx,.xls,.xlsx,.zip
PRESIGNED_URL_EXPIRY_SECONDS=3600

Scripts

npm run dev              # Start development server (Turbopack)
npm run build            # Build for production
npm run start            # Start production server
npm run lint             # Run ESLint
npm run sync-permissions # Sync permissions.yaml to Redis
npm run init-buckets     # Create S3 buckets
npm run docker:up        # Start Docker services
npm run docker:down      # Stop Docker services

Docker

Development

# Start MinIO + Redis
docker compose up -d

# Access MinIO Console
open http://localhost:9001

Production

# Build and run the app
docker compose --profile app up -d

# Or build manually
docker build -t s3-browser .
docker run -p 3000:3000 --env-file .env.local s3-browser

Security Checklist

  • βœ… All S3 operations are server-side only
  • βœ… Presigned URLs with expiration
  • βœ… Permission checks before every operation
  • βœ… Audit logging for all file access
  • βœ… Path sanitization and validation
  • βœ… File type and size restrictions
  • βœ… CSRF protection with Auth.js v5
  • βœ… Server Actions for authentication

Development

VS Code

The project includes VS Code launch configurations for debugging:

  1. Next.js: Debug Server - Debug the Next.js server
  2. Next.js: Full Stack - Debug both server and client

Use nvm use to switch to Node.js 22 before running.

Node.js Version

This project requires Node.js 22+. Use the included .nvmrc:

nvm use

License

MIT

About

S3 file browser with RBAC permissions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published