# ahsanhanif657/supermarket-backend architecture

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

- Interactive diagram: https://gitdiagram.com/ahsanhanif657/supermarket-backend
- Repository: https://github.com/ahsanhanif657/supermarket-backend

## Overview

This is a small Express backend for supermarket product CRUD, backed by SQLite. A client request enters through the server, is routed to product handlers, and reads or changes product records before receiving a response. Category CRUD is also implemented in separate routes and handlers, with validation on category creation and updates, but index.js does not mount those routes. The sampled database setup creates only the products table. Product validation and the error handler are present but are not wired into the sampled request flow.

Main entry points: [`database/db.js`](https://github.com/ahsanhanif657/supermarket-backend/blob/master/database/db.js) (Database connection), [`routes/categoryroutes.js`](https://github.com/ahsanhanif657/supermarket-backend/blob/master/routes/categoryroutes.js) (Category routes), [`index.js`](https://github.com/ahsanhanif657/supermarket-backend/blob/master/index.js) (Express server), [`routes/productRoutes.js`](https://github.com/ahsanhanif657/supermarket-backend/blob/master/routes/productRoutes.js) (Product routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_routing["HTTP routing"]
  node_server["Express server<br/>[index.js]"]
  node_product_routes["Product routes<br/>[productRoutes.js]"]
  node_category_routes["Category routes<br/>[categoryroutes.js]"]
end

subgraph group_handlers["Domain handlers"]
  node_category_validation["Category validation"]
  node_product_controller["Product handlers"]
  node_category_controller["Category handlers"]
end

subgraph group_storage["SQLite storage"]
  node_db_module["Database connection<br/>[db.js]"]
  node_sqlite[("SQLite database<br/>[supermarket.db]")]
end

node_client(("API client"))

node_client -->|"sends requests"| node_server
node_server -->|"mounts /products"| node_product_routes
node_product_routes -->|"dispatches CRUD"| node_product_controller
node_category_routes -->|"validates writes"| node_category_validation
node_category_routes -->|"dispatches CRUD"| node_category_controller
node_product_controller -->|"queries products"| node_db_module
node_category_controller -->|"queries categories"| node_db_module
node_db_module -->|"opens database"| node_sqlite

click node_server "https://github.com/ahsanhanif657/supermarket-backend/blob/master/index.js"
click node_product_routes "https://github.com/ahsanhanif657/supermarket-backend/blob/master/routes/productRoutes.js"
click node_category_routes "https://github.com/ahsanhanif657/supermarket-backend/blob/master/routes/categoryroutes.js"
click node_category_validation "https://github.com/ahsanhanif657/supermarket-backend/blob/master/middleware/categoryValidation.js"
click node_product_controller "https://github.com/ahsanhanif657/supermarket-backend/blob/master/controllers/productController.js"
click node_category_controller "https://github.com/ahsanhanif657/supermarket-backend/blob/master/controllers/categorycontroller.js"
click node_db_module "https://github.com/ahsanhanif657/supermarket-backend/blob/master/database/db.js"
click node_sqlite "https://github.com/ahsanhanif657/supermarket-backend/blob/master/database/supermarket.db"

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_product_routes,node_category_routes,node_client toneBlue
class node_category_validation,node_product_controller,node_category_controller toneAmber
class node_db_module,node_sqlite toneMint
```

## Components

### HTTP routing

- [Express server](https://github.com/ahsanhanif657/supermarket-backend/blob/master/index.js): `index.js`
- [Product routes](https://github.com/ahsanhanif657/supermarket-backend/blob/master/routes/productRoutes.js): `routes/productRoutes.js`
- [Category routes](https://github.com/ahsanhanif657/supermarket-backend/blob/master/routes/categoryroutes.js): `routes/categoryroutes.js`

### Domain handlers

- [Category validation](https://github.com/ahsanhanif657/supermarket-backend/blob/master/middleware/categoryValidation.js): `middleware/categoryValidation.js`
- [Product handlers](https://github.com/ahsanhanif657/supermarket-backend/blob/master/controllers/productController.js): `controllers/productController.js`
- [Category handlers](https://github.com/ahsanhanif657/supermarket-backend/blob/master/controllers/categorycontroller.js): `controllers/categorycontroller.js`

### SQLite storage

- [Database connection](https://github.com/ahsanhanif657/supermarket-backend/blob/master/database/db.js): `database/db.js`
- [SQLite database](https://github.com/ahsanhanif657/supermarket-backend/blob/master/database/supermarket.db): `database/supermarket.db`

### Other components

- **API client**

## Connections

- API client → Express server: sends requests
- Express server → Product routes: mounts /products
- Product routes → Product handlers: dispatches CRUD
- Category routes → Category validation: validates writes
- Category routes → Category handlers: dispatches CRUD
- Product handlers → Database connection: queries products
- Category handlers → Database connection: queries categories
- Database connection → SQLite database: opens database
