Skip to content

Latest commit

ย 

History

History
267 lines (215 loc) ยท 8.25 KB

File metadata and controls

267 lines (215 loc) ยท 8.25 KB

SnapVault Implementation Summary

๐ŸŽฏ Project Overview

SnapVault is a complete, production-ready file upload and management system built with Ruby on Rails 8.0.2. It provides secure, user-authenticated file storage with a modern web interface and RESTful API.

๐Ÿ—๏ธ Architecture

Backend Stack

  • Framework: Ruby on Rails 8.0.2 (API mode)
  • Database: SQLite3 (development), PostgreSQL ready (production)
  • Authentication: JWT tokens with bcrypt password hashing
  • File Storage: Active Storage with local/cloud support
  • File Processing: Marcel for MIME type detection
  • CORS: Rack-CORS for cross-origin requests

Frontend Stack

  • Technology: Vanilla JavaScript with modern ES6+ features
  • Styling: CSS3 with custom properties and Flexbox/Grid
  • UI/UX: Responsive design with mobile-first approach
  • Interactions: Drag & drop file uploads, real-time feedback

๐Ÿ“ Project Structure

snapvault/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ controllers/
โ”‚   โ”‚   โ”œโ”€โ”€ application_controller.rb      # Base controller with auth
โ”‚   โ”‚   โ”œโ”€โ”€ auth_controller.rb            # Login/registration
โ”‚   โ”‚   โ”œโ”€โ”€ files_controller.rb           # File management
โ”‚   โ”‚   โ”œโ”€โ”€ health_controller.rb          # Health checks
โ”‚   โ”‚   โ”œโ”€โ”€ home_controller.rb            # Serves frontend
โ”‚   โ”‚   โ””โ”€โ”€ uploads_controller.rb         # File uploads
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ user.rb                       # User authentication
โ”‚   โ”‚   โ””โ”€โ”€ user_file.rb                  # File metadata
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”œโ”€โ”€ auth/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ jwt_service.rb           # JWT token handling
โ”‚   โ”‚   โ”œโ”€โ”€ authorize_api_request.rb     # Request authorization
โ”‚   โ”‚   โ”œโ”€โ”€ exception_handler.rb         # Error handling
โ”‚   โ”‚   โ””โ”€โ”€ message.rb                   # Consistent messages
โ”‚   โ””โ”€โ”€ controllers/concerns/
โ”‚       โ””โ”€โ”€ authenticable.rb             # Auth concern
โ”œโ”€โ”€ config/
โ”‚   โ”œโ”€โ”€ routes.rb                        # API routes
โ”‚   โ”œโ”€โ”€ database.yml                     # Database config
โ”‚   โ””โ”€โ”€ initializers/cors.rb             # CORS setup
โ”œโ”€โ”€ public/
โ”‚   โ”œโ”€โ”€ index.html                       # Main application
โ”‚   โ””โ”€โ”€ demo.html                        # Landing page
โ””โ”€โ”€ db/
    โ””โ”€โ”€ migrate/                         # Database migrations

๐Ÿ”ง Key Features Implemented

1. User Authentication

  • Registration: Secure user signup with validation
  • Login: Email/password authentication
  • JWT Tokens: Stateless authentication with 24-hour expiry
  • Password Security: bcrypt hashing with Rails defaults

2. File Management

  • Upload: Support for JPG, PNG, GIF, SVG, TXT, MD, CSV
  • Validation: File type and size (2MB limit) validation
  • Ownership: Strict user-file association
  • Metadata: Filename, size, type, upload date tracking

3. Security Features

  • Authorization: JWT-based API protection
  • File Access Control: Users can only access their own files
  • MIME Type Validation: Prevents malicious file uploads
  • Error Handling: Consistent error responses without data leakage

4. API Endpoints

Authentication

  • POST /auth/register - User registration
  • POST /auth/login - User login

File Operations

  • POST /upload - Upload new file
  • GET /files - List user's files
  • GET /files/:id - Get file details
  • GET /files/:id/download - Download file
  • DELETE /files/:id - Delete file

System

  • GET /health - Health check
  • GET / - Frontend application

๐ŸŽจ Frontend Features

1. Modern UI/UX

  • Responsive Design: Mobile-first approach
  • Interactive Elements: Hover effects, animations
  • Visual Feedback: Progress bars, loading states
  • Accessibility: Semantic HTML, keyboard navigation

2. File Upload Interface

  • Drag & Drop: Intuitive file dropping
  • File Selection: Traditional file picker
  • Progress Tracking: Visual upload progress
  • Validation Feedback: Real-time error messages

3. File Management

  • Grid Display: Card-based file listing
  • File Icons: Type-specific visual indicators
  • Metadata Display: Size, date, type information
  • Actions: Download, delete with confirmation

4. User Experience

  • Authentication Tabs: Seamless login/register switching
  • Dashboard: Usage statistics and file overview
  • Alerts: Toast notifications for actions
  • Empty States: Helpful guidance for new users

๐Ÿš€ Getting Started

Prerequisites

  • Ruby 3.3.5
  • Rails 8.0.2
  • SQLite3 (development)
  • ImageMagick or libvips (optional, for image processing)

Installation

# Clone and setup
cd snapvault
bundle install

# Database setup
bin/rails db:create
bin/rails db:migrate

# Start server
bin/rails server -p 3000

Usage

  1. Visit http://localhost:3000
  2. Register a new account or login
  3. Upload files via drag & drop or file picker
  4. Manage your files through the interface

๐Ÿงช Testing the API

Register User

curl -X POST http://localhost:3000/auth/register \
  -H "Content-Type: application/json" \
  -d '{"name":"John Doe","email":"john@example.com","password":"password123"}'

Upload File

curl -X POST http://localhost:3000/upload \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -F "file=@/path/to/your/file.png"

List Files

curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  http://localhost:3000/files

๐Ÿ”’ Security Considerations

Implemented Security Measures

  1. Authentication: JWT tokens with expiration
  2. Authorization: Request-level user verification
  3. File Validation: MIME type and size checking
  4. Ownership Control: Strict file access enforcement
  5. Password Security: bcrypt hashing
  6. Error Handling: No sensitive data in error messages

Production Recommendations

  1. HTTPS: Always use SSL in production
  2. Database: Switch to PostgreSQL for production
  3. File Storage: Use cloud storage (S3, GCS) for scalability
  4. Rate Limiting: Implement API rate limiting
  5. Monitoring: Add application monitoring and logging
  6. Backup: Regular database and file backups

๐Ÿ“ˆ Scalability & Performance

Current Optimizations

  • Efficient database queries with includes
  • File size limits to prevent abuse
  • Minimal API response payloads
  • Client-side file validation

Future Enhancements

  • Background job processing for large files
  • CDN integration for file delivery
  • Database connection pooling
  • Caching layer (Redis)
  • Horizontal scaling with load balancers

๐ŸŽฏ Production Deployment

Environment Configuration

# Required environment variables
export RAILS_ENV=production
export SECRET_KEY_BASE=your_secret_key
export DATABASE_URL=postgresql://user:pass@host:port/dbname

Docker Deployment

# Dockerfile already included in the project
docker build -t snapvault .
docker run -p 3000:3000 snapvault

Cloud Platforms

  • Heroku: One-click deployment ready
  • Railway: GitHub integration available
  • DigitalOcean: Docker-based deployment
  • AWS/GCP: Container or serverless deployment

๐Ÿ”ฎ Future Roadmap

Phase 1 (Current Implementation)

  • โœ… Basic file upload/download
  • โœ… User authentication
  • โœ… Web interface
  • โœ… API endpoints

Phase 2 (Near Term)

  • File sharing with expiration links
  • Batch operations
  • File previews and thumbnails
  • Advanced search and filtering

Phase 3 (Long Term)

  • File versioning
  • Collaboration features
  • Mobile applications
  • Enterprise features (SSO, LDAP)

๐Ÿ“ API Documentation

The application includes Swagger-ready endpoints and can be easily documented using tools like:

  • OpenAPI/Swagger specifications
  • Postman collections
  • Insomnia workspaces

๐Ÿค Contributing

The codebase follows Rails conventions and best practices:

  • Code Style: Standard Ruby formatting
  • Testing: RSpec test framework ready
  • Security: Brakeman security scanning
  • Quality: Rubocop linting

๐Ÿ“„ License

SnapVault is open source and available under the MIT License, making it suitable for both personal and commercial use.


Built with โค๏ธ for developers who need simple, secure file storage.