A comprehensive Power Management Dashboard for NPCL built with Next.js 14, TypeScript, Prisma, and PostgreSQL.
- User Authentication & Authorization: Role-based access control (Admin, Operator, Viewer)
- Real-time Power Monitoring: Live power generation tracking and efficiency monitoring
- Equipment Management: Power unit status tracking and maintenance scheduling
- Dashboard Analytics: Comprehensive statistics and data visualization
- Audit Logging: Complete audit trail for all system activities
- Report Generation: Automated daily, weekly, monthly, and annual reports
- Responsive Design: Mobile-friendly interface with Tailwind CSS
- Frontend: Next.js 14 (App Router), React 18, TypeScript
- Backend: Next.js API Routes, Prisma ORM
- Database: PostgreSQL
- Authentication: NextAuth.js with JWT strategy
- Styling: Tailwind CSS
- Testing: Jest, React Testing Library
- Deployment: Vercel-ready
npcl-dashboard/
├── app/ # Next.js App Router
│ ├── api/ # API routes
│ ├── auth/ # Authentication pages
│ ├── dashboard/ # Dashboard pages
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout
│ └── page.tsx # Home page
├── src/components/ # React components
│ ├── auth/ # Authentication components
│ ├── dashboard/ # Dashboard components
│ └── ui/ # Reusable UI components
├── lib/ # Utility libraries
│ ├── auth.ts # Authentication utilities
│ ├── prisma.ts # Prisma client
│ ├── utils.ts # General utilities
│ └── validations.ts # Zod schemas
├── middleware/ # Custom middleware
├── models/ # Data models
├── types/ # TypeScript type definitions
├── config/ # Configuration files
├── prisma/ # Database schema and migrations
├── __tests__/ # Test files
└── public/ # Static assets
- Node.js 18+
- PostgreSQL 12+
- npm or yarn
-
Clone the repository
git clone https://github.com/your-username/npcl-dashboard.git cd npcl-dashboard
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env
Update the
.env
file with your configuration:DATABASE_URL=\"postgresql://username:password@localhost:5432/npcl_dashboard\" NEXTAUTH_SECRET=\"your-secret-key-here-make-it-long-and-random\" NEXTAUTH_URL=\"http://localhost:3000\"
-
Set up the database
# Generate Prisma client npm run db:generate # Push database schema npm run db:push # Seed the database with sample data npm run db:seed
-
Start the development server
npm run dev
-
Open your browser Navigate to http://localhost:3000
After seeding the database, you can log in with these default accounts:
Role | Password | |
---|---|---|
Admin | admin@npcl.com | admin123 |
Operator | operator@npcl.com | operator123 |
Viewer | viewer@npcl.com | viewer123 |
npm run dev
- Start development servernpm run build
- Build for productionnpm run start
- Start production servernpm run lint
- Run ESLintnpm run test
- Run testsnpm run test:watch
- Run tests in watch modenpm run test:coverage
- Run tests with coveragenpm run db:generate
- Generate Prisma clientnpm run db:push
- Push schema to databasenpm run db:migrate
- Run database migrationsnpm run db:studio
- Open Prisma Studionpm run db:seed
- Seed database with sample data
POST /api/auth/signin/credentials
- User login (NextAuth.js)POST /api/auth/signout
- User logout (NextAuth.js)GET /api/auth/session
- Get session info (NextAuth.js)POST /api/auth/register
- User registration (Custom)POST /api/auth/forgot-password
- Password reset request (Custom)POST /api/auth/reset-password
- Password reset confirmation (Custom)POST /api/auth/change-password
- Change password (Custom)
GET /api/auth/test-session
- Session debuggingPOST /api/auth/test-login
- Credential validation testing
GET /api/dashboard/stats
- Get dashboard statisticsGET /api/dashboard/power-units
- Get power units with readings
GET /api/auth/users
- Get all usersPUT /api/auth/users/[id]
- Update userDELETE /api/auth/users/[id]
- Delete user
The application uses the following main entities:
- Users: System users with role-based access
- PowerUnits: Power generation units (thermal, hydro, solar, wind, nuclear)
- PowerReadings: Real-time power generation data
- MaintenanceRecords: Equipment maintenance tracking
- Reports: Generated reports and analytics
- AuditLogs: System activity audit trail
- SystemConfig: Application configuration
Run the test suite:
# Run all tests
npm run test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
The project includes comprehensive test coverage for:
- Authentication: Login, registration, JWT handling, NextAuth configuration
- Authorization: Role-based access control (RBAC), permissions
- API Routes: All authentication endpoints, rate limiting, error handling
- Components: LoginForm validation, user interactions, accessibility
- Utilities: Password hashing, validation schemas, rate limiting logic
- Middleware: Authentication middleware, route protection
- Integration: Database operations with proper mocking
The project underwent comprehensive test suite improvements to ensure reliability:
- Fixed Authentication Tests: Resolved mock conflicts and import path issues
- Enhanced NextAuth Integration: Proper JWT callback handling and session management
- Improved Rate Limiting Tests: Fixed mock setup and integration testing
- Component Testing: Resolved React component testing with proper jsdom environment
- Mock Architecture: Implemented proper mock isolation and dependency management
- Test Cleanup: Removed skipped tests and external dependencies for faster execution
Multiple TypeScript compilation issues were resolved:
- Cache Import Errors: Fixed module import paths for cache middleware
- Missing Dependencies: Replaced external dependencies with custom implementations
- Type Safety: Added proper null checks and type assertions
- Touch Events: Enhanced mobile touch event handling with safety checks
- Image Optimization: Improved type safety for image element properties
- Lazy Loading: Implemented component lazy loading with error boundaries
- Image Optimization: Added optimized image components with intersection observer
- Touch Optimization: Enhanced mobile touch interactions
- Cache Management: Implemented Redis caching with proper error handling
- Push your code to GitHub
- Connect your repository to Vercel
- Set environment variables in Vercel dashboard
- Deploy
# Build Docker image
docker build -t npcl-dashboard .
# Run container
docker run -p 3000:3000 npcl-dashboard
Variable | Description | Required |
---|---|---|
DATABASE_URL |
PostgreSQL connection string | Yes |
NEXTAUTH_SECRET |
JWT secret key | Yes |
NEXTAUTH_URL |
Application URL | Yes |
JWT_EXPIRES_IN |
JWT expiration time | No |
EMAIL_HOST |
SMTP host for notifications | No |
EMAIL_PORT |
SMTP port | No |
EMAIL_USER |
SMTP username | No |
EMAIL_PASS |
SMTP password | No |
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, email support@npcl.com or create an issue in the GitHub repository.
- Real-time WebSocket connections for live data
- Advanced analytics and forecasting
- Mobile application
- Integration with external monitoring systems
- Advanced reporting with PDF export
- Multi-language support
- Dark mode theme
- Advanced user permissions
- API rate limiting
- Data export functionality