A comprehensive full-stack marketplace for buying and selling used smartphones with built-in user analytics and behavioral tracking.
- Frontend deployed at : http://4.213.225.5:3000/
- Server deployed at : http://4.213.225.5:4000/
- User Registration & Login - Secure authentication with bcrypt password hashing
- Session Management - Redis-based session storage with automatic tracking
- Admin Access - Special admin privileges for analytics and management
- User Profiles - Personal account management
- User Behaviour Tracking - Comprehensive behavioral analytics including:
- Page visit tracking with time spent analysis
- Click event monitoring and element interaction
- Session duration and user journey mapping
- Device, browser, and OS detection
- IP geolocation and user demographics
- Admin Analytics Dashboard - Detailed reports featuring:
- Total unique user visits and engagement metrics
- Top 10 most visited pages and user flow analysis
- Average time spent per page
- Popular devices and device category breakdown
- Most clicked elements and interaction heatmaps
- Logged-in vs anonymous user statistics
- Average sessions per user and retention metrics
- Framework: Next.js
- Language: TypeScript
- Styling: Tailwind CSS
- Components: Radix UI primitives
- Icons: Lucide React
- State Management: React Context API
- Notifications: Sonner toast notifications
- Runtime: Node.js with Express.js
- Language: TypeScript
- Database: PostgreSQL with TypeORM
- Session Store: Redis
- Authentication: bcrypt password hashing
- Analytics: Custom tracking system
- Additional Libraries:
geoip-lite- IP geolocation servicesuseragent- User agent parsing and device detectionexpress-session- Session management
- Node.js (v18 or higher)
- PostgreSQL database
- Redis server
- npm or yarn package manager
-
Navigate to server directory
cd server -
Install backend dependencies
npm install
-
Environment Configuration Create a
.envfile in the server directory:# PostgreSQL Configuration POSTGRES_USER=your_postgres_user POSTGRES_PASS=your_postgres_password PG_HOST=your_postgres_host PG_PORT=5432 PG_URI=your_complete_postgres_uri # Redis Configuration REDIS_URL=your_redis_host REDIS_PASSWORD=your_redis_password # Server Configuration PORT=4000
-
Database Setup
# Ensure PostgreSQL is running # Create database: oru_user_tracking # TypeORM will auto-create tables
-
Navigate to client directory
cd client # or root directory if frontend is in root
-
Install frontend dependencies
npm install
-
Environment Configuration Create a
.env.localfile:NEXT_PUBLIC_BASE_URL=http://localhost:4000
-
Start the backend server
cd server npm run build npm start -
Start the frontend development server
cd client npm run dev -
Access the application
- Frontend:
http://localhost:3000 - Backend API:
http://localhost:4000
- Frontend:
- users - User accounts with authentication data
- user_session_data - Session tracking with device and location info
- user_visits - Page visit records with engagement metrics
- visit_actions - User interaction and click event logging
/ # Homepage with featured deals
/bestdeals # Product listings with filters
/bestdeals/product/[model] # Individual product details
/login # User authentication
/register # User registration
/admin # Analytics dashboard (admin only)
POST /register- User registrationPOST /login- User authenticationPOST /logout- Session termination
GET /session- Current session informationPOST /usertrack- Submit tracking data
GET /admin/analytics- Comprehensive analytics report- Query Parameters:
startDate,endDate
- Query Parameters:
The admin dashboard provides comprehensive insights including:
{
"totalUniqueVisits": 1234,
"topPages": [
{ "pageUrl": "/bestdeals", "visitCount": "500" },
{ "pageUrl": "/", "visitCount": "400" }
],
"avgTimeSpent": [
{ "pageUrl": "/bestdeals/product/iphone-12", "avgTime": "120.5" }
],
"topDevices": [
{ "device": "iPhone", "count": "300" },
{ "device": "Samsung Galaxy", "count": "250" }
],
"topClickedElements": [
{ "element": "product-card", "clicks": "450" },
{ "element": "filter-button", "clicks": "320" }
],
"deviceCategories": [
{ "category": "Apple", "count": 400 },
{ "category": "Samsung", "count": 300 }
],
"loggedStatusStats": [
{ "isLoggedIn": true, "count": "600" },
{ "isLoggedIn": false, "count": "634" }
],
"avgSessionsPerUser": 2.8
}- Password Security: bcrypt hashing with 10 salt rounds
- Session Protection: HTTP-only cookies with SameSite protection
- Admin Authorization: Middleware-based route protection
- Input Validation: Comprehensive request validation
- CORS Configuration: Secure cross-origin requests
oldphones-marketplace/
βββ server/ # Backend application
β βββ controller/ # Route controllers
β β βββ adminController.ts # Analytics and reporting
β β βββ authController.ts # User authentication
β β βββ userTracking.ts # Behavioral tracking
β βββ db/ # Database configuration
β β βββ entities/ # TypeORM entity definitions
β β βββ connectToDB.ts # PostgreSQL connection
β β βββ typeorm.ts # ORM configuration
β βββ middlewares/ # Express middlewares
β β βββ admin.ts # Admin access control
β β βββ sessionTracker.ts # Session and device tracking
β βββ routes/ # API route definitions
β βββ types/ # TypeScript type definitions
β βββ server.ts # Main server application
βββ client/ # Frontend application
βββ src/
β βββ app/ # Next.js app router pages
β βββ components/ # Reusable UI components
β βββ context/ # React context providers
β βββ hooks/ # Custom React hooks
β βββ lib/ # Utility functions
βββ package.json
- TypeScript: Full type safety with strict checking
- Hot Reload: Use
ts-nodefor development - Database Sync: Automatic schema synchronization
- Next.js: App router with server components
- TypeScript: Strict type checking enabled
- Tailwind CSS: Utility-first styling approach
- Component Library: Radix UI primitives
This project is licensed under the ISC License.
For support and questions, please open an issue in the GitHub repository.
OLDPhones - Revolutionizing the second-hand smartphone market with data-driven insights and seamless user experience.
