# ahanafintesher/prisma-postgresql-server architecture

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

- Interactive diagram: https://gitdiagram.com/ahanafintesher/prisma-postgresql-server
- Repository: https://github.com/ahanafintesher/prisma-postgresql-server

## Overview

WorkSphere EMS is a REST backend for the Super Admin Portal. An administrator calls the Express gateway, which mounts service routes across direct, API, and versioned prefixes; protected routes authenticate and authorize requests before domain handlers return management results. The API covers identity, tenant operations, billing, governance, support, and platform settings, backed by Prisma/PostgreSQL and optional hybrid Redis caching. Shared pagination and response utilities support domain handlers. The graph follows documented capabilities and indexed references; unsampled controller internals are not assumed to prove specific calls.

Main entry points: [`src/routes/index.ts`](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/routes/index.ts) (Route Mounts), [`src/lib/prisma.ts`](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/lib/prisma.ts) (Prisma Client), [`src/lib/redis.ts`](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/lib/redis.ts) (Redis and Memory Cache), [`src/lib/pagination.ts`](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/lib/pagination.ts) (Pagination)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["API Gateway"]
  node_express["Express App<br/>[app.ts]"]
  node_router["Route Mounts<br/>[index.ts]"]
end

subgraph group_domains["Admin Domains"]
  node_auth["Authentication<br/>[auth.controller.ts]"]
  node_companies["Company Lifecycle"]
  node_dashboard["Dashboard Metrics"]
  node_subscriptions["Plans and Subscriptions"]
  node_payments["Payments and Promotions"]
  node_support["Support and Notices"]
  node_admins["Admin Accounts"]
  node_roles["Roles and Permissions"]
  node_audit["Audit Logs"]
  node_settings["Settings and Telemetry"]
end

subgraph group_shared["Shared Runtime"]
  node_security["JWT and RBAC<br/>[auth.middleware.ts]"]
  node_cachemw["Cache Middleware"]
  node_pagination["Pagination<br/>[pagination.ts]"]
  node_response["Response Envelopes<br/>[response.ts]"]
end

subgraph group_state["Persistence and Cache"]
  node_dbclient["Prisma Client<br/>[prisma.ts]"]
  node_database[("PostgreSQL<br/>[schema.prisma]")]
  node_cache[("Redis and Memory Cache<br/>[redis.ts]")]
end

node_admin(("Super Admin"))

node_admin -->|"sends requests"| node_express
node_express -->|"mounts routes"| node_router
node_express -->|"routes health checks"| node_settings
node_router -->|"mounts"| node_auth
node_router -->|"mounts"| node_companies
node_router -->|"mounts"| node_dashboard
node_router -->|"mounts"| node_subscriptions
node_router -->|"mounts"| node_payments
node_router -->|"mounts"| node_support
node_router -->|"mounts"| node_admins
node_router -->|"mounts"| node_roles
node_router -->|"mounts"| node_audit
node_router -->|"mounts"| node_settings
node_router -->|"applies guards"| node_security
node_router -->|"applies caching"| node_cachemw
node_security -->|"checks admin role"| node_dbclient
node_cachemw -->|"reads and writes"| node_cache
node_companies -->|"uses pagination"| node_pagination
node_subscriptions -->|"uses pagination"| node_pagination
node_payments -->|"uses pagination"| node_pagination
node_support -->|"uses pagination"| node_pagination
node_pagination -->|"builds envelopes"| node_response
node_subscriptions -->|"invalidates categories"| node_cache
node_payments -->|"invalidates categories"| node_cache
node_support -->|"invalidates categories"| node_cache
node_settings -->|"reads health"| node_cache
node_express -->|"checks health"| node_cache
node_dbclient -->|"queries"| node_database
node_companies -->|"uses client"| node_dbclient
node_dashboard -->|"uses client"| node_dbclient
node_subscriptions -->|"uses client"| node_dbclient
node_payments -->|"uses client"| node_dbclient
node_support -->|"uses client"| node_dbclient
node_admins -->|"uses client"| node_dbclient
node_roles -->|"uses client"| node_dbclient
node_audit -->|"uses client"| node_dbclient
node_settings -->|"uses client"| node_dbclient
node_auth -->|"uses client"| node_dbclient
node_companies -->|"formats results"| node_response
node_auth -->|"formats results"| node_response

click node_express "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/app.ts"
click node_router "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/routes/index.ts"
click node_auth "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/auth/auth.controller.ts"
click node_companies "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/companies/company.controller.ts"
click node_dashboard "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/dashboard/dashboard.controller.ts"
click node_subscriptions "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/subscriptions/subscription.controller.ts"
click node_payments "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/payments/payment.controller.ts"
click node_support "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/support/support.controller.ts"
click node_admins "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/admin-users/admin-users.controller.ts"
click node_roles "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/roles/roles.controller.ts"
click node_audit "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/audit/audit.controller.ts"
click node_settings "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/settings/settings.controller.ts"
click node_security "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/middleware/auth.middleware.ts"
click node_cachemw "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/middleware/cache.middleware.ts"
click node_pagination "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/lib/pagination.ts"
click node_response "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/lib/response.ts"
click node_dbclient "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/lib/prisma.ts"
click node_database "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/prisma/schema.prisma"
click node_cache "https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/lib/redis.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_express,node_router toneBlue
class node_auth,node_companies,node_dashboard,node_subscriptions,node_payments,node_support,node_admins,node_roles,node_audit,node_settings toneAmber
class node_security,node_cachemw,node_pagination,node_response toneMint
class node_dbclient,node_database,node_cache toneRose
class node_admin toneIndigo
```

## Components

### API Gateway

- [Express App](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/app.ts): `src/app.ts`
- [Route Mounts](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/routes/index.ts): `src/routes/index.ts`

### Admin Domains

- [Authentication](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/auth/auth.controller.ts): `src/services/auth/auth.controller.ts`
- [Company Lifecycle](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/companies/company.controller.ts): `src/services/companies/company.controller.ts`
- [Dashboard Metrics](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/dashboard/dashboard.controller.ts): `src/services/dashboard/dashboard.controller.ts`
- [Plans and Subscriptions](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/subscriptions/subscription.controller.ts): `src/services/subscriptions/subscription.controller.ts`
- [Payments and Promotions](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/payments/payment.controller.ts): `src/services/payments/payment.controller.ts`
- [Support and Notices](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/support/support.controller.ts): `src/services/support/support.controller.ts`
- [Admin Accounts](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/admin-users/admin-users.controller.ts): `src/services/admin-users/admin-users.controller.ts`
- [Roles and Permissions](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/roles/roles.controller.ts): `src/services/roles/roles.controller.ts`
- [Audit Logs](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/audit/audit.controller.ts): `src/services/audit/audit.controller.ts`
- [Settings and Telemetry](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/services/settings/settings.controller.ts): `src/services/settings/settings.controller.ts`

### Shared Runtime

- [JWT and RBAC](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/middleware/auth.middleware.ts): `src/middleware/auth.middleware.ts`
- [Cache Middleware](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/middleware/cache.middleware.ts): `src/middleware/cache.middleware.ts`
- [Pagination](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/lib/pagination.ts): `src/lib/pagination.ts`
- [Response Envelopes](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/lib/response.ts): `src/lib/response.ts`

### Persistence and Cache

- [Prisma Client](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/lib/prisma.ts): `src/lib/prisma.ts`
- [PostgreSQL](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/prisma/schema.prisma): `prisma/schema.prisma`
- [Redis and Memory Cache](https://github.com/ahanafintesher/prisma-postgresql-server/blob/main/src/lib/redis.ts): `src/lib/redis.ts`

### Other components

- **Super Admin**

## Connections

- Super Admin → Express App: sends requests (evidence: `README.md`)
- Express App → Route Mounts: mounts routes (evidence: `src/app.ts`)
- Express App → Settings and Telemetry: routes health checks (evidence: `src/app.ts`)
- Route Mounts → Authentication: mounts (evidence: `src/routes/index.ts`)
- Route Mounts → Company Lifecycle: mounts (evidence: `src/routes/index.ts`)
- Route Mounts → Dashboard Metrics: mounts (evidence: `src/routes/index.ts`)
- Route Mounts → Plans and Subscriptions: mounts (evidence: `src/routes/index.ts`)
- Route Mounts → Payments and Promotions: mounts (evidence: `src/routes/index.ts`)
- Route Mounts → Support and Notices: mounts (evidence: `src/routes/index.ts`)
- Route Mounts → Admin Accounts: mounts (evidence: `src/routes/index.ts`)
- Route Mounts → Roles and Permissions: mounts (evidence: `src/routes/index.ts`)
- Route Mounts → Audit Logs: mounts (evidence: `src/routes/index.ts`)
- Route Mounts → Settings and Telemetry: mounts (evidence: `src/routes/index.ts`)
- Route Mounts → JWT and RBAC: applies guards (evidence: `src/routes/index.ts`)
- Route Mounts → Cache Middleware: applies caching (evidence: `src/routes/index.ts`)
- JWT and RBAC → Prisma Client: checks admin role (evidence: `src/middleware/auth.middleware.ts`)
- Cache Middleware → Redis and Memory Cache: reads and writes (evidence: `src/middleware/cache.middleware.ts`)
- Company Lifecycle → Pagination: uses pagination (evidence: `src/services/companies/company.controller.ts`)
- Plans and Subscriptions → Pagination: uses pagination (evidence: `src/services/subscriptions/subscription.controller.ts`)
- Payments and Promotions → Pagination: uses pagination (evidence: `src/services/payments/payment.controller.ts`)
- Support and Notices → Pagination: uses pagination (evidence: `src/services/support/support.controller.ts`)
- Pagination → Response Envelopes: builds envelopes (evidence: `src/lib/pagination.ts`)
- Plans and Subscriptions → Redis and Memory Cache: invalidates categories (evidence: `src/services/subscriptions/subscription.controller.ts`)
- Payments and Promotions → Redis and Memory Cache: invalidates categories (evidence: `src/services/payments/payment.controller.ts`)
- Support and Notices → Redis and Memory Cache: invalidates categories (evidence: `src/services/support/support.controller.ts`)
- Settings and Telemetry → Redis and Memory Cache: reads health (evidence: `src/services/settings/settings.controller.ts`)
- Express App → Redis and Memory Cache: checks health (evidence: `src/app.ts`)
- Prisma Client → PostgreSQL: queries (evidence: `src/lib/prisma.ts`)
- Company Lifecycle → Prisma Client: uses client (evidence: `src/services/companies/company.controller.ts`)
- Dashboard Metrics → Prisma Client: uses client (evidence: `src/services/dashboard/dashboard.controller.ts`)
- Plans and Subscriptions → Prisma Client: uses client (evidence: `src/services/subscriptions/subscription.controller.ts`)
- Payments and Promotions → Prisma Client: uses client (evidence: `src/services/payments/payment.controller.ts`)
- Support and Notices → Prisma Client: uses client (evidence: `src/services/support/support.controller.ts`)
- Admin Accounts → Prisma Client: uses client (evidence: `src/services/admin-users/admin-users.controller.ts`)
- Roles and Permissions → Prisma Client: uses client (evidence: `src/services/roles/roles.controller.ts`)
- Audit Logs → Prisma Client: uses client (evidence: `src/services/audit/audit.controller.ts`)
- Settings and Telemetry → Prisma Client: uses client (evidence: `src/services/settings/settings.controller.ts`)
- Authentication → Prisma Client: uses client (evidence: `src/services/auth/auth.controller.ts`)
- Company Lifecycle → Response Envelopes: formats results (evidence: `src/services/companies/company.controller.ts`)
- Authentication → Response Envelopes: formats results (evidence: `src/services/auth/auth.controller.ts`)
