# mardan-shah/haizra-backend architecture

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

- Interactive diagram: https://gitdiagram.com/mardan-shah/haizra-backend
- Repository: https://github.com/mardan-shah/haizra-backend

## Overview

1. This is a Bun-based backend service, not a full-stack app. The runtime entrypoint is `src/index.ts`, and the README indicates the server is started directly with Bun.

2. The code is organized around a resource-oriented API layer in `src/api/`. Each file corresponds to a domain area: `users`, `products`, `orders`, `auctions`, `reviews`, and `storefronts`. These modules are the main request-handling boundary.

3. The API layer is backed by a database access layer in `src/db/`. `src/db/db.ts` likely centralizes the database connection, while `src/db/migrate.ts` handles schema migrations or migration execution.

4. Database structure is defined with Drizzle ORM under `src/db/schema/`. The schema is split by business concept: `users`, `addresses`, `products`, `orders`, `auctions`, `ratings`, and `transactions`, plus `relations.ts` for table relationships and `index.ts` as the schema export surface.

5. The repository includes committed SQL migrations in the top-level `drizzle/` directory and matching snapshots in `drizzle/meta/`. This means schema evolution is managed through versioned migration artifacts rather than ad hoc runtime DDL.

6. The main data flow is: incoming request → resource module in `src/api/` → shared DB layer → Drizzle schema/migrations-backed PostgreSQL-style tables. The architecture is centered on persistence-first domain modules rather than in-memory services.

7. Authentication-related logic appears isolated in `src/utils/auth.ts`. That suggests auth is treated as a cross-cutting utility rather than being embedded inside each API resource.

8. There are two utility scripts at the repo root: `reset-db.ts` for rebuilding or clearing the database state, and `debug-schema.ts` for inspecting schema behavior. These are operational/support tools, not part of the request path.

9. Configuration and environment management are explicit: `.env.example` documents required runtime settings, `drizzle.config.ts` wires Drizzle tooling, `bunfig.toml` configures the Bun runtime, and `nixpacks.toml` suggests deployment/build-time packaging support.

10. The most important architectural boundary is between domain API modules and persistence. There is no evidence of separate frontend, queue worker, or microservice boundaries; this repo is a single-process backend exposing several business domains over a shared database.

Main entry points: [`src/db/schema/index.ts`](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/index.ts) (Schema export), [`src/index.ts`](https://github.com/mardan-shah/haizra-backend/blob/main/src/index.ts) (Server entry), [`src/db/db.ts`](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/db.ts) (DB layer), [`src/db/migrate.ts`](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/migrate.ts) (Migrator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_src_index(("Server entry<br/>bun entrypoint<br/>[index.ts]"))
end

subgraph group_api["API"]
  node_api_users["Users API<br/>resource module<br/>[users.ts]"]
  node_api_products["Products API<br/>resource module<br/>[products.ts]"]
  node_api_orders["Orders API<br/>resource module<br/>[orders.ts]"]
  node_api_auctions["Auctions API<br/>resource module<br/>[auctions.ts]"]
  node_api_reviews["Reviews API<br/>resource module<br/>[reviews.ts]"]
  node_api_storefronts["Storefronts API<br/>resource module<br/>[storefronts.ts]"]
end

subgraph group_persistence["Persistence"]
  node_db_layer[("DB layer<br/>database access<br/>[db.ts]")]
  node_db_migrate["Migrator<br/>schema migration<br/>[migrate.ts]"]
  node_schema_index["Schema export<br/>schema surface<br/>[index.ts]"]
  node_schema_users["Users table<br/>table schema<br/>[users.ts]"]
  node_schema_addresses["Addresses<br/>table schema<br/>[addresses.ts]"]
  node_schema_products["Products table<br/>table schema<br/>[products.ts]"]
  node_schema_orders["Orders table<br/>table schema<br/>[orders.ts]"]
  node_schema_auctions["Auctions table<br/>table schema<br/>[auctions.ts]"]
  node_schema_ratings["Ratings table<br/>table schema<br/>[ratings.ts]"]
  node_schema_tx["Transactions<br/>table schema<br/>[transactions.ts]"]
  node_schema_rel["Relations<br/>[relations.ts]"]
  node_migrations["Migrations<br/>sql history"]
end

subgraph group_ops["Ops"]
  node_debug_schema["Schema debug<br/>ops script<br/>[debug-schema.ts]"]
  node_reset_db["Reset DB<br/>ops script<br/>[reset-db.ts]"]
  node_env_example["Env sample<br/>config template<br/>[.env.example]"]
  node_bunfig["Bun config<br/>runtime config<br/>[bunfig.toml]"]
  node_drizzle_config["Drizzle config<br/>tooling config<br/>[drizzle.config.ts]"]
  node_nixpacks["Nixpacks<br/>deploy config<br/>[nixpacks.toml]"]
end

node_src_index -->|"routes to"| node_api_users
node_src_index -->|"routes to"| node_api_products
node_src_index -->|"routes to"| node_api_orders
node_src_index -->|"routes to"| node_api_auctions
node_src_index -->|"routes to"| node_api_reviews
node_src_index -->|"routes to"| node_api_storefronts
node_api_users -->|"queries"| node_db_layer
node_api_products -->|"queries"| node_db_layer
node_api_orders -->|"queries"| node_db_layer
node_api_auctions -->|"queries"| node_db_layer
node_api_reviews -->|"queries"| node_db_layer
node_api_storefronts -->|"queries"| node_db_layer
node_db_layer -->|"uses schema"| node_schema_index
node_schema_index -->|"exports"| node_schema_users
node_schema_index -->|"exports"| node_schema_addresses
node_schema_index -->|"exports"| node_schema_products
node_schema_index -->|"exports"| node_schema_orders
node_schema_index -->|"exports"| node_schema_auctions
node_schema_index -->|"exports"| node_schema_ratings
node_schema_index -->|"exports"| node_schema_tx
node_schema_index -->|"exports"| node_schema_rel
node_db_migrate -->|"applies"| node_migrations
node_db_migrate -->|"aligns with"| node_schema_index
node_debug_schema -.->|"inspects"| node_schema_index
node_reset_db -.->|"operates on"| node_db_layer
node_drizzle_config -->|"targets"| node_migrations
node_bunfig -.->|"configures"| node_src_index
node_env_example -.->|"documents"| node_src_index
node_nixpacks -.->|"packages"| node_src_index

click node_src_index "https://github.com/mardan-shah/haizra-backend/blob/main/src/index.ts"
click node_api_users "https://github.com/mardan-shah/haizra-backend/blob/main/src/api/users.ts"
click node_api_products "https://github.com/mardan-shah/haizra-backend/blob/main/src/api/products.ts"
click node_api_orders "https://github.com/mardan-shah/haizra-backend/blob/main/src/api/orders.ts"
click node_api_auctions "https://github.com/mardan-shah/haizra-backend/blob/main/src/api/auctions.ts"
click node_api_reviews "https://github.com/mardan-shah/haizra-backend/blob/main/src/api/reviews.ts"
click node_api_storefronts "https://github.com/mardan-shah/haizra-backend/blob/main/src/api/storefronts.ts"
click node_db_layer "https://github.com/mardan-shah/haizra-backend/blob/main/src/db/db.ts"
click node_db_migrate "https://github.com/mardan-shah/haizra-backend/blob/main/src/db/migrate.ts"
click node_schema_index "https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/index.ts"
click node_schema_users "https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/users.ts"
click node_schema_addresses "https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/addresses.ts"
click node_schema_products "https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/products.ts"
click node_schema_orders "https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/orders.ts"
click node_schema_auctions "https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/auctions.ts"
click node_schema_ratings "https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/ratings.ts"
click node_schema_tx "https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/transactions.ts"
click node_schema_rel "https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/relations.ts"
click node_migrations "https://github.com/mardan-shah/haizra-backend/tree/main/drizzle"
click node_debug_schema "https://github.com/mardan-shah/haizra-backend/blob/main/debug-schema.ts"
click node_reset_db "https://github.com/mardan-shah/haizra-backend/blob/main/reset-db.ts"
click node_env_example "https://github.com/mardan-shah/haizra-backend/blob/main/.env.example"
click node_bunfig "https://github.com/mardan-shah/haizra-backend/blob/main/bunfig.toml"
click node_drizzle_config "https://github.com/mardan-shah/haizra-backend/blob/main/drizzle.config.ts"
click node_nixpacks "https://github.com/mardan-shah/haizra-backend/blob/main/nixpacks.toml"

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_src_index toneBlue
class node_api_users,node_api_products,node_api_orders,node_api_auctions,node_api_reviews,node_api_storefronts toneAmber
class node_db_layer,node_db_migrate,node_schema_index,node_schema_users,node_schema_addresses,node_schema_products,node_schema_orders,node_schema_auctions,node_schema_ratings,node_schema_tx,node_schema_rel,node_migrations toneMint
class node_debug_schema,node_reset_db,node_env_example,node_bunfig,node_drizzle_config,node_nixpacks toneRose
```

## Components

### Runtime

Bun entrypoint and process startup

- [Server entry](https://github.com/mardan-shah/haizra-backend/blob/main/src/index.ts): bun entrypoint · Starts the backend process with Bun · `src/index.ts`

### API

Resource-oriented request handlers

- [Users API](https://github.com/mardan-shah/haizra-backend/blob/main/src/api/users.ts): resource module · Handles user-facing requests and domain actions · `src/api/users.ts`
- [Products API](https://github.com/mardan-shah/haizra-backend/blob/main/src/api/products.ts): resource module · Handles product-related requests · `src/api/products.ts`
- [Orders API](https://github.com/mardan-shah/haizra-backend/blob/main/src/api/orders.ts): resource module · Handles order lifecycle requests · `src/api/orders.ts`
- [Auctions API](https://github.com/mardan-shah/haizra-backend/blob/main/src/api/auctions.ts): resource module · Handles auction workflow requests · `src/api/auctions.ts`
- [Reviews API](https://github.com/mardan-shah/haizra-backend/blob/main/src/api/reviews.ts): resource module · Handles review and rating requests · `src/api/reviews.ts`
- [Storefronts API](https://github.com/mardan-shah/haizra-backend/blob/main/src/api/storefronts.ts): resource module · Handles storefront-related requests · `src/api/storefronts.ts`

### Persistence

Shared database access, schema, and migrations

- [DB layer](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/db.ts): database access · Shared database connection and query access · `src/db/db.ts`
- [Migrator](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/migrate.ts): schema migration · Runs or coordinates database migrations · `src/db/migrate.ts`
- [Schema export](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/index.ts): schema surface · Central export surface for Drizzle schema modules · `src/db/schema/index.ts`
- [Users table](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/users.ts): table schema · User identity and account data · `src/db/schema/users.ts`
- [Addresses](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/addresses.ts): table schema · Address records used by domain tables · `src/db/schema/addresses.ts`
- [Products table](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/products.ts): table schema · Product catalog persistence · `src/db/schema/products.ts`
- [Orders table](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/orders.ts): table schema · Order persistence and status data · `src/db/schema/orders.ts`
- [Auctions table](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/auctions.ts): table schema · Auction persistence and lifecycle data · `src/db/schema/auctions.ts`
- [Ratings table](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/ratings.ts): table schema · Review and rating persistence · `src/db/schema/ratings.ts`
- [Transactions](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/transactions.ts): table schema · Transactional and payment-related persistence · `src/db/schema/transactions.ts`
- [Relations](https://github.com/mardan-shah/haizra-backend/blob/main/src/db/schema/relations.ts): schema relations · Defines table relationships for Drizzle · `src/db/schema/relations.ts`
- [Migrations](https://github.com/mardan-shah/haizra-backend/tree/main/drizzle): sql history · Versioned SQL migration files tracked in drizzle/ · `drizzle`

### Ops

Support scripts and runtime configuration

- [Schema debug](https://github.com/mardan-shah/haizra-backend/blob/main/debug-schema.ts): ops script · Inspects schema behavior during development · `debug-schema.ts`
- [Reset DB](https://github.com/mardan-shah/haizra-backend/blob/main/reset-db.ts): ops script · Clears or rebuilds database state · `reset-db.ts`
- [Env sample](https://github.com/mardan-shah/haizra-backend/blob/main/.env.example): config template · Documents required runtime environment variables · `.env.example`
- [Bun config](https://github.com/mardan-shah/haizra-backend/blob/main/bunfig.toml): runtime config · Configures Bun behavior for the project · `bunfig.toml`
- [Drizzle config](https://github.com/mardan-shah/haizra-backend/blob/main/drizzle.config.ts): tooling config · Configures Drizzle ORM tooling and migration paths · `drizzle.config.ts`
- [Nixpacks](https://github.com/mardan-shah/haizra-backend/blob/main/nixpacks.toml): deploy config · Build and deployment packaging configuration · `nixpacks.toml`

## Connections

- Server entry → Users API: routes to · Entrypoint loads resource handlers
- Server entry → Products API: routes to · Entrypoint loads resource handlers
- Server entry → Orders API: routes to · Entrypoint loads resource handlers
- Server entry → Auctions API: routes to · Entrypoint loads resource handlers
- Server entry → Reviews API: routes to · Entrypoint loads resource handlers
- Server entry → Storefronts API: routes to · Entrypoint loads resource handlers
- Users API → DB layer: queries · User requests read and write through shared DB access
- Products API → DB layer: queries · Product requests read and write through shared DB access
- Orders API → DB layer: queries · Order requests read and write through shared DB access
- Auctions API → DB layer: queries · Auction requests read and write through shared DB access
- Reviews API → DB layer: queries · Review requests read and write through shared DB access
- Storefronts API → DB layer: queries · Storefront requests read and write through shared DB access
- DB layer → Schema export: uses schema · Database access is shaped by the shared schema surface
- Schema export → Users table: exports · Aggregates schema modules
- Schema export → Addresses: exports · Aggregates schema modules
- Schema export → Products table: exports · Aggregates schema modules
- Schema export → Orders table: exports · Aggregates schema modules
- Schema export → Auctions table: exports · Aggregates schema modules
- Schema export → Ratings table: exports · Aggregates schema modules
- Schema export → Transactions: exports · Aggregates schema modules
- Schema export → Relations: exports · Aggregates schema modules
- Migrator → Migrations: applies · Migration runner consumes committed SQL history
- Migrator → Schema export: aligns with · Migration execution is kept in sync with schema definitions
- Schema debug → Schema export: inspects · Development tool examines schema behavior
- Reset DB → DB layer: operates on · Reset script uses shared database access
- Drizzle config → Migrations: targets · Tooling points at migration artifacts
- Bun config → Server entry: configures · Runtime configuration supports Bun startup
- Env sample → Server entry: documents · Sample environment settings for startup
- Nixpacks → Server entry: packages · Deployment config supports running the server
