How nic13gamer/better-upload works
Main Components of the Project
• Client Library – Found under “packages/better-upload/src/client”. This contains:
• React hooks (such as use-upload-file and use-upload-files), which abstract the upload logic for user-facing React components.
• Client utilities and types, ensuring correct handling of errors, internal states, and interface types.
• Server Library – Found under “packages/better-upload/src/server”. This includes:
• API route handlers (in “router/handlers”) that implement upload endpoints (supporting single, multipart, and multiple uploads).
• Integration with various S3-compatible services through helper clients (e.g., for Backblaze, Minio, Wasabi, R2) located in “server-helpers/clients”.
• Server-side utilities, configurations, routing integrations (like the Next.js integration in “router/integrations/next”), and validations.
• Documentation & Example Applications – Two separate “apps” folders:
• “apps/docs” – Provides thorough documentation, demo components, API references, and helper content.
• “apps/example” – Contains a working Next.js example that shows how to integrate the upload functionality into an application.
Identifying Relationships and Interactions
• The client components (hooks and UI components) interact with your front-end code and are designed to be dropped into React-based projects.
• When an upload is initiated on the frontend, the client library communicates with the server-side APIs. This communication might involve:
• Sending file data (or file metadata) to corresponding API routes defined in “apps/example/src/app/api/upload/route.ts” (and similar endpoints) or those handled by frameworks integrating with Better Upload.
• The server library (using its router and helper clients) receives these requests, handles file processing, validation, and then interacts with the external storage service (S3-compatible services).
• The documentation and examples demonstrate both the implementation details and usage conventions, which help guide developers using the library.
Architectural Patterns & Design Principles
• Separation of Concerns – The clear division between client and server components ensures that UI-specific logic is decoupled from file handling and integration logic.
• Modular Design – The repository is structured as a monorepo (as seen with pnpm and turborepo configurations) where the “better-upload” package can be updated or extended independent of the documentation and examples.
• Framework Agnosticism – Although optimized for Next.js, client and server libraries are written to work with any standard server framework, emphasizing reusability and integration flexibility.
Technologies and Frameworks
• React/Next.js – For building the client components and handling app routes (as seen in apps/docs and apps/example).
• Node.js Environment – With routing, server-side logic, and integration with various S3 storage clients.
• S3-Compatible Storage – Direct integration is provided via specific modules for Backblaze, Minio, Wasabi, and R2.
• Tooling – Uses Turborepo for monorepo management, pnpm for dependency management, TypeScript for type safety (with multiple tsconfig.json files), and Prettier for code formatting.