Welcome to AdtFoods, a modern full-stack food ordering application designed specifically for campus environments. Built with React Native (Expo) for the mobile frontend and Node.js/Express for the backend, this platform makes ordering food from campus restaurants a breeze!
- Browse Restaurants: Explore all available campus restaurants and their menus
- Smart Menu Discovery: View detailed food items with prices, descriptions, and availability
- Easy Ordering: Add items to cart and place orders with just a few taps
- Order Tracking: Monitor your order status in real-time with OTP verification
- Secure Payments: Integrated with Razorpay for safe online transactions
- Order History: Keep track of all your past orders
- Menu Management: Update food item availability on the fly
- Order Management: View and process incoming orders
- Status Updates: Mark orders as ready for pickup
- Redis Caching: Lightning-fast response times for frequently accessed data
- Optimized Queries: Efficient database operations with MongoDB
- Graceful Degradation: App works seamlessly even without Redis
- Framework: React Native with Expo
- Navigation: Expo Router
- State Management: React Context API
- Styling: NativeWind (Tailwind CSS for React Native)
- HTTP Client: Axios
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with Mongoose ODM
- Caching: Redis (optional but recommended)
- Authentication: JWT (JSON Web Tokens)
- Payment Gateway: Razorpay
βββββββββββββββββββ
β Mobile App β
β (React Native) β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β API Server β
β (Express.js) β
ββββββ¬ββββββββ¬βββββ
β β
βΌ βΌ
βββββββββββ ββββββββββββ
β MongoDB β β Redis β
β (Data) β β (Cache) β
βββββββββββ ββββββββββββ
Before you begin, ensure you have the following installed:
- Node.js (v16 or higher) - Download
- MongoDB (v5 or higher) - Download
- Redis (optional) - Download
- Expo CLI - Install with:
npm install -g expo-cli - Git - Download
-
Clone the Repository
git clone https://github.com/Surya2004-janardhan/AdtFoods.git cd AdtFoods -
Install Dependencies
npm install
-
Set Up Environment Variables
# Copy the example environment file cp .env.example .env # Edit .env with your actual configuration # Use your favorite text editor (nano, vim, or VS Code) nano .env
Important Configuration Notes:
- Set
MONGO_URIto your MongoDB connection string - Set
JWT_SECRETto a strong random string - Configure Redis (optional but recommended for better performance)
- Add your Razorpay credentials for payment functionality
- Set
-
Start MongoDB (if running locally)
# On macOS/Linux mongod # On Windows # Start MongoDB service from Services panel
-
Start Redis (optional but recommended)
# On macOS/Linux redis-server # On Windows # Start Redis service or use WSL
-
Start the Backend Server
# From the project root node Backend/server.js # Or use nodemon for auto-restart during development npx nodemon Backend/server.js
The server will start on
http://localhost:3500 -
Start the Mobile App
# In a new terminal, from the project root npm start # Then choose your platform: # - Press 'a' for Android # - Press 'i' for iOS # - Press 'w' for Web
All configuration is done through environment variables. See .env.example for a complete list of available options.
MONGO_URI: MongoDB connection stringJWT_SECRET: Secret key for JWT token generation
REDIS_URLorREDIS_HOST: Redis connection details for cachingRAZORPAY_KEY_IDandRAZORPAY_KEY_SECRET: Payment gateway credentialsPORT: Server port (default: 3500)
Redis caching is optional but highly recommended for production use. The application intelligently handles Redis availability:
- β With Redis: Faster response times, reduced database load
- β Without Redis: Full functionality, direct database queries
| Data Type | Cache Duration | Why? |
|---|---|---|
| Food Items | 5 minutes | Menu items don't change frequently |
| Restaurants | 5 minutes | Restaurant list is relatively static |
| Restaurant Menus | 2 minutes | Balance between freshness and performance |
| User Orders | 30 seconds | Recent orders, moderate freshness |
| Order Count | 1 minute | Quick statistics lookup |
| Device Tokens | 10 minutes | Infrequently changing notification data |
The system automatically clears relevant caches when data changes:
- Creating/updating orders β Clears order and order-count caches
- Updating food availability β Clears food items and menu caches
- Saving device tokens β Clears token caches
This ensures users always see accurate information while maintaining optimal performance!
AdtFoods/
βββ Backend/ # Backend API Server
β βββ config/ # Configuration files
β β βββ database.js # MongoDB connection
β β βββ redis.js # Redis cache setup
β β βββ constants.js # Environment constants
β βββ controllers/ # Business logic
β β βββ authController.js # Authentication
β β βββ foodController.js # Food & restaurant management
β β βββ orderController.js # Order processing
β β βββ paymentController.js # Payment handling
β βββ middleware/ # Express middleware
β β βββ auth.js # JWT authentication
β β βββ cache.js # Redis caching logic
β β βββ errorHandler.js # Error handling
β β βββ validateRequest.js # Input validation
β βββ models/ # Database schemas
β β βββ User.js
β β βββ FoodItem.js
β β βββ Restaurant.js
β β βββ Order.js
β β βββ Token.js
β βββ routes/ # API routes
β β βββ authRoutes.js
β β βββ foodRoutes.js
β β βββ orderRoutes.js
β β βββ paymentRoutes.js
β βββ server.js # Entry point
βββ app/ # React Native app screens
βββ components/ # Reusable UI components
βββ context/ # React Context providers
βββ .env.example # Environment template
βββ package.json # Dependencies
βββ README.md # You are here!
POST /login- User loginPOST /signup- User registrationGET /verify- Verify JWT tokenGET /get-token- Get device token (cached)POST /save-token- Save device token
GET /restaurants- List all restaurants (cached 5 min)GET /restaurants/:id- Get restaurant details (cached 5 min)GET /restaurants/:restaurantId/menu- Get restaurant menu (cached 2 min)GET /food-items- List all food items (cached 5 min)PUT /food-items/:id- Update food item (staff only)
GET /orders- Get all orders (staff only, cached 30 sec)GET /orders/:userId- Get user orders (cached 30 sec)POST /orders- Create new orderPUT /orders/:id/status- Update order status (staff only)GET /orders/count- Get total order count (cached 1 min)
POST /create-order- Create Razorpay orderPOST /verify-payment- Verify payment signature
GET /health- System health status (includes Redis status)
curl http://localhost:3500/healthThis returns comprehensive system information including:
- Server status and uptime
- MongoDB connection status
- Redis cache status
- Memory usage
- Request details
-
Make a request to a cached endpoint:
curl http://localhost:3500/restaurants
-
Check the server logs - You should see:
β Cache MISS: restaurants:all -
Make the same request again - You should see:
β Cache HIT: restaurants:all
The second request will be significantly faster!
Request β Is Redis Available?
β
ββ No β Fetch from Database β Return to User
β
ββ Yes β Check Cache
β
ββ Cache HIT β Return Cached Data β¨ (Fast!)
β
ββ Cache MISS β Fetch from Database
β Store in Cache
β Return to User
- User signs up β Account created in MongoDB
- User logs in β JWT token generated and returned
- User makes requests β Token verified by middleware
- Protected routes β Require valid JWT token
- User browses menu (cached for performance)
- User adds items to cart
- User proceeds to checkout
- Payment processed via Razorpay
- Order created with OTP
- Staff sees order
- Staff marks as ready
- User picks up order with OTP verification
"MongoDB connection error"
- Ensure MongoDB is running:
mongodor check your cloud MongoDB service - Verify
MONGO_URIin.envis correct
"Redis not configured - running without cache"
- This is just a warning! The app works fine without Redis
- To enable Redis: Install and start Redis, then configure in
.env
"Port 3500 already in use"
- Change the
PORTin.envto another port like 3501 - Or kill the process using port 3500
Mobile app can't connect to backend
- If using physical device, ensure both devices are on the same network
- Update API URL in mobile app configuration to use your computer's IP
- Check firewall settings
- Never commit
.envfile - It's in.gitignorefor a reason! - Use strong JWT secrets - Generate random strings for production
- Enable Redis authentication - Set
REDIS_PASSWORDin production - Use HTTPS - Always use SSL/TLS in production
- Sanitize inputs - The app includes input validation middleware
- Regular updates - Keep dependencies up to date
- express - Web framework
- mongoose - MongoDB ODM
- redis - Redis client for caching
- jsonwebtoken - JWT authentication
- razorpay - Payment gateway
- dotenv - Environment variable management
- cors - Cross-origin resource sharing
- morgan - HTTP request logger
- expo - React Native framework
- expo-router - File-based navigation
- axios - HTTP client
- nativewind - Tailwind CSS for React Native
- react-native-razorpay - Payment integration
We welcome contributions! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is part of an academic/campus initiative. Please check with the repository owner for licensing details.
- Built with β€οΈ for campus food lovers
- Powered by open-source technologies
- Inspired by the need for better campus food ordering
Having issues? Here's how to get help:
- Check the Troubleshooting section
- Review the API documentation
- Open an issue on GitHub
- Check server logs for detailed error messages
Happy Ordering! π
Made with π by the AdtFoods Team