# aswin-cs/safaiwatch-backend architecture

> Architecture diagram of the GitHub repository aswin-cs/safaiwatch-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aswin-cs/safaiwatch-backend
- Repository: https://github.com/aswin-cs/safaiwatch-backend

## Overview

This is a backend for a community cleanup and rewards platform. Users authenticate, report or mark cleanup spots, and the service tracks assignment and completion; profiles, feeds, and rewards provide supporting features. The graph separates API routing, domain controllers, persistence, and integrations. The excerpts show selected controller behavior and app routing; several subsystems are represented from the source index and tree, so uncertain internal links are omitted.

Main entry points: [`src/controllers/spots.controller.js`](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/spots.controller.js) (Cleanup spots), [`src/controllers/profile.controller.js`](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/profile.controller.js) (Profile management), [`src/middlewares/authorize.middleware.js`](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/middlewares/authorize.middleware.js) (Authorization), [`src/app.js`](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/app.js) (Express app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_app["Express app<br/>[app.js]"]
  node_authroutes["Auth routes<br/>[auth.routes.js]"]
  node_profileroutes["Profile routes<br/>[profile.routes.js]"]
  node_spotsroutes["Spot routes<br/>[spots.routes.js]"]
  node_feedsroutes["Feed routes<br/>[feeds.routes.js]"]
  node_rewardsroutes["Reward routes<br/>[rewards.routes.js]"]
  node_authorization["Authorization"]
end

subgraph group_domain["Product workflows"]
  node_auth["Authentication<br/>[auth.controller.js]"]
  node_profile["Profile management"]
  node_spots["Cleanup spots"]
  node_feeds["Community feeds"]
  node_rewards["Rewards and rankings"]
end

subgraph group_data["Domain data"]
  node_user[("User records<br/>[user.model.js]")]
  node_userstatus[("User activity")]
  node_spotrecords[("Spot records")]
  node_rewardrecords[("Reward records")]
  node_feedrecords[("Feed records<br/>[feeds.model.js]")]
  node_otp[("OTP records<br/>[sample.modal.js]")]
  node_onetime[("One-time codes<br/>[one-time.model.js]")]
end

subgraph group_integrations["Integrations"]
  node_cloudinary["Cloudinary media"]
  node_verification["Photo verification"]
  node_rewardlogic["Reward calculations<br/>[rewards.utils.js]"]
  node_socket["Socket.IO events<br/>[socketIoConfig.js]"]
  node_response["Response formatting<br/>[responseHandler.js]"]
  node_errors["Error handling<br/>[errorHandler.js]"]
end

node_clients(("API clients"))

node_clients -->|"send requests"| node_app
node_app -->|"mounts"| node_authroutes
node_app -->|"mounts"| node_profileroutes
node_app -->|"mounts"| node_spotsroutes
node_app -->|"mounts"| node_feedsroutes
node_app -->|"mounts"| node_rewardsroutes
node_authroutes -->|"routes to"| node_auth
node_profileroutes -->|"routes to"| node_profile
node_spotsroutes -->|"routes to"| node_spots
node_feedsroutes -->|"routes to"| node_feeds
node_rewardsroutes -->|"routes to"| node_rewards
node_authroutes -->|"applies access"| node_authorization
node_profileroutes -->|"applies access"| node_authorization
node_spotsroutes -->|"applies access"| node_authorization
node_feedsroutes -->|"applies access"| node_authorization
node_rewardsroutes -->|"applies access"| node_authorization
node_auth -->|"reads and writes"| node_user
node_auth -->|"reads and writes"| node_otp
node_authorization -->|"loads user"| node_user
node_authorization -->|"loads OTP"| node_otp
node_profile -->|"reads profile"| node_user
node_profile -->|"reads activity"| node_userstatus
node_profile -->|"reads spots"| node_spotrecords
node_profile -->|"reads rewards"| node_rewardrecords
node_profile -->|"reads posts"| node_feedrecords
node_profile -->|"uploads media"| node_cloudinary
node_spots -->|"manages spots"| node_spotrecords
node_spots -->|"uploads media"| node_cloudinary
node_spots -->|"verifies photos"| node_verification
node_spots -->|"emits events"| node_socket
node_spots -->|"calculates rewards"| node_rewardlogic
node_spots -.->|"uses codes"| node_onetime
node_feeds -->|"manages posts"| node_feedrecords
node_rewards -->|"manages rewards"| node_rewardrecords
node_rewards -->|"calculates rewards"| node_rewardlogic
node_spots -->|"formats responses"| node_response
node_spots -->|"creates errors"| node_errors

click node_app "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/app.js"
click node_authroutes "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/routes/auth.routes.js"
click node_profileroutes "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/routes/profile.routes.js"
click node_spotsroutes "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/routes/spots.routes.js"
click node_feedsroutes "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/routes/feeds.routes.js"
click node_rewardsroutes "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/routes/rewards.routes.js"
click node_authorization "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/middlewares/authorize.middleware.js"
click node_auth "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/auth.controller.js"
click node_profile "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/profile.controller.js"
click node_spots "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/spots.controller.js"
click node_feeds "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/feeds.controller.js"
click node_rewards "https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/rewards.controller.js"
click node_user "https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/user.model.js"
click node_userstatus "https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/userStatus.model.js"
click node_spotrecords "https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/markedSpots.model.js"
click node_rewardrecords "https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/userRewards.model.js"
click node_feedrecords "https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/feeds.model.js"
click node_otp "https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/sample.modal.js"
click node_onetime "https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/one-time.model.js"
click node_cloudinary "https://github.com/aswin-cs/safaiwatch-backend/blob/master/utils/Cloudinaryimage.utils.js"
click node_verification "https://github.com/aswin-cs/safaiwatch-backend/blob/master/utils/aiPhotoVerification.utils.js"
click node_rewardlogic "https://github.com/aswin-cs/safaiwatch-backend/blob/master/utils/rewards.utils.js"
click node_socket "https://github.com/aswin-cs/safaiwatch-backend/blob/master/config/socketIoConfig.js"
click node_response "https://github.com/aswin-cs/safaiwatch-backend/blob/master/utils/responseHandler.js"
click node_errors "https://github.com/aswin-cs/safaiwatch-backend/blob/master/utils/errorHandler.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_authroutes,node_profileroutes,node_spotsroutes,node_feedsroutes,node_rewardsroutes,node_authorization,node_clients toneBlue
class node_auth,node_profile,node_spots,node_feeds,node_rewards toneAmber
class node_user,node_userstatus,node_spotrecords,node_rewardrecords,node_feedrecords,node_otp,node_onetime toneMint
class node_cloudinary,node_verification,node_rewardlogic,node_socket,node_response,node_errors toneRose
```

## Components

### API and access

- [Express app](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/app.js): `src/app.js`
- [Auth routes](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/routes/auth.routes.js): `src/routes/auth.routes.js`
- [Profile routes](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/routes/profile.routes.js): `src/routes/profile.routes.js`
- [Spot routes](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/routes/spots.routes.js): `src/routes/spots.routes.js`
- [Feed routes](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/routes/feeds.routes.js): `src/routes/feeds.routes.js`
- [Reward routes](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/routes/rewards.routes.js): `src/routes/rewards.routes.js`
- [Authorization](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/middlewares/authorize.middleware.js): `src/middlewares/authorize.middleware.js`

### Product workflows

- [Authentication](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/auth.controller.js): `src/controllers/auth.controller.js`
- [Profile management](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/profile.controller.js): `src/controllers/profile.controller.js`
- [Cleanup spots](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/spots.controller.js): `src/controllers/spots.controller.js`
- [Community feeds](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/feeds.controller.js): `src/controllers/feeds.controller.js`
- [Rewards and rankings](https://github.com/aswin-cs/safaiwatch-backend/blob/master/src/controllers/rewards.controller.js): `src/controllers/rewards.controller.js`

### Domain data

- [User records](https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/user.model.js): `models/user.model.js`
- [User activity](https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/userStatus.model.js): `models/userStatus.model.js`
- [Spot records](https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/markedSpots.model.js): `models/markedSpots.model.js`
- [Reward records](https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/userRewards.model.js): `models/userRewards.model.js`
- [Feed records](https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/feeds.model.js): `models/feeds.model.js`
- [OTP records](https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/sample.modal.js): `models/sample.modal.js`
- [One-time codes](https://github.com/aswin-cs/safaiwatch-backend/blob/master/models/one-time.model.js): `models/one-time.model.js`

### Integrations

- [Cloudinary media](https://github.com/aswin-cs/safaiwatch-backend/blob/master/utils/Cloudinaryimage.utils.js): `utils/Cloudinaryimage.utils.js`
- [Photo verification](https://github.com/aswin-cs/safaiwatch-backend/blob/master/utils/aiPhotoVerification.utils.js): `utils/aiPhotoVerification.utils.js`
- [Reward calculations](https://github.com/aswin-cs/safaiwatch-backend/blob/master/utils/rewards.utils.js): `utils/rewards.utils.js`
- [Socket.IO events](https://github.com/aswin-cs/safaiwatch-backend/blob/master/config/socketIoConfig.js): `config/socketIoConfig.js`
- [Response formatting](https://github.com/aswin-cs/safaiwatch-backend/blob/master/utils/responseHandler.js): `utils/responseHandler.js`
- [Error handling](https://github.com/aswin-cs/safaiwatch-backend/blob/master/utils/errorHandler.js): `utils/errorHandler.js`

### Other components

- **API clients**

## Connections

- API clients → Express app: send requests (evidence: `src/app.js`)
- Express app → Auth routes: mounts (evidence: `src/app.js`)
- Express app → Profile routes: mounts (evidence: `src/app.js`)
- Express app → Spot routes: mounts (evidence: `src/app.js`)
- Express app → Feed routes: mounts (evidence: `src/app.js`)
- Express app → Reward routes: mounts (evidence: `src/app.js`)
- Auth routes → Authentication: routes to (evidence: `src/routes/auth.routes.js`)
- Profile routes → Profile management: routes to (evidence: `src/routes/profile.routes.js`)
- Spot routes → Cleanup spots: routes to (evidence: `src/routes/spots.routes.js`)
- Feed routes → Community feeds: routes to (evidence: `src/routes/feeds.routes.js`)
- Reward routes → Rewards and rankings: routes to (evidence: `src/routes/rewards.routes.js`)
- Auth routes → Authorization: applies access (evidence: `src/routes/auth.routes.js`)
- Profile routes → Authorization: applies access (evidence: `src/routes/profile.routes.js`)
- Spot routes → Authorization: applies access (evidence: `src/routes/spots.routes.js`)
- Feed routes → Authorization: applies access (evidence: `src/routes/feeds.routes.js`)
- Reward routes → Authorization: applies access (evidence: `src/routes/rewards.routes.js`)
- Authentication → User records: reads and writes (evidence: `src/controllers/auth.controller.js`)
- Authentication → OTP records: reads and writes (evidence: `src/controllers/auth.controller.js`)
- Authorization → User records: loads user (evidence: `src/middlewares/authorize.middleware.js`)
- Authorization → OTP records: loads OTP (evidence: `src/middlewares/authorize.middleware.js`)
- Profile management → User records: reads profile (evidence: `src/controllers/profile.controller.js`)
- Profile management → User activity: reads activity (evidence: `src/controllers/profile.controller.js`)
- Profile management → Spot records: reads spots (evidence: `src/controllers/profile.controller.js`)
- Profile management → Reward records: reads rewards (evidence: `src/controllers/profile.controller.js`)
- Profile management → Feed records: reads posts (evidence: `src/controllers/profile.controller.js`)
- Profile management → Cloudinary media: uploads media (evidence: `src/controllers/profile.controller.js`)
- Cleanup spots → Spot records: manages spots (evidence: `src/controllers/spots.controller.js`)
- Cleanup spots → Cloudinary media: uploads media (evidence: `src/controllers/spots.controller.js`)
- Cleanup spots → Photo verification: verifies photos (evidence: `src/controllers/spots.controller.js`)
- Cleanup spots → Socket.IO events: emits events (evidence: `src/controllers/spots.controller.js`)
- Cleanup spots → Reward calculations: calculates rewards (evidence: `src/controllers/spots.controller.js`)
- Cleanup spots → One-time codes: uses codes (evidence: `src/controllers/spots.controller.js`)
- Community feeds → Feed records: manages posts (evidence: `src/controllers/feeds.controller.js`)
- Rewards and rankings → Reward records: manages rewards (evidence: `src/controllers/rewards.controller.js`)
- Rewards and rankings → Reward calculations: calculates rewards (evidence: `src/controllers/rewards.controller.js`)
- Cleanup spots → Response formatting: formats responses (evidence: `src/controllers/spots.controller.js`)
- Cleanup spots → Error handling: creates errors (evidence: `src/controllers/spots.controller.js`)
