A comprehensive agricultural data management system built with Next.js, designed for commissioners to manage farmers, products, auctions, and bills in agricultural markets.
- Authentication System: Secure JWT-based authentication with automatic token refresh
- Farmer Management: Complete CRUD operations for farmer profiles
- Product Catalog: Manage agricultural products with categories and units
- Commissioner Profiles: User profile management with commission rates
- Auction System: Manage auction sessions and items (in development)
- Bill Generation: Generate and manage bills for farmers (in development)
- Real-time Validation: Client and server-side validation using Zod
- Responsive Design: Mobile-first responsive UI with Tailwind CSS
- Database Integration: PostgreSQL with Prisma ORM
- API Documentation: Comprehensive API documentation
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
- Backend: Next.js API Routes, Node.js
- Database: PostgreSQL with Prisma ORM
- Authentication: JWT with httpOnly cookies
- Validation: Zod schemas
- Styling: Tailwind CSS
- Package Manager: pnpm
- Node.js 18 or higher
- PostgreSQL database
- pnpm package manager
- Clone the repository
git clone <repository-url>
cd data-entry- Install dependencies
pnpm install- Environment Configuration
Create a
.env.localfile in the root directory:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/data_entry"
# JWT Secrets
JWT_SECRET="your-super-secret-jwt-key-here"
JWT_REFRESH_SECRET="your-super-secret-refresh-key-here"
# Application
NODE_ENV="development"
NEXTAUTH_URL="http://localhost:3000"- Database Setup
# Generate Prisma client
pnpm prisma generate
# Run database migrations
pnpm prisma migrate dev
# Seed the database (optional)
pnpm prisma db seed- Start Development Server
pnpm devOpen http://localhost:3000 to view the application.
βββ src/
β βββ app/ # Next.js App Router
β β βββ (routes)/
β β β βββ api/ # API endpoints
β β β βββ auth/ # Authentication endpoints
β β β βββ farmers/ # Farmer management
β β β βββ products/ # Product management
β β β βββ commissioner/ # Commissioner management
β β βββ layout.tsx # Root layout
β β βββ page.tsx # Home page
β βββ components/ # React components
β β βββ ui/ # Reusable UI components
β β βββ layout/ # Layout components
β βββ hooks/ # Custom React hooks
β βββ lib/ # Utility libraries
β βββ schemas/ # Zod validation schemas
β βββ types/ # TypeScript type definitions
β βββ styles/ # Global styles
βββ prisma/ # Database schema and migrations
βββ doc/ # Documentation
βββ public/ # Static assets
Comprehensive documentation is available in the doc/ directory:
- API Overview - Complete API documentation
- Authentication Guide - Authentication system details
- Farmers API - Farmer management endpoints
- Products API - Product management endpoints
- Commissioner API - Commissioner endpoints
- Validation Guide - Zod validation system
- Error Handling - Error handling patterns
- Data Models - Database models and types
- Frontend Components - React components guide
- Deployment Guide - Deployment instructions
The application uses JWT-based authentication with the following flow:
- Users login with email/password
- Server returns JWT tokens as httpOnly cookies
- Tokens are automatically included in subsequent requests
- System handles token refresh automatically
All protected endpoints require authentication cookies:
# Login first
curl -X POST "http://localhost:3000/api/auth/login" \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "password"}' \
-c cookies.txt
# Use cookies for protected endpoints
curl -X GET "http://localhost:3000/api/farmers" -b cookies.txtUse the provided test flows in the API documentation:
# 1. Login to get authentication cookies
curl -X POST "http://localhost:3000/api/auth/login" \
-H "Content-Type: application/json" \
-d '{"email": "test@example.com", "password": "password"}' \
-c cookies.txt
# 2. Test farmer endpoints
curl -X GET "http://localhost:3000/api/farmers" -b cookies.txt
curl -X POST "http://localhost:3000/api/farmers" \
-H "Content-Type: application/json" \
-b cookies.txt \
-d '{"name": "Test Farmer", "phone": "1234567890", "village": "Test Village"}'# View data in Prisma Studio
pnpm prisma studio
# Reset database (development only)
pnpm prisma migrate reset# Build and run with Docker Compose
docker-compose up -d
# Run migrations
docker-compose exec app pnpm prisma migrate deploy# Build the application
pnpm build
# Start production server
pnpm startFor detailed deployment instructions, see the Deployment Guide.
The application uses PostgreSQL with the following main entities:
- Commissioner: Users who manage the system
- Farmer: Agricultural producers registered by commissioners
- Product: Agricultural products available in the system
- AuctionSession: Auction events conducted by commissioners
- AuctionItem: Individual items sold in auctions
- Bill: Bills generated for farmers
- Buyer: Purchasers at auctions
See Data Models for complete schema details.
- JWT authentication with secure httpOnly cookies
- Password hashing with bcrypt
- Request validation with Zod schemas
- SQL injection prevention with Prisma
- CORS protection
- Rate limiting (configurable)
- Environment-based configuration
- Server-side rendering with Next.js
- Database query optimization with Prisma
- Image optimization
- Font optimization
- Compression enabled
- Caching strategies
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Check the documentation first
- Search existing issues
- Create a new issue with detailed information
- Include error messages, logs, and reproduction steps
Built with β€οΈ using Next.js, TypeScript, and modern web technologies.