Skip to content
rahul-singh92Public

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

80 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeGram

CodeGram Logo

A full-stack Instagram-inspired social platform built for developers. Share code screenshots, project previews, and development work with your network.


Tech Stack

  • Frontend — React 18, React Router v6
  • Backend / Database — Supabase (PostgreSQL, Auth, Storage, Realtime)
  • Styling — Plain CSS with CSS variables
  • Icons — FontAwesome, Lucide React
  • Image Processing — browser-image-compression, Canvas API

Features

Auth & Accounts

  • Email/password signup with real-time username availability check
  • Login via username or email
  • Auto-detects country on signup via IP geolocation
  • Protected and public route guards
  • Global loader with minimum display time to prevent flash

Profile

  • View and edit your own profile (bio, gender, avatar)
  • Avatar upload with compression (max 0.3MB, 512px) and removal
  • Public vs private account toggle
  • Posts grid + Saved tab (own profile only)
  • Follow / unfollow with optimistic UI
  • Followers / following counts with clickable overlays
  • Bio with "more / less" expand for long bios
  • URL syncs between /profile and /profile/saved
  • Visiting /user/:username redirects to /profile if it's your own account
  • Private accounts show lock screen to non-followers
  • About this account modal (join date, country)
  • Copy profile link, visitor three-dots menu

Posts

  • Create posts with multi-image support (up to N images)
  • Full crop tool: Original / 1:1 / 4:5 / 16:9 aspect ratios
  • Zoom slider and drag-to-reposition in crop view
  • Filters: Aden, Clarendon, Crema, Gingham, Juno, Lark, Ludwig, Moon, Perpetua, Reyes, Slumber
  • Adjustments: Brightness, Contrast, Fade, Saturation, Temperature, Vignette
  • All edits applied via Canvas API before upload — images stored already processed
  • Caption with emoji picker and 2,200 character limit
  • Advanced settings: hide like counts, turn off commenting
  • Multi-image drag-to-reorder gallery
  • Sharing loader overlay with branded animation
  • Discard confirmation on back/close

Feed (Home)

  • Shows posts only from people you follow
  • Infinite scroll — loads 10 posts per page
  • Skeleton loading for initial 3 posts
  • Like (with optimistic update), comment, share, bookmark
  • Double-tap image to like
  • Carousel support with arrows and dot indicators
  • Caption expand ("more")
  • "You're all caught up" end state
  • Opens full PostViewerModal on comment click

Posts Page (Reels-style)

  • Vertical full-screen feed with smooth slide animations
  • Two-slot animation system (slot A exits, slot B enters) — no snap-back bug
  • Navigation: arrow buttons, keyboard (↑ ↓), trackpad wheel (80px threshold + 500ms cooldown), touch swipe
  • Ranked feed: score = likesCount + 10 × e^(−ageDays / 7)
  • URL syncs to /posts/:postId on each navigation
  • Direct link support — jumps to post on load
  • Pre-fetches next batch when 3 posts from end
  • Like, comment overlay, share, bookmark from right panel
  • Dots menu: Go to post, Copy link, About this account

Post Viewer Modal

  • Split view: image left, details right
  • Multi-image carousel with dots
  • Prev / next post navigation arrows
  • Like with liker avatars display
  • Real-time comments via Supabase postgres_changes
  • Two-step comment fetch (comments → profiles separately, avoids FK alias issues)
  • Post comment with emoji picker
  • Delete own comments
  • Edit post (caption + image management)
  • Delete post (with storage cleanup and notification cleanup)
  • Bookmark (save/unsave) with filled/outline icon and pop animation
  • Share to DM with message
  • Comment username click → navigate to their profile
  • About this account from three-dots menu

Explore

  • Infinite scroll grid of public posts
  • Opens PostViewerModal on click with prev/next navigation

Post Page (/p/:postId)

  • Universal shareable post URL
  • Privacy check — redirects to author's profile if account is private and viewer doesn't follow
  • Background blurred post image with overlay while modal loads
  • Author hint pill shown during load
  • On close → redirects to author's profile (own or /user/:username)
  • Prev/next navigation through all posts by same author

Messages

  • Conversation list with real-time updates
  • Pin conversations (per-user, doesn't affect the other person)
  • Mark as unread / mark as read
  • Delete conversation with confirmation modal
  • Three-dot context menu on hover per conversation
  • Unread blue dot disappears immediately on click (optimistic local state)
  • New message modal — search all users by username or full name, click to open chat instantly
  • Chat panel with paginated message loading (20 per page)
  • Lazy-load older messages on scroll to top with scroll-position preservation
  • Skeleton loading at bottom (latest position) on initial load
  • Real-time new message delivery via Supabase Realtime (replaces polling)
  • Optimistic message send with temp ID replaced by real DB id
  • Copy and Unsend message options
  • Date group headers (weekday or full date)
  • "Beginning of conversation" marker
  • Emoji picker
  • Delete chat from details panel
  • Share posts to DM — post thumbnail card in chat, click to open PostViewerModal

Notifications

  • Grouped by Today / Yesterday / This Week / This Month / Older
  • Skeleton loading
  • Relative time display
  • Unread highlight
  • Click follow notification → navigate to that user's profile
  • Click like / comment notification → open PostViewerModal for that post
  • Post thumbnail shown inline for like/comment notifications
  • Marks all as read on open
  • Real-time new notification dot in sidebar

Search

  • Debounced search (300ms) against all profiles
  • Recent searches stored in Supabase (recent_searches table)
  • Delete individual recent searches or clear all
  • Click result → adds to recent + navigates to profile

Settings

  • Edit Profile: bio, gender, avatar
  • Notifications: push notifications toggle, email notifications toggle
  • Account Privacy: private/public account toggle
  • All settings persist to Supabase profiles table and update global context instantly

Sidebar

  • Collapses to icon-only (70px), expands on hover (220px)
  • Messages badge — number of conversations with unread messages, real-time updates
  • Notifications dot — appears when there are unread notifications, real-time updates
  • Create post, search, explore, feed, posts (reels), profile navigation

Database Schema

Core Tables

profiles          -- id, username, email, full_name, bio, gender, avatar_url,
                  -- date_of_birth, country, is_private, push_notifications,
                  -- email_notifications, created_at

posts             -- id, user_id, caption, hide_like_counts,
                  -- turn_off_commenting, created_at

post_images       -- id, post_id, image_path, order_index

likes             -- id, user_id, post_id

comments          -- id, post_id, user_id, content, created_at

follows           -- id, follower_id, following_id, created_at

notifications     -- id, user_id, actor_id, post_id, type (like|comment|follow),
                  -- message, is_read, created_at

bookmarks         -- id, user_id, post_id, created_at
                  -- UNIQUE (user_id, post_id)

conversations     -- id, user1_id, user2_id, created_at
                  -- UNIQUE INDEX on (LEAST(user1_id,user2_id), GREATEST(user1_id,user2_id))

messages          -- id, conversation_id, sender_id, content, message_type (text|post),
                  -- post_id (nullable), is_read, created_at

conversation_settings  -- id, user_id, conversation_id, is_pinned, is_unread
                       -- UNIQUE (user_id, conversation_id)

recent_searches   -- id, user_id, searched_user_id, created_at
                  -- UPSERT on (user_id, searched_user_id)

Storage Buckets

Bucket Contents
posts Post images, path: {user_id}/{post_id}/{uuid}.jpg
avatars Profile avatars, path: {user_id}.{ext}

Environment Variables

Create a .env file in the project root:

REACT_APP_SUPABASE_URL=your_supabase_project_url
REACT_APP_SUPABASE_ANON_KEY=your_supabase_anon_key

Getting Started

# Install dependencies
npm install

# Start development server
npm start

# Build for production
npm run build

Routes

Route Component Description
/ Login Login page (public only)
/signup Signup Signup page (public only)
/feed FeedPage Home feed from followed users
/posts PostsPage Ranked reels-style vertical feed
/posts/:postId PostsPage Direct link to specific post in reels
/p/:postId PostPage Universal shareable post URL
/profile Profile Own profile, Posts tab
/profile/saved Profile Own profile, Saved tab
/user/:username Profile Visiting another user's profile
/explore ExplorePage Explore public posts grid
/messages MessagesPage Direct messages
/settings Settings → EditProfile Profile settings
/settings/notifications Settings → Notifications Notification preferences
/settings/privacy Settings → AccountPrivacy Privacy settings

Note: /profile/saved must be declared before /profile in your router to prevent React Router from treating "saved" as a :username param.


Key Architecture Decisions

Comment fetching (two-step): Comments are fetched first, then profiles are fetched separately with .in("id", userIds) and merged via a profile map. This avoids FK alias conflicts in Supabase joined queries.

Stale closure prevention (PostsPage): Navigation functions (goNext / goPrev) are created once with useCallback([]) and read live values from refs (indexRef, postsLengthRef, showCommentsRef). Event listeners are registered once and never stale.

Animation (PostsPage): Two-slot system — slot A exits while slot B enters — prevents the snap-back bug that occurs when a single element's position class is swapped. Keys are a-${idx} / b-${idx} to force remount.

Scroll position preservation (ChatPanel): Before prepending older messages, scrollHeight is saved. After React re-renders, requestAnimationFrame sets scrollTop = newScrollHeight - oldScrollHeight to keep the viewport in place.

Per-user conversation settings: Pin and mark-as-unread are stored in conversation_settings keyed by (user_id, conversation_id). This means pinning a conversation only affects your view, not the other person's.

Optimistic updates: Likes, bookmarks, follows, and message reads all update local state immediately before the DB call completes. Rollback is only implemented where data integrity matters (likes).

Image processing pipeline: All crop, filter, and adjustment edits are applied to a <canvas> element before upload. The server only ever stores the final processed JPEG — no edit metadata is persisted.

Signed URLs: All post images use signed URLs with a 1-hour expiry. The profile page refreshes them every 55 minutes via setInterval.


Project Structure

src/
├── assets/
│   ├── brand logo.svg
│   └── editor login preview.png
├── components/
│   ├── icons/
│   │   └── AppIcons.jsx
│   ├── AboutAccountModal.jsx
│   ├── AvatarModal.jsx
│   ├── ChatPanel.jsx
│   ├── ConversationList.jsx
│   ├── CreatePostModal.jsx
│   ├── EditPostModal.jsx
│   ├── FollowListOverlay.jsx
│   ├── GlobalLoader.jsx
│   ├── NewMessageModal.jsx
│   ├── NotificationsSidebar.jsx
│   ├── PostViewerModal.jsx
│   ├── ProtectedRoute.jsx
│   ├── PublicRoute.jsx
│   ├── SearchModal.jsx
│   ├── SettingsSidebar.jsx
│   ├── SharePostModal.jsx
│   └── Sidebar.jsx
├── context/
│   └── UserContext.jsx
├── hooks/
│   └── useAvatarUpload.js
├── lib/
│   └── supabase.js
├── pages/
│   ├── settings/
│   │   ├── AccountPrivacy.jsx
│   │   ├── EditProfile.jsx
│   │   └── Notifications.jsx
│   ├── ExplorePage.jsx
│   ├── FeedPage.jsx
│   ├── Login.jsx
│   ├── MessagesPage.jsx
│   ├── PostPage.jsx
│   ├── PostsPage.jsx
│   ├── Profile.jsx
│   ├── Settings.jsx
│   └── Signup.jsx
└── styles/
    ├── editPostModal.css
    ├── explore.css
    ├── feedPage.css
    ├── followListOverlay.css
    ├── global-loader.css
    ├── login.css
    ├── messages.css
    ├── postPage.css
    ├── postsPage.css
    ├── postViewerModal.css
    ├── profile.css
    ├── searchModal.css
    ├── sharePostModal.css
    ├── sidebar.css
    └── signup.css

SQL Files to Run (in order)

  1. Core tables: profiles, posts, post_images, likes, comments, follows, notifications
  2. bookmarks_table.sql — bookmarks with unique constraint
  3. conversation_settings.sql — per-user pin and unread settings
  4. messages_post_sharing.sql — adds message_type and post_id columns to messages

Credits

Built by RSJ. Inspired by Instagram, designed for developers.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages