Skip to content

FloodSync/floodsync-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

60 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FloodSync Backend

Prerequisites

  • Node.js (v18 or higher)
  • pnpm (install with npm install -g pnpm)

Installation

# Install dependencies
pnpm install

Environment Setup

Create a .env file in the root directory with the following variables:

NODE_ENV=development
PORT=4000
CORE_APP_PORT = 8000
DATABASE_URL=your_database_url

OPENROUTER_API_KEY=your_openrouter_api_key

Note: OPENROUTER_API_KEY is optional but recommended. Without it, you may encounter rate limits on free models. Get your API key from OpenRouter.

Running the Project

Development

# Start Express API server
pnpm run dev

The Express API server will start on http://localhost:8000 (or the port specified in your .env file).

Mastra Studio (AI Development)

# Start Mastra dev server (runs on port 3001)
pnpm run mastra:dev

Note: Mastra Studio runs on port 4000 to avoid conflicts with the Express API server. You can run both servers simultaneously:

  • Express API: http://localhost:8000
  • Mastra Studio: http://localhost:4000

Production

# Build the project
pnpm run build

# Start the server
pnpm start

Available Scripts

  • pnpm run dev - Start Express development server with hot reload (port 8000)
  • pnpm run mastra:dev - Start Mastra Studio for AI development (port 3001)
  • pnpm run build - Build the project for production
  • pnpm run lint - Run ESLint
  • pnpm run format - Format code with Prettier
  • pnpm run type-check - Run TypeScript type checking

Important: Never commit your .env file or hardcode credentials. Always use environment variables.

🌊 FloodSync API Documentation

πŸ” Authentication

Register User

POST
https://localhost:8000/api/v1/user/register

Body

{
  "name": "test user",
  "email": "test@gmail.com",
  "password": "password",
  "phone": "091122334455",
  "city": "Yangon",
  "township": "Dagon"
}

Login User

POST
https://localhost:8000/api/v1/user/login

Body

{
  "email": "test@gmail.com",
  "password": "password"
}

Logout User

POST
https://localhost:8000/api/v1/user/logout


🟒 Safe Routes

Create Safe Status

POST
https://localhost:8000/api/v1/safe

Body

{
  "userId": "6912e2c09c5bb1e00e41d376",
  "status": "safe"
}

Get Safe Average

GET
https://localhost:8000/api/v1/safe/average


Get Safe Average by City

GET
https://localhost:8000/api/v1/safe/average/:city


πŸ‘₯ User Routes

Get All Users

GET
https://localhost:8000/api/v1/user/get-all-user


Add Friend

POST
https://localhost:8000/api/v1/user/add-friend

Body

{
  "myId": "6912e2c09c5bb1e00e41d376",
  "phone": "091122334455"
}

Get Friends by User ID

GET
https://localhost:8000/api/v1/user/:userId/friends

Params

userId = "6912e2c09c5bb1e00e41d376"

Update User by ID

PATCH
https://localhost:8000/api/v1/user/:userId/update


Delete User by ID

DELETE
https://localhost:8000/api/v1/user/:userId/destroy


🌧 Flooding Data Routes

Get Flood Chance Percentage

GET
http://127.0.0.1:8000/api/v1/flooding/chance-percentage

Request Parameters

lat, lon, days

Response Example

{
  "date": "2025-11-12",
  "river_discharge": 340,
  "flood_risk_percent": 65
}

πŸ’‘ Use this route to get flood risk percentage for a single location (e.g., to notify users about the risk).


Get Flood Chance Percentage by City and Township

GET
http://127.0.0.1:8000/api/v1/flooding/chance-percentage-by-city-town

Response Example

[
  {
    "city": "Ayeyarwady",
    "township": "Labutta",
    "coords": [16.15, 94.783],
    "status": "Moderate Risk",
    "chance": 56,
    "locals": 315240,
    "items": {
      "medical kit": 13,
      "food and water": 17,
      "shelter": 14,
      "clothing": 13,
      "hygiene items": 11,
      "baby care": 10,
      "power and lighting": 12,
      "safety and rescue gear": 10
    },
    "safePercentage": 55,
    "unsafePercentage": 35,
    "noresponsePercentage": 10
  }
]

⚠️ This route returns only Moderate and High Risk locations with coordinates, local population, and survey result summaries.


πŸ“¦ Supply Category

Get Supply Categories

GET
http://127.0.0.1:8000/api/v1/supply-category

Response Example

[
  {
    "category": "food and water"
  },
  {
    "category": "medical kit"
  }
]

🧾 This route provides the list of categories used for supply surveys in high-risk areas.


πŸ“ Supply Survey Summit

Submit Supply Survey

POST
http://127.0.0.1:8000/api/v1/supply-survey

Body

{
  "userId": "6912e2c09c5bb1e00e41d376",
  "city": "Yangon",
  "township": "Dagon",
  "supplyList": ["food and water", "shelter", "medical kit"]
}

🧍 Each user can submit their available supplies based on predefined categories.
Multiple items can be selected in supplyList.


βœ… Base URL:
http://127.0.0.1:8000/api/v1/

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •