How musheer0/ex-drive-web works
Project Type and Purpose
• This is a full-stack, React/Next.js 13 application using the new “app” router.
• It provides a cloud-drive/media-management UI (upload, browse public/private media, real-time features via sockets).
• It exposes serverless API routes (src/app/api/*) for token management and likely other operations.
• It integrates a database layer (src/DB/dexi.ts), JWT-based auth (private.key, token APIs), and WebSockets for real-time updates.
File Structure & Key Components
• Frontend
– src/app contains all page routes: dashboard, upload, media (private & public), search, dev & socket demos, onboarding, shared layout.
– src/components holds React UI components (auth, dashboard nav/sidebar, media scrollers, search, socket listeners, file-upload UI, generic UI primitives).
– src/hooks and src/stores implement state management, side effects, and client-side caching (dashboard, media, search, socket, upload).
• Backend/API
– src/app/api/token/*/route.ts defines serverless token create/change endpoints.
– middleware.ts for request preprocessing (auth, session).
– src/DB/dexi.ts wraps database access logic.
• Cross-cutting
– src/lib has shared utilities: API fetch wrapper, auth helpers (decode-token, get-user-info), URL links, types, general utils.
– WebSockets under src/components/socket and src/hooks/use-socket.ts.
– Static assets under public (manifest.json).
– Configuration: Next.js (next.config.ts), ESLint, Tailwind, TypeScript.
README for Additional Insights
• The README is minimal, but the name “ex-drive-web” implies a user-focused drive/media storage service.
Main Architectural Components & Interactions
a. User’s Browser (Client)
– Renders React pages/SSR/SSG endpoints from Next.js.
– Uses React Contexts, custom hooks to manage auth, state, theme, search, media lists, upload progress.
– Initiates WebSocket connections for real-time updates (e.g., new file notifications).
– Calls REST-style API routes under /api/token/... and any other future endpoints (/api/media, etc.).
b. Next.js Server (App Router + API Routes)
– Serves page requests (SSR/SSG) and processes API calls.
– Runs middleware.ts for authorization, session management.
– Provides the server side of the WebSocket endpoint (if implemented via Next.js or a separate WS server).
c. Database Layer
– The dexi.ts module encapsulates all read/write operations to your chosen database (e.g., DynamoDB, PostgreSQL, etc.).
– Called directly from API route handlers or server components.
d. Authentication
– JWT tokens signed with private.key.
– /api/token/add and /api/token/change endpoints generate and rotate tokens.
– Client stores token (cookie/local storage), passed on each request.
e. Media Storage
– Could be local filesystem or external object storage (not shown in code but often integrated in the DB or via SDK).
– Upload flows handled in src/components/file-uploader.tsx + use-upload-file.tsx.
f. WebSocket Server
– Real-time channel for socket events (under src/components/socket/demo.tsx & use-socket.ts).
– Broadcasts new media uploads, search updates, dashboard events.
g. Optional External Services
– Analytics, CDN for media, third-party auth (none explicitly shown).
Architectural Patterns & Principles
• Separation of Concerns:
– UI layer (src/app, src/components),
– Business logic/API (src/app/api/*, lib),
– Data layer (src/DB/*).
• Layered Architecture: Client ↔ Next.js (presentation & API) ↔ DB.
• Serverless Functions: Each API route is its own handler.
• Context & Hooks: Encapsulate state & side effects for reusability.
• Modular UI: Atomic components (ui/, media/, search/) to compose pages.
• Security: JWT auth, middleware gating, token rotation.