Skip to content

Sundhar22/Data-entry

Repository files navigation

Data Entry Application

A comprehensive agricultural data management system built with Next.js, designed for commissioners to manage farmers, products, auctions, and bills in agricultural markets.

πŸš€ Features

  • 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

πŸ› οΈ Tech Stack

  • 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

πŸ“¦ Installation

Prerequisites

  • Node.js 18 or higher
  • PostgreSQL database
  • pnpm package manager

Setup Steps

  1. Clone the repository
git clone <repository-url>
cd data-entry
  1. Install dependencies
pnpm install
  1. Environment Configuration Create a .env.local file 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"
  1. Database Setup
# Generate Prisma client
pnpm prisma generate

# Run database migrations
pnpm prisma migrate dev

# Seed the database (optional)
pnpm prisma db seed
  1. Start Development Server
pnpm dev

Open http://localhost:3000 to view the application.

πŸ—οΈ Project Structure

β”œβ”€β”€ 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

πŸ“š Documentation

Comprehensive documentation is available in the doc/ directory:

πŸ” Authentication

The application uses JWT-based authentication with the following flow:

  1. Users login with email/password
  2. Server returns JWT tokens as httpOnly cookies
  3. Tokens are automatically included in subsequent requests
  4. System handles token refresh automatically

API Authentication

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.txt

πŸ§ͺ Testing

API Testing

Use 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"}'

Database Testing

# View data in Prisma Studio
pnpm prisma studio

# Reset database (development only)
pnpm prisma migrate reset

πŸš€ Deployment

Quick Deployment with Docker

# Build and run with Docker Compose
docker-compose up -d

# Run migrations
docker-compose exec app pnpm prisma migrate deploy

Manual Deployment

# Build the application
pnpm build

# Start production server
pnpm start

For detailed deployment instructions, see the Deployment Guide.

πŸ“Š Database Schema

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.

πŸ›‘οΈ Security Features

  • 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

πŸ“ˆ Performance Features

  • Server-side rendering with Next.js
  • Database query optimization with Prisma
  • Image optimization
  • Font optimization
  • Compression enabled
  • Caching strategies

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

For support and questions:

  1. Check the documentation first
  2. Search existing issues
  3. Create a new issue with detailed information
  4. Include error messages, logs, and reproduction steps

πŸ”— Links


Built with ❀️ using Next.js, TypeScript, and modern web technologies.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages