A comprehensive admin panel for managing IoT products, orders, and user accounts built with Next.js 14, TypeScript, and PostgreSQL.
- Product Management: Create, edit, sync, and view IoT products with firmware information
- Order Management: Process and track orders with Excel import/export capabilities
- User Management: Manage user accounts and permissions
- Attachment Handling: Upload, download, and manage file attachments with secure hash-based storage
- OAuth Authentication: Secure login with JWT token-based authentication
- Dashboard Analytics: Real-time insights and statistics
- Responsive UI: Modern interface built with Radix UI and Tailwind CSS
- Data Tables: Advanced sorting, filtering, and pagination
- Excel Integration: Import/export order data with XLSX support
- Framework: Next.js 14 (App Router)
- Language: TypeScript
- Database: PostgreSQL with Kysely query builder
- Authentication: JWT with OAuth flow
- UI Components: Radix UI primitives
- Styling: Tailwind CSS
- Form Handling: React Hook Form with Zod validation
- State Management: SWR for data fetching
- File Processing: XLSX, Cheerio, DOMPurify
- Testing: Jest, React Testing Library
- Node.js 18+
- PostgreSQL database
- PM2 (for production deployment)
- Docker & Docker Compose (optional, for containerized deployment)
The fastest way to get started:
# Clone the repository
git clone <repository-url>
cd pm.acme.cn
# Start with Docker Compose
docker-compose up -d
# Application will be available at http://localhost:3080For detailed setup instructions, see the sections below.
- 
Clone the repository git clone <repository-url> cd pm.acme.cn 
- 
Install dependencies npm install 
- 
Set up environment variables Create a .env.localfile in the root directory with the following variables:# Database DATABASE_URL=postgresql://user:password@localhost:5432/acme_pm # JWT Secret JWT_SECRET=your-secret-key-here # OAuth Configuration OAUTH_CLIENT_ID=your-client-id OAUTH_CLIENT_SECRET=your-client-secret OAUTH_REDIRECT_URI=http://localhost:3080/api/auth/callback # Application NEXT_PUBLIC_APP_URL=http://localhost:3080 
- 
Run database migrations npm run db:migrate 
- 
Start development server npm run dev The application will be available at http://localhost:3080
- npm run dev- Start development server on port 3080
- npm run build- Build for production
- npm run build:analyze- Build with bundle analyzer
- npm start- Start production server
- npm run lint- Run ESLint
- npm run lint:fix- Fix ESLint issues
- npm run type-check- Run TypeScript type checking
- npm run db:migrate- Run database migrations
- npm run security:scan- Run npm security audit
- npm run restart:prod- Restart PM2 process
- npm run pm2:restart- Build and restart PM2
pm.acme.cn/
βββ src/
β   βββ app/                    # Next.js App Router pages
β   β   βββ admin/             # Admin panel routes
β   β   β   βββ dashboard/     # Analytics dashboard
β   β   β   βββ orders/        # Order management
β   β   β   βββ products/      # Product management
β   β   β   βββ users/         # User management
β   β   β   βββ attachments/   # File management
β   β   βββ api/               # API routes
β   β   β   βββ auth/          # Authentication endpoints
β   β   β   βββ orders/        # Order CRUD operations
β   β   β   βββ products/      # Product CRUD operations
β   β   β   βββ users/         # User management APIs
β   β   β   βββ attachments/   # File upload/download
β   β   βββ login/             # Login page
β   βββ components/
β   β   βββ ui/                # Reusable UI components
β   β   βββ examples/          # Example components
β   βββ contexts/              # React contexts
β   β   βββ auth-context.tsx   # Authentication state
β   β   βββ use-products.tsx   # Product data hooks
β   βββ lib/
β       βββ auth/              # Authentication utilities
β       βββ db/                # Database layer
β       β   βββ migrations/    # Database migrations
β       β   βββ table_*.ts     # Table definitions
β       βββ config/            # Configuration
β       βββ confluence/        # External integrations
βββ uploads/                   # File storage directory
βββ public/                    # Static assets
The application uses OAuth 2.0 flow with JWT tokens:
- User initiates login
- Redirected to OAuth provider
- Callback receives authorization code
- Exchange code for access token
- JWT token issued for session management
The application manages the following main entities:
- Users: User accounts and profiles
- Products: IoT product catalog with firmware info
- Orders: Customer orders with status tracking
- Attachments: File uploads with secure storage
- OAuth States: OAuth flow state management
- 
Build the application npm run build 
- 
Start with PM2 pm2 start ecosystem.config.js 
- 
Monitor pm2 status pm2 logs pm.acme.cn 
The project includes:
- ecosystem.config.js- PM2 configuration
- pm.acme.cn.conf- Nginx configuration template
Run tests with:
npm test- Input validation with Zod schemas
- XSS protection with DOMPurify
- SQL injection prevention via parameterized queries (Kysely)
- JWT-based authentication
- File upload validation
- Regular security audits via npm run security:scan
- GET /api/auth/authorize-url- Get OAuth authorization URL
- GET /api/auth/callback- OAuth callback handler
- GET /api/auth/user- Get current user
- POST /api/auth/logout- Logout
- GET /api/products- List products
- POST /api/products- Create product
- GET /api/products/[id]- Get product
- PUT /api/products/[id]- Update product
- DELETE /api/products/[id]- Delete product
- GET /api/products/spider-firmware- Fetch firmware info
- GET /api/orders- List orders
- POST /api/orders- Create order
- GET /api/orders/[id]- Get order
- PUT /api/orders/[id]- Update order
- DELETE /api/orders/[id]- Delete order
- POST /api/orders/bulk- Bulk operations
- GET /api/users- List users
- POST /api/users- Create user
- PUT /api/users/[id]- Update user
- GET /api/attachments- List attachments
- POST /api/attachments- Upload file
- GET /api/attachments/[id]- Get attachment info
- DELETE /api/attachments/[id]- Delete attachment
- GET /api/attachments/download/[hash]- Download file
- Fork the repository
- Create a feature branch (git checkout -b feature/amazing-feature)
- Commit your changes (git commit -m 'Add amazing feature')
- Push to the branch (git push origin feature/amazing-feature)
- Open a Pull Request
This project includes GitLab CI/CD configuration for automated testing and deployment.
- Enable GitLab runner for your project
- Configure CI/CD variables in GitLab (Settings β CI/CD β Variables)
- Push to mainordevelopbranch
- CI/CD Setup Guide - Complete setup instructions
- Quick Reference - Common commands and workflows
- PM2: Traditional deployment with PM2 process manager
- Docker: Containerized deployment with Docker Compose
- GitLab CI/CD: Automated deployment pipeline
For detailed instructions, see CI-CD-SETUP.md.
Copyright Β© 2025 ACME IoT. All rights reserved.
Ensure PostgreSQL is running and environment variables are correctly set.
Change the port in package.json scripts or kill the process using port 3080:
lsof -ti:3080 | xargs kill -9Clear Next.js cache:
rm -rf .next
npm run buildFor issues and questions, please open an issue in the repository.
Built with β€οΈ using Next.js and TypeScript