Skip to content

added redis layer - #33

Merged
hey-Zayn merged 1 commit into
mainfrom
Live-0
Mar 26, 2026
Merged

added redis layer#33
hey-Zayn merged 1 commit into
mainfrom
Live-0

Conversation

@hey-Zayn

@hey-Zayn hey-Zayn commented Mar 26, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

Release Notes

  • New Features

    • Added keyboard shortcuts for playback control (Space, Arrow keys, M for mute).
    • Implemented drag-and-drop file uploads in admin interface.
    • Added search functionality to admin tables.
    • Introduced confirmation dialogs for delete actions.
  • Performance

    • Integrated Redis caching for improved response times on stats and song lists.
  • Improvements

    • Enhanced responsive design across pages.
    • Added skeleton loading states and marquee animations.
    • Refined toast notification styling and positioning.

@vercel

vercel Bot commented Mar 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
music-app Ready Ready Preview, Comment Mar 28, 2026 7:44am
music-app-9r1o Ready Ready Preview, Comment Mar 28, 2026 7:44am

@coderabbitai

coderabbitai Bot commented Mar 26, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 10e3a942-c0fd-48b5-911a-0b3ad4e92010

📥 Commits

Reviewing files that changed from the base of the PR and between 3bff669 and e0e4f49.

⛔ Files ignored due to path filters (2)
  • backend/package-lock.json is excluded by !**/package-lock.json
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (49)
  • .gitignore
  • backend/package.json
  • backend/src/__tests__/cacheManager.test.js
  • backend/src/__tests__/stats.controller.test.js
  • backend/src/controllers/admin.controller.js
  • backend/src/controllers/album.controller.js
  • backend/src/controllers/song.controller.js
  • backend/src/controllers/stats.controller.js
  • backend/src/lib/cacheManager.js
  • backend/src/lib/cloudinaryHelper.js
  • backend/src/lib/redis.js
  • backend/src/middleware/auth.middleware.js
  • backend/src/models/song.model.js
  • backend/src/routes/album.route.js
  • backend/src/routes/songs.route.js
  • backend/src/seeds/migrate_song_creators.js
  • frontend/package.json
  • frontend/src/components/layout/MainLayout.tsx
  • frontend/src/components/layout/components/FriendsActivity.tsx
  • frontend/src/components/layout/components/LeftSidebar.jsx
  • frontend/src/components/layout/components/PlaybackControls.tsx
  • frontend/src/components/ui/alert-dialog.tsx
  • frontend/src/components/ui/skeleton.tsx
  • frontend/src/index.css
  • frontend/src/main.tsx
  • frontend/src/pages/admin/AdminPage.tsx
  • frontend/src/pages/admin/components/AddAlbumDialog.tsx
  • frontend/src/pages/admin/components/AddSongDialog.tsx
  • frontend/src/pages/admin/components/AlbumsTabContent.tsx
  • frontend/src/pages/admin/components/AlbumsTable.tsx
  • frontend/src/pages/admin/components/DashboardStats.tsx
  • frontend/src/pages/admin/components/EditAlbumDialog.tsx
  • frontend/src/pages/admin/components/EditSongDialog.tsx
  • frontend/src/pages/admin/components/Header.tsx
  • frontend/src/pages/admin/components/SongsTabContent.tsx
  • frontend/src/pages/admin/components/SongsTable.tsx
  • frontend/src/pages/album/AlbumPage.tsx
  • frontend/src/pages/home/components/FeaturedSection.jsx
  • frontend/src/pages/home/page/HomePage.tsx
  • frontend/src/pages/playlists/PlaylistPage.tsx
  • frontend/src/store/useAlbumStore.ts
  • frontend/src/store/useMusicStore.test.tsx
  • frontend/src/store/useMusicStore.tsx
  • frontend/src/store/useSongStore.test.ts
  • frontend/src/store/useSongStore.ts
  • frontend/src/store/useStatsStore.ts
  • frontend/src/types/index.ts
  • report/unit-test-report.md
  • report/unit_test_report-2.md

📝 Walkthrough

Walkthrough

This PR introduces a Redis-backed caching layer for aggregate stats and featured song endpoints, refactors the frontend store architecture into modular domain-specific stores (album, song, stats), and adds enhanced UI components with Radix primitives and drag-and-drop file upload support. Backend controllers now cache frequently accessed data and invalidate caches on mutations, while frontend components are updated to consume the new store structure.

Changes

Cohort / File(s) Summary
Caching Infrastructure
backend/src/lib/redis.js, backend/src/lib/cacheManager.js
New Redis client initialization and CacheManager utility providing getOrFetch with graceful degradation, purgePattern for wildcard cache eviction, and error handling.
Backend Cache Integration
backend/src/controllers/stats.controller.js, backend/src/controllers/song.controller.js, backend/src/controllers/admin.controller.js
Wrapped stats, featured/trending/made-for-you song endpoints with CacheManager, added cache invalidation on song/album mutations (global stats, curator stats, song lists, albums).
Backend Helper Extraction
backend/src/lib/cloudinaryHelper.js, backend/src/middleware/auth.middleware.js
Centralized Cloudinary getPublicId and uploadToCloudinary functions; extracted isAdminUser helper for consistent admin auth checks across controllers.
Album Controller Refactor
backend/src/controllers/album.controller.js
Renamed exports (AllAlbumsgetAlbums, AllAlbumsByIdgetAlbumById), added pagination support, cache integration with user/global scoping, simplified admin auth using new helper.
Song Controller Refactor
backend/src/controllers/song.controller.js
Renamed export (getAllSongsgetSongs), added caching for featured/trending/made-for-you endpoints, simplified admin auth via isAdminUser helper, extracted Cloudinary logic.
Backend Routes & Schema
backend/src/routes/album.route.js, backend/src/routes/songs.route.js, backend/src/models/song.model.js
Updated route handlers to use renamed controllers; changed Song.creator field from optional to required.
Backend Tests & Migration
backend/src/__tests__/cacheManager.test.js, backend/src/__tests__/stats.controller.test.js, backend/src/seeds/migrate_song_creators.js
Added Vitest test suites for CacheManager and StatsController with Redis mocking; added migration script to backfill creator field for existing songs/albums.
Package Dependencies
.gitignore, backend/package.json, frontend/package.json
Updated .gitignore to exclude analysis_report.md and plan/ directory; added redis (^5.11.0) and radix-ui (^1.4.3) dependencies.
Frontend Store Refactoring
frontend/src/store/useAlbumStore.ts, frontend/src/store/useSongStore.ts, frontend/src/store/useStatsStore.ts
New specialized Zustand stores replacing monolithic useMusicStore; each handles CRUD, fetching, and error/loading state for its domain with consistent try/catch patterns.
Frontend Store Removal & Tests
frontend/src/store/useMusicStore.tsx, frontend/src/store/useMusicStore.test.tsx, frontend/src/store/useSongStore.test.ts
Removed consolidated music store; added isolated unit tests for new song and music stores using mocked Axios.
Admin Components Store Migration
frontend/src/pages/admin/components/SongsTabContent.tsx, frontend/src/pages/admin/components/AlbumsTabContent.tsx, frontend/src/pages/admin/components/DashboardStats.tsx, frontend/src/pages/admin/components/EditSongDialog.tsx, frontend/src/pages/admin/components/EditAlbumDialog.tsx
Updated admin panel components to consume songs/albums/stats from specialized stores instead of useMusicStore.
Admin Table Components
frontend/src/pages/admin/components/SongsTable.tsx, frontend/src/pages/admin/components/AlbumsTable.tsx
Added memoization, client-side search/filter, and AlertDialog confirmation patterns for destructive actions; wrapped in memo for render optimization.
Admin Dialog Components
frontend/src/pages/admin/components/AddSongDialog.tsx, frontend/src/pages/admin/components/AddAlbumDialog.tsx
Added drag-and-drop file upload with visual feedback; switched data sources to specialized stores; implemented MIME type validation for dropped files.
Frontend Page Components
frontend/src/pages/home/page/HomePage.tsx, frontend/src/pages/home/components/FeaturedSection.jsx, frontend/src/pages/album/AlbumPage.tsx
Updated home/featured/album pages to fetch from useStatsStore and useAlbumStore; added skeleton loading state; improved responsive typography and layout.
UI Component Library
frontend/src/components/ui/alert-dialog.tsx, frontend/src/components/ui/skeleton.tsx
New Radix UI wrapper components providing alert dialogs with customizable sizing and skeleton loaders with pulsing animation.
Layout & Playback
frontend/src/components/layout/MainLayout.tsx, frontend/src/components/layout/components/FriendsActivity.tsx, frontend/src/components/layout/components/LeftSidebar.jsx, frontend/src/components/layout/components/PlaybackControls.tsx
Updated MainLayout formatting; improved FriendsActivity text truncation with min-w-0; switched LeftSidebar to useAlbumStore; added keyboard shortcuts (Space/Arrows/M) and marquee animation to PlaybackControls.
Frontend Styling & Configuration
frontend/src/index.css, frontend/src/main.tsx
Added marquee keyframe animation and .animate-marquee utility; updated Toaster to center position with custom styling (3s duration, dark theme, colored icon variants).
Utility Components
frontend/src/pages/admin/components/Header.tsx, frontend/src/pages/playlists/PlaylistPage.tsx
Updated header to responsive flex-col/row layout with centered text on mobile; removed ScrollArea wrapper from PlaylistPage.
Type Updates
frontend/src/types/index.ts
Updated Song interface: renamed updateAtupdatedAt, added optional creator?: string.
Documentation
report/unit_test_report-2.md
Added unit test report documenting caching and stats controller test strategy, isolation via Vitest mocking, cache hit/miss verification, and Redis failover validation.

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant Controller
    participant CacheManager
    participant Redis
    participant Database

    Client->>Controller: GET /stats (or featured songs)
    Controller->>CacheManager: getOrFetch(key, ttl, fetcher)
    
    CacheManager->>Redis: get(key)
    alt Cache Hit
        Redis-->>CacheManager: cached JSON string
        CacheManager->>CacheManager: parse JSON
        CacheManager-->>Controller: cached stats/songs
    else Cache Miss or Redis Error
        CacheManager->>Database: invoke fetcher()
        Database-->>CacheManager: raw stats/songs
        CacheManager->>Redis: setEx(key, ttl, JSON.stringify(data))
        Note over Redis: set with expiry
        CacheManager-->>Controller: fetched stats/songs
    end
    
    Controller-->>Client: HTTP 200 + JSON response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • test-report #29: Modifies .gitignore to exclude analysis_report.md and plan directory, overlapping configuration changes.
  • Live 0 #24: Updates many of the same backend modules (admin/song controllers, package.json dependencies, test infrastructure, auth/logging libraries), indicating shared caching/refactoring work.

Poem

🐰 With Redis cache and stores so neat,
The frontend dances, stores compete,
Drag, drop, search—a user's delight,
Admin tables query the light,
One store split three makes code so right! 🚀

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch Live-0

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hey-Zayn
hey-Zayn merged commit 481fc54 into main Mar 26, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant