A comprehensive school directory management system built with Next.js, React Hook Form, and MySQL. This project allows users to add schools with detailed information and browse them in a responsive, ecommerce-style grid layout.
- Add School Form: Complete form with validation using react-hook-form
- Image Upload: Upload and store school images with automatic file handling
- Responsive Design: Works seamlessly on desktop, tablet, and mobile devices
- School Directory: Browse schools in a beautiful grid layout
- Form Validation: Email validation, phone number validation, and required field validation
- Modern UI: Clean, professional interface using Tailwind CSS
- Frontend: Next.js 14, React, Tailwind CSS
- Backend: Next.js API Routes
- Database: MySQL
- Form Handling: React Hook Form
- File Upload: Multer with Next.js
- Styling: Tailwind CSS
Before running this project, make sure you have:
- Node.js (version 14 or higher)
- MySQL database server
- npm or yarn package manager
-
Clone the repository
git clone <your-repo-url> cd school-management
-
Install dependencies
npm install
-
Set up the database
- Create a MySQL database named
school_management - Run the SQL schema from
database/schema.sql:
mysql -u your_username -p school_management < database/schema.sql
- Create a MySQL database named
-
Configure environment variables
- Copy
.env.localand update the database credentials:
DB_HOST=localhost DB_USER=your_mysql_username DB_PASSWORD=your_mysql_password DB_NAME=school_management
- Copy
-
Run the development server
npm run dev
-
Open your browser Navigate to http://localhost:3000
school-management/
βββ src/
β βββ app/
β β βββ addSchool/
β β β βββ page.js # Add school form page
β β βββ showSchools/
β β β βββ page.js # Display schools page
β β βββ api/
β β β βββ schools/
β β β βββ route.js # API endpoints for schools
β β βββ globals.css # Global styles
β β βββ layout.js # App layout
β β βββ page.js # Home page
βββ lib/
β βββ db.js # Database connection
βββ public/
β βββ schoolImages/ # Uploaded school images
βββ database/
β βββ schema.sql # Database schema
βββ .env.local # Environment variables
βββ README.md
- Landing page with navigation to other features
- Overview of system capabilities
- Quick access buttons to add or view schools
- Comprehensive form with the following fields:
- School Name (required)
- Address (required)
- City (required)
- State (required)
- Contact Number (required, 10 digits)
- Email Address (required, valid email format)
- School Image (optional)
- Form validation using react-hook-form
- Image upload functionality
- Success/error messaging
- Grid layout displaying all schools
- Each school card shows:
- School image (or placeholder)
- School name
- Address
- City and state
- Responsive design (1-4 columns based on screen size)
- Loading states and error handling
Add a new school to the database.
Request Body (FormData):
name: School nameaddress: School addresscity: Citystate: Statecontact: Contact numberemail_id: Email addressimage: School image file (optional)
Retrieve all schools from the database.
Response: Array of school objects with all fields.
- Responsive Grid: Adapts from 1 column (mobile) to 4 columns (desktop)
- Modern Cards: Clean card design with hover effects
- Form Validation: Real-time validation with error messages
- Loading States: Proper loading indicators
- Error Handling: User-friendly error messages
- Image Handling: Automatic placeholder for schools without images
- Mobile: 1 column grid (< 640px)
- Tablet: 2 columns grid (640px - 1024px)
- Desktop: 3 columns grid (1024px - 1280px)
- Large Desktop: 4 columns grid (> 1280px)
- Push your code to GitHub
- Connect your repository to Vercel
- Add environment variables in Vercel dashboard
- Deploy automatically
- Netlify: Use for static deployment (API routes won't work)
- Railway: Good for full-stack deployment with database
- Heroku: Traditional deployment option
# Database Configuration
DB_HOST=your_database_host
DB_USER=your_database_username
DB_PASSWORD=your_database_password
DB_NAME=school_management
# Next.js Configuration
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-keyTo test the application:
-
Add a school:
- Go to
/addSchool - Fill out the form with valid data
- Upload an image (optional)
- Submit the form
- Go to
-
View schools:
- Go to
/showSchools - Verify the school appears in the grid
- Check responsive behavior on different screen sizes
- Go to
- 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.
-
Database Connection Error
- Verify MySQL is running
- Check database credentials in
.env.local - Ensure database exists
-
Image Upload Issues
- Check if
public/schoolImagesdirectory exists - Verify file permissions
- Ensure file size is reasonable
- Check if
-
Build Errors
- Run
npm installto ensure all dependencies are installed - Check for any TypeScript/JavaScript syntax errors
- Run
If you encounter any issues or have questions, please:
- Check the troubleshooting section above
- Review the GitHub issues
- Create a new issue with detailed information