# ralitsavoronevska/rest-api-with-nodejs architecture

> Architecture diagram of the GitHub repository ralitsavoronevska/rest-api-with-nodejs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ralitsavoronevska/rest-api-with-nodejs
- Repository: https://github.com/ralitsavoronevska/rest-api-with-nodejs

## Overview

#### Purpose and runtime
This repository is a Node.js/Express REST API for a basic shop domain: user authentication, product inventory, and orders. It follows MVC-style separation over MongoDB Atlas via Mongoose. The process starts in `server.js`, with Express application assembly in `app.js`.

#### HTTP application boundary
`app.js` configures request parsing, logging, static/upload handling, route mounting, and centralized error responses. It is the boundary between HTTP clients and domain handlers; requests flow from Express middleware to resource routes, then controllers and Mongoose models.

#### Resource routing
Three route modules expose resource-oriented endpoints:
- Users: signup/login through `api/routes/user.js`
- Products: collection and item CRUD through `api/routes/products.js`
- Orders: collection and item operations through `api/routes/orders.js`

Routes define public versus protected operations and delegate business/request handling rather than directly persisting data.

#### Authentication and authorization
User registration and login are implemented in `api/controllers/user.js`, backed by `api/models/user.js`. Passwords are hashed with bcrypt; successful login produces JWTs. Protected product/order endpoints pass through `api/middleware/check-auth.js`, which validates the bearer token before controller execution.

#### Product inventory and file uploads
Product API behavior is concentrated in `api/controllers/products.js`, with persistence schema/model logic in `api/models/product.js`. Product creation supports multipart image uploads through Multer; uploaded assets are stored under `uploads`, while product responses expose product resources and associated image paths. Public reads provide product listing/detail access; mutations require authentication.

#### Orders and product references
`api/controllers/orders.js` implements order creation, retrieval, and deletion against `api/models/order.js`. Order processing sits at the integrity boundary between orders and products: controllers use Mongoose to resolve product records and persist order data, returning resource links/status responses. Protected access prevents unauthenticated order operations.

#### Infrastructure and dependencies
The service runs on Node.js and Express, using MongoDB Atlas as its persistence service and Mongoose as the ODM. Cross-cutting middleware includes body parsing, Morgan request logging, Multer upload processing, and async error propagation. Nodemon supports local restart-on-change development; Postman is the documented API client/testing workflow.

Main entry points: [`app.js`](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/app.js) (Express app), [`api/middleware/check-auth.js`](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/middleware/check-auth.js) (JWT auth middleware), [`api/controllers/products.js`](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/controllers/products.js) (Product controller), [`api/routes/products.js`](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/routes/products.js) (Product routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_server["Server entry<br/>Node.js entrypoint<br/>[server.js]"]
end

subgraph group_http["HTTP API"]
  node_app["Express app<br/>HTTP assembly<br/>[app.js]"]
  node_user_routes["User routes<br/>Express routes<br/>[user.js]"]
  node_product_routes["Product routes<br/>Express routes<br/>[products.js]"]
  node_order_routes["Order routes<br/>Express routes<br/>[orders.js]"]
  node_auth{{"JWT auth middleware<br/>Express middleware<br/>[check-auth.js]"}}
end

subgraph group_domain["Domain"]
  node_user_controller["User controller<br/>Auth handler<br/>[user.js]"]
  node_product_controller["Product controller<br/>Inventory handler<br/>[products.js]"]
  node_order_controller["Order controller<br/>Order handler<br/>[orders.js]"]
end

subgraph group_data["Data &amp; assets"]
  node_user_model["User model<br/>Mongoose model<br/>[user.js]"]
  node_product_model["Product model<br/>Mongoose model<br/>[product.js]"]
  node_order_model["Order model<br/>Mongoose model<br/>[order.js]"]
  node_uploads[("Upload assets<br/>File storage")]
  node_mongodb[("MongoDB Atlas<br/>Database service")]
end

node_server -->|"starts"| node_app
node_app -->|"mounts"| node_user_routes
node_app -->|"mounts"| node_product_routes
node_app -->|"mounts"| node_order_routes
node_user_routes -->|"delegates"| node_user_controller
node_product_routes -->|"protects mutations"| node_auth
node_order_routes -->|"protects operations"| node_auth
node_auth -->|"authorizes"| node_product_controller
node_auth -->|"authorizes"| node_order_controller
node_product_routes -->|"public reads"| node_product_controller
node_user_controller -->|"uses"| node_user_model
node_product_controller -->|"uses"| node_product_model
node_product_controller -->|"stores images"| node_uploads
node_order_controller -->|"uses"| node_order_model
node_order_controller -->|"resolves product"| node_product_model
node_user_model -->|"persists via Mongoose"| node_mongodb
node_product_model -->|"persists via Mongoose"| node_mongodb
node_order_model -->|"persists via Mongoose"| node_mongodb

click node_server "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/server.js"
click node_app "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/app.js"
click node_user_routes "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/routes/user.js"
click node_product_routes "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/routes/products.js"
click node_order_routes "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/routes/orders.js"
click node_auth "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/middleware/check-auth.js"
click node_user_controller "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/controllers/user.js"
click node_product_controller "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/controllers/products.js"
click node_order_controller "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/controllers/orders.js"
click node_user_model "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/models/user.js"
click node_product_model "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/models/product.js"
click node_order_model "https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/models/order.js"
click node_uploads "https://github.com/ralitsavoronevska/rest-api-with-nodejs/tree/master/uploads"

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 toneBlue
class node_app,node_user_routes,node_product_routes,node_order_routes,node_auth toneAmber
class node_user_controller,node_product_controller,node_order_controller toneMint
class node_user_model,node_product_model,node_order_model,node_uploads,node_mongodb toneRose
```

## Components

### Runtime

- [Server entry](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/server.js): Node.js entrypoint · Starts the API process. · `server.js`

### HTTP API

- [Express app](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/app.js): HTTP assembly · Configures middleware, routes, static files, and error responses. · `app.js`
- [User routes](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/routes/user.js): Express routes · Exposes signup and login. · `api/routes/user.js`
- [Product routes](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/routes/products.js): Express routes · Exposes public reads and protected mutations. · `api/routes/products.js`
- [Order routes](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/routes/orders.js): Express routes · Exposes protected order operations. · `api/routes/orders.js`
- [JWT auth middleware](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/middleware/check-auth.js): Express middleware · Validates bearer tokens before protected handlers. · `api/middleware/check-auth.js`

### Domain

- [User controller](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/controllers/user.js): Auth handler · Hashes passwords and issues JWTs. · `api/controllers/user.js`
- [Product controller](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/controllers/products.js): Inventory handler · Handles product CRUD and image-backed creation. · `api/controllers/products.js`
- [Order controller](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/controllers/orders.js): Order handler · Resolves products and persists orders. · `api/controllers/orders.js`

### Data & assets

- [User model](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/models/user.js): Mongoose model · `api/models/user.js`
- [Product model](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/models/product.js): Mongoose model · `api/models/product.js`
- [Order model](https://github.com/ralitsavoronevska/rest-api-with-nodejs/blob/master/api/models/order.js): Mongoose model · Stores order data with product references. · `api/models/order.js`
- [Upload assets](https://github.com/ralitsavoronevska/rest-api-with-nodejs/tree/master/uploads): File storage · Stores Multer-managed product images. · `uploads`
- **MongoDB Atlas**: Database service · Persistent datastore accessed through Mongoose.

## Connections

- Server entry → Express app: starts
- Express app → User routes: mounts
- Express app → Product routes: mounts
- Express app → Order routes: mounts
- User routes → User controller: delegates
- Product routes → JWT auth middleware: protects mutations
- Order routes → JWT auth middleware: protects operations
- JWT auth middleware → Product controller: authorizes
- JWT auth middleware → Order controller: authorizes
- Product routes → Product controller: public reads
- User controller → User model: uses
- Product controller → Product model: uses
- Product controller → Upload assets: stores images
- Order controller → Order model: uses
- Order controller → Product model: resolves product
- User model → MongoDB Atlas: persists via Mongoose
- Product model → MongoDB Atlas: persists via Mongoose
- Order model → MongoDB Atlas: persists via Mongoose
