# neerjhar/app_builders-backend architecture

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

- Interactive diagram: https://gitdiagram.com/neerjhar/app_builders-backend
- Repository: https://github.com/neerjhar/app_builders-backend

## Overview

1. This repository is a backend-only Node.js service built around a single Express application entry point in `backend/server.js`. It exposes HTTP APIs for turf discovery and, according to the README, booking/payment support.

2. The core runtime boundary is:
   - HTTP clients or a frontend app
   - Express API server
   - MongoDB via Mongoose
   - Razorpay for payment orchestration

3. The main domain model lives in `backend/models/Truf.js` (note the filename typo). This is the Mongoose schema for turf records and is the persistence boundary between route handlers and the `turffdata` collection in MongoDB.

4. Turf discovery is implemented in `backend/routes/turfRoutes.js`. This route layer is responsible for:
   - listing all turfs
   - searching by query text
   - nearby turf discovery using geospatial coordinates

5. The nearby-search path is an important architectural feature. Turf documents include a GeoJSON `location` field with `[longitude, latitude]`, and the model creates a `2dsphere` index so MongoDB can answer proximity queries efficiently.

6. `backend/data/turfs.json` is sample/fixture data, not the live source of truth. It likely supports seeding or local testing, while MongoDB remains the authoritative store for API reads.

7. The README describes booking/payment endpoints under `/api/booking` for Razorpay order creation and signature verification. Those routes are not present in the provided file tree, so for an architecture diagram they should be shown as either an omitted module or an adjacent payment subsystem, not as part of the visible core snapshot.

8. Environment and configuration are file-based through `backend/.env` and `dotenv`. The service expects at least:
   - `MONGO_URI` for MongoDB connection
   - `PORT` for the Express listener
   - Razorpay API credentials for payment flows

9. MongoDB is used locally, with the README calling out the `admin` database and `turffdata` collection. This means the backend is stateful and depends on a running local database instance for all real turf data operations.

10. The principal request flow for turf discovery is:
    client request → Express route handler → Mongoose query → MongoDB → JSON response. Search and nearby discovery are both read-heavy flows, with nearby search relying on geospatial index support.

11. The payment flow described in the README is separate from turf discovery:
    client initiates booking → backend creates Razorpay order → browser completes payment → backend verifies signature. Razorpay is the external service boundary here.

12. Operationally, the repo is lightweight: there is no separate frontend, job worker, or microservice decomposition visible in the file tree. The architecture is a single-process API server with one database and one external payment provider.

Main entry points: [`backend/server.js`](https://github.com/neerjhar/app_builders-backend/blob/main/backend/server.js) (Express Server), [`backend/routes/turfRoutes.js`](https://github.com/neerjhar/app_builders-backend/blob/main/backend/routes/turfRoutes.js) (Turf Routes), [`backend/models/Truf.js`](https://github.com/neerjhar/app_builders-backend/blob/main/backend/models/Truf.js) (Truf Model), [`backend/.env`](https://github.com/neerjhar/app_builders-backend/blob/main/backend/.env) (Env Config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client_api["Client/API"]
  node_http_client(("HTTP Client<br/>caller"))
  node_express_server["Express Server<br/>api host<br/>[server.js]"]
  node_turf_routes["Turf Routes<br/>route layer<br/>[turfRoutes.js]"]
  node_booking_api["Booking API<br/>payment routes"]
end

subgraph group_domain_data["Domain/Data"]
  node_turf_model["Truf Model<br/>mongoose schema<br/>[Truf.js]"]
  node_mongoose_layer["Mongoose<br/>ODM"]
end

subgraph group_storage["Storage"]
  node_mongo_db[("MongoDB<br/>database")]
  node_turffdata_collection[("turffdata<br/>collection")]
  node_sample_data["Sample Data<br/>fixture json<br/>[turfs.json]"]
end

subgraph group_external["External Services"]
  node_razorpay{{"Razorpay<br/>payment provider"}}
end

subgraph group_ops["Config"]
  node_env_config["Env Config<br/>dotenv<br/>[.env]"]
end

node_http_client -->|"HTTP requests"| node_express_server
node_express_server -->|"mounts"| node_turf_routes
node_express_server -.->|"exposes"| node_booking_api
node_express_server -->|"reads config"| node_env_config
node_turf_routes -->|"queries via"| node_mongoose_layer
node_booking_api -.->|"creates/verifies"| node_razorpay
node_mongoose_layer -->|"uses schema"| node_turf_model
node_turf_model -->|"persists to"| node_mongo_db
node_mongo_db -->|"stores"| node_turffdata_collection
node_turf_routes -.->|"reads turf data"| node_turffdata_collection
node_sample_data -.->|"seed source"| node_mongo_db
node_turf_model -.->|"matches shape"| node_sample_data
node_env_config -->|"MONGO_URI"| node_mongo_db
node_env_config -->|"API creds"| node_razorpay

click node_express_server "https://github.com/neerjhar/app_builders-backend/blob/main/backend/server.js"
click node_turf_routes "https://github.com/neerjhar/app_builders-backend/blob/main/backend/routes/turfRoutes.js"
click node_turf_model "https://github.com/neerjhar/app_builders-backend/blob/main/backend/models/Truf.js"
click node_sample_data "https://github.com/neerjhar/app_builders-backend/blob/main/backend/data/turfs.json"
click node_env_config "https://github.com/neerjhar/app_builders-backend/blob/main/backend/.env"

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_http_client,node_express_server,node_turf_routes,node_booking_api toneBlue
class node_turf_model,node_mongoose_layer toneAmber
class node_mongo_db,node_turffdata_collection,node_sample_data toneMint
class node_razorpay toneRose
class node_env_config toneIndigo
```

## Components

### Client/API

HTTP entrypoint and request handling boundary

- **HTTP Client**: caller · Frontend app or API consumer issuing requests to the backend
- [Express Server](https://github.com/neerjhar/app_builders-backend/blob/main/backend/server.js): api host · Single Node.js entry point that mounts the HTTP API · `backend/server.js`
- [Turf Routes](https://github.com/neerjhar/app_builders-backend/blob/main/backend/routes/turfRoutes.js): route layer · Handles listing, search, and nearby turf discovery endpoints · `backend/routes/turfRoutes.js`
- **Booking API**: payment routes · README-described booking and payment endpoints; not present in the visible file tree

### Domain/Data

Turf discovery logic and persistence model

- [Truf Model](https://github.com/neerjhar/app_builders-backend/blob/main/backend/models/Truf.js): mongoose schema · Mongoose schema for turf records, including GeoJSON location and geospatial indexing · `backend/models/Truf.js`
- **Mongoose**: ODM · Query and schema layer between route handlers and MongoDB

### Storage

MongoDB-backed data sources

- **MongoDB**: database · Stateful backing store for live turf data
- **turffdata**: collection · MongoDB collection storing turf documents referenced by the model
- [Sample Data](https://github.com/neerjhar/app_builders-backend/blob/main/backend/data/turfs.json): fixture json · Local fixture or seed data for testing and bootstrapping · `backend/data/turfs.json`

### External Services

Outside dependencies used by the backend

- **Razorpay**: payment provider · External payment orchestration and signature verification service

### Config

Environment and runtime configuration

- [Env Config](https://github.com/neerjhar/app_builders-backend/blob/main/backend/.env): dotenv · Runtime configuration loaded from environment variables such as MongoDB, port, and Razorpay credentials · `backend/.env`

## Connections

- HTTP Client → Express Server: HTTP requests · Clients send API calls to the Node/Express service
- Express Server → Turf Routes: mounts · Server delegates turf discovery endpoints to the route layer
- Express Server → Booking API: exposes · Server is expected to expose booking/payment endpoints described in the README
- Express Server → Env Config: reads config · Listener and database/payment settings come from environment variables
- Turf Routes → Mongoose: queries via · Route handlers use Mongoose to read turf records
- Booking API → Razorpay: creates/verifies · Booking flow orchestrates Razorpay order creation and signature verification
- Mongoose → Truf Model: uses schema · Mongoose operates through the turf schema definition
- Truf Model → MongoDB: persists to · The schema maps turf records into MongoDB
- MongoDB → turffdata: stores · Live turf documents reside in the turffdata collection
- Turf Routes → turffdata: reads turf data · Discovery endpoints ultimately resolve against the MongoDB collection
- Sample Data → MongoDB: seed source · Fixture data can bootstrap or test the live database
- Truf Model → Sample Data: matches shape · Fixture records reflect the modelled turf document structure
- Env Config → MongoDB: MONGO_URI · Database connection is configured from environment variables
- Env Config → Razorpay: API creds · Payment credentials are supplied through environment configuration
