Welcome to the backend API of FoodHub – a comprehensive food delivery and restaurant management platform. This server is built using modern web technologies to ensure scalability, robust performance, and type safety.
- Framework: Express.js (Node.js)
- Language: TypeScript
- ORM: Prisma
- Database: PostgreSQL
- Validation: Zod
- Authentication: JWT (JSON Web Tokens) & bcrypt
The server follows a modular architecture. Core functionalities are divided into distinct domains:
- User / Admin: Authentication, authorization, and administrative controls.
- Provider / Restaurant: Management of restaurant details and profiles.
- Category: Categorization of food items.
- Meal: Endpoints for adding, updating, and fetching food items.
- Cart: Shopping cart management for users.
- Order: Order placement, tracking, and status updates.
- Review: Customer ratings and reviews for meals/providers.
- Favorite: Users' favorite meals or restaurants.
Make sure you have the following installed on your machine:
- Node.js (v16 or higher)
- PostgreSQL (Running locally or via a cloud provider)
git clone <repository-url>
cd foodHub-servernpm installCreate a .env file in the root directory and configure the following variables (use .env.example if available):
PORT=5000
DATABASE_URL="postgresql://user:password@localhost:5432/foodhub?schema=public"
JWT_SECRET="your_super_secret_jwt_key"
JWT_EXPIRES_IN="7d"Generate the Prisma Client and push the schema to your database:
npx prisma generate
npx prisma db push(Optional) If you have seed data configured:
npm run seedFor Development (Auto-restarts on save):
npm run devFor Production:
npm run build
npm start- main: Production-ready and stable code. Only tested and reviewed changes are merged here.
- dev: Active development branch. All new features and fixes should be developed on top of this branch.
Typical workflow:
- Checkout the
devbranch:git checkout dev - (Optional) Create a feature branch from
dev:git checkout -b feature/<feature-name> - Work on your changes and commit them.
- Merge your feature branch back into
dev. - After testing,
devis merged intomainfor release.
npm run dev: Starts the server in development mode usingts-node-dev.npm run build: Compiles TypeScript files into thedistfolder.npm start: Runs the compiled server fromdist/server.js.npm run lint: Checks for linting errors using ESLint.npm run lint:fix: Fixes auto-correctable linting errors.npm run format: Formats code using Prettier.npm run seed: Populates the database with initial seed data.
The API uses Bearer tokens (JWT) for secure routes.
- Ensure you pass the token in the
Authorizationheader:Bearer <your_token> - Different roles (e.g.,
user,admin,provider) have distinct access controls enforced via middleware.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.