Prerequisites
Before you begin, ensure you have the following installed on your system:- Node.js 18+ - Download Node.js
- pnpm 8.6+ - Fast package manager (install with
npm install -g pnpm) - MySQL 8.0+ - Database server Download MySQL
- Git - Version control system
Khedma Market uses pnpm as its package manager. While npm and yarn may work, pnpm is recommended for consistency with the project configuration.
Setup Guide
Follow these steps to get Khedma Market running on your local machine:Clone the repository
Clone the Khedma Market repository from GitHub:This downloads the complete source code to your local machine.
Install dependencies
Install all required packages using pnpm:This command:
- Installs all dependencies from
package.json - Automatically runs
prisma generatevia the postinstall script - Creates the Prisma Client for database access
The installation may take 2-3 minutes depending on your internet connection.
Setup MySQL database
Create a new MySQL database for Khedma Market:
Using the provided start-database.sh script
Using the provided start-database.sh script
The repository includes a This script automates MySQL setup for local development.
start-database.sh script that can help you set up a database quickly:Configure environment variables
Create a Edit the
.env file in the root directory by copying the example file:.env file with your configuration:.env
Environment variable details
Environment variable details
Required:
DATABASE_URL- MySQL connection string (update username/password if different)NEXTAUTH_SECRET- Secret key for NextAuth.js session encryptionNEXTAUTH_URL- Base URL of your application
GITHUB_CLIENT_ID&GITHUB_CLIENT_SECRET- Enable GitHub OAuth loginGOOGLE_CLIENT_ID&GOOGLE_CLIENT_SECRET- Enable Google OAuth loginRESEND_API_KEY- Email service for verification emailsFROM_EMAIL- Sender email address for transactional emails
Generate NEXTAUTH_SECRET
Generate NEXTAUTH_SECRET
Generate a secure secret key using OpenSSL:Copy the output and paste it as your
NEXTAUTH_SECRET value.Setup OAuth providers (Optional)
Setup OAuth providers (Optional)
To enable social login:GitHub OAuth:
- Go to GitHub Developer Settings
- Create a new OAuth App
- Set Authorization callback URL to:
http://localhost:3000/api/auth/callback/github - Copy Client ID and Client Secret to your
.env
- Go to Google Cloud Console
- Create a new project and enable OAuth
- Set Authorized redirect URI to:
http://localhost:3000/api/auth/callback/google - Copy Client ID and Client Secret to your
.env
Run database migrations
Apply all database migrations to create the schema:This command:
- Creates all tables in your MySQL database
- Sets up relationships and indexes
- Applies any pending migrations
You should see output indicating successful migration of tables like users, gigs, orders, conversations, etc.
Alternative: Push schema directly
Alternative: Push schema directly
For rapid development without migrations:This pushes the Prisma schema directly to the database without creating migration files.
Seed the database (Optional)
Seed the database (Optional)
Populate your database with sample data:This runs the seed script at
prisma/seed.ts which can create:- Sample users with different roles
- Example gigs and packages
- Test categories and skills
- Demo conversations and messages
Start the development server
Launch the Next.js development server:The application will start with:
- Next.js server running on
http://localhost:3000 - Turbopack enabled for faster builds
- Hot Module Replacement for instant updates
The first build may take 30-60 seconds. Subsequent builds will be much faster thanks to Turbopack.
Access the application
Open your browser and navigate to:You should see the Khedma Market homepage!
Key pages to explore
Key pages to explore
/- Homepage with marketplace overview/auth/sign-in- Login page with credentials and OAuth options/auth/sign-up- Registration page for new users/dashboard- User dashboard (after authentication)/gigs- Browse available gigs/services/jobs- Job postings from companies
Available Scripts
Here are the most useful npm scripts for development:Project Structure
Understanding the codebase structure:Development Workflow
Troubleshooting
Database connection errors
Database connection errors
Error:
Can't reach database serverSolutions:- Verify MySQL is running:
sudo systemctl status mysql - Check DATABASE_URL in
.envmatches your MySQL credentials - Ensure the database
khedma-marketexists - Try connecting manually:
mysql -u root -p
Port 3000 already in use
Port 3000 already in use
Error:
Port 3000 is already in useSolutions:- Kill the process using port 3000:
- Or use a different port:
Prisma Client errors
Prisma Client errors
Error:
PrismaClient is unable to be run in the browserSolutions:- Make sure you’re importing from
@/server/dbnot@prisma/clientin client components - Regenerate Prisma Client:
pnpm db:generate - Restart the development server
Authentication issues
Authentication issues
Error:
[next-auth][error][NO_SECRET]Solutions:- Ensure
NEXTAUTH_SECRETis set in.env - Generate a new secret:
openssl rand -base64 32 - Verify
NEXTAUTH_URLmatches your local URL
Module not found errors
Module not found errors
Error:
Cannot find module 'xyz'Solutions:- Clear node_modules and reinstall:
- Clear Next.js cache:
Using Prisma Studio
Prisma Studio provides a visual database browser:http://localhost:5555 where you can:
- Browse all database tables
- View, create, update, and delete records
- Test relationships between models
- Execute raw SQL queries
Next Steps
Now that you have Khedma Market running locally:Explore Features
Learn about freelancer profiles, gigs, orders, and messaging
API Documentation
Understand the tRPC API structure and available endpoints
Database Schema
Deep dive into the Prisma schema and data models
User Guides
Role-specific guides for using the platform
Contributing? Check out the CONTRIBUTING.md file in the repository for guidelines on submitting pull requests.