# sourav-roy/apinodejs architecture

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

- Interactive diagram: https://gitdiagram.com/sourav-roy/apinodejs
- Repository: https://github.com/sourav-roy/apinodejs

## Overview

#### Purpose and entry points
This is an Express/Node.js REST API for DevCamper: bootcamps, their courses, user reviews, and user administration. The server is initialized in `index.js`; database connection is centralized in `db/db.js` and re-exported via `db/index.js`. Deployment configuration is present in `vercel.json`.

#### HTTP composition and request pipeline
Routes are mounted through the route aggregation layer, then dispatched to resource controllers:
- `routes/index.js`
- `routes/authRoute.js`
- `routes/bootcampsRoute.js`
- `controllers/index.js`
- `controllers/bootcampsController.js`

Cross-cutting middleware enforces authentication, validation, error handling, logging, and paginated/filterable results before or around controller execution:
- `middleware/auth.js`
- `middleware/advancedResults.js`
- `middleware/error.js`

#### Domain and persistence model
MongoDB/Mongoose-backed models represent the core aggregate relationships: bootcamps own or associate with courses; reviews are authored by users and target bootcamps; users carry authentication and role state.
- `models/BootcampModel.js`
- `models/CourseModel.js`
- `models/ReviewModel.js`
- `models/UserModel.js`

Controllers implement CRUD, ownership/role authorization, nested-resource handling, profile/password changes, and authentication workflows:
- `controllers/coursesController.js`
- `controllers/reviewsController.js`
- `controllers/usersController.js`
- `controllers/authController.js`

#### Authentication and authorization boundary
Authentication uses JWT and cookies, with role-based access for User, Publisher, and Admin. The auth controller handles registration, login/logout, protected-user retrieval, password reset, and credential updates; authorization middleware resolves the requesting user and gates privileged actions.
- `controllers/authController.js`
- `middleware/auth.js`
- `routes/authRoute.js`

#### Bootcamp enrichment and media
Bootcamp writes incorporate geocoding to derive location/radius data, and bootcamp endpoints support photo upload. Geocoding is an external-service boundary; uploaded media is handled at the controller/API boundary rather than by the data model alone.
- `controllers/bootcampsController.js`
- `utils/geocoder.js`
- `models/BootcampModel.js`

#### Security, reliability, and external integration
The API applies rate limiting, NoSQL-injection protection, XSS/HPP protection, CORS, password encryption, centralized async error propagation, and request logging. Email is an external integration used by password-reset flows.
- `middleware/async.js`
- `middleware/validate.js`
- `utils/ErrorResponse.js`
- `utils/sendMail.js`

#### Data lifecycle and operations
Development/demo data is maintained as JSON fixtures and loaded through the seeding entry point. The repository also carries API and system-design documentation for consumers and maintainers.
- `seeder.js`
- `_data/bootcamps.json`
- `_data/courses.json`
- `docs/API_REFERENCE.md`

Main entry points: [`models/BootcampModel.js`](https://github.com/sourav-roy/apinodejs/blob/SOURAV/models/BootcampModel.js) (Mongoose aggregates), [`index.js`](https://github.com/sourav-roy/apinodejs/blob/SOURAV/index.js) (Server bootstrap), [`routes/index.js`](https://github.com/sourav-roy/apinodejs/blob/SOURAV/routes/index.js) (Route aggregation), [`controllers/index.js`](https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/index.js) (Controller exports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_server["Server bootstrap<br/>Express entry point<br/>[index.js]"]
  node_routes["Route aggregation<br/>router composition<br/>[index.js]"]
  node_auth_routes["Auth routes<br/>router<br/>[authRoute.js]"]
  node_bootcamp_routes["Bootcamp routes<br/>router<br/>[bootcampsRoute.js]"]
  node_controllers["Controller exports<br/>controller composition<br/>[index.js]"]
  node_authz{{"JWT &amp; role guard<br/>auth middleware<br/>[auth.js]"}}
  node_results["Query results middleware<br/>pagination/filtering<br/>[advancedResults.js]"]
  node_validation_errors["Validation &amp; error boundary<br/>middleware<br/>[validate.js]"]
end

subgraph group_domain["Domain"]
  node_bootcamps["Bootcamp controller<br/>resource controller"]
  node_courses["Course controller<br/>resource controller"]
  node_reviews["Review controller<br/>resource controller"]
  node_users["User controller<br/>user administration<br/>[usersController.js]"]
  node_auth["Auth controller<br/>identity workflow<br/>[authController.js]"]
  node_models[("Mongoose aggregates<br/>persistence models<br/>[BootcampModel.js]")]
  node_database[("MongoDB connection<br/>database adapter<br/>[db.js]")]
end

subgraph group_integrations["Integrations &amp; operations"]
  node_geocoder{{"Geocoding service<br/>external service adapter<br/>[geocoder.js]"}}
  node_email{{"Email delivery<br/>external integration<br/>[sendMail.js]"}}
  node_seeder["Data seeder<br/>development operation<br/>[seeder.js]"]
  node_fixtures["Bootcamp fixtures<br/>seed data<br/>[bootcamps.json]"]
  node_deployment["Vercel deployment<br/>deployment config<br/>[vercel.json]"]
end

node_deployment -.->|"deploys"| node_server
node_server -->|"mounts"| node_routes
node_server -->|"applies"| node_authz
node_server -->|"applies"| node_validation_errors
node_routes -->|"includes"| node_auth_routes
node_routes -->|"includes"| node_bootcamp_routes
node_routes -->|"dispatches through"| node_controllers
node_auth_routes -->|"dispatches"| node_auth
node_bootcamp_routes -->|"dispatches"| node_bootcamps
node_authz -->|"protects"| node_auth
node_authz -->|"authorizes"| node_users
node_results -->|"enriches queries"| node_bootcamps
node_controllers -->|"exports"| node_courses
node_controllers -->|"exports"| node_reviews
node_controllers -->|"exports"| node_users
node_bootcamps -->|"persists"| node_models
node_courses -->|"persists"| node_models
node_reviews -->|"persists"| node_models
node_users -->|"persists"| node_models
node_auth -->|"manages users"| node_models
node_models -->|"uses"| node_database
node_bootcamps -->|"geocodes writes"| node_geocoder
node_auth -->|"sends reset email"| node_email
node_seeder -->|"loads"| node_fixtures
node_seeder -->|"seeds"| node_database

click node_server "https://github.com/sourav-roy/apinodejs/blob/SOURAV/index.js"
click node_routes "https://github.com/sourav-roy/apinodejs/blob/SOURAV/routes/index.js"
click node_auth_routes "https://github.com/sourav-roy/apinodejs/blob/SOURAV/routes/authRoute.js"
click node_bootcamp_routes "https://github.com/sourav-roy/apinodejs/blob/SOURAV/routes/bootcampsRoute.js"
click node_controllers "https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/index.js"
click node_authz "https://github.com/sourav-roy/apinodejs/blob/SOURAV/middleware/auth.js"
click node_results "https://github.com/sourav-roy/apinodejs/blob/SOURAV/middleware/advancedResults.js"
click node_validation_errors "https://github.com/sourav-roy/apinodejs/blob/SOURAV/middleware/validate.js"
click node_bootcamps "https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/bootcampsController.js"
click node_courses "https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/coursesController.js"
click node_reviews "https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/reviewsController.js"
click node_users "https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/usersController.js"
click node_auth "https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/authController.js"
click node_models "https://github.com/sourav-roy/apinodejs/blob/SOURAV/models/BootcampModel.js"
click node_database "https://github.com/sourav-roy/apinodejs/blob/SOURAV/db/db.js"
click node_geocoder "https://github.com/sourav-roy/apinodejs/blob/SOURAV/utils/geocoder.js"
click node_email "https://github.com/sourav-roy/apinodejs/blob/SOURAV/utils/sendMail.js"
click node_seeder "https://github.com/sourav-roy/apinodejs/blob/SOURAV/seeder.js"
click node_fixtures "https://github.com/sourav-roy/apinodejs/blob/SOURAV/_data/bootcamps.json"
click node_deployment "https://github.com/sourav-roy/apinodejs/blob/SOURAV/vercel.json"

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_routes,node_auth_routes,node_bootcamp_routes,node_controllers,node_authz,node_results,node_validation_errors toneBlue
class node_bootcamps,node_courses,node_reviews,node_users,node_auth,node_models,node_database toneAmber
class node_geocoder,node_email,node_seeder,node_fixtures,node_deployment toneMint
```

## Components

### HTTP API

Express request composition and cross-cutting enforcement.

- [Server bootstrap](https://github.com/sourav-roy/apinodejs/blob/SOURAV/index.js): Express entry point · `index.js`
- [Route aggregation](https://github.com/sourav-roy/apinodejs/blob/SOURAV/routes/index.js): router composition · `routes/index.js`
- [Auth routes](https://github.com/sourav-roy/apinodejs/blob/SOURAV/routes/authRoute.js): router · `routes/authRoute.js`
- [Bootcamp routes](https://github.com/sourav-roy/apinodejs/blob/SOURAV/routes/bootcampsRoute.js): router · `routes/bootcampsRoute.js`
- [Controller exports](https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/index.js): controller composition · `controllers/index.js`
- [JWT & role guard](https://github.com/sourav-roy/apinodejs/blob/SOURAV/middleware/auth.js): auth middleware · Resolves users and gates User, Publisher, and Admin actions. · `middleware/auth.js`
- [Query results middleware](https://github.com/sourav-roy/apinodejs/blob/SOURAV/middleware/advancedResults.js): pagination/filtering · `middleware/advancedResults.js`
- [Validation & error boundary](https://github.com/sourav-roy/apinodejs/blob/SOURAV/middleware/validate.js): middleware · Validates requests and centralizes async error responses. · `middleware/validate.js`

### Domain

Resource workflows and MongoDB persistence.

- [Bootcamp controller](https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/bootcampsController.js): resource controller · CRUD, ownership checks, nested resources, and photo upload. · `controllers/bootcampsController.js`
- [Course controller](https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/coursesController.js): resource controller · `controllers/coursesController.js`
- [Review controller](https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/reviewsController.js): resource controller · `controllers/reviewsController.js`
- [User controller](https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/usersController.js): user administration · `controllers/usersController.js`
- [Auth controller](https://github.com/sourav-roy/apinodejs/blob/SOURAV/controllers/authController.js): identity workflow · Registration, sessions, password reset, and credential changes. · `controllers/authController.js`
- [Mongoose aggregates](https://github.com/sourav-roy/apinodejs/blob/SOURAV/models/BootcampModel.js): persistence models · Bootcamps, courses, reviews, and users encode core relationships. · `models/BootcampModel.js`
- [MongoDB connection](https://github.com/sourav-roy/apinodejs/blob/SOURAV/db/db.js): database adapter · `db/db.js`

### Integrations & operations

External services, deployment, and development data.

- [Geocoding service](https://github.com/sourav-roy/apinodejs/blob/SOURAV/utils/geocoder.js): external service adapter · Derives bootcamp location and radius data. · `utils/geocoder.js`
- [Email delivery](https://github.com/sourav-roy/apinodejs/blob/SOURAV/utils/sendMail.js): external integration · Used by password-reset flows. · `utils/sendMail.js`
- [Data seeder](https://github.com/sourav-roy/apinodejs/blob/SOURAV/seeder.js): development operation · Loads demo fixtures into MongoDB. · `seeder.js`
- [Bootcamp fixtures](https://github.com/sourav-roy/apinodejs/blob/SOURAV/_data/bootcamps.json): seed data · `_data/bootcamps.json`
- [Vercel deployment](https://github.com/sourav-roy/apinodejs/blob/SOURAV/vercel.json): deployment config · `vercel.json`

## Connections

- Vercel deployment → Server bootstrap: deploys
- Server bootstrap → Route aggregation: mounts
- Server bootstrap → JWT & role guard: applies
- Server bootstrap → Validation & error boundary: applies
- Route aggregation → Auth routes: includes
- Route aggregation → Bootcamp routes: includes
- Route aggregation → Controller exports: dispatches through
- Auth routes → Auth controller: dispatches
- Bootcamp routes → Bootcamp controller: dispatches
- JWT & role guard → Auth controller: protects
- JWT & role guard → User controller: authorizes
- Query results middleware → Bootcamp controller: enriches queries
- Controller exports → Course controller: exports
- Controller exports → Review controller: exports
- Controller exports → User controller: exports
- Bootcamp controller → Mongoose aggregates: persists
- Course controller → Mongoose aggregates: persists
- Review controller → Mongoose aggregates: persists
- User controller → Mongoose aggregates: persists
- Auth controller → Mongoose aggregates: manages users
- Mongoose aggregates → MongoDB connection: uses
- Bootcamp controller → Geocoding service: geocodes writes
- Auth controller → Email delivery: sends reset email
- Data seeder → Bootcamp fixtures: loads
- Data seeder → MongoDB connection: seeds
