# rejancortess/k-warriors-backend architecture

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

- Interactive diagram: https://gitdiagram.com/rejancortess/k-warriors-backend
- Repository: https://github.com/rejancortess/k-warriors-backend

## Overview

K-Warriors is an inventory-management API. Clients enter through the Express app, which mounts authentication, dashboard, product, stock, transaction, and user endpoints. Authenticated workflows verify Firebase tokens and associate users with PostgreSQL records; inventory workflows expose product management, stock movements, transaction history, and dashboard statistics. The graph follows shown route, controller, and service relationships. The README is empty, so product capabilities are inferred from the available source index and excerpts; unsampled service details are not expanded.

Main entry points: [`src/app.ts`](https://github.com/rejancortess/k-warriors-backend/blob/main/src/app.ts) (Express API), [`src/lib/prisma.ts`](https://github.com/rejancortess/k-warriors-backend/blob/main/src/lib/prisma.ts) (Prisma client), [`src/middleware/requireAuth.ts`](https://github.com/rejancortess/k-warriors-backend/blob/main/src/middleware/requireAuth.ts) (Auth middleware), [`src/lib/firebase-admin.ts`](https://github.com/rejancortess/k-warriors-backend/blob/main/src/lib/firebase-admin.ts) (Firebase Admin)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entry and auth"]
  node_app["Express API<br/>[app.ts]"]
  node_auth_routes["Auth routes<br/>[auth.routes.ts]"]
  node_auth_controller["Auth controller<br/>[auth.controller.ts]"]
  node_auth_service["Auth service<br/>[auth.service.ts]"]
  node_auth_middleware["Auth middleware<br/>[requireAuth.ts]"]
  node_users_routes["User routes<br/>[user.routes.ts]"]
  node_users_controller["User controller<br/>[user.controller.ts]"]
  node_users_service["User service<br/>[user.service.ts]"]
end

subgraph group_inventory["Inventory operations"]
  node_products_routes["Product routes<br/>[product.routes.ts]"]
  node_products_controller["Product controller"]
  node_products_service["Product service<br/>[product.service.ts]"]
  node_stock_routes["Stock routes<br/>[stock.routes.ts]"]
  node_stock_controller["Stock controller"]
  node_stock_schema["Movement schema<br/>[stock.schema.ts]"]
  node_stock_service["Stock service<br/>[stock.service.ts]"]
end

subgraph group_insights["History and insights"]
  node_transactions_routes["Transaction routes"]
  node_transactions_controller["Transaction controller"]
  node_transactions_service["Transaction service"]
  node_dashboard_routes["Dashboard routes"]
  node_dashboard_controller["Dashboard controller"]
  node_dashboard_service["Dashboard service"]
end

subgraph group_infrastructure["Persistence and identity"]
  node_prisma_client["Prisma client<br/>[prisma.ts]"]
  node_database[("PostgreSQL data<br/>[schema.prisma]")]
  node_firebase_admin["Firebase Admin<br/>[firebase-admin.ts]"]
end

node_client(("API client"))
node_firebase{{"Firebase Auth"}}

node_client -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_auth_routes
node_app -->|"mounts routes"| node_dashboard_routes
node_app -->|"mounts routes"| node_products_routes
node_app -->|"mounts routes"| node_stock_routes
node_app -->|"mounts routes"| node_transactions_routes
node_app -->|"mounts routes"| node_users_routes
node_auth_routes -->|"dispatches to"| node_auth_controller
node_auth_routes -->|"protects routes"| node_auth_middleware
node_auth_controller -->|"calls"| node_auth_service
node_auth_service -->|"verifies tokens"| node_firebase_admin
node_auth_middleware -->|"verifies tokens"| node_firebase_admin
node_auth_service -->|"syncs user records"| node_prisma_client
node_auth_middleware -->|"loads user"| node_prisma_client
node_users_routes -->|"dispatches to"| node_users_controller
node_users_routes -->|"protects routes"| node_auth_middleware
node_users_controller -->|"calls"| node_users_service
node_users_service -->|"manages users"| node_prisma_client
node_users_service -->|"uses identity admin"| node_firebase_admin
node_products_routes -->|"dispatches to"| node_products_controller
node_products_routes -->|"protects routes"| node_auth_middleware
node_products_controller -->|"calls"| node_products_service
node_products_service -->|"queries inventory"| node_prisma_client
node_stock_routes -->|"dispatches to"| node_stock_controller
node_stock_routes -->|"protects routes"| node_auth_middleware
node_stock_controller -->|"validates with"| node_stock_schema
node_stock_controller -->|"calls"| node_stock_service
node_stock_service -->|"records movements"| node_prisma_client
node_transactions_routes -->|"dispatches to"| node_transactions_controller
node_transactions_controller -->|"calls"| node_transactions_service
node_transactions_service -->|"queries history"| node_prisma_client
node_dashboard_routes -->|"dispatches to"| node_dashboard_controller
node_dashboard_routes -->|"protects routes"| node_auth_middleware
node_dashboard_controller -->|"calls"| node_dashboard_service
node_dashboard_service -->|"queries metrics"| node_prisma_client
node_prisma_client -.->|"reads and writes"| node_database
node_firebase_admin -.->|"configures client"| node_firebase

click node_app "https://github.com/rejancortess/k-warriors-backend/blob/main/src/app.ts"
click node_auth_routes "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/auth/auth.routes.ts"
click node_auth_controller "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/auth/auth.controller.ts"
click node_auth_service "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/auth/auth.service.ts"
click node_auth_middleware "https://github.com/rejancortess/k-warriors-backend/blob/main/src/middleware/requireAuth.ts"
click node_users_routes "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/users/user.routes.ts"
click node_users_controller "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/users/user.controller.ts"
click node_users_service "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/users/user.service.ts"
click node_products_routes "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/products/product.routes.ts"
click node_products_controller "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/products/product.controller.ts"
click node_products_service "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/products/product.service.ts"
click node_stock_routes "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/stock/stock.routes.ts"
click node_stock_controller "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/stock/stock.controller.ts"
click node_stock_schema "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/stock/stock.schema.ts"
click node_stock_service "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/stock/stock.service.ts"
click node_transactions_routes "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/transactions/transaction.routes.ts"
click node_transactions_controller "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/transactions/transaction.controller.ts"
click node_transactions_service "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/transactions/transaction.service.ts"
click node_dashboard_routes "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/dashboard/dashboard.routes.ts"
click node_dashboard_controller "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/dashboard/dashboard.controller.ts"
click node_dashboard_service "https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/dashboard/dashboard.service.ts"
click node_prisma_client "https://github.com/rejancortess/k-warriors-backend/blob/main/src/lib/prisma.ts"
click node_database "https://github.com/rejancortess/k-warriors-backend/blob/main/prisma/schema.prisma"
click node_firebase_admin "https://github.com/rejancortess/k-warriors-backend/blob/main/src/lib/firebase-admin.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_app,node_auth_routes,node_auth_controller,node_auth_service,node_auth_middleware,node_users_routes,node_users_controller,node_users_service,node_client toneBlue
class node_products_routes,node_products_controller,node_products_service,node_stock_routes,node_stock_controller,node_stock_schema,node_stock_service toneAmber
class node_transactions_routes,node_transactions_controller,node_transactions_service,node_dashboard_routes,node_dashboard_controller,node_dashboard_service toneMint
class node_prisma_client,node_database,node_firebase_admin toneRose
class node_firebase toneIndigo
```

## Components

### API entry and auth

- [Express API](https://github.com/rejancortess/k-warriors-backend/blob/main/src/app.ts): `src/app.ts`
- [Auth routes](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/auth/auth.routes.ts): `src/modules/auth/auth.routes.ts`
- [Auth controller](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/auth/auth.controller.ts): `src/modules/auth/auth.controller.ts`
- [Auth service](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/auth/auth.service.ts): `src/modules/auth/auth.service.ts`
- [Auth middleware](https://github.com/rejancortess/k-warriors-backend/blob/main/src/middleware/requireAuth.ts): `src/middleware/requireAuth.ts`
- [User routes](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/users/user.routes.ts): `src/modules/users/user.routes.ts`
- [User controller](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/users/user.controller.ts): `src/modules/users/user.controller.ts`
- [User service](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/users/user.service.ts): `src/modules/users/user.service.ts`

### Inventory operations

- [Product routes](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/products/product.routes.ts): `src/modules/products/product.routes.ts`
- [Product controller](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/products/product.controller.ts): `src/modules/products/product.controller.ts`
- [Product service](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/products/product.service.ts): `src/modules/products/product.service.ts`
- [Stock routes](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/stock/stock.routes.ts): `src/modules/stock/stock.routes.ts`
- [Stock controller](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/stock/stock.controller.ts): `src/modules/stock/stock.controller.ts`
- [Movement schema](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/stock/stock.schema.ts): `src/modules/stock/stock.schema.ts`
- [Stock service](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/stock/stock.service.ts): `src/modules/stock/stock.service.ts`

### History and insights

- [Transaction routes](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/transactions/transaction.routes.ts): `src/modules/transactions/transaction.routes.ts`
- [Transaction controller](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/transactions/transaction.controller.ts): `src/modules/transactions/transaction.controller.ts`
- [Transaction service](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/transactions/transaction.service.ts): `src/modules/transactions/transaction.service.ts`
- [Dashboard routes](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/dashboard/dashboard.routes.ts): `src/modules/dashboard/dashboard.routes.ts`
- [Dashboard controller](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/dashboard/dashboard.controller.ts): `src/modules/dashboard/dashboard.controller.ts`
- [Dashboard service](https://github.com/rejancortess/k-warriors-backend/blob/main/src/modules/dashboard/dashboard.service.ts): `src/modules/dashboard/dashboard.service.ts`

### Persistence and identity

- [Prisma client](https://github.com/rejancortess/k-warriors-backend/blob/main/src/lib/prisma.ts): `src/lib/prisma.ts`
- [PostgreSQL data](https://github.com/rejancortess/k-warriors-backend/blob/main/prisma/schema.prisma): `prisma/schema.prisma`
- [Firebase Admin](https://github.com/rejancortess/k-warriors-backend/blob/main/src/lib/firebase-admin.ts): `src/lib/firebase-admin.ts`

### Other components

- **API client**
- **Firebase Auth**

## Connections

- API client → Express API: sends requests (evidence: `src/app.ts`)
- Express API → Auth routes: mounts routes (evidence: `src/app.ts`)
- Express API → Dashboard routes: mounts routes (evidence: `src/app.ts`)
- Express API → Product routes: mounts routes (evidence: `src/app.ts`)
- Express API → Stock routes: mounts routes (evidence: `src/app.ts`)
- Express API → Transaction routes: mounts routes (evidence: `src/app.ts`)
- Express API → User routes: mounts routes (evidence: `src/app.ts`)
- Auth routes → Auth controller: dispatches to (evidence: `src/modules/auth/auth.routes.ts`)
- Auth routes → Auth middleware: protects routes (evidence: `src/modules/auth/auth.routes.ts`)
- Auth controller → Auth service: calls (evidence: `src/modules/auth/auth.controller.ts`)
- Auth service → Firebase Admin: verifies tokens (evidence: `src/modules/auth/auth.service.ts`)
- Auth middleware → Firebase Admin: verifies tokens (evidence: `src/middleware/requireAuth.ts`)
- Auth service → Prisma client: syncs user records (evidence: `src/modules/auth/auth.service.ts`)
- Auth middleware → Prisma client: loads user (evidence: `src/middleware/requireAuth.ts`)
- User routes → User controller: dispatches to (evidence: `src/modules/users/user.routes.ts`)
- User routes → Auth middleware: protects routes (evidence: `src/modules/users/user.routes.ts`)
- User controller → User service: calls (evidence: `src/modules/users/user.controller.ts`)
- User service → Prisma client: manages users (evidence: `src/modules/users/user.service.ts`)
- User service → Firebase Admin: uses identity admin (evidence: `src/modules/users/user.service.ts`)
- Product routes → Product controller: dispatches to (evidence: `src/modules/products/product.routes.ts`)
- Product routes → Auth middleware: protects routes (evidence: `src/modules/products/product.routes.ts`)
- Product controller → Product service: calls (evidence: `src/modules/products/product.controller.ts`)
- Product service → Prisma client: queries inventory (evidence: `src/modules/products/product.service.ts`)
- Stock routes → Stock controller: dispatches to (evidence: `src/modules/stock/stock.routes.ts`)
- Stock routes → Auth middleware: protects routes (evidence: `src/modules/stock/stock.routes.ts`)
- Stock controller → Movement schema: validates with (evidence: `src/modules/stock/stock.controller.ts`)
- Stock controller → Stock service: calls (evidence: `src/modules/stock/stock.controller.ts`)
- Stock service → Prisma client: records movements (evidence: `src/modules/stock/stock.service.ts`)
- Transaction routes → Transaction controller: dispatches to (evidence: `src/modules/transactions/transaction.routes.ts`)
- Transaction controller → Transaction service: calls (evidence: `src/modules/transactions/transaction.controller.ts`)
- Transaction service → Prisma client: queries history (evidence: `src/modules/transactions/transaction.service.ts`)
- Dashboard routes → Dashboard controller: dispatches to (evidence: `src/modules/dashboard/dashboard.routes.ts`)
- Dashboard routes → Auth middleware: protects routes (evidence: `src/modules/dashboard/dashboard.routes.ts`)
- Dashboard controller → Dashboard service: calls (evidence: `src/modules/dashboard/dashboard.controller.ts`)
- Dashboard service → Prisma client: queries metrics (evidence: `src/modules/dashboard/dashboard.service.ts`)
- Prisma client → PostgreSQL data: reads and writes
- Firebase Admin → Firebase Auth: configures client
