Skip to content

Repository files navigation

πŸ› BugKhoji Frontend

A modern bug bounty platform interface built with React, TypeScript, and Tailwind CSS.

πŸš€ Quick Start

# Navigate to frontend
cd bugkhoji-frontend

# Install dependencies
npm install

# Start development server
npm run dev

Application runs on http://localhost:8080 (or next available port)

πŸ“‹ Prerequisites

  • Node.js 16+
  • npm or yarn
  • BugKhoji Backend running on port 4001

πŸ› οΈ Setup

1. Install Dependencies

npm install

2. Environment Configuration

Create .env file:

VITE_API_BASE_URL=http://localhost:4001
VITE_APP_NAME=BugKhoji
VITE_APP_VERSION=1.0.0

3. Start Development Server

npm run dev

The app will open at http://localhost:8080 or show the port in terminal.

🎨 Features

πŸ” Authentication

  • User registration (Researcher/Organizer)
  • Secure login with JWT
  • Password reset
  • Session management
  • Auto token refresh

πŸ‘¨β€πŸ’» Researcher Dashboard

  • View all bug bounty programs
  • Submit vulnerability reports
  • Track report status
  • View rewards and earnings
  • Real-time notifications
  • Personal leaderboard ranking

🏒 Organizer Dashboard

  • Create and manage programs
  • Review submitted reports
  • Award bounties
  • Manage program participants
  • View analytics
  • Process rewards

πŸ‘¨β€πŸ’Ό Admin Panel

  • User management
  • System analytics
  • Program oversight
  • Report moderation
  • User ban/unban
  • Platform statistics

πŸ† Leaderboard

  • Global researcher rankings
  • Program-specific leaderboards
  • Time-based filters (all-time, monthly, weekly)
  • Personal rank tracking

πŸ’° Rewards System

  • View earning history
  • Track pending rewards
  • Payment status
  • Transaction details

πŸ”” Notifications

  • Real-time updates
  • Report status changes
  • Reward notifications
  • System announcements
  • Mark as read
  • Unread count badge

πŸ“± Pages & Routes

Public Routes

/                     β†’ Landing page
/login               β†’ Login page
/register            β†’ Registration page
/forgot-password     β†’ Password reset

Researcher Routes

/dashboard           β†’ Researcher dashboard
/programs            β†’ Browse programs
/programs/:id        β†’ Program details
/reports             β†’ My reports
/reports/new         β†’ Submit report
/rewards             β†’ My rewards
/leaderboard         β†’ Rankings
/profile             β†’ Profile settings
/notifications       β†’ Notifications

Organizer Routes

/organizer/dashboard β†’ Organizer dashboard
/organizer/programs  β†’ Manage programs
/organizer/reports   β†’ Review reports
/organizer/rewards   β†’ Manage rewards
/organizer/analytics β†’ Program analytics

Admin Routes

/admin/dashboard     β†’ Admin dashboard
/admin/users         β†’ User management
/admin/programs      β†’ Program oversight
/admin/reports       β†’ Report moderation
/admin/analytics     β†’ System analytics

πŸ”Œ API Integration

Authentication Flow

// Login
const response = await fetch('http://localhost:4001/v1/login/researcher', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ email, password })
});

const { token, refreshToken } = await response.json();
localStorage.setItem('token', token);

Protected Requests

// Fetch with auth token
const response = await fetch('http://localhost:4001/api/v1/programs', {
  headers: {
    'Authorization': `Bearer ${localStorage.getItem('token')}`
  }
});

API Service Structure

// services/api.ts
const API_BASE = import.meta.env.VITE_API_BASE_URL;

export const api = {
  // Auth
  login: (credentials) => post('/v1/login/researcher', credentials),
  register: (data) => post('/v1/register/researcher', data),
  
  // Programs
  getPrograms: () => get('/api/v1/programs'),
  getProgram: (id) => get(`/api/v1/programs/${id}`),
  
  // Reports
  submitReport: (data) => post('/api/v1/reports', data),
  getMyReports: () => get('/api/v1/researcher/reports'),
  
  // Leaderboard
  getLeaderboard: () => get('/user/leaderboard'),
  getMyRank: () => get('/user/leaderboard/my-rank'),
  
  // Rewards
  getRewards: () => get('/api/v1/researcher/rewards'),
  
  // Notifications
  getNotifications: () => get('/notifications'),
  markAsRead: (id) => patch(`/notifications/${id}/read`),
};

🎨 Component Structure

src/
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ common/
β”‚   β”‚   β”œβ”€β”€ Button.tsx
β”‚   β”‚   β”œβ”€β”€ Input.tsx
β”‚   β”‚   β”œβ”€β”€ Modal.tsx
β”‚   β”‚   β”œβ”€β”€ Card.tsx
β”‚   β”‚   └── Badge.tsx
β”‚   β”œβ”€β”€ layout/
β”‚   β”‚   β”œβ”€β”€ Header.tsx
β”‚   β”‚   β”œβ”€β”€ Sidebar.tsx
β”‚   β”‚   β”œβ”€β”€ Footer.tsx
β”‚   β”‚   └── Layout.tsx
β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”œβ”€β”€ LoginForm.tsx
β”‚   β”‚   β”œβ”€β”€ RegisterForm.tsx
β”‚   β”‚   └── ProtectedRoute.tsx
β”‚   β”œβ”€β”€ dashboard/
β”‚   β”‚   β”œβ”€β”€ StatsCard.tsx
β”‚   β”‚   β”œβ”€β”€ RecentReports.tsx
β”‚   β”‚   └── ProgramList.tsx
β”‚   β”œβ”€β”€ programs/
β”‚   β”‚   β”œβ”€β”€ ProgramCard.tsx
β”‚   β”‚   β”œβ”€β”€ ProgramDetails.tsx
β”‚   β”‚   └── ProgramForm.tsx
β”‚   β”œβ”€β”€ reports/
β”‚   β”‚   β”œβ”€β”€ ReportCard.tsx
β”‚   β”‚   β”œβ”€β”€ ReportForm.tsx
β”‚   β”‚   └── ReportDetails.tsx
β”‚   β”œβ”€β”€ leaderboard/
β”‚   β”‚   β”œβ”€β”€ LeaderboardTable.tsx
β”‚   β”‚   β”œβ”€β”€ RankBadge.tsx
β”‚   β”‚   └── UserStats.tsx
β”‚   └── notifications/
β”‚       β”œβ”€β”€ NotificationBell.tsx
β”‚       β”œβ”€β”€ NotificationList.tsx
β”‚       └── NotificationItem.tsx
β”œβ”€β”€ pages/
β”‚   β”œβ”€β”€ HomePage.tsx
β”‚   β”œβ”€β”€ LoginPage.tsx
β”‚   β”œβ”€β”€ DashboardPage.tsx
β”‚   β”œβ”€β”€ ProgramsPage.tsx
β”‚   β”œβ”€β”€ ReportsPage.tsx
β”‚   β”œβ”€β”€ LeaderboardPage.tsx
β”‚   └── AdminPage.tsx
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ api.ts
β”‚   β”œβ”€β”€ auth.ts
β”‚   └── storage.ts
β”œβ”€β”€ hooks/
β”‚   β”œβ”€β”€ useAuth.ts
β”‚   β”œβ”€β”€ usePrograms.ts
β”‚   β”œβ”€β”€ useReports.ts
β”‚   └── useNotifications.ts
β”œβ”€β”€ contexts/
β”‚   β”œβ”€β”€ AuthContext.tsx
β”‚   └── ThemeContext.tsx
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ formatters.ts
β”‚   β”œβ”€β”€ validators.ts
β”‚   └── constants.ts
β”œβ”€β”€ types/
β”‚   β”œβ”€β”€ user.ts
β”‚   β”œβ”€β”€ program.ts
β”‚   └── report.ts
β”œβ”€β”€ App.tsx
└── main.tsx

🎨 Styling

Tailwind CSS Configuration

// tailwind.config.js
module.exports = {
  content: ['./src/**/*.{js,jsx,ts,tsx}'],
  theme: {
    extend: {
      colors: {
        primary: '#3B82F6',
        secondary: '#10B981',
        danger: '#EF4444',
        warning: '#F59E0B',
      }
    }
  }
}

Custom Styles

/* src/index.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer components {
  .btn-primary {
    @apply bg-primary text-white px-4 py-2 rounded hover:bg-primary-dark;
  }
  
  .card {
    @apply bg-white shadow-md rounded-lg p-6;
  }
}

πŸ”’ Authentication State Management

// contexts/AuthContext.tsx
interface AuthContextType {
  user: User | null;
  token: string | null;
  login: (email: string, password: string) => Promise<void>;
  logout: () => void;
  isAuthenticated: boolean;
  isLoading: boolean;
}

// Usage in components
const { user, isAuthenticated, login, logout } = useAuth();

πŸ“Š State Management

Context API (Current)

  • AuthContext - User authentication
  • ThemeContext - Dark/light mode
  • NotificationContext - Real-time notifications

Future: Redux/Zustand (Optional)

// store/index.ts
export const useStore = create((set) => ({
  programs: [],
  reports: [],
  setPrograms: (programs) => set({ programs }),
  addReport: (report) => set((state) => ({ 
    reports: [...state.reports, report] 
  })),
}));

πŸ§ͺ Testing

Run Tests

# Unit tests
npm test

# E2E tests
npm run test:e2e

# Coverage
npm run test:coverage

Example Test

import { render, screen } from '@testing-library/react';
import { LoginForm } from './LoginForm';

test('renders login form', () => {
  render(<LoginForm />);
  expect(screen.getByText('Login')).toBeInTheDocument();
});

πŸ”§ Build & Deployment

Development Build

npm run dev

Production Build

npm run build

Preview Production Build

npm run preview

Deploy to Vercel

vercel

Deploy to Netlify

netlify deploy --prod

πŸ› Troubleshooting

Backend Connection Issues

Problem: Cannot connect to backend

# Check backend is running
curl http://localhost:4001/api/health

# Verify CORS settings in backend
# Check .env VITE_API_BASE_URL

Solution: Ensure backend is running on port 4001

Build Errors

Problem: TypeScript errors

# Clear node_modules
rm -rf node_modules
npm install

# Clear cache
rm -rf dist
npm run build

Hot Reload Not Working

# Restart dev server
npm run dev

# Clear browser cache
# Ctrl + Shift + R (hard refresh)

Port Already in Use

# Kill process on port 8080
lsof -i :8080
kill -9 <PID>

# Or use different port
npm run dev -- --port 3000

πŸ“¦ Key Dependencies

{
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.20.0",
    "axios": "^1.6.0",
    "tailwindcss": "^3.3.0"
  },
  "devDependencies": {
    "@vitejs/plugin-react": "^4.2.0",
    "typescript": "^5.3.0",
    "vite": "^5.0.0"
  }
}

πŸš€ Performance Optimization

Code Splitting

// Lazy load routes
const Dashboard = lazy(() => import('./pages/Dashboard'));
const Programs = lazy(() => import('./pages/Programs'));

Image Optimization

// Use WebP format
<img src="image.webp" alt="..." loading="lazy" />

Caching Strategy

// Cache API responses
const cachedPrograms = localStorage.getItem('programs');
if (cachedPrograms && !isStale) {
  return JSON.parse(cachedPrograms);
}

πŸ“± Responsive Design

Breakpoints

sm: 640px   β†’ Mobile
md: 768px   β†’ Tablet
lg: 1024px  β†’ Desktop
xl: 1280px  β†’ Large Desktop

Usage

<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
  {/* Responsive grid */}
</div>

🎯 Browser Support

  • Chrome 90+
  • Firefox 88+
  • Safari 14+
  • Edge 90+

πŸ“Š Features Checklist

  • βœ… User authentication
  • βœ… Program browsing
  • βœ… Report submission
  • βœ… Leaderboard
  • βœ… Rewards tracking
  • βœ… Notifications
  • βœ… Admin panel
  • βœ… Responsive design
  • βœ… Dark mode ready
  • βœ… Error handling

πŸ” Security Best Practices

  1. Token Storage: Store JWT in httpOnly cookies (recommended) or localStorage
  2. CSRF Protection: Use CSRF tokens for state-changing operations
  3. XSS Prevention: Sanitize user inputs, use React's built-in escaping
  4. HTTPS: Always use HTTPS in production
  5. Content Security Policy: Configure CSP headers

πŸ“ž Support

For issues:

  1. Check backend is running
  2. Verify API endpoints
  3. Check browser console
  4. Review network tab
  5. Clear cache and try again

πŸ“„ Scripts Reference

npm run dev          # Start dev server
npm run build        # Build for production
npm run preview      # Preview production build
npm test             # Run tests
npm run lint         # Lint code
npm run format       # Format code with Prettier
npm run type-check   # TypeScript type checking

🎨 Design System

Colors, typography, and component patterns are documented in src/styles/design-system.md

πŸ“„ License

MIT License - See LICENSE file


Built with ❀️ for BugKhoji Platform

Need help? Check the backend README for API documentation.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages