A Next.js 15 admin-only application providing API endpoints and management interface for hardware inventory. Designed to serve as the backend for a Symfony frontend application.
HardwareHouse Admin API is a comprehensive hardware inventory management system that provides:
- Admin Dashboard: Complete inventory management interface for authorized administrators
- REST API: Endpoints for external Symfony application integration
- Authentication: Clerk-based admin authentication and authorization
- Database Management: MongoDB with Prisma ORM for reliable data persistence
This application is not a public store - it's an internal management system that serves API data to an external Symfony application.
βββββββββββββββββββββββ HTTP API ββββββββββββββββββββββββ
β Symfony Frontend β ββββββββββββββββΊ β HardwareHouse API β
β (Public Store) β REST Calls β (Admin Backend) β
βββββββββββββββββββββββ ββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β MongoDB β
β (Database) β
ββββββββββββββββββββββββ
- Next.js 16.1.7 - React framework with App Router for admin interface and API routes
- React 19.2.3 - UI library for admin dashboard
- TypeScript 5 - Type-safe development
- MongoDB - NoSQL database for inventory data
- Prisma 6.19 - Database ORM and query builder
- Clerk - Admin-only authentication system
@clerk/nextjs: ^7.0.5@clerk/localizations: ^3.34.0
- Tailwind CSS 4 - Utility-first CSS framework
- Radix UI - Accessible admin interface components
- Lucide React 0.545.0 - Consistent iconography
- TanStack Table 8.21.3 - Advanced data table management
- React Hook Form 7.64.0 + Zod 4.1.12 - Form handling and validation in admin
- SWR - Data fetching and caching
hardwarehouse-api/
βββ app/
β βββ (admin)/ # Admin dashboard routes (protected)
β β βββ admin/
β β β βββ brands/ # Brand management pages
β β β βββ categories/ # Category management pages
β β β βββ products/ # Product management pages
β β β βββ discounts/ # Discount management system
β β β βββ stocks/ # Stock management pages
β β β βββ purchase-orders/ # Purchase order management
β β β βββ transactions/ # Transaction tracking
β β β βββ users/ # User management
β β βββ (site)/ # Public auth pages
β βββ api/v1/ # Versioned REST API endpoints
β βββ brands/ # Brand API routes
β βββ categories/ # Category API routes
β βββ products/ # Product API routes
β βββ discounts/ # Discount API routes
β βββ stocks/ # Stock API routes
β βββ transactions/ # Transaction API routes
β βββ users/ # User API routes
β βββ upload/ # File upload endpoints
β βββ stats/ # Analytics endpoints
βββ components/
β βββ admin/ # Admin dashboard components
β β βββ discounts/ # Discount management components
β β βββ ... # Other admin components
β βββ ui/ # Reusable UI components
βββ lib/
β βββ api/ # API utilities & error handling
β βββ discounts/ # Discount business logic
β βββ validators/ # Zod schema validators
β βββ ... # Other utilities
βββ services/ # Service layer for API calls
β βββ discount.service.ts # Discount service
β βββ ... # Other services
βββ scripts/ # Background scripts
β βββ sync-discounts.ts # Discount sync cron job
βββ prisma/ # Database schema and seeds
βββ ecosystem.config.js # PM2 configuration for cron jobs
βββ middleware.ts # Clerk auth middleware
- Admin Login: Only authorized users (configured in Clerk) can access the system
- Protected Routes: All admin routes require authentication
- API Access: External API calls from Symfony app (may require API key authentication)
- Create, read, update, delete brands
- Manage product categories and hierarchies
- Full product catalog management
- Real-time stock level management
- View analytics and reports
GET /api/v1/brands # List all brands
POST /api/v1/brands # Create new brand
GET /api/v1/brands/[slug] # Get brand details
PATCH /api/v1/brands/[slug] # Update brand
DELETE /api/v1/brands/[slug] # Delete brand
GET /api/v1/brands/[slug]/products # Get brand products
GET /api/v1/categories # List all categories
POST /api/v1/categories # Create new category
GET /api/v1/categories/[slug] # Get category details
PATCH /api/v1/categories/[slug] # Update category
DELETE /api/v1/categories/[slug] # Delete category
GET /api/v1/categories/[slug]/products # Get category products
GET /api/v1/categories/[slug]/attributes # Get category attributes
GET /api/v1/products # List all products
POST /api/v1/products # Create new product
GET /api/v1/products/[slug] # Get product details
PATCH /api/v1/products/[slug] # Update product
DELETE /api/v1/products/[slug] # Delete product
GET /api/v1/discounts # List all discounts
POST /api/v1/discounts # Create new discount
GET /api/v1/discounts/[id] # Get discount details
PATCH /api/v1/discounts/[id] # Update discount
DELETE /api/v1/discounts/[id] # Delete discount
GET /api/v1/discounts/product/[slug] # Get product discounts
GET /api/v1/discounts/category/[slug] # Get category discounts
GET /api/v1/stocks # List all stock levels
POST /api/v1/stocks # Create new stock entry
GET /api/v1/stocks/[id] # Get stock details
PATCH /api/v1/stocks/[id] # Update stock levels
DELETE /api/v1/stocks/[id] # Remove stock entry
GET /api/v1/transactions # List all transactions
POST /api/v1/transactions # Create new transaction
GET /api/v1/transactions/[id] # Get transaction details
DELETE /api/v1/transactions/[id] # Delete transaction
GET /api/v1/transactions/product/[slug] # Get product transactions
GET /api/v1/users # List all users
POST /api/v1/users # Create new user
GET /api/v1/users/[id] # Get user details
PATCH /api/v1/users/[id] # Update user
DELETE /api/v1/users/[id] # Delete user
GET /api/v1/users/[id]/orders # Get user orders
GET /api/v1/users/[id]/transactions # Get user transactions
GET /api/v1/stats/product # Product statistics
GET /api/v1/stats/product/[id] # Specific product stats
GET /api/v1/stats/stock # Stock statistics
POST /api/v1/upload/brands/[slug] # Upload brand images
POST /api/v1/upload/categories/[slug] # Upload category images
POST /api/v1/upload/products/[slug] # Upload product images
GET /api/v1/upload/products/[slug]/[filename] # Get product image
- Node.js 20+
- MongoDB instance
- Clerk account with admin users configured
git clone <repository-url>
cd hardwarehouse-api
npm installcp .env.example .env.localConfigure these variables:
NODE_ENV="development"
DATABASE_URL="mongodb+srv://user:pass@host/dbname"
# Clerk Admin Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key
# API Configuration for Symfony integration
NEXT_PUBLIC_API_URL=http://localhost:3000/api
API_KEY=your_secure_api_key_for_symfonynpm run db:generate # Generate Prisma client
npm run db:push # Create database schema
npm run db:seed # Populate with initial data- Go to your Clerk dashboard
- Add authorized admin email addresses
- Configure authentication settings
- Set up admin role permissions
npm run dev- Admin Dashboard: http://localhost:3000
- API Base URL: http://localhost:3000/api
| Script | Purpose |
|---|---|
npm run dev |
Start development server |
npm run build |
Build for production |
npm start |
Start production server |
npm run lint |
Code quality checks |
npm run test |
Run unit tests |
npm run cypress:open |
Open E2E testing |
npm run db:generate |
Generate Prisma client |
npm run db:push |
Update database schema |
npm run db:studio |
Open database GUI |
npm run db:seed |
Populate test data |
npm run db:reset |
Reset database completely |
The application includes an automated background service that manages discount lifecycle:
# Start both the main app and cron job
pm2 start ecosystem.config.js
# Monitor processes
pm2 status
pm2 logs- Automatic Activation: Activates discounts when their start date is reached
- Automatic Expiration: Deactivates discounts when their end date passes
- Price Recalculation: Updates product prices in real-time
- Error Handling: Robust error handling with logging
- Performance: Parallel processing for bulk operations
# Run sync script manually
npx tsx scripts/sync-discounts.ts- Error logs:
./logs/cron-error.log - Output logs:
./logs/cron-out.log - Sync frequency: Every 1 minute (configurable)
# Build and run the application
docker compose up --buildThe application will be available at http://localhost:3333
Option 1: Docker Compose (Recommended)
docker compose up --buildOption 2: Manual Docker Build
# Build the image
docker build -t hardwarehouse-admin .
# Run the container
docker run -p 3333:3333 hardwarehouse-adminOption 3: Multi-platform Build (for cloud deployment)
# Build for different CPU architecture (e.g., Mac M1 to amd64 cloud)
docker build --platform=linux/amd64 -t hardwarehouse-admin .
# Push to registry
docker push myregistry.com/hardwarehouse-adminNODE_ENV="production"
DATABASE_URL="your_production_mongodb_url"
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="prod_clerk_key"
CLERK_SECRET_KEY="prod_clerk_secret"
API_KEY="secure_production_api_key"π For detailed Docker instructions and cloud deployment guide, see README.Docker.md
Include the API key in your Symfony HTTP requests:
// In your Symfony service
$response = $this->httpClient->request('GET', 'http://your-admin-api.com/api/products', [
'headers' => [
'Authorization' => 'Bearer ' . $this->apiKey,
'Content-Type' => 'application/json'
]
]);{
"success": true,
"data": [
{
"id": "product_id",
"name": "Product Name",
"slug": "product-slug",
"brand": "Brand Name",
"category": "Category Name",
"price": 99.99,
"discountedPrice": 79.99,
"stock": 50,
"sku": "SKU12345",
"mpn": "MPN67890",
"ean13": "1234567890123",
"promote": true,
"createdAt": "2024-01-01T00:00:00Z"
}
],
"pagination": {
"page": 1,
"limit": 20,
"total": 100
}
}- Brands: Manufacturer information
- Categories: Product categorization (hierarchical)
- Products: Complete product catalog with SKU/MPN/EAN13
- Discounts: Time-based discounts for products/categories
- Stocks: Inventory levels and tracking
- Transactions: Stock movement history
- Users: Customer management
- Purchase Orders: Procurement tracking
Brands (1) ββββββββββββ (N) Products
Categories (1) ββββββββ (N) Products
Products (1) ββββββββββββ (1) Stock
Products (1) ββββββββββββ (N) Discounts
Categories (1) βββββββββββ (N) Discounts
Products (1) ββββββββββββ (N) Transactions
Users (1) βββββββββββββββ (N) Transactions
Last Updated: March 2026
- Complete discount infrastructure with time-based activation/expiration
- Product & Category discounts - Apply discounts to individual products or entire categories
- Automated discount sync - Background cron job automatically activates/deactivates discounts
- Real-time price calculation - Products automatically show discounted prices when applicable
- Admin interface - Full CRUD operations with form validation and error handling
- Product identification codes - Added SKU, MPN, and EAN13 fields
- Product promotion flags - Mark products as promoted for featured display
- Improved seeding - Enhanced database seeder with realistic product data
- API versioning - All endpoints now use
/api/v1/structure - Enhanced error handling - Centralized error handling with proper HTTP status codes
- File upload system - Image upload endpoints for brands, categories, and products
- Analytics endpoints - Product and stock statistics API
- User management - Complete user CRUD with order/transaction tracking
- PM2 ecosystem - Production-ready process management configuration
- Automated discount sync - Cron job runs every minute to sync discount states
- Logging system - Proper logging for background processes with rotation
- TypeScript strict mode - Enhanced type safety across the application
- Zod validation - Comprehensive input validation for all forms and API endpoints
- Centralized error handling - Consistent error responses across all API endpoints
- Enhanced development scripts - Improved database management and development workflow
- API endpoints moved from
/api/to/api/v1/ - All PATCH operations now use proper HTTP PATCH instead of PUT
- Enhanced validation requires specific data formats for all inputs
- Fixed TypeScript compilation issues in discount form components
- Improved form validation with proper error messages
- Enhanced database seeder with more realistic data
- Fixed redirect timing issues after CRUD operations
- Improved toast notification system
- Admin-Only Access: No public routes or user registration
- API Authentication: Secure API key validation for external calls
- Data Validation: Comprehensive input validation using Zod
- CORS Configuration: Restricted to authorized domains
- Environment Variables: All sensitive data in environment variables
Admins are managed through Clerk:
- Add Admin: Invite users through Clerk dashboard
- Role Assignment: Configure admin permissions
- Access Control: Middleware handles route protection
- Session Management: Automatic session handling via Clerk
MIT License - Internal use only for HardwareHouse inventory management.
Note: This application is designed specifically as an admin backend for a Symfony frontend. It does not include public-facing store functionality.