A comprehensive, professional laptop repair management system built with Next.js, TypeScript, MongoDB, and Tailwind CSS. This system provides complete tracking and management of laptop repair requests with authentication, status management, and resolution tracking.
- Features
- Project Structure
- Tech Stack
- System Architecture
- Project Modules
- Component Structure
- API Endpoints
- Workflow Chart
- Installation
- Usage
- Environment Variables
- Scripts
- Contributing
- π Secure Authentication System: JWT-based authentication with protected routes
- π Query Management: Submit, track, and manage laptop repair requests
- π Status Tracking: Real-time status updates (Pending, Resolved, Not Resolved)
- π― Priority System: Assign priorities (Low, Medium, High, Urgent)
- π° Cost Management: Track estimated and actual repair costs
- π Advanced Filtering: Filter queries by status, priority, and other criteria
- π± Responsive Design: Mobile-first design with Tailwind CSS
- π Real-time Updates: Dynamic updates without page refresh
- π‘οΈ Data Validation: Comprehensive server-side and client-side validation
- π Dashboard Analytics: Overview of repair statistics and metrics
laptop-repair-management/
βββ π components/ # Reusable React components
β βββ AddLaptopQuery.tsx # Form for submitting new repair requests
β βββ Layout.tsx # Main layout wrapper
β βββ ListSection.tsx # Display pending queries
β βββ Navigation.tsx # Navigation component
β βββ ProtectedRoute.tsx # Route protection wrapper
β βββ ResolvedSection.tsx # Display resolved queries
βββ π contexts/ # React context providers
β βββ AuthContext.tsx # Authentication context
βββ π lib/ # Utility libraries
β βββ mongoose.ts # MongoDB connection
βββ π models/ # Database models
β βββ LaptopQuery.ts # Laptop query schema
β βββ User.ts # User authentication schema
βββ π pages/ # Next.js pages
β βββ π api/ # API routes
β β βββ π auth/ # Authentication endpoints
β β β βββ backup-login.ts
β β β βββ complete-reset.ts
β β β βββ force-reset-users.ts
β β β βββ init-users.ts
β β β βββ login.ts
β β β βββ logout.ts
β β β βββ me.ts
β β β βββ reset-users.ts
β β β βββ simple-login.ts
β β βββ π debug/ # Debug endpoints
β β β βββ db-status.ts
β β β βββ detailed-users.ts
β β β βββ env-check.ts
β β β βββ test-login.ts
β β βββ π queries/ # Query management endpoints
β β βββ [id].ts # Individual query operations
β β βββ index.ts # Main query operations
β β βββ pending.ts # Pending queries
β β βββ resolved.ts # Resolved queries
β βββ _app.tsx # App wrapper with providers
β βββ _error.tsx # Error page
β βββ index.tsx # Home page
β βββ login.tsx # Login page
βββ π scripts/ # Utility scripts
β βββ check-mongodb-users.js
β βββ complete-fix.js
β βββ final-setup.js
β βββ fix-credentials.js
β βββ init-users.js
β βββ mongodb-status.js
β βββ quick-test.js
β βββ reset-users.js
β βββ setup-auth.js
β βββ test-credentials.js
β βββ test-db.js
βββ π styles/ # Global styles
β βββ globals.css # Tailwind CSS and global styles
βββ next.config.js # Next.js configuration
βββ package.json # Dependencies and scripts
βββ postcss.config.js # PostCSS configuration
βββ tailwind.config.js # Tailwind CSS configuration
βββ tsconfig.json # TypeScript configuration
βββ README.md # Project documentation
- Next.js 14.2.5: React framework with SSR and API routes
- React 18: Frontend library
- TypeScript 5: Type-safe JavaScript
- Tailwind CSS 3.4.1: Utility-first CSS framework
- Node.js: Runtime environment
- Next.js API Routes: Server-side API endpoints
- MongoDB 6.8.0: NoSQL database
- Mongoose 8.5.2: MongoDB object modeling
- JSON Web Tokens (JWT) 9.0.2: Secure authentication
- bcryptjs 3.0.2: Password hashing
- Protected Routes: Client-side route protection
- ESLint: Code linting
- PostCSS: CSS processing
- Autoprefixer: CSS vendor prefixes
The system follows a modern full-stack architecture:
- Frontend Layer: React components with TypeScript
- API Layer: Next.js API routes handling business logic
- Database Layer: MongoDB with Mongoose ODM
- Authentication Layer: JWT-based secure authentication
- State Management: React Context for global state
- Purpose: Manages user authentication state
- Features:
- JWT token management
- User session persistence
- Login/logout functionality
- Protected route handling
- Auto-redirect on authentication failure
- Purpose: User data model and authentication
- Features:
- User schema definition
- Password hashing with bcrypt
- Password comparison methods
- Username uniqueness validation
- Purpose: Laptop repair request data model
- Features:
- Comprehensive query schema
- Status tracking (pending, resolved, not_resolved)
- Priority levels (low, medium, high, urgent)
- Cost management (estimated vs actual)
- Timestamp tracking
login.ts
: User authentication endpointlogout.ts
: User logout endpointme.ts
: Current user informationinit-users.ts
: Initialize default usersreset-users.ts
: Reset user database
index.ts
: Main CRUD operations for queries[id].ts
: Individual query operationspending.ts
: Fetch pending queriesresolved.ts
: Fetch resolved queries
db-status.ts
: Database connection statusenv-check.ts
: Environment variable validationtest-login.ts
: Authentication testing
- Layout.tsx: Main application layout wrapper
- Navigation.tsx: Navigation bar with user actions
- ProtectedRoute.tsx: Route protection wrapper
- AddLaptopQuery.tsx: New repair request form
- ListSection.tsx: Pending queries display
- ResolvedSection.tsx: Resolved queries display
- Purpose: MongoDB connection management
- Features:
- Connection pooling
- Error handling
- Environment-based configuration
- Database initialization and maintenance scripts
- User management utilities
- Connection testing tools
interface AddLaptopQueryProps {
onQueryAdded: () => void
}
- Purpose: Form for submitting new repair requests
- Features: Real-time validation, success/error messaging, responsive design
interface ListSectionProps {
onQueryUpdated: () => void
}
- Purpose: Display and manage pending queries
- Features: Status updates, priority filtering, cost tracking
- Purpose: Display completed repair requests
- Features: Resolution details, cost analysis, completion statistics
- Purpose: Main navigation and user management
- Features: User profile, logout functionality, responsive menu
Method | Endpoint | Description |
---|---|---|
POST | /api/auth/login |
User authentication |
POST | /api/auth/logout |
User logout |
GET | /api/auth/me |
Get current user |
POST | /api/auth/init-users |
Initialize users |
Method | Endpoint | Description |
---|---|---|
GET | /api/queries |
Get all queries |
POST | /api/queries |
Create new query |
GET | /api/queries/[id] |
Get specific query |
PUT | /api/queries/[id] |
Update query |
DELETE | /api/queries/[id] |
Delete query |
GET | /api/queries/pending |
Get pending queries |
GET | /api/queries/resolved |
Get resolved queries |
Method | Endpoint | Description |
---|---|---|
GET | /api/debug/db-status |
Database status |
GET | /api/debug/env-check |
Environment check |
POST | /api/debug/test-login |
Test authentication |
graph TD
A[π Application Start] --> B{π€ User Authenticated?}
B -->|No| C[π Login Page]
B -->|Yes| D[π Dashboard]
C --> E[π Enter Credentials]
E --> F{β
Valid Credentials?}
F -->|No| G[β Show Error]
G --> E
F -->|Yes| H[π― Generate JWT Token]
H --> I[πΎ Store Auth State]
I --> D
D --> J[π Main Navigation]
J --> K{π― User Action}
K -->|Add Query| L[π Add Laptop Query Form]
K -->|View Pending| M[π List Pending Queries]
K -->|View Resolved| N[β
Resolved Queries]
K -->|Logout| O[πͺ Logout Process]
L --> P[π Form Validation]
P --> Q{βοΈ Valid Data?}
Q -->|No| R[β οΈ Show Validation Error]
R --> L
Q -->|Yes| S[π€ Submit to API]
S --> T[πΎ Save to MongoDB]
T --> U[π Update UI]
U --> D
M --> V[π Fetch Pending Queries]
V --> W[π Display Query List]
W --> X{π οΈ Update Query?}
X -->|Yes| Y[βοΈ Edit Query Form]
X -->|No| D
Y --> Z[π Update Form]
Z --> AA[π€ Submit Update]
AA --> BB[πΎ Update MongoDB]
BB --> CC[π Refresh List]
CC --> W
N --> DD[π Fetch Resolved Queries]
DD --> EE[π Display Resolved List]
EE --> FF{π View Details?}
FF -->|Yes| GG[π Show Query Details]
FF -->|No| D
GG --> EE
O --> HH[ποΈ Clear Auth Token]
HH --> II[πΎ Clear User State]
II --> JJ[π Redirect to Login]
JJ --> C
style A fill:#e1f5fe
style B fill:#fff3e0
style C fill:#fce4ec
style D fill:#e8f5e8
style L fill:#f3e5f5
style M fill:#e0f2f1
style N fill:#e3f2fd
style O fill:#fff8e1
- Application Start: User visits the application
- Authentication Check: System verifies if user has valid JWT token
- Login Process: If not authenticated, redirect to login page
- Credential Validation: Server validates username/password against MongoDB
- Token Generation: Create JWT token with user information
- State Management: Store authentication state in React context
-
Query Submission:
- User fills out repair request form
- Client-side validation checks required fields
- Data submitted to
/api/queries
endpoint - Server validates and saves to MongoDB
- UI updates with success/error message
-
Query Listing:
- Fetch queries from database based on status filter
- Display in organized list with search/filter capabilities
- Real-time updates when queries are modified
-
Query Updates:
- Admin can update query status, priority, costs
- Changes immediately reflected in database
- UI updates without page refresh
- Frontend β API: User interactions trigger API calls
- API β Database: API routes handle business logic and database operations
- Database β API: MongoDB returns requested data
- API β Frontend: Formatted response sent to client
- Frontend Update: React components re-render with new data
- Request Intercepting: All protected routes check for valid JWT
- Token Validation: Server validates token signature and expiration
- User Context: Authenticated user data available throughout app
- Auto-logout: Invalid/expired tokens trigger automatic logout
- Node.js 18+ installed
- MongoDB database (local or cloud)
- Git for version control
- Clone the repository:
git clone https://github.com/techbizloanindia/TechFix-Pro---Next-Gen-Laptop-Repair-Management.git
cd laptop-repair-management
- Install dependencies:
npm install
- Environment setup:
cp .env.example .env.local
-
Configure environment variables (see Environment Variables)
-
Initialize database:
npm run init-db
- Start development server:
npm run dev
- Open application:
Visit
http://localhost:3000
- Username:
admin
- Password:
admin123
- Navigate to "Add Query" tab
- Fill out the repair request form:
- Customer name
- Laptop brand/model
- Issue description
- Contact information (optional)
- Submit the form
- Query will appear in "Pending" section
- View pending queries in "List" tab
- Update status, priority, or costs as needed
- Mark queries as resolved with resolution details
- View completed repairs in "Resolved" tab
- User management through API endpoints
- Database maintenance scripts
- System status monitoring
Create a .env.local
file in the root directory:
# Database Configuration
MONGODB_URI=mongodb://localhost:27017/laptop-repair-db
# or for MongoDB Atlas:
# MONGODB_URI=mongodb+srv://username:[email protected]/laptop-repair-db
# Authentication
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_EXPIRES_IN=7d
# Application
NEXT_PUBLIC_APP_URL=http://localhost:3000
NODE_ENV=development
# Optional: For production deployment
NEXTAUTH_URL=https://your-domain.com
NEXTAUTH_SECRET=your-nextauth-secret
MONGODB_URI
: MongoDB connection stringJWT_SECRET
: Secret key for JWT token signingJWT_EXPIRES_IN
: JWT token expiration timeNEXT_PUBLIC_APP_URL
: Application URL for client-side requestsNODE_ENV
: Environment mode (development/production)
Available npm scripts:
# Development
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint
# Database Management
npm run init-db # Initialize database with default users
npm run reset-db # Reset database (caution: deletes all data)
npm run check-db # Check database connection
# Testing
npm run test-auth # Test authentication endpoints
npm run test-db # Test database connection
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes with proper TypeScript types
- Test your changes thoroughly
- Commit with descriptive messages:
git commit -m 'Add amazing feature'
- Push to your branch:
git push origin feature/amazing-feature
- Create a Pull Request
- Use TypeScript for all new code
- Follow ESLint configuration
- Write meaningful component and function names
- Add proper error handling
- Include JSDoc comments for complex functions
- Ensure responsive design with Tailwind CSS
- Test all API endpoints with various input scenarios
- Verify authentication flows work correctly
- Check responsive design on multiple screen sizes
- Validate form inputs and error handling
This project is licensed under the MIT License - see the LICENSE file for details.
- Next.js team for the amazing framework
- MongoDB team for the robust database solution
- Tailwind CSS for the utility-first CSS framework
- React team for the powerful frontend library
- All contributors who help improve this project
Built with β€οΈ by Nitish Singh
Transform your laptop repair business with professional management tools.