Skip to content

HackElite-IIIT-Bhagalpur/Code-Intrusion-Frontend

Repository files navigation

CTF Platform Frontend

A modern, high-performance CTF (Capture The Flag) platform frontend built with Next.js 14, React Query, and Zustand.

πŸš€ Features

  • βœ… Landing Page - Beautiful hero section with organization info
  • βœ… Authentication - Secure login with JWT/session support
  • βœ… Leaderboard - Real-time rankings with auto-refresh
  • βœ… User Profile - Comprehensive stats and achievements
  • βœ… Challenge System - Category-based challenges with flag submission
  • βœ… Responsive Design - Mobile-first, works on all devices
  • βœ… State Management - Zustand for client state + React Query for server state
  • βœ… Type Safety - Full TypeScript coverage
  • βœ… Performance - Optimized with Next.js App Router

πŸ›  Tech Stack

Core

  • Framework: Next.js 14 (App Router)
  • Language: TypeScript 5
  • Styling: Tailwind CSS 3

State Management (Production-Grade)

  • Client State: Zustand with persistence
  • Server State: React Query (TanStack Query)
    • Automatic caching and background refetching
    • Optimistic updates
    • Request deduplication
    • Error handling and retries

Data Fetching

  • HTTP Client: Axios with interceptors
  • Form Handling: React Hook Form
  • Validation: Zod schemas

πŸ“¦ Installation

Prerequisites

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

Steps

  1. Install dependencies

    npm install
  2. Configure environment

    # Copy the example env file
    copy .env.example .env.local
    
    # Edit .env.local and set your backend API URL
    # NEXT_PUBLIC_API_URL=http://localhost:8000/api
  3. Run development server

    npm run dev
  4. Open browser

    http://localhost:3000
    

πŸ“ Project Structure

src/
β”œβ”€β”€ app/                    # Next.js App Router pages
β”‚   β”œβ”€β”€ page.tsx           # Landing page
β”‚   β”œβ”€β”€ login/             # Login page
β”‚   β”œβ”€β”€ profile/           # User profile
β”‚   β”œβ”€β”€ leaderboard/       # Leaderboard
β”‚   β”œβ”€β”€ challenges/        # Challenge browser
β”‚   β”œβ”€β”€ layout.tsx         # Root layout
β”‚   └── globals.css        # Global styles
β”‚
β”œβ”€β”€ components/            # React components
β”‚   β”œβ”€β”€ ui/               # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ Button.tsx
β”‚   β”‚   β”œβ”€β”€ Card.tsx
β”‚   β”‚   β”œβ”€β”€ Input.tsx
β”‚   β”‚   └── Badge.tsx
β”‚   β”œβ”€β”€ Navbar.tsx        # Navigation
β”‚   └── Footer.tsx        # Footer
β”‚
β”œβ”€β”€ store/                # Zustand stores
β”‚   └── useAuthStore.ts   # Authentication state
β”‚
β”œβ”€β”€ lib/                  # Utilities and configs
β”‚   β”œβ”€β”€ api.ts           # Axios instance + interceptors
β”‚   β”œβ”€β”€ apiEndpoints.ts  # API helper functions
β”‚   β”œβ”€β”€ queryClient.tsx  # React Query provider
β”‚   └── config.ts        # App configuration
β”‚
└── types/               # TypeScript types
    └── index.ts         # Shared types

🎯 Key Features Explained

State Management Architecture

Zustand (Client State)

  • βœ… User authentication state
  • βœ… Persisted to localStorage
  • βœ… Simple, lightweight (~1KB)
  • βœ… No boilerplate, just works

React Query (Server State)

  • βœ… Automatic caching (5min default)
  • βœ… Background refetching
  • βœ… Optimistic UI updates
  • βœ… Request deduplication
  • βœ… Automatic retries on failure
  • βœ… DevTools for debugging

API Layer

  • Centralized axios instance
  • Request/response interceptors
  • Automatic token injection
  • Global error handling
  • Type-safe endpoints

Authentication Flow

  1. User submits login form
  2. API call with credentials
  3. Store user + token in Zustand
  4. Token auto-attached to all requests
  5. Protected routes check auth status
  6. Auto-redirect on 401 errors

Challenge Submission Flow

  1. User selects genre
  2. Load challenges for genre
  3. Submit flag with optimistic update
  4. Update cache on success
  5. Refresh user stats
  6. Show success/error feedback

πŸ”§ Available Scripts

# Development
npm run dev          # Start dev server

# Production
npm run build        # Build for production
npm run start        # Start production server

# Linting
npm run lint         # Run ESLint

🌐 API Endpoints Expected

Your backend should implement these endpoints:

Authentication

  • POST /auth/login - Login with email/password
  • POST /auth/logout - Logout user
  • GET /auth/profile - Get current user

Challenges

  • GET /genres - List all challenge categories
  • GET /challenges/:genreId - Get challenges by genre
  • POST /submit-flag - Submit flag for validation

Leaderboard

  • GET /leaderboard - Get top players

User

  • GET /users/:id - Get user by ID
  • PATCH /users/profile - Update user profile

🎨 UI Components

All components are built with:

  • Accessibility in mind
  • Mobile-first responsive design
  • Consistent design tokens
  • Loading states
  • Error handling
  • Keyboard navigation

Component Examples

// Button with loading state
<Button isLoading={isPending} onClick={handleClick}>
  Submit
</Button>

// Input with validation
<Input 
  label="Email" 
  error={errors.email?.message}
  {...register("email")}
/>

// Card layouts
<Card variant="elevated">
  <CardHeader>Title</CardHeader>
  <CardBody>Content</CardBody>
</Card>

🚦 Performance Optimizations

  1. Next.js App Router - React Server Components
  2. Code Splitting - Automatic route-based splitting
  3. Image Optimization - Next.js Image component
  4. Query Caching - React Query smart caching
  5. Lazy Loading - Components loaded on demand
  6. Memoization - Prevent unnecessary re-renders

πŸ“± Responsive Design

  • Mobile: < 768px
  • Tablet: 768px - 1024px
  • Desktop: > 1024px

All pages are fully responsive with mobile-first approach.

πŸ” Security

  • βœ… XSS protection via React
  • βœ… CSRF tokens (if backend implements)
  • βœ… HTTP-only cookies support
  • βœ… Secure token storage
  • βœ… Auto logout on 401
  • βœ… Input validation

πŸ§ͺ Testing Recommendations

# Install testing libraries (not included)
npm install --save-dev @testing-library/react @testing-library/jest-dom jest

πŸ“ Environment Variables

Create .env.local:

NEXT_PUBLIC_API_URL=http://localhost:8000/api
NEXT_PUBLIC_APP_NAME="CTF Platform"
NEXT_PUBLIC_APP_URL=http://localhost:3000

🀝 Contributing

  1. Follow the existing code style
  2. Use TypeScript types
  3. Write clean, readable code
  4. Test your changes
  5. Keep components small and focused

πŸ“„ License

MIT License - feel free to use for your CTF events!

πŸ†˜ Support

For issues or questions:

  1. Check the documentation
  2. Review API responses
  3. Check browser console
  4. Verify environment variables

πŸŽ“ Learning Resources


Built with ❀️ for CTF enthusiasts

This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors