Skip to content

kavix/secureaware

Β 
Β 

Repository files navigation

SecureAware - Complete Implementation Guide

A modern, full-stack security awareness platform built with Next.js 15 (App Router), Clerk Authentication, Convex for real-time data management, and JWT token integration.

πŸš€ Implemented Features

πŸ” Authentication & Security

  • βœ… Clerk Authentication - Complete sign-up/sign-in system
  • βœ… JWT Token Integration - Access and verify JWT tokens server/client-side
  • βœ… Protected Routes - Server-side authentication middleware
  • βœ… Session Management - Secure user session handling
  • βœ… Token Verification - Custom JWT verification utilities
  • βœ… Role-Based Access Control (RBAC) - Complete permission system with Admin/Teacher/Student roles

πŸ—οΈ Architecture & Framework

  • βœ… Next.js 15 with App Router architecture
  • βœ… TypeScript for complete type safety
  • βœ… Server Components for optimal performance
  • βœ… API Routes for backend functionality
  • βœ… Middleware for authentication routing

🎨 UI & Design

  • βœ… Responsive Design - Mobile-first approach
  • βœ… Tailwind CSS - Modern utility-first styling
  • βœ… Radix UI Components - Accessible component library
  • βœ… Interactive Dashboard - Real-time user interface
  • βœ… Component Library - Reusable UI components

πŸ—„οΈ Database & Backend

  • βœ… Convex Integration - Real-time database setup
  • βœ… Convex Auth Config - Authentication integration
  • βœ… API Endpoints - RESTful API structure
  • βœ… Data Validation - Type-safe data handling

πŸ“± User Experience

  • βœ… Dashboard - Comprehensive user dashboard
  • βœ… JWT Token Demo - Interactive token exploration
  • βœ… Authentication Status - Real-time auth state
  • βœ… Error Handling - Graceful error management
  • βœ… Loading States - Smooth user interactions
  • βœ… Admin Dashboard - User management and role assignment
  • βœ… RBAC Guards - Permission-based UI components

πŸ“‹ Quick Start

Prerequisites

Installation

  1. Clone and install dependencies:
git clone <repository-url>
cd secureaware
npm install
  1. Set up environment variables: Create a .env.local file with your keys:
# Get these from https://dashboard.clerk.com
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key

# Get these from https://dashboard.convex.dev
CONVEX_DEPLOYMENT=your_convex_deployment
NEXT_PUBLIC_CONVEX_URL=your_convex_url
  1. Run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.

  1. Open your browser: Visit http://localhost:3000 to see the application.

πŸ“š Comprehensive Documentation

Authentication Guides

Implementation Summary

βœ… Authentication System

  • Clerk Integration: Full authentication with social providers
  • JWT Tokens: Server and client-side JWT token access
  • Protected Routes: Middleware-based route protection
  • Session Management: Secure session handling
  • RBAC System: Complete role-based access control with Admin/Teacher/Student roles

βœ… Role-Based Access Control (RBAC)

  • Three User Roles: Admin, Teacher, Student with hierarchical permissions
  • Permission System: Granular permission controls (CREATE_QUIZ, MANAGE_USERS, etc.)
  • Route Protection: Middleware-based role checking for protected routes
  • API Security: Role-based API endpoint protection
  • UI Guards: Permission-based component rendering
  • Admin Dashboard: Complete user management interface
  • Audit Trail: Role assignment tracking and logging
  • User Management: Complete user lifecycle management

βœ… API Implementation

  • /api/user: User data and JWT token endpoint
  • /api/auth/verify-token: JWT token verification service
  • Authentication Middleware: Route protection and token extraction
  • Type-Safe APIs: Full TypeScript support

βœ… Component Library

  • JWTTokenDemo: Interactive JWT token explorer
  • Dashboard: Enhanced user dashboard
  • UI Components: Complete Radix UI component library
  • Responsive Design: Mobile-first responsive components

βœ… Developer Experience

  • TypeScript: Full type safety throughout the project
  • ESLint: Code quality and consistency
  • Hot Reload: Fast development with Turbopack
  • Error Handling: Comprehensive error management

πŸ› οΈ Development Commands & Scripts

# Development
npm run dev              # Start dev server with Turbopack (port 3000/3001)
npm run build           # Build for production with Turbopack
npm run start           # Start production server
npm run lint            # Run ESLint for code quality

# Type Checking & Debugging
npx tsc --noEmit        # TypeScript type checking
npm run dev -- --port 3001  # Specify custom port

# Clean & Reset
rm -rf .next            # Clear Next.js cache
rm -rf node_modules && npm install  # Fresh install

βš™οΈ Tech Stack & Dependencies

Core Framework

  • Next.js 15.5.4 - App Router with Turbopack
  • React 19.1.0 - Latest React with concurrent features
  • TypeScript 5 - Full type safety

Authentication & Security

  • @clerk/nextjs 6.32.2 - Authentication system
  • @clerk/backend 2.15.0 - JWT verification utilities

UI & Styling

  • Tailwind CSS 4 - Utility-first styling
  • Radix UI - Accessible component primitives
  • Lucide React - Icon library

Database & Backend

  • Convex 1.27.3 - Real-time database
  • React Hook Form - Form management
  • Zod - Runtime type validation

Developer Tools

  • ESLint 9 - Code linting
  • PostCSS - CSS processing
  • Date-fns - Date utilities

πŸ—οΈ Complete Project Structure

secureaware/
β”œβ”€β”€ πŸ“ app/                           # Next.js App Router
β”‚   β”œβ”€β”€ πŸ“ api/                      # API Routes
β”‚   β”‚   β”œβ”€β”€ πŸ“ auth/
β”‚   β”‚   β”‚   └── πŸ“ verify-token/     # JWT token verification API
β”‚   β”‚   β”‚       └── route.ts         # Token verification endpoint
β”‚   β”‚   └── πŸ“ user/                 # User data API
β”‚   β”‚       └── route.ts             # User info + JWT tokens endpoint
β”‚   β”œβ”€β”€ πŸ“ dashboard/                # Protected Dashboard
β”‚   β”‚   └── page.tsx                 # Enhanced dashboard with JWT demo
β”‚   β”œβ”€β”€ πŸ“ sign-in/                  # Authentication Pages
β”‚   β”‚   └── πŸ“ [[...sign-in]]/
β”‚   β”‚       └── page.tsx             # Clerk sign-in page
β”‚   β”œβ”€β”€ πŸ“ sign-up/
β”‚   β”‚   └── πŸ“ [[...sign-up]]/
β”‚   β”‚       └── page.tsx             # Clerk sign-up page
β”‚   β”œβ”€β”€ layout.tsx                   # Root layout with ClerkProvider
β”‚   β”œβ”€β”€ page.tsx                     # Enhanced home page
β”‚   └── globals.css                  # Global styles
β”œβ”€β”€ πŸ“ components/                   # React Components
β”‚   β”œβ”€β”€ JWTTokenDemo.tsx            # Interactive JWT token component
β”‚   └── πŸ“ ui/                      # Radix UI components
β”‚       β”œβ”€β”€ alert.tsx
β”‚       β”œβ”€β”€ badge.tsx
β”‚       β”œβ”€β”€ button.tsx
β”‚       β”œβ”€β”€ card.tsx
β”‚       β”œβ”€β”€ checkbox.tsx
β”‚       β”œβ”€β”€ dialog.tsx
β”‚       β”œβ”€β”€ form.tsx
β”‚       β”œβ”€β”€ input.tsx
β”‚       β”œβ”€β”€ label.tsx
β”‚       β”œβ”€β”€ progress.tsx
β”‚       β”œβ”€β”€ radio-group.tsx
β”‚       β”œβ”€β”€ select.tsx
β”‚       β”œβ”€β”€ separator.tsx
β”‚       β”œβ”€β”€ sheet.tsx
β”‚       β”œβ”€β”€ sidebar.tsx
β”‚       β”œβ”€β”€ skeleton.tsx
β”‚       β”œβ”€β”€ table.tsx
β”‚       β”œβ”€β”€ tabs.tsx
β”‚       β”œβ”€β”€ textarea.tsx
β”‚       └── tooltip.tsx
β”œβ”€β”€ πŸ“ convex/                      # Convex Backend
β”‚   β”œβ”€β”€ auth.config.ts              # Convex + Clerk integration
β”‚   β”œβ”€β”€ mutations.ts                # Database mutations
β”‚   β”œβ”€β”€ queries.ts                  # Database queries
β”‚   β”œβ”€β”€ schema.ts                   # Database schema
β”‚   └── πŸ“ _generated/              # Auto-generated Convex files
β”œβ”€β”€ πŸ“ hooks/                       # React Hooks
β”‚   └── use-mobile.ts               # Mobile detection hook
β”œβ”€β”€ πŸ“ lib/                         # Utilities & Helpers
β”‚   β”œβ”€β”€ jwt-verify.ts               # JWT verification utilities
β”‚   └── utils.ts                    # General utilities
β”œβ”€β”€ πŸ“ public/                      # Static Assets
β”‚   β”œβ”€β”€ file.svg
β”‚   β”œβ”€β”€ globe.svg
β”‚   β”œβ”€β”€ next.svg
β”‚   β”œβ”€β”€ vercel.svg
β”‚   └── window.svg
β”œβ”€β”€ middleware.ts                   # Clerk authentication middleware
β”œβ”€β”€ .env.local                      # Environment variables (configured)
β”œβ”€β”€ .gitignore                      # Git ignore rules
β”œβ”€β”€ components.json                 # shadcn/ui configuration
β”œβ”€β”€ eslint.config.mjs               # ESLint configuration
β”œβ”€β”€ next-env.d.ts                   # Next.js TypeScript definitions
β”œβ”€β”€ next.config.ts                  # Next.js configuration
β”œβ”€β”€ package.json                    # Dependencies and scripts
β”œβ”€β”€ postcss.config.mjs              # PostCSS configuration
β”œβ”€β”€ tsconfig.json                   # TypeScript configuration
β”œβ”€β”€ πŸ“š CLERK_SETUP.md              # Comprehensive Clerk guide
β”œβ”€β”€ πŸ“š JWT_WITH_CLERK.md           # JWT integration guide
β”œβ”€β”€ πŸ“š CUSTOM_JWT_AUTH.md          # Custom JWT implementation
└── πŸ“š README.md                   # This file

πŸ” Authentication Implementation Details

🎯 Implemented Authentication Features

Clerk Authentication (Primary)

  • βœ… Complete Setup: Fully configured Clerk integration
  • βœ… Social Auth: Support for multiple OAuth providers
  • βœ… Email Auth: Username/password authentication
  • βœ… User Profiles: Complete user management system
  • βœ… Session Management: Secure session handling

JWT Token System

  • βœ… Server-Side Access: auth().getToken() implementation
  • βœ… Client-Side Access: useAuth().getToken() hooks
  • βœ… Token Verification: Custom verification utilities
  • βœ… API Authentication: Bearer token support
  • βœ… Token Debugging: Interactive token explorer

Security Features

  • βœ… Route Protection: Middleware-based authentication
  • βœ… Server-Side Validation: Protected API endpoints
  • βœ… Token Extraction: Headers and cookies support
  • βœ… Error Handling: Graceful authentication failures

πŸ”‘ Available API Endpoints

// User Data + JWT Tokens
GET  /api/user              // Get user info and JWT tokens
POST /api/user              // Authenticated API example

// Token Verification
POST /api/auth/verify-token // Verify JWT token payload
GET  /api/auth/verify-token // Extract & verify from headers

πŸ› οΈ JWT Utilities

// Server-side utilities (lib/jwt-verify.ts)
verifyClerkJWT(token)       // Verify JWT token
extractToken(request)       // Extract from headers/cookies
decodeJWT(token)           // Decode without verification

// Component usage
<JWTTokenDemo />           // Interactive JWT explorer

πŸ—„οΈ Database

Convex provides:

  • Real-time data synchronization
  • TypeScript-first database operations
  • Built-in authentication integration
  • Serverless function deployment

🎨 UI Components

Built with:

  • Tailwind CSS for styling
  • Radix UI for accessible components
  • Lucide React for icons
  • Custom components in /components directory

πŸ“± Responsive Design

The application is fully responsive and works on:

  • πŸ“± Mobile devices (320px+)
  • πŸ“± Tablets (768px+)
  • πŸ’» Desktop (1024px+)
  • πŸ–₯️ Large screens (1440px+)

πŸš€ Deployment & Production

βœ… Current Environment Configuration

# βœ… Configured in .env.local
CONVEX_DEPLOYMENT=dev:wry-goldfinch-589
NEXT_PUBLIC_CONVEX_URL=https://wry-goldfinch-589.convex.cloud
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_[configured]
CLERK_SECRET_KEY=sk_test_[configured]
NEXT_PUBLIC_CLERK_SIGN_IN_URL="/sign-in"
NEXT_PUBLIC_CLERK_SIGN_UP_URL="/sign-up"
NEXT_PUBLIC_CLERK_SIGN_IN_FORCE_REDIRECT_URL="/dashboard"
NEXT_PUBLIC_CLERK_SIGN_UP_FORCE_REDIRECT_URL="/dashboard"

🌐 Deployment Platforms

Vercel (Recommended)

  1. βœ… Ready to Deploy - Project is production-ready
  2. Connect GitHub repository to Vercel
  3. Add production environment variables
  4. Deploy with automatic CI/CD

Other Platforms

  • Netlify: npm run build β†’ .next directory
  • Railway: GitHub integration + env vars
  • Heroku: Next.js buildpack supported
  • Cloudflare Pages: Full-stack deployment

πŸ”’ Production Environment Variables

For production deployment, update these variables:

# Production Clerk Keys
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_your_production_key
CLERK_SECRET_KEY=sk_live_your_production_key

# Production Convex
NEXT_PUBLIC_CONVEX_URL=https://your-production.convex.cloud
CONVEX_DEPLOYMENT=production:your-deployment

# Production URLs (update domains)
NEXT_PUBLIC_CLERK_SIGN_IN_URL="/sign-in"
NEXT_PUBLIC_CLERK_SIGN_UP_URL="/sign-up"
NEXT_PUBLIC_CLERK_SIGN_IN_FORCE_REDIRECT_URL="/dashboard"
NEXT_PUBLIC_CLERK_SIGN_UP_FORCE_REDIRECT_URL="/dashboard"

βœ… Build Status

  • βœ… Development Build: Working (npm run dev)
  • βœ… Production Build: Tested (npm run build)
  • βœ… TypeScript: No errors
  • βœ… ESLint: All checks passing
  • βœ… Authentication: Fully functional

πŸ”§ Troubleshooting

Common Issues

Build fails with Clerk error:

  • Verify your API keys are correct
  • Check that keys are set in environment variables

Authentication not working:

  • Ensure middleware.ts is in the root directory
  • Verify Clerk dashboard domain settings

Development server issues:

  • Try npm run dev -- --port 3001 if port 3000 is busy
  • Clear .next folder and restart: rm -rf .next && npm run dev

For more troubleshooting, see CLERK_SETUP.md.

οΏ½ Implementation Summary

βœ… Completed Implementations

Feature Status Details
πŸ” Authentication βœ… Complete Clerk integration with JWT tokens
πŸ›‘οΈ Authorization βœ… Complete Protected routes and middleware
πŸ—οΈ API Routes βœ… Complete User data and token verification
🎨 UI Components βœ… Complete Radix UI + Tailwind CSS
πŸ“± Dashboard βœ… Complete Interactive user dashboard
πŸ”‘ JWT Integration βœ… Complete Token access and verification
πŸ“š Documentation βœ… Complete Comprehensive guides
πŸš€ Build System βœ… Complete Production-ready builds
πŸ“¦ Dependencies βœ… Updated Latest stable versions
🎯 TypeScript βœ… Complete Full type safety

πŸ§ͺ Testing Status

βœ… Development Server: Working (localhost:3001)
βœ… Production Build:   Successful
βœ… Authentication:     Functional
βœ… JWT Tokens:         Implemented & Tested
βœ… API Endpoints:      Working
βœ… UI Components:      Responsive
βœ… Error Handling:     Graceful
βœ… TypeScript:         No errors
βœ… ESLint:             Passing

🎯 Next Development Steps

Ready for security training functionality implementation:

  1. Training Module Creation System

    • Training builder interface
    • Content management
    • Multiple learning formats support
  2. Training Experience

    • Progress tracking
    • Completion scoring
    • Interactive content delivery
  3. Results & Analytics

    • Score calculation
    • Performance analytics
    • Leaderboards
  4. Advanced Features

    • Categories and tags
    • Difficulty levels
    • Group training sessions

πŸ“š Learning Resources

🀝 Development Workflow

# Start development
npm run dev

# Test authentication
# 1. Visit http://localhost:3001
# 2. Sign up/Sign in
# 3. Access /dashboard
# 4. Explore JWT token functionality

# Build for production
npm run build

# Deploy to production
# 1. Push to GitHub
# 2. Connect to Vercel
# 3. Set environment variables
# 4. Deploy automatically

οΏ½ Support & Maintenance

  • Issue Tracking: GitHub Issues
  • Documentation: Comprehensive guides included
  • Code Quality: ESLint + TypeScript
  • Security: Clerk enterprise-grade auth
  • Performance: Next.js 15 optimizations

πŸ“ Project Status: βœ… PRODUCTION READY

Built with modern technologies:

  • ⚑ Next.js 15 + React 19
  • πŸ” Clerk Authentication + JWT
  • πŸ—„οΈ Convex Real-time Database
  • 🎨 Tailwind CSS + Radix UI
  • πŸ“ TypeScript + ESLint

Ready for security awareness training feature development and deployment! πŸš€

About

Modern security awareness platform with Next.js 15, Clerk Auth, RBAC, and real-time database for enterprise security training.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 96.4%
  • JavaScript 2.4%
  • CSS 1.2%