Skip to content

lugondev/comunia

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

717 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Comunia Frontend

A responsive and accessible social media application built with Next.js 16, connecting to a NestJS backend.

✨ Key Features

πŸ” Authentication & Security

  • Login with email and password
  • OAuth 2.0 login (Github, Google, and Facebook)
  • JWT token authentication with NextAuth.js
  • Middleware for route protection

πŸ‘€ Profile Management

  • Update personal information, profile picture, and cover photo
  • Profile page with tabs: Posts, Media, About
  • Display lists of followers and following
  • Search for users with filters

πŸ“ Content Interaction

  • Create, edit, and delete posts, comments, and replies
  • Like/unlike posts, comments, and replies
  • Add images and videos to posts
  • Drag & drop to sort media when creating/editing a post
  • Support for hashtags in posts
  • @mention users in posts, comments, and replies

πŸ“± Feed & Discovery

  • Personalized feed with infinite scrolling
  • Real-time feed with auto-refresh
  • Trending page with popular hashtags
  • Search and discover new content
  • Bookmarks to save favorite posts
  • Activity history

πŸ”” Notifications & Activity

  • Real-time notification system
  • Activity logging
  • Notifications for new interactions

🎨 UI & Experience

  • Fully responsive design (mobile-first)
  • Dark/Light theme with theme switcher
  • Accessible components with React Aria
  • Full-page gallery for viewing photos/videos
  • Smooth animations with Framer Motion
  • Modern UI with shadcn/ui components

πŸ‘₯ Groups & Community

  • Join and manage groups
  • "My Groups" page to view joined groups
  • Admin panel for moderation

πŸ› οΈ Tech Stack

Frontend Core

  • Next.js 16 - React framework with App Router, Turbopack default bundler
  • React 19 - UI library with Server & Client Components and React Compiler support
  • TypeScript - Type safety
  • Tailwind CSS - Utility-first CSS framework

State Management & Data Fetching

UI Components & Styling

Forms & Validation

Authentication & Security

Media & Rich Content

Development & Code Quality

πŸ“ Project Structure

comunia/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                    # Next.js App Router
β”‚   β”‚   β”œβ”€β”€ (auth)/            # Auth layout group
β”‚   β”‚   β”œβ”€β”€ (protected)/       # Protected routes
β”‚   β”‚   β”‚   β”œβ”€β”€ feed/          # Main feed page
β”‚   β”‚   β”‚   β”œβ”€β”€ [username]/    # User profile pages
β”‚   β”‚   β”‚   β”œβ”€β”€ groups/        # Groups functionality
β”‚   β”‚   β”‚   β”œβ”€β”€ notifications/ # Notifications page
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”œβ”€β”€ (unprotected)/     # Public routes
β”‚   β”‚   β”œβ”€β”€ admin/             # Admin panel
β”‚   β”‚   └── layout.tsx         # Root layout
β”‚   β”œβ”€β”€ components/            # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ ui/               # Base UI components (shadcn/ui)
β”‚   β”‚   β”œβ”€β”€ feed/             # Feed-related components
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ hooks/                # Custom React hooks
β”‚   β”œβ”€β”€ lib/                  # Utility functions
β”‚   β”œβ”€β”€ types/                # TypeScript type definitions
β”‚   β”œβ”€β”€ contexts/             # React contexts
β”‚   └── constants/            # App constants
β”œβ”€β”€ public/                   # Static assets
└── docs/                    # Documentation

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn
  • Backend API running on port 3001

Installation

  1. Clone repository:
git clone https://github.com/lugondev/comunia.git
cd comunia
  1. Install dependencies:
pnpm install
  1. Environment Setup: Create a .env.local file in the root directory:
# NextAuth Configuration
NEXTAUTH_URL=http://localhost:3002
NEXTAUTH_SECRET=your-secret-key

# OAuth Providers
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret

GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret

FACEBOOK_CLIENT_ID=your-facebook-client-id
FACEBOOK_CLIENT_SECRET=your-facebook-client-secret

# Backend API
NEXT_PUBLIC_API_URL=http://localhost:3001
API_URL=http://localhost:3001

# Database (if needed)
DATABASE_URL=postgresql://username:password@localhost:5432/comunia
  1. Run development server:
pnpm run dev

The frontend will run on http://localhost:3002

Build for Production

pnpm run build
pnpm run start

🧰 Troubleshooting

  • If you see a warning like "Ignored build scripts ... Run pnpm approve-builds":
    pnpm approve-builds
    Then re-run the install/build command.

πŸ—οΈ Architecture

Next.js App Router

The project uses Next.js 16 with the App Router, leveraging:

  • Server Components - Render server-side for performance
  • Client Components - Interactive UI components
  • Route Groups - Organize routes by layout
  • Nested Layouts - Shared layouts for route groups
  • Middleware - Authentication & route protection
  • Turbopack - Default dev bundler in Next 16 for faster HMR and rebuilds
  • React Compiler - Leverages React 19 compiler improvements

State Management

  • TanStack Query - Server state, caching, and synchronization
  • React Context - Authentication state and theme
  • Local State - Component-level state with useState/useReducer

Data Fetching Pattern

// Example: Custom hook with TanStack Query
export function useFeed(feedType: FeedType) {
    return useInfiniteQuery({
        queryKey: ['feed', feedType],
        queryFn: ({ pageParam = 1 }) => fetchFeed(feedType, pageParam),
        getNextPageParam: (lastPage) => lastPage.nextPage,
        staleTime: 5 * 60 * 1000, // 5 minutes
    })
}

Component Structure

// Composition pattern with compound components
<FeedContainer>
    <FeedTabs />
    <PostList>
        <PostCard>
            <PostHeader />
            <PostContent />
            <PostActions />
        </PostCard>
    </PostList>
</FeedContainer>

🎨 UI Components

Design System

  • Color System: Semantic colors with CSS variables
  • Typography: Poppins font family with responsive sizing
  • Spacing: Consistent spacing scale with Tailwind
  • Breakpoints: Mobile-first responsive design

Component Library

Using shadcn/ui as a base, extended with:

  • Custom animations with Framer Motion
  • Accessible components with React Aria
  • Form components with React Hook Form integration

πŸ” Authentication Flow

  1. Login Page - Email/password or OAuth providers
  2. Middleware Check - Verify JWT token
  3. Protected Routes - Redirect if not authenticated
  4. Token Refresh - Auto-refresh expired tokens
  5. Logout - Clear tokens and redirect

πŸ“± Responsive Design

Breakpoints

  • Mobile: < 768px - Single column layout
  • Tablet: 768px - 1024px - Adapted layouts
  • Desktop: > 1024px - Multi-column with sidebar

Mobile-First Features

  • Touch-friendly interactions
  • Swipe gestures for media gallery
  • Bottom navigation on mobile
  • Optimized infinite scroll

πŸš€ Performance Optimizations

Code Splitting

  • Route-based code splitting with Next.js
  • Dynamic imports for heavy components
  • Lazy loading for images and videos

Caching Strategy

  • TanStack Query cache with stale-while-revalidate
  • Next.js static generation for public pages
  • Browser caching for static assets

Bundle Optimization

// next.config.js
module.exports = {
    experimental: {
        optimizePackageImports: ['lucide-react', '@radix-ui/react-*'],
    },
    images: {
        domains: ['localhost', 'your-cdn-domain.com'],
    },
}

πŸ§ͺ Testing Strategy

Testing Stack

  • Unit Tests: Jest + React Testing Library
  • Integration Tests: Playwright
  • E2E Tests: Cypress (planned)

Test Commands

npm run test           # Unit tests
npm run test:watch     # Watch mode
npm run test:e2e       # E2E tests

πŸ”§ Development Guidelines

Code Style

  • ESLint + Prettier - Enforced code formatting
  • TypeScript Strict Mode - Type safety
  • Absolute Imports - Clean import paths with @/ alias

Commit Convention

feat: add new post creation modal
fix: resolve infinite scroll bug
docs: update README with deployment steps
style: improve mobile navigation layout

Component Guidelines

// Use function declarations for components
export default function ComponentName() {
    // Custom hooks at the top
    const { user } = useUser()
    const { data, isLoading } = useQuery(...)
    
    // Event handlers
    const handleClick = useCallback(() => {
        // Implementation
    }, [])
    
    // Early returns for loading/error states
    if (isLoading) return <LoadingSkeleton />
    
    return (
        <div className="component-container">
            {/* JSX content */}
        </div>
    )
}

πŸš€ Deployment

Frontend Deployment on EC2

  1. Setup Environment:
# Clone repository
git clone https://github.com/lugondev/comunia.git
cd comunia

# Install dependencies
npm install

# Setup environment variables
cp .env.example .env.local
# Edit .env.local with production values
  1. Build Application:
# Production build
npm run build

# Start production server
npm start
# or use PM2
npm run pm2
  1. Nginx Configuration:
server {
        listen 80;
        server_name your-domain.com;
        
        location / {
                proxy_pass http://localhost:3002;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
}

Environment Variables for Production

NODE_ENV=production
NEXTAUTH_URL=https://your-domain.com
NEXT_PUBLIC_API_URL=https://api.your-domain.com
# Add other production secrets

πŸ“Š Monitoring & Analytics

Performance Monitoring

  • Next.js Analytics - Core Web Vitals tracking
  • Vercel Analytics - Real-time performance data
  • Custom Metrics - User engagement tracking

Error Tracking

  • Sentry Integration - Error monitoring and alerting
  • Console Logging - Development debugging

🀝 Contributing

Development Setup

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'feat: add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Pull Request Guidelines

  • Ensure all tests pass
  • Update documentation if necessary
  • Follow coding conventions
  • Add screenshots for UI changes

πŸ“š Additional Resources

Documentation

Backend Integration

  • Backend API documentation: /docs/backend-api-status-report.md
  • Authentication flow: /docs/auth-system.md
  • Database schema: /comunia-backend/prisma/schema.prisma

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Lugon - GitHub


Note: This project is under active development and may contain bugs. It will be continuously updated to keep up with the latest framework changes.

About

Munia - an open source social media web application built wth Next.js App Router.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 96.9%
  • JavaScript 2.8%
  • Other 0.3%