# nourzeidan/core-service architecture

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

- Interactive diagram: https://gitdiagram.com/nourzeidan/core-service
- Repository: https://github.com/nourzeidan/core-service

## Overview

Core-service is the restaurant, staff-access, branch, and catalog backend for a food-delivery platform. Its main workflow is an HTTP request through route guards and a feature controller into business services and PostgreSQL repositories; registration additionally creates a user, restaurant, and owner membership before issuing tokens. The graph preserves the documented auth, RBAC, geospatial branch search, product, customer-address, pagination, and internal order-service capabilities. Some feature internals are unsampled, so their links are limited to README and source-index evidence.

Main entry points: [`src/routes.ts`](https://github.com/nourzeidan/core-service/blob/main/src/routes.ts) (API routes), [`src/app/auth/service/auth.service.ts`](https://github.com/nourzeidan/core-service/blob/main/src/app/auth/service/auth.service.ts) (Auth workflows), [`src/lib/knex/knex.ts`](https://github.com/nourzeidan/core-service/blob/main/src/lib/knex/knex.ts) (Knex database access), [`src/app/auth/controller/auth.controller.ts`](https://github.com/nourzeidan/core-service/blob/main/src/app/auth/controller/auth.controller.ts) (Auth controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["HTTP entry"]
  node_routes["API routes<br/>[routes.ts]"]
  node_auth_routes["Auth routes<br/>[routes.ts]"]
  node_auth_controller["Auth controller<br/>[auth.controller.ts]"]
  node_member_routes["Member routes<br/>[routes.ts]"]
  node_member_controller["Member controller"]
  node_restaurant_routes["Restaurant routes<br/>[routes.ts]"]
  node_restaurant_controller["Restaurant controller<br/>[rest.controller.ts]"]
  node_branch_controller["Branch endpoints"]
  node_product_controller["Product endpoints"]
end

subgraph group_identity["Identity and access"]
  node_auth_service["Auth workflows<br/>[auth.service.ts]"]
  node_user_service["User accounts<br/>[user.service.ts]"]
  node_user_repo["User records<br/>[users.repo.ts]"]
  node_auth_guard["JWT guard<br/>[guard.ts]"]
  node_rbac["Permission checks<br/>[rbac.ts]"]
  node_member_service["Staff membership<br/>[member.service.ts]"]
end

subgraph group_operations["Restaurant operations"]
  node_restaurant_service["Restaurant workflows"]
  node_branch_service["Branch operations<br/>[branch.service.ts]"]
  node_product_service["Catalog and stock<br/>[product.service.ts]"]
  node_address_service["Customer addresses<br/>[address.service.ts]"]
end

subgraph group_platform["Shared platform"]
  node_validation["DTO validation<br/>[validate.ts]"]
  node_pagination["List pagination"]
  node_db_access["Knex database access<br/>[knex.ts]"]
  node_email["Email provider<br/>[email.interface.ts]"]
end

node_client(("API clients"))
node_postgres[("PostgreSQL and PostGIS")]
node_internal_order(("Order service"))

node_client -->|"sends requests"| node_routes
node_routes -->|"mounts auth"| node_auth_routes
node_auth_routes -->|"dispatches"| node_auth_controller
node_auth_controller -->|"calls"| node_auth_service
node_auth_controller -->|"validates input"| node_validation
node_auth_service -->|"creates account"| node_user_service
node_auth_service -->|"looks up users"| node_user_repo
node_auth_service -->|"creates restaurant"| node_restaurant_service
node_auth_service -->|"creates owner membership"| node_member_service
node_auth_service -->|"sends reset email"| node_email
node_routes -->|"protects routes"| node_auth_guard
node_routes -->|"mounts members"| node_member_routes
node_member_routes -->|"dispatches"| node_member_controller
node_member_controller -->|"calls"| node_member_service
node_routes -->|"mounts restaurants"| node_restaurant_routes
node_restaurant_routes -->|"dispatches"| node_restaurant_controller
node_restaurant_controller -->|"calls"| node_restaurant_service
node_restaurant_controller -->|"parses pagination"| node_pagination
node_routes -->|"mounts branches"| node_branch_controller
node_branch_controller -->|"calls"| node_branch_service
node_routes -->|"mounts products"| node_product_controller
node_product_controller -->|"calls"| node_product_service
node_routes -->|"mounts customer routes"| node_address_service
node_member_routes -->|"checks permissions"| node_rbac
node_restaurant_routes -->|"checks permissions"| node_rbac
node_auth_guard -->|"verifies access token"| node_auth_service
node_user_service -.->|"persists users"| node_user_repo
node_restaurant_service -->|"queries via Knex"| node_db_access
node_member_service -->|"uses transactions"| node_db_access
node_db_access -->|"queries"| node_postgres
node_internal_order -->|"calls internal API"| node_routes
node_product_service -.->|"stores catalog and stock"| node_db_access
node_branch_service -.->|"queries locations"| node_db_access

click node_routes "https://github.com/nourzeidan/core-service/blob/main/src/routes.ts"
click node_auth_routes "https://github.com/nourzeidan/core-service/blob/main/src/app/auth/routes.ts"
click node_auth_controller "https://github.com/nourzeidan/core-service/blob/main/src/app/auth/controller/auth.controller.ts"
click node_auth_service "https://github.com/nourzeidan/core-service/blob/main/src/app/auth/service/auth.service.ts"
click node_user_service "https://github.com/nourzeidan/core-service/blob/main/src/app/user/service/user.service.ts"
click node_user_repo "https://github.com/nourzeidan/core-service/blob/main/src/app/user/repository/users.repo.ts"
click node_auth_guard "https://github.com/nourzeidan/core-service/blob/main/src/lib/auth/guard.ts"
click node_rbac "https://github.com/nourzeidan/core-service/blob/main/src/app/auth/rbac.ts"
click node_member_routes "https://github.com/nourzeidan/core-service/blob/main/src/app/rbac/routes.ts"
click node_member_controller "https://github.com/nourzeidan/core-service/blob/main/src/app/rbac/controller/member.controller.ts"
click node_member_service "https://github.com/nourzeidan/core-service/blob/main/src/app/rbac/service/member.service.ts"
click node_restaurant_routes "https://github.com/nourzeidan/core-service/blob/main/src/app/restaurant/routes.ts"
click node_restaurant_controller "https://github.com/nourzeidan/core-service/blob/main/src/app/restaurant/controller/rest.controller.ts"
click node_restaurant_service "https://github.com/nourzeidan/core-service/blob/main/src/app/restaurant/service/restaurant.service.ts"
click node_branch_controller "https://github.com/nourzeidan/core-service/blob/main/src/app/branch/controller/branch.controller.ts"
click node_branch_service "https://github.com/nourzeidan/core-service/blob/main/src/app/branch/service/branch.service.ts"
click node_product_controller "https://github.com/nourzeidan/core-service/blob/main/src/app/product/controller/product.controller.ts"
click node_product_service "https://github.com/nourzeidan/core-service/blob/main/src/app/product/service/product.service.ts"
click node_address_service "https://github.com/nourzeidan/core-service/blob/main/src/app/customer/addresses/service/address.service.ts"
click node_validation "https://github.com/nourzeidan/core-service/blob/main/src/lib/validation/validate.ts"
click node_pagination "https://github.com/nourzeidan/core-service/blob/main/src/lib/http/pagination/cursor-pagination.ts"
click node_db_access "https://github.com/nourzeidan/core-service/blob/main/src/lib/knex/knex.ts"
click node_email "https://github.com/nourzeidan/core-service/blob/main/src/pkg/email/email.interface.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_routes,node_auth_routes,node_auth_controller,node_member_routes,node_member_controller,node_restaurant_routes,node_restaurant_controller,node_branch_controller,node_product_controller,node_client toneBlue
class node_auth_service,node_user_service,node_user_repo,node_auth_guard,node_rbac,node_member_service,node_postgres toneAmber
class node_restaurant_service,node_branch_service,node_product_service,node_address_service toneMint
class node_validation,node_pagination,node_db_access,node_email toneRose
class node_internal_order toneIndigo
```

## Components

### HTTP entry

- [API routes](https://github.com/nourzeidan/core-service/blob/main/src/routes.ts): `src/routes.ts`
- [Auth routes](https://github.com/nourzeidan/core-service/blob/main/src/app/auth/routes.ts): `src/app/auth/routes.ts`
- [Auth controller](https://github.com/nourzeidan/core-service/blob/main/src/app/auth/controller/auth.controller.ts): `src/app/auth/controller/auth.controller.ts`
- [Member routes](https://github.com/nourzeidan/core-service/blob/main/src/app/rbac/routes.ts): `src/app/rbac/routes.ts`
- [Member controller](https://github.com/nourzeidan/core-service/blob/main/src/app/rbac/controller/member.controller.ts): `src/app/rbac/controller/member.controller.ts`
- [Restaurant routes](https://github.com/nourzeidan/core-service/blob/main/src/app/restaurant/routes.ts): `src/app/restaurant/routes.ts`
- [Restaurant controller](https://github.com/nourzeidan/core-service/blob/main/src/app/restaurant/controller/rest.controller.ts): `src/app/restaurant/controller/rest.controller.ts`
- [Branch endpoints](https://github.com/nourzeidan/core-service/blob/main/src/app/branch/controller/branch.controller.ts): `src/app/branch/controller/branch.controller.ts`
- [Product endpoints](https://github.com/nourzeidan/core-service/blob/main/src/app/product/controller/product.controller.ts): `src/app/product/controller/product.controller.ts`

### Identity and access

- [Auth workflows](https://github.com/nourzeidan/core-service/blob/main/src/app/auth/service/auth.service.ts): `src/app/auth/service/auth.service.ts`
- [User accounts](https://github.com/nourzeidan/core-service/blob/main/src/app/user/service/user.service.ts): `src/app/user/service/user.service.ts`
- [User records](https://github.com/nourzeidan/core-service/blob/main/src/app/user/repository/users.repo.ts): `src/app/user/repository/users.repo.ts`
- [JWT guard](https://github.com/nourzeidan/core-service/blob/main/src/lib/auth/guard.ts): `src/lib/auth/guard.ts`
- [Permission checks](https://github.com/nourzeidan/core-service/blob/main/src/app/auth/rbac.ts): `src/app/auth/rbac.ts`
- [Staff membership](https://github.com/nourzeidan/core-service/blob/main/src/app/rbac/service/member.service.ts): `src/app/rbac/service/member.service.ts`

### Restaurant operations

- [Restaurant workflows](https://github.com/nourzeidan/core-service/blob/main/src/app/restaurant/service/restaurant.service.ts): `src/app/restaurant/service/restaurant.service.ts`
- [Branch operations](https://github.com/nourzeidan/core-service/blob/main/src/app/branch/service/branch.service.ts): `src/app/branch/service/branch.service.ts`
- [Catalog and stock](https://github.com/nourzeidan/core-service/blob/main/src/app/product/service/product.service.ts): `src/app/product/service/product.service.ts`
- [Customer addresses](https://github.com/nourzeidan/core-service/blob/main/src/app/customer/addresses/service/address.service.ts): `src/app/customer/addresses/service/address.service.ts`

### Shared platform

- [DTO validation](https://github.com/nourzeidan/core-service/blob/main/src/lib/validation/validate.ts): `src/lib/validation/validate.ts`
- [List pagination](https://github.com/nourzeidan/core-service/blob/main/src/lib/http/pagination/cursor-pagination.ts): `src/lib/http/pagination/cursor-pagination.ts`
- [Knex database access](https://github.com/nourzeidan/core-service/blob/main/src/lib/knex/knex.ts): `src/lib/knex/knex.ts`
- [Email provider](https://github.com/nourzeidan/core-service/blob/main/src/pkg/email/email.interface.ts): `src/pkg/email/email.interface.ts`

### Other components

- **API clients**
- **PostgreSQL and PostGIS**
- **Order service**

## Connections

- API clients → API routes: sends requests (evidence: `src/routes.ts`)
- API routes → Auth routes: mounts auth (evidence: `src/routes.ts`)
- Auth routes → Auth controller: dispatches (evidence: `src/app/auth/routes.ts`)
- Auth controller → Auth workflows: calls (evidence: `src/app/auth/controller/auth.controller.ts`)
- Auth controller → DTO validation: validates input (evidence: `src/app/auth/controller/auth.controller.ts`)
- Auth workflows → User accounts: creates account (evidence: `src/app/auth/service/auth.service.ts`)
- Auth workflows → User records: looks up users (evidence: `src/app/auth/service/auth.service.ts`)
- Auth workflows → Restaurant workflows: creates restaurant (evidence: `src/app/auth/service/auth.service.ts`)
- Auth workflows → Staff membership: creates owner membership (evidence: `src/app/auth/service/auth.service.ts`)
- Auth workflows → Email provider: sends reset email (evidence: `src/app/auth/service/auth.service.ts`)
- API routes → JWT guard: protects routes (evidence: `README.md`)
- API routes → Member routes: mounts members (evidence: `src/routes.ts`)
- Member routes → Member controller: dispatches (evidence: `src/app/rbac/routes.ts`)
- Member controller → Staff membership: calls (evidence: `src/app/rbac/controller/member.controller.ts`)
- API routes → Restaurant routes: mounts restaurants (evidence: `src/routes.ts`)
- Restaurant routes → Restaurant controller: dispatches (evidence: `src/app/restaurant/routes.ts`)
- Restaurant controller → Restaurant workflows: calls (evidence: `src/app/restaurant/controller/rest.controller.ts`)
- Restaurant controller → List pagination: parses pagination (evidence: `src/app/restaurant/controller/rest.controller.ts`)
- API routes → Branch endpoints: mounts branches (evidence: `src/routes.ts`)
- Branch endpoints → Branch operations: calls (evidence: `src/app/branch/controller/branch.controller.ts`)
- API routes → Product endpoints: mounts products (evidence: `src/routes.ts`)
- Product endpoints → Catalog and stock: calls (evidence: `src/app/product/controller/product.controller.ts`)
- API routes → Customer addresses: mounts customer routes (evidence: `src/routes.ts`)
- Member routes → Permission checks: checks permissions (evidence: `README.md`)
- Restaurant routes → Permission checks: checks permissions (evidence: `README.md`)
- JWT guard → Auth workflows: verifies access token (evidence: `src/lib/auth/guard.ts`)
- User accounts → User records: persists users
- Restaurant workflows → Knex database access: queries via Knex (evidence: `src/app/restaurant/service/restaurant.service.ts`)
- Staff membership → Knex database access: uses transactions (evidence: `src/app/rbac/service/member.service.ts`)
- Knex database access → PostgreSQL and PostGIS: queries (evidence: `README.md`)
- Order service → API routes: calls internal API (evidence: `src/routes.ts`)
- Catalog and stock → Knex database access: stores catalog and stock
- Branch operations → Knex database access: queries locations
