# kirtikara/neighborfit architecture

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

- Interactive diagram: https://gitdiagram.com/kirtikara/neighborfit
- Repository: https://github.com/kirtikara/neighborfit

## Overview

NeighborFit matches people to Indian neighborhoods using safety, pollution, cleanliness, greenery, and budget preferences. The principal workflow is a client request to the Express API, which queries neighborhood records, ranks matches, and returns results; separate API routes support registration, login, and admin-managed listings. Data scripts populate those records from OpenAQ and estimated or research-based metrics. The tree contains no frontend source files, so the documented React interface is not mapped. Relationships below are limited to README statements and shown backend references/calls.

Main entry points: [`backend/index.js`](https://github.com/kirtikara/neighborfit/blob/master/backend/index.js) (Express API), [`backend/models/Neighborhood.js`](https://github.com/kirtikara/neighborfit/blob/master/backend/models/Neighborhood.js) (Neighborhood model), [`backend/scripts/fetch_real_data.js`](https://github.com/kirtikara/neighborfit/blob/master/backend/scripts/fetch_real_data.js) (Research data loader), [`backend/scripts/fetch_data.js`](https://github.com/kirtikara/neighborfit/blob/master/backend/scripts/fetch_data.js) (Data loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and matching"]
  node_server["Express API<br/>[index.js]"]
  node_matcher["Preference matcher<br/>[match.js]"]
  node_listing_api["Neighborhood API<br/>[neighborhoods.js]"]
end

subgraph group_identity["Accounts and access"]
  node_auth_api["Authentication API<br/>[auth.js]"]
  node_user_model["User model<br/>[User.js]"]
end

subgraph group_data["Neighborhood data"]
  node_neighborhood_model["Neighborhood model<br/>[Neighborhood.js]"]
  node_mongo[("MongoDB")]
end

subgraph group_ingestion["Data ingestion"]
  node_real_ingest["Research data loader<br/>[fetch_real_data.js]"]
  node_basic_ingest["Data loader<br/>[fetch_data.js]"]
end

node_client(("App users"))
node_openaq["OpenAQ"]

node_client -->|"requests API"| node_server
node_server -->|"routes requests"| node_matcher
node_server -->|"routes requests"| node_listing_api
node_server -->|"routes requests"| node_auth_api
node_matcher -->|"queries records"| node_neighborhood_model
node_listing_api -->|"manages records"| node_neighborhood_model
node_auth_api -->|"checks and saves"| node_user_model
node_server -->|"connects to"| node_mongo
node_real_ingest -->|"creates records"| node_neighborhood_model
node_basic_ingest -->|"creates records"| node_neighborhood_model
node_real_ingest -->|"connects and writes"| node_mongo
node_basic_ingest -->|"connects and writes"| node_mongo
node_real_ingest -->|"fetches pollution"| node_openaq
node_basic_ingest -->|"fetches pollution"| node_openaq

click node_server "https://github.com/kirtikara/neighborfit/blob/master/backend/index.js"
click node_matcher "https://github.com/kirtikara/neighborfit/blob/master/backend/routes/match.js"
click node_listing_api "https://github.com/kirtikara/neighborfit/blob/master/backend/routes/neighborhoods.js"
click node_auth_api "https://github.com/kirtikara/neighborfit/blob/master/backend/routes/auth.js"
click node_user_model "https://github.com/kirtikara/neighborfit/blob/master/backend/models/User.js"
click node_neighborhood_model "https://github.com/kirtikara/neighborfit/blob/master/backend/models/Neighborhood.js"
click node_real_ingest "https://github.com/kirtikara/neighborfit/blob/master/backend/scripts/fetch_real_data.js"
click node_basic_ingest "https://github.com/kirtikara/neighborfit/blob/master/backend/scripts/fetch_data.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_server,node_matcher,node_listing_api,node_client toneBlue
class node_auth_api,node_user_model toneAmber
class node_neighborhood_model,node_mongo toneMint
class node_real_ingest,node_basic_ingest toneRose
class node_openaq toneIndigo
```

## Components

### API and matching

- [Express API](https://github.com/kirtikara/neighborfit/blob/master/backend/index.js): `backend/index.js`
- [Preference matcher](https://github.com/kirtikara/neighborfit/blob/master/backend/routes/match.js): `backend/routes/match.js`
- [Neighborhood API](https://github.com/kirtikara/neighborfit/blob/master/backend/routes/neighborhoods.js): `backend/routes/neighborhoods.js`

### Accounts and access

- [Authentication API](https://github.com/kirtikara/neighborfit/blob/master/backend/routes/auth.js): `backend/routes/auth.js`
- [User model](https://github.com/kirtikara/neighborfit/blob/master/backend/models/User.js): `backend/models/User.js`

### Neighborhood data

- [Neighborhood model](https://github.com/kirtikara/neighborfit/blob/master/backend/models/Neighborhood.js): `backend/models/Neighborhood.js`
- **MongoDB**

### Data ingestion

- [Research data loader](https://github.com/kirtikara/neighborfit/blob/master/backend/scripts/fetch_real_data.js): `backend/scripts/fetch_real_data.js`
- [Data loader](https://github.com/kirtikara/neighborfit/blob/master/backend/scripts/fetch_data.js): `backend/scripts/fetch_data.js`

### Other components

- **App users**
- **OpenAQ**

## Connections

- App users → Express API: requests API (evidence: `README.md`)
- Express API → Preference matcher: routes requests (evidence: `backend/index.js`)
- Express API → Neighborhood API: routes requests (evidence: `backend/index.js`)
- Express API → Authentication API: routes requests (evidence: `backend/index.js`)
- Preference matcher → Neighborhood model: queries records (evidence: `backend/routes/match.js`)
- Neighborhood API → Neighborhood model: manages records (evidence: `backend/routes/neighborhoods.js`)
- Authentication API → User model: checks and saves (evidence: `backend/routes/auth.js`)
- Express API → MongoDB: connects to (evidence: `backend/index.js`)
- Research data loader → Neighborhood model: creates records (evidence: `backend/scripts/fetch_real_data.js`)
- Data loader → Neighborhood model: creates records (evidence: `backend/scripts/fetch_data.js`)
- Research data loader → MongoDB: connects and writes (evidence: `backend/scripts/fetch_real_data.js`)
- Data loader → MongoDB: connects and writes (evidence: `backend/scripts/fetch_data.js`)
- Research data loader → OpenAQ: fetches pollution (evidence: `backend/scripts/fetch_real_data.js`)
- Data loader → OpenAQ: fetches pollution (evidence: `backend/scripts/fetch_data.js`)
