Skip to content

parth-476/backend001

Repository files navigation

🚨 CrisisBrain - Disaster Management Backend System

A Complete Backend Evaluation Project Covering All Syllabus Topics

Node.js Express License


📚 Syllabus Coverage

This project implements ALL topics from your backend course syllabus:

✅ Lectures 1-4: Client-Server Architecture

  • Understanding request-response cycle
  • Client-side (HTML/JS) and Server-side (Node.js) implementation
  • HTTP communication basics

✅ Lectures 5-8: File Handling & Environment

  • Node.js installation and setup
  • File system operations (fs module)
  • File dependency management
  • JSON file-based storage

✅ Lectures 9-12: Node.js Understanding

  • Advantages: JavaScript everywhere, non-blocking I/O, NPM ecosystem
  • Disadvantages: CPU-intensive tasks, callback management
  • Real-world application examples

✅ Lectures 13-16: HTTP Module & Endpoints

  • Native HTTP module server (basic-http-server.js)
  • Creating endpoints without frameworks
  • Request handling and body parsing
  • Module imports and NPM usage

✅ Lectures 17-20: Express Framework

  • Express.js setup and configuration
  • Middleware implementation
  • Simplified routing
  • Framework advantages

✅ Lectures 21-24: Advanced Routing & File Streaming

  • All HTTP methods (GET, POST, PUT, DELETE, PATCH)
  • Route parameters and query strings
  • Static file serving
  • File streaming implementation
  • Global exception handling

🎯 Project Purpose

A full-stack disaster management platform demonstrating practical backend concepts through a real-world crisis response system.

Key Features:

  • 📝 Submit disaster reports
  • 🎯 Predict high-risk zones
  • 🚨 Generate emergency alerts
  • 🆘 Suggest resource allocation
  • 🎮 Run disaster simulations

🚀 Quick Start

Prerequisites

  • Node.js v18 or higher
  • npm (comes with Node.js)

Installation

# Install dependencies
npm install

# Start Express server (Port 3000)
npm start

# OR start HTTP module server (Port 4000)
npm run start:http

Access the Application


📂 Project Structure

Crisis/
├── 📄 server.js                    # Express Framework Server (Lectures 17-24)
├── 📄 basic-http-server.js         # HTTP Module Server (Lectures 13-16)
├── 📄 package.json                 # NPM Configuration
│
├── 📁 data/
│   └── reports.json                # File-based Database (Lectures 5-8)
│
├── 📁 public/                      # Static Files (Lectures 21-24)
│   ├── index.html                  # Frontend Interface
│   ├── app.js                      # Client JavaScript
│   ├── style.css                   # Modern UI Styling
│   └── report-guide.html           # Documentation Page
│
├── 📁 src/modules/                 # Custom Modules (Lectures 13-16)
│   ├── dataStore.js                # CRUD Operations & File Handling
│   ├── riskEngine.js               # Risk Prediction Logic
│   ├── alertEngine.js              # Alert Generation
│   └── logger.js                   # Request Logging Middleware
│
└── 📁 Documentation/
    ├── BACKEND_GUIDE.md            # Complete Technical Documentation
    ├── BACKEND_GUIDE_HINGLISH.md   # Hinglish Explanation
    └── API_TESTING_GUIDE.md        # API Testing Reference

🔥 API Endpoints

Health & Info

GET  /api/health              # Server health check

CRUD Operations (Lectures 21-24)

GET    /api/disasters         # Get all reports
GET    /api/disasters/:id     # Get single report
POST   /api/reports           # Create new report
PUT    /api/reports/:id       # Update entire report
PATCH  /api/reports/:id       # Partial update
DELETE /api/reports/:id       # Delete report

Risk Analysis

GET  /api/risk-zones          # Predict high-risk zones
POST /api/alerts/test         # Generate alert
POST /api/resources/suggest   # Resource allocation
POST /api/simulate            # Run emergency drill

File Streaming (Lecture 21-24)

GET  /report-guide            # Stream HTML file

👉 Full API documentation: See API_TESTING_GUIDE.md


📖 Documentation Files

1. BACKEND_GUIDE.md (English)

Complete technical documentation covering:

  • All syllabus topics explained
  • Code examples with explanations
  • Module structure breakdown
  • Interview Q&A

2. BACKEND_GUIDE_HINGLISH.md (Hindi/Urdu)

Easy-to-understand explanation in Hinglish:

  • Har topic ka simple explanation
  • Code examples with Hindi comments
  • Testing guide
  • Exam preparation tips

3. API_TESTING_GUIDE.md

Comprehensive API testing reference:

  • All endpoints with examples
  • Postman/Thunder Client usage
  • cURL commands
  • PowerShell testing
  • Error handling examples

🧪 Testing the Backend

Using Browser (GET requests only)

http://localhost:3000/api/health
http://localhost:3000/api/disasters

Using Postman/Thunder Client

Create Report:

POST http://localhost:3000/api/reports
Content-Type: application/json

{
  "zone": "Coastal-East",
  "severity": "high",
  "issueType": "flood",
  "population": 5000,
  "notes": "Rising water levels"
}

Update Report:

PUT http://localhost:3000/api/reports/1234567890
Content-Type: application/json

{
  "zone": "Updated Zone",
  "severity": "critical",
  "issueType": "flood",
  "population": 8000
}

Delete Report:

DELETE http://localhost:3000/api/reports/1234567890

Using Command Line (cURL)

# Health check
curl http://localhost:3000/api/health

# Create report
curl -X POST http://localhost:3000/api/reports \
  -H "Content-Type: application/json" \
  -d '{"zone":"Test","severity":"high","issueType":"flood","population":2000}'

🎓 Key Concepts Demonstrated

1. Module System (Lectures 13-16)

// Export
module.exports = { functionName };

// Import
const { functionName } = require("./module");

2. File Handling (Lectures 5-8)

// Read JSON file
const data = await fs.readFile(path, "utf-8");
const object = JSON.parse(data);

// Write JSON file
await fs.writeFile(path, JSON.stringify(object, null, 2));

3. Express Middleware (Lectures 17-20)

// Logger middleware
app.use((req, res, next) => {
  console.log(`${req.method} ${req.url}`);
  next();
});

4. Routing Methods (Lectures 21-24)

app.get("/api/data", handler);      // Read
app.post("/api/data", handler);     // Create
app.put("/api/data/:id", handler);  // Update
app.delete("/api/data/:id", handler); // Delete

5. File Streaming (Lectures 21-24)

const stream = fs.createReadStream(filePath);
stream.pipe(res);  // Efficient file transfer

6. Exception Handling (Lectures 21-24)

// Try-catch in routes
try {
  const data = await getData();
  res.json(data);
} catch (error) {
  next(error);  // Pass to error handler
}

// Global error handler
app.use((err, req, res, next) => {
  res.status(500).json({ error: err.message });
});

💡 How to Use This for Your Exam

Step 1: Understand Architecture

Read BACKEND_GUIDE_HINGLISH.md for easy explanation of each topic

Step 2: Study Code

  • basic-http-server.js → HTTP module concepts
  • server.js → Express framework
  • src/modules/dataStore.js → File handling

Step 3: Test Everything

Use API_TESTING_GUIDE.md to test all endpoints

Step 4: Explain Flow

Be able to explain:

User submits form → 
POST request → 
Express route → 
Middleware → 
Controller function → 
Data saved to JSON → 
Response sent back

🎯 Interview Questions Covered

  1. Client-Server Architecture
  2. File handling in Node.js
  3. Module system (require/exports)
  4. HTTP module vs Express
  5. Middleware concept
  6. Routing methods (GET/POST/PUT/DELETE/PATCH)
  7. Route parameters vs Query parameters
  8. File streaming
  9. Exception handling
  10. Async/await in Node.js

Detailed answers: See BACKEND_GUIDE.md


🏆 Features Implemented

  • ✅ Native HTTP server (no framework)
  • ✅ Express framework server
  • ✅ File-based CRUD operations
  • ✅ All HTTP methods (GET, POST, PUT, PATCH, DELETE)
  • ✅ Route parameters and query strings
  • ✅ Static file serving
  • ✅ File streaming
  • ✅ Custom middleware
  • ✅ Global error handling
  • ✅ Request logging
  • ✅ Modern UI with animations
  • ✅ Complete API documentation

📊 Status Codes Used

Code Meaning When Used
200 OK Successful GET, PUT, DELETE
201 Created Successful POST
400 Bad Request Missing required fields
404 Not Found Resource not found
500 Server Error Internal error

🛠️ Technologies Used

  • Runtime: Node.js v18+
  • Framework: Express.js v5.2
  • Storage: File-based JSON
  • Frontend: Vanilla JavaScript
  • Styling: Modern CSS with animations

📝 Scripts

npm start           # Start Express server (port 3000)
npm run start:http  # Start HTTP module server (port 4000)

🤝 Contributing

This is an educational project for backend evaluation. Feel free to:

  • Add more features
  • Improve documentation
  • Add test cases
  • Enhance UI/UX

📞 Support

If you have questions about any concept:

  1. Check BACKEND_GUIDE.md for technical details
  2. Check BACKEND_GUIDE_HINGLISH.md for easy explanation
  3. Check API_TESTING_GUIDE.md for testing help
  4. Look at code comments in each file

🎉 Acknowledgments

Built for backend course evaluation demonstrating:

  • Professional code structure
  • Industry best practices
  • Complete syllabus coverage
  • Real-world application design

📄 License

Educational Use Only


Made with ❤️ for Backend Students

Star ⭐ this repo if it helped you understand backend concepts!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors