# abhinks151/stockflow architecture

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

- Interactive diagram: https://gitdiagram.com/abhinks151/stockflow
- Repository: https://github.com/abhinks151/stockflow

## Overview

This is a StockFlow-style e-commerce backend split into an API gateway and user, inventory, order, and notification services. The main workflow is a customer request to create an order: the order service obtains user and product details, checks and deducts stock, persists the order, then publishes an event for confirmation email processing. User registration/login and profile operations, plus product catalog and stock management, are separate capabilities. Edges reflect shown imports and calls; cross-service transport and event-broker links are marked unverified where implementation excerpts were unavailable.

Main entry points: [`order-service/src/services/order.service.ts`](https://github.com/abhinks151/stockflow/blob/main/order-service/src/services/order.service.ts) (Order workflow), [`api-gateway/src/index.ts`](https://github.com/abhinks151/stockflow/blob/main/api-gateway/src/index.ts) (Gateway), [`user-service/src/services/user.service.ts`](https://github.com/abhinks151/stockflow/blob/main/user-service/src/services/user.service.ts) (User logic), [`inventory-service/src/services/product.service.ts`](https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/services/product.service.ts) (Product logic)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["API Gateway"]
  node_gateway_app["Gateway<br/>[index.ts]"]
  node_gateway_auth["Gateway auth<br/>[auth.middleware.ts]"]
end

subgraph group_users["User Service"]
  node_user_routes["User routes<br/>[user.routes.ts]"]
  node_user_controller["User controller<br/>[user.controller.ts]"]
  node_user_service["User logic<br/>[user.service.ts]"]
  node_user_repository["User repository<br/>[user.repository.ts]"]
  node_user_model["User model<br/>[user.model.ts]"]
  node_user_db[("User database<br/>[db.ts]")]
  node_user_grpc["User gRPC<br/>[user.grpc.ts]"]
  node_user_types["User contracts<br/>[user.interface.ts]"]
end

subgraph group_inventory["Inventory Service"]
  node_inventory_routes["Product routes<br/>[product.routes.ts]"]
  node_product_controller["Product controller"]
  node_product_service["Product logic<br/>[product.service.ts]"]
  node_product_repository["Product repository"]
  node_inventory_db[("Inventory database<br/>[db.ts]")]
  node_inventory_grpc["Inventory gRPC<br/>[inventory.grpc.ts]"]
  node_product_types["Product contracts"]
end

subgraph group_orders["Order Service"]
  node_order_routes["Order routes<br/>[order.routes.ts]"]
  node_order_controller["Order controller"]
  node_order_service["Order workflow<br/>[order.service.ts]"]
  node_order_repository["Order repository"]
  node_order_model["Order model<br/>[order.model.ts]"]
  node_order_db[("Order database<br/>[db.ts]")]
  node_order_types["Order contracts<br/>[order.interface.ts]"]
  node_inventory_client["Inventory client"]
  node_user_client["User client<br/>[user.client.ts]"]
  node_event_publisher["Event publisher<br/>[publisher.ts]"]
end

subgraph group_notifications["Notifications"]
  node_notification_consumer["Event consumer<br/>[consumer.ts]"]
  node_email_service["Email service<br/>[email.service.ts]"]
end

node_customer(("Customer"))
node_broker["Message broker"]
node_smtp(("SMTP service"))

node_customer -.->|"sends requests"| node_gateway_app
node_gateway_app -->|"uses auth"| node_gateway_auth
node_gateway_app -.->|"forwards requests"| node_user_routes
node_gateway_app -.->|"forwards requests"| node_inventory_routes
node_gateway_app -.->|"forwards requests"| node_order_routes
node_user_routes -->|"dispatches"| node_user_controller
node_user_controller -->|"invokes"| node_user_service
node_user_service -->|"reads and writes"| node_user_repository
node_user_repository -->|"uses model"| node_user_model
node_user_repository -->|"accesses"| node_user_db
node_user_model -->|"implements"| node_user_types
node_user_service -->|"uses contracts"| node_user_types
node_user_grpc -->|"calls"| node_user_service
node_inventory_routes -->|"dispatches"| node_product_controller
node_product_controller -->|"invokes"| node_product_service
node_product_service -->|"reads and writes"| node_product_repository
node_product_repository -->|"accesses"| node_inventory_db
node_product_service -->|"uses contracts"| node_product_types
node_inventory_grpc -->|"calls"| node_product_service
node_order_routes -->|"dispatches"| node_order_controller
node_order_controller -->|"invokes"| node_order_service
node_order_service -->|"fetches user"| node_user_client
node_order_service -->|"fetches product"| node_inventory_client
node_order_service -->|"deducts stock"| node_inventory_client
node_user_client -.->|"requests user"| node_user_grpc
node_inventory_client -.->|"requests inventory"| node_inventory_grpc
node_order_service -->|"persists order"| node_order_repository
node_order_service -->|"publishes event"| node_event_publisher
node_order_repository -->|"uses model"| node_order_model
node_order_repository -.->|"accesses"| node_order_db
node_order_model -->|"implements"| node_order_types
node_event_publisher -.->|"publishes"| node_broker
node_broker -.->|"delivers events"| node_notification_consumer
node_notification_consumer -->|"requests email"| node_email_service
node_email_service -->|"sends mail"| node_smtp

click node_gateway_app "https://github.com/abhinks151/stockflow/blob/main/api-gateway/src/index.ts"
click node_gateway_auth "https://github.com/abhinks151/stockflow/blob/main/api-gateway/src/middleware/auth.middleware.ts"
click node_user_routes "https://github.com/abhinks151/stockflow/blob/main/user-service/src/routes/user.routes.ts"
click node_user_controller "https://github.com/abhinks151/stockflow/blob/main/user-service/src/controllers/user.controller.ts"
click node_user_service "https://github.com/abhinks151/stockflow/blob/main/user-service/src/services/user.service.ts"
click node_user_repository "https://github.com/abhinks151/stockflow/blob/main/user-service/src/repositories/user.repository.ts"
click node_user_model "https://github.com/abhinks151/stockflow/blob/main/user-service/src/models/user.model.ts"
click node_user_db "https://github.com/abhinks151/stockflow/blob/main/user-service/src/config/db.ts"
click node_user_grpc "https://github.com/abhinks151/stockflow/blob/main/user-service/src/grpc/user.grpc.ts"
click node_user_types "https://github.com/abhinks151/stockflow/blob/main/user-service/src/interfaces/user.interface.ts"
click node_inventory_routes "https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/routes/product.routes.ts"
click node_product_controller "https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/controllers/product.controller.ts"
click node_product_service "https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/services/product.service.ts"
click node_product_repository "https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/repositories/product.repository.ts"
click node_inventory_db "https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/config/db.ts"
click node_inventory_grpc "https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/grpc/inventory.grpc.ts"
click node_product_types "https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/interfaces/product.interface.ts"
click node_order_routes "https://github.com/abhinks151/stockflow/blob/main/order-service/src/routes/order.routes.ts"
click node_order_controller "https://github.com/abhinks151/stockflow/blob/main/order-service/src/controllers/order.controller.ts"
click node_order_service "https://github.com/abhinks151/stockflow/blob/main/order-service/src/services/order.service.ts"
click node_order_repository "https://github.com/abhinks151/stockflow/blob/main/order-service/src/repositories/order.repository.ts"
click node_order_model "https://github.com/abhinks151/stockflow/blob/main/order-service/src/models/order.model.ts"
click node_order_db "https://github.com/abhinks151/stockflow/blob/main/order-service/src/config/db.ts"
click node_order_types "https://github.com/abhinks151/stockflow/blob/main/order-service/src/interfaces/order.interface.ts"
click node_inventory_client "https://github.com/abhinks151/stockflow/blob/main/order-service/src/clients/inventory.client.ts"
click node_user_client "https://github.com/abhinks151/stockflow/blob/main/order-service/src/clients/user.client.ts"
click node_event_publisher "https://github.com/abhinks151/stockflow/blob/main/order-service/src/events/publisher.ts"
click node_notification_consumer "https://github.com/abhinks151/stockflow/blob/main/notification-service/src/events/consumer.ts"
click node_email_service "https://github.com/abhinks151/stockflow/blob/main/notification-service/src/services/email.service.ts"

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_gateway_app,node_gateway_auth toneBlue
class node_user_routes,node_user_controller,node_user_service,node_user_repository,node_user_model,node_user_db,node_user_grpc,node_user_types toneAmber
class node_inventory_routes,node_product_controller,node_product_service,node_product_repository,node_inventory_db,node_inventory_grpc,node_product_types toneMint
class node_order_routes,node_order_controller,node_order_service,node_order_repository,node_order_model,node_order_db,node_order_types,node_inventory_client,node_user_client,node_event_publisher toneRose
class node_notification_consumer,node_email_service,node_customer,node_broker,node_smtp toneIndigo
```

## Components

### API Gateway

- [Gateway](https://github.com/abhinks151/stockflow/blob/main/api-gateway/src/index.ts): `api-gateway/src/index.ts`
- [Gateway auth](https://github.com/abhinks151/stockflow/blob/main/api-gateway/src/middleware/auth.middleware.ts): `api-gateway/src/middleware/auth.middleware.ts`

### User Service

- [User routes](https://github.com/abhinks151/stockflow/blob/main/user-service/src/routes/user.routes.ts): `user-service/src/routes/user.routes.ts`
- [User controller](https://github.com/abhinks151/stockflow/blob/main/user-service/src/controllers/user.controller.ts): `user-service/src/controllers/user.controller.ts`
- [User logic](https://github.com/abhinks151/stockflow/blob/main/user-service/src/services/user.service.ts): `user-service/src/services/user.service.ts`
- [User repository](https://github.com/abhinks151/stockflow/blob/main/user-service/src/repositories/user.repository.ts): `user-service/src/repositories/user.repository.ts`
- [User model](https://github.com/abhinks151/stockflow/blob/main/user-service/src/models/user.model.ts): `user-service/src/models/user.model.ts`
- [User database](https://github.com/abhinks151/stockflow/blob/main/user-service/src/config/db.ts): `user-service/src/config/db.ts`
- [User gRPC](https://github.com/abhinks151/stockflow/blob/main/user-service/src/grpc/user.grpc.ts): `user-service/src/grpc/user.grpc.ts`
- [User contracts](https://github.com/abhinks151/stockflow/blob/main/user-service/src/interfaces/user.interface.ts): `user-service/src/interfaces/user.interface.ts`

### Inventory Service

- [Product routes](https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/routes/product.routes.ts): `inventory-service/src/routes/product.routes.ts`
- [Product controller](https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/controllers/product.controller.ts): `inventory-service/src/controllers/product.controller.ts`
- [Product logic](https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/services/product.service.ts): `inventory-service/src/services/product.service.ts`
- [Product repository](https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/repositories/product.repository.ts): `inventory-service/src/repositories/product.repository.ts`
- [Inventory database](https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/config/db.ts): `inventory-service/src/config/db.ts`
- [Inventory gRPC](https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/grpc/inventory.grpc.ts): `inventory-service/src/grpc/inventory.grpc.ts`
- [Product contracts](https://github.com/abhinks151/stockflow/blob/main/inventory-service/src/interfaces/product.interface.ts): `inventory-service/src/interfaces/product.interface.ts`

### Order Service

- [Order routes](https://github.com/abhinks151/stockflow/blob/main/order-service/src/routes/order.routes.ts): `order-service/src/routes/order.routes.ts`
- [Order controller](https://github.com/abhinks151/stockflow/blob/main/order-service/src/controllers/order.controller.ts): `order-service/src/controllers/order.controller.ts`
- [Order workflow](https://github.com/abhinks151/stockflow/blob/main/order-service/src/services/order.service.ts): `order-service/src/services/order.service.ts`
- [Order repository](https://github.com/abhinks151/stockflow/blob/main/order-service/src/repositories/order.repository.ts): `order-service/src/repositories/order.repository.ts`
- [Order model](https://github.com/abhinks151/stockflow/blob/main/order-service/src/models/order.model.ts): `order-service/src/models/order.model.ts`
- [Order database](https://github.com/abhinks151/stockflow/blob/main/order-service/src/config/db.ts): `order-service/src/config/db.ts`
- [Order contracts](https://github.com/abhinks151/stockflow/blob/main/order-service/src/interfaces/order.interface.ts): `order-service/src/interfaces/order.interface.ts`
- [Inventory client](https://github.com/abhinks151/stockflow/blob/main/order-service/src/clients/inventory.client.ts): `order-service/src/clients/inventory.client.ts`
- [User client](https://github.com/abhinks151/stockflow/blob/main/order-service/src/clients/user.client.ts): `order-service/src/clients/user.client.ts`
- [Event publisher](https://github.com/abhinks151/stockflow/blob/main/order-service/src/events/publisher.ts): `order-service/src/events/publisher.ts`

### Notifications

- [Event consumer](https://github.com/abhinks151/stockflow/blob/main/notification-service/src/events/consumer.ts): `notification-service/src/events/consumer.ts`
- [Email service](https://github.com/abhinks151/stockflow/blob/main/notification-service/src/services/email.service.ts): `notification-service/src/services/email.service.ts`

### Other components

- **Customer**
- **Message broker**
- **SMTP service**

## Connections

- Customer → Gateway: sends requests
- Gateway → Gateway auth: uses auth (evidence: `api-gateway/src/index.ts`)
- Gateway → User routes: forwards requests
- Gateway → Product routes: forwards requests
- Gateway → Order routes: forwards requests
- User routes → User controller: dispatches (evidence: `user-service/src/routes/user.routes.ts`)
- User controller → User logic: invokes (evidence: `user-service/src/controllers/user.controller.ts`)
- User logic → User repository: reads and writes (evidence: `user-service/src/services/user.service.ts`)
- User repository → User model: uses model (evidence: `user-service/src/repositories/user.repository.ts`)
- User repository → User database: accesses (evidence: `user-service/src/repositories/user.repository.ts`)
- User model → User contracts: implements (evidence: `user-service/src/models/user.model.ts`)
- User logic → User contracts: uses contracts (evidence: `user-service/src/services/user.service.ts`)
- User gRPC → User logic: calls
- Product routes → Product controller: dispatches (evidence: `inventory-service/src/routes/product.routes.ts`)
- Product controller → Product logic: invokes (evidence: `inventory-service/src/controllers/product.controller.ts`)
- Product logic → Product repository: reads and writes (evidence: `inventory-service/src/services/product.service.ts`)
- Product repository → Inventory database: accesses (evidence: `inventory-service/src/repositories/product.repository.ts`)
- Product logic → Product contracts: uses contracts (evidence: `inventory-service/src/services/product.service.ts`)
- Inventory gRPC → Product logic: calls (evidence: `inventory-service/src/grpc/inventory.grpc.ts`)
- Order routes → Order controller: dispatches (evidence: `order-service/src/routes/order.routes.ts`)
- Order controller → Order workflow: invokes (evidence: `order-service/src/controllers/order.controller.ts`)
- Order workflow → User client: fetches user (evidence: `order-service/src/services/order.service.ts`)
- Order workflow → Inventory client: fetches product (evidence: `order-service/src/services/order.service.ts`)
- Order workflow → Inventory client: deducts stock (evidence: `order-service/src/services/order.service.ts`)
- User client → User gRPC: requests user
- Inventory client → Inventory gRPC: requests inventory
- Order workflow → Order repository: persists order (evidence: `order-service/src/services/order.service.ts`)
- Order workflow → Event publisher: publishes event (evidence: `order-service/src/services/order.service.ts`)
- Order repository → Order model: uses model (evidence: `order-service/src/repositories/order.repository.ts`)
- Order repository → Order database: accesses
- Order model → Order contracts: implements (evidence: `order-service/src/models/order.model.ts`)
- Event publisher → Message broker: publishes
- Message broker → Event consumer: delivers events
- Event consumer → Email service: requests email (evidence: `notification-service/src/events/consumer.ts`)
- Email service → SMTP service: sends mail (evidence: `notification-service/src/services/email.service.ts`)
