A secure, AI-powered file management system built with Next.js, featuring user authentication, file upload/download, and comprehensive security measures.
- Node.js 18+
- npm, yarn, pnpm, or bun
-
Clone and install dependencies:
git clone <repository-url> cd engineering-day-hack npm install
-
Initialize the database and environment:
npm run setup
This will:
- Create the SQLite database with required tables
- Copy
.env.exampleto.env.local - Set up authentication tables and file management schema
-
Start the development server:
npm run dev
-
Open your browser: Navigate to http://localhost:3000
Run the comprehensive API test suite:
npm run test:filesThis tests all file operations:
- File upload (multiple formats)
- File retrieval and listing
- File deletion
- Error handling
- Security validations
-
Web Interface Testing:
- Visit http://localhost:3000
- Sign up/login to test authentication
- Navigate to upload section
- Test drag-and-drop file uploads
- Test file viewing and deletion
-
API Testing with cURL:
# Upload a file curl -X POST http://localhost:3000/api/files \ -F "file=@path/to/your/file.jpg" # List all files curl http://localhost:3000/api/files # Delete a file curl -X DELETE http://localhost:3000/api/files/{file-id}
-
Interactive Test Page: If available, visit the test upload page for direct API interaction
Core Functionality:
- User registration and login
- File upload (images, documents, PDFs)
- File listing and pagination
- File download/viewing
- File deletion
- Large file handling (up to 10MB)
Security Features:
- File type validation (try uploading .exe files)
- File size limits (try files > 10MB)
- Authentication protection
- Error handling
Edge Cases:
- Network interruption during upload
- Duplicate file names
- Special characters in filenames
- Empty files
- Malformed requests
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
- Backend: Next.js API Routes, Better Auth
- Database: SQLite with Drizzle ORM
- File Storage: Local file system (uploads directory)
- Security: Multi-layer validation, content-type checking
engineering-day-hack/
βββ src/
β βββ app/ # Next.js app router
β β βββ api/ # API endpoints
β β β βββ files/ # File management APIs
β β β βββ auth/ # Authentication APIs
β β βββ auth/ # Auth pages
β β βββ upload/ # File upload interface
β β βββ files/ # File management interface
β βββ components/ # Reusable UI components
β βββ types/ # TypeScript definitions
β βββ utils/ # Utility functions
βββ uploads/ # File storage directory
βββ sqlite.db # SQLite database
βββ middleware.ts # Request middleware
Authentication System:
- Built with Better Auth
- Session-based authentication
- User registration and login
- Secure session management
File Management:
- Multi-format file support (images, documents, PDFs)
- UUID-based file naming for security
- Metadata storage in SQLite
- Stream-based upload processing
Security Layers:
- Client-side validation (immediate feedback)
- HTTP middleware validation (early request filtering)
- Stream validation (real-time monitoring)
- Save-time validation (final verification)
Core Tables:
user- User accounts and profilessession- Authentication sessionsfiles- File metadata and relationshipsaccount- OAuth account linkingverification- Email verification tokens
# Development
npm run dev # Start development server with turbopack
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint
# Database
npm run db:generate # Generate database migrations
npm run db:migrate # Run database migrations
npm run db:push # Push schema changes
npm run db:studio # Open Drizzle Studio
# Setup & Testing
npm run setup # Complete initial setup
npm run auth:setup # Initialize database only
npm run test:files # Run file API testsPOST /api/auth/sign-up- User registrationPOST /api/auth/sign-in- User loginPOST /api/auth/sign-out- User logout
POST /api/files- Upload filesGET /api/files- List files (with pagination)GET /api/files/[id]- Get file detailsDELETE /api/files/[id]- Delete fileGET /uploads/[filename]- Access file content
File Upload Security:
- Whitelist-based file type validation
- File size limits (10MB max)
- Content-type verification
- Filename sanitization
- Stream-based validation to prevent DoS attacks
Authentication Security:
- Session-based authentication
- CSRF protection
- Secure password hashing
- Email verification support
General Security:
- Security headers (HSTS, CSP, etc.)
- Rate limiting on sensitive endpoints
- Input validation and sanitization
- Error message sanitization
Database initialization fails:
# Delete existing database and retry
rm sqlite.db sqlite.db-shm sqlite.db-wal
npm run auth:setupEnvironment variables not found:
# Ensure .env.local exists and is properly configured
cp .env.example .env.local
# Edit .env.local with your valuesFile uploads failing:
- Check file size (must be < 10MB)
- Verify file type is supported
- Ensure uploads directory exists and is writable
- Check network connectivity
Authentication not working:
- Verify database is initialized
- Check session configuration in .env.local
- Clear browser cookies/sessions
API endpoints returning 404:
- Ensure development server is running on port 3000
- Check API route file structure
- Verify Next.js app router configuration
Slow file uploads:
- Check file sizes (large files take longer)
- Verify network connection
- Consider implementing upload progress indicators
Database slow queries:
- Run
npm run db:studioto inspect data - Check for proper indexing
- Consider pagination for large file lists
- Files API Usage Guide - Comprehensive API documentation
- Security Implementation - Detailed security measures
- Logging Implementation - Logging and monitoring
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
npm run test:files - Run linting:
npm run lint - Submit a pull request
- Update TypeScript types in
src/types/ - Add appropriate tests
- Update API documentation
- Consider security implications
β
Secure File Upload - Multi-layer security validation
β
User Authentication - Complete auth system with Better Auth
β
File Management - Upload, view, download, delete files
β
Responsive Design - Modern UI with Tailwind CSS
β
API-First Design - RESTful APIs for all operations
β
Type Safety - Full TypeScript implementation
β
Database Integration - SQLite with Drizzle ORM
β
Security Hardened - Protection against common attacks
- Images: JPEG, PNG, GIF, WebP
- Documents: PDF, DOC, DOCX, XLS, XLSX
- Text: Plain text files
- Size Limit: 10MB per file
Need Help? Check the troubleshooting section above or review the detailed documentation files for specific topics.