This is a full-stack web application built with React (frontend) and Node.js/Express (backend) that implements a points-based leaderboard system. Users can select from a list of participants, claim random points for them, and view real-time rankings. The system includes user management, point claiming functionality, and historical tracking of all point awards.
Preferred communication style: Simple, everyday language.
- Framework: React with TypeScript
- UI Library: Radix UI components with shadcn/ui styling
- Styling: Tailwind CSS with CSS variables for theming
- State Management: TanStack Query (React Query) for server state
- Routing: Wouter for client-side routing
- Form Handling: React Hook Form with Zod validation
- Build Tool: Vite for development and production builds
- Runtime: Node.js with Express.js framework
- Database: MongoDB Atlas (cloud-hosted MongoDB)
- Database Driver: Native MongoDB driver for Node.js
- API Pattern: RESTful API endpoints
- Storage Layer: Abstracted storage interface with MongoDB and in-memory implementations
- Development: Hot reload with tsx
├── client/ # React frontend
│ ├── src/
│ │ ├── components/ # Reusable UI components
│ │ ├── pages/ # Route components
│ │ ├── hooks/ # Custom React hooks
│ │ └── lib/ # Utilities and API client
├── server/ # Express backend
│ ├── routes.ts # API route definitions
│ ├── storage.ts # Data layer abstraction
│ └── index.ts # Server entry point
├── shared/ # Shared types and schemas
│ └── schema.ts # Database schema and validation
└── migrations/ # Database migrations
- Users Collection: Stores user information (id, name, points, avatar, createdAt)
- ClaimHistory Collection: Tracks every point claim (id, userId, pointsAwarded, claimedAt)
- Relationships: One-to-many between users and claim history using userId field
GET /api/users- Retrieve all users with current pointsPOST /api/users- Create a new userPOST /api/users/:id/claim- Claim random points (1-10) for a userGET /api/claim-history- Get recent claim history with user details
- Leaderboard Page: Main interface with user selection, claim button, and rankings
- User Management: Add new users with name and avatar
- Real-time Updates: Automatic refresh of rankings after point claims
- Claim History: Display of recent point award activities
- Memory Storage: In-memory fallback for development (server/storage.ts)
- MongoDB Atlas: Cloud-hosted MongoDB for production data persistence
- Data Abstraction: IStorage interface for easy storage provider switching
- Auto-fallback: Automatically falls back to memory storage if MongoDB connection fails
- User Selection: Frontend displays dropdown of available users
- Point Claiming: User clicks claim button → API generates random points (1-10) → Updates user's total points → Creates history record
- Real-time Updates: TanStack Query invalidates cache → Refetches updated user data → Updates leaderboard rankings
- Ranking Calculation: Users automatically sorted by total points in descending order
- History Tracking: Every claim creates a timestamped record linking user and points awarded
- UI Components: Radix UI primitives for accessible components
- Styling: Tailwind CSS for utility-first styling
- State Management: TanStack Query for server state synchronization
- Form Validation: Zod for type-safe schema validation
- Icons: Lucide React for consistent iconography
- Database: MongoDB Atlas (cloud-hosted MongoDB)
- Database Driver: Native MongoDB driver for Node.js
- Development: tsx for TypeScript execution in development
- Vite: Frontend build tool and development server
- ESBuild: Server-side bundling for production
- TypeScript: Type checking and compilation
- Frontend: Vite dev server with hot reload
- Backend: tsx with file watching for auto-restart
- Database: MongoDB Atlas connection or fallback to memory storage
- Frontend: Vite builds optimized static assets to
dist/public - Backend: ESBuild bundles server code to
dist/index.js - Database: MongoDB Atlas connection via MONGODB_URI environment variable
- Deployment: Single node.js process serving both API and static files
- MONGODB_URI: MongoDB Atlas connection string (optional - falls back to memory storage)
- NODE_ENV: Environment mode (development/production)
- Auto-fallback: Gracefully handles MongoDB connection failures
The application uses a modern full-stack TypeScript architecture with strong type safety throughout the data flow, real-time updates, and a clean separation between frontend and backend concerns.