# mshchebetiuk/authentication-service architecture

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

- Interactive diagram: https://gitdiagram.com/mshchebetiuk/authentication-service
- Repository: https://github.com/mshchebetiuk/authentication-service

## Overview

This repository is a REST authentication and authorization service. Clients register or log in through the API, receive access and refresh tokens, use access tokens on protected profile and admin endpoints, and can rotate or revoke refresh tokens. The graph separates request routing, authentication and authorization, domain services, and persistence. Some health, admin, and user-service internals were not excerpted; their documented capabilities are included, but uncertain internal calls are omitted.

Main entry points: [`src/app.ts`](https://github.com/mshchebetiuk/authentication-service/blob/main/src/app.ts) (Express app), [`src/config/prisma.ts`](https://github.com/mshchebetiuk/authentication-service/blob/main/src/config/prisma.ts) (Prisma client), [`src/routes/adminRoutes.ts`](https://github.com/mshchebetiuk/authentication-service/blob/main/src/routes/adminRoutes.ts) (Admin routes), [`src/controllers/authController.ts`](https://github.com/mshchebetiuk/authentication-service/blob/main/src/controllers/authController.ts) (Auth controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API routing"]
  node_server["HTTP server<br/>[server.ts]"]
  node_app["Express app<br/>[app.ts]"]
  node_auth_routes["Auth routes<br/>[authRoutes.ts]"]
  node_user_routes["User routes<br/>[userRoutes.ts]"]
  node_admin_routes["Admin routes<br/>[adminRoutes.ts]"]
  node_health_routes["Health routes<br/>[healthRoutes.ts]"]
  node_auth_controller["Auth controller<br/>[authController.ts]"]
  node_user_controller["Profile controller<br/>[userController.ts]"]
  node_admin_controller["Admin controller<br/>[adminController.ts]"]
  node_health_controller["Health controller"]
  node_error_handler["Error handling<br/>[errorHandler.ts]"]
end

subgraph group_security["Identity and access"]
  node_auth_middleware["JWT middleware<br/>[authMiddleware.ts]"]
  node_role_middleware["Role guard<br/>[requireRole.ts]"]
  node_rate_limiter["Rate limiter<br/>[rateLimiter.ts]"]
  node_auth_schema["Auth validation<br/>[authSchema.ts]"]
  node_jwt["JWT utilities<br/>[jwt.ts]"]
end

subgraph group_domain["Domain services"]
  node_auth_service["Account auth<br/>[authService.ts]"]
  node_refresh_service["Refresh tokens"]
  node_user_service["Profile service<br/>[userService.ts]"]
  node_admin_service["User administration<br/>[adminService.ts]"]
  node_health_service["Health check<br/>[healthService.ts]"]
end

subgraph group_persistence["Persistence"]
  node_prisma["Prisma client<br/>[prisma.ts]"]
  node_database[("PostgreSQL data<br/>[schema.prisma]")]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]

node_client -->|"sends requests"| node_server
node_server -->|"starts"| node_app
node_app -->|"mounts"| node_auth_routes
node_app -->|"mounts"| node_user_routes
node_app -->|"mounts"| node_admin_routes
node_app -->|"mounts"| node_health_routes
node_app -->|"handles errors"| node_error_handler
node_auth_routes -->|"dispatches"| node_auth_controller
node_auth_routes -->|"limits register login"| node_rate_limiter
node_user_routes -->|"protects route"| node_auth_middleware
node_user_routes -->|"dispatches"| node_user_controller
node_admin_routes -->|"authenticates"| node_auth_middleware
node_admin_routes -->|"checks role"| node_role_middleware
node_admin_routes -->|"dispatches"| node_admin_controller
node_health_routes -->|"dispatches"| node_health_controller
node_auth_controller -->|"validates input"| node_auth_schema
node_auth_controller -->|"registers and logs in"| node_auth_service
node_auth_controller -->|"rotates or revokes"| node_refresh_service
node_user_controller -->|"loads profile"| node_user_service
node_auth_middleware -->|"verifies access token"| node_jwt
node_auth_service -->|"creates refresh token"| node_refresh_service
node_auth_service -->|"creates access token"| node_jwt
node_auth_service -->|"reads and writes users"| node_prisma
node_refresh_service -->|"stores token hashes"| node_prisma
node_user_service -->|"reads user data"| node_prisma
node_admin_service -->|"queries users"| node_prisma
node_health_controller -->|"uses health check"| node_health_service
node_prisma -->|"persists records"| node_database
node_database -->|"uses"| node_postgres

click node_server "https://github.com/mshchebetiuk/authentication-service/blob/main/src/server.ts"
click node_app "https://github.com/mshchebetiuk/authentication-service/blob/main/src/app.ts"
click node_auth_routes "https://github.com/mshchebetiuk/authentication-service/blob/main/src/routes/authRoutes.ts"
click node_user_routes "https://github.com/mshchebetiuk/authentication-service/blob/main/src/routes/userRoutes.ts"
click node_admin_routes "https://github.com/mshchebetiuk/authentication-service/blob/main/src/routes/adminRoutes.ts"
click node_health_routes "https://github.com/mshchebetiuk/authentication-service/blob/main/src/routes/healthRoutes.ts"
click node_auth_controller "https://github.com/mshchebetiuk/authentication-service/blob/main/src/controllers/authController.ts"
click node_user_controller "https://github.com/mshchebetiuk/authentication-service/blob/main/src/controllers/userController.ts"
click node_admin_controller "https://github.com/mshchebetiuk/authentication-service/blob/main/src/controllers/adminController.ts"
click node_health_controller "https://github.com/mshchebetiuk/authentication-service/blob/main/src/controllers/healthController.ts"
click node_auth_middleware "https://github.com/mshchebetiuk/authentication-service/blob/main/src/middlewares/authMiddleware.ts"
click node_role_middleware "https://github.com/mshchebetiuk/authentication-service/blob/main/src/middlewares/requireRole.ts"
click node_rate_limiter "https://github.com/mshchebetiuk/authentication-service/blob/main/src/middlewares/rateLimiter.ts"
click node_auth_schema "https://github.com/mshchebetiuk/authentication-service/blob/main/src/schemas/authSchema.ts"
click node_jwt "https://github.com/mshchebetiuk/authentication-service/blob/main/src/utils/jwt.ts"
click node_auth_service "https://github.com/mshchebetiuk/authentication-service/blob/main/src/services/authService.ts"
click node_refresh_service "https://github.com/mshchebetiuk/authentication-service/blob/main/src/services/refreshTokenService.ts"
click node_user_service "https://github.com/mshchebetiuk/authentication-service/blob/main/src/services/userService.ts"
click node_admin_service "https://github.com/mshchebetiuk/authentication-service/blob/main/src/services/adminService.ts"
click node_health_service "https://github.com/mshchebetiuk/authentication-service/blob/main/src/services/healthService.ts"
click node_error_handler "https://github.com/mshchebetiuk/authentication-service/blob/main/src/middlewares/errorHandler.ts"
click node_prisma "https://github.com/mshchebetiuk/authentication-service/blob/main/src/config/prisma.ts"
click node_database "https://github.com/mshchebetiuk/authentication-service/blob/main/prisma/schema.prisma"

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_server,node_app,node_auth_routes,node_user_routes,node_admin_routes,node_health_routes,node_auth_controller,node_user_controller,node_admin_controller,node_health_controller,node_error_handler,node_client toneBlue
class node_auth_middleware,node_role_middleware,node_rate_limiter,node_auth_schema,node_jwt,node_postgres toneAmber
class node_auth_service,node_refresh_service,node_user_service,node_admin_service,node_health_service toneMint
class node_prisma,node_database toneRose
```

## Components

### API routing

- [HTTP server](https://github.com/mshchebetiuk/authentication-service/blob/main/src/server.ts): `src/server.ts`
- [Express app](https://github.com/mshchebetiuk/authentication-service/blob/main/src/app.ts): `src/app.ts`
- [Auth routes](https://github.com/mshchebetiuk/authentication-service/blob/main/src/routes/authRoutes.ts): `src/routes/authRoutes.ts`
- [User routes](https://github.com/mshchebetiuk/authentication-service/blob/main/src/routes/userRoutes.ts): `src/routes/userRoutes.ts`
- [Admin routes](https://github.com/mshchebetiuk/authentication-service/blob/main/src/routes/adminRoutes.ts): `src/routes/adminRoutes.ts`
- [Health routes](https://github.com/mshchebetiuk/authentication-service/blob/main/src/routes/healthRoutes.ts): `src/routes/healthRoutes.ts`
- [Auth controller](https://github.com/mshchebetiuk/authentication-service/blob/main/src/controllers/authController.ts): `src/controllers/authController.ts`
- [Profile controller](https://github.com/mshchebetiuk/authentication-service/blob/main/src/controllers/userController.ts): `src/controllers/userController.ts`
- [Admin controller](https://github.com/mshchebetiuk/authentication-service/blob/main/src/controllers/adminController.ts): `src/controllers/adminController.ts`
- [Health controller](https://github.com/mshchebetiuk/authentication-service/blob/main/src/controllers/healthController.ts): `src/controllers/healthController.ts`
- [Error handling](https://github.com/mshchebetiuk/authentication-service/blob/main/src/middlewares/errorHandler.ts): `src/middlewares/errorHandler.ts`

### Identity and access

- [JWT middleware](https://github.com/mshchebetiuk/authentication-service/blob/main/src/middlewares/authMiddleware.ts): `src/middlewares/authMiddleware.ts`
- [Role guard](https://github.com/mshchebetiuk/authentication-service/blob/main/src/middlewares/requireRole.ts): `src/middlewares/requireRole.ts`
- [Rate limiter](https://github.com/mshchebetiuk/authentication-service/blob/main/src/middlewares/rateLimiter.ts): `src/middlewares/rateLimiter.ts`
- [Auth validation](https://github.com/mshchebetiuk/authentication-service/blob/main/src/schemas/authSchema.ts): `src/schemas/authSchema.ts`
- [JWT utilities](https://github.com/mshchebetiuk/authentication-service/blob/main/src/utils/jwt.ts): `src/utils/jwt.ts`

### Domain services

- [Account auth](https://github.com/mshchebetiuk/authentication-service/blob/main/src/services/authService.ts): `src/services/authService.ts`
- [Refresh tokens](https://github.com/mshchebetiuk/authentication-service/blob/main/src/services/refreshTokenService.ts): `src/services/refreshTokenService.ts`
- [Profile service](https://github.com/mshchebetiuk/authentication-service/blob/main/src/services/userService.ts): `src/services/userService.ts`
- [User administration](https://github.com/mshchebetiuk/authentication-service/blob/main/src/services/adminService.ts): `src/services/adminService.ts`
- [Health check](https://github.com/mshchebetiuk/authentication-service/blob/main/src/services/healthService.ts): `src/services/healthService.ts`

### Persistence

- [Prisma client](https://github.com/mshchebetiuk/authentication-service/blob/main/src/config/prisma.ts): `src/config/prisma.ts`
- [PostgreSQL data](https://github.com/mshchebetiuk/authentication-service/blob/main/prisma/schema.prisma): `prisma/schema.prisma`

### Other components

- **API client**
- **PostgreSQL**

## Connections

- API client → HTTP server: sends requests (evidence: `README.md`)
- HTTP server → Express app: starts (evidence: `src/server.ts`)
- Express app → Auth routes: mounts (evidence: `src/app.ts`)
- Express app → User routes: mounts (evidence: `src/app.ts`)
- Express app → Admin routes: mounts (evidence: `src/app.ts`)
- Express app → Health routes: mounts (evidence: `src/app.ts`)
- Express app → Error handling: handles errors (evidence: `src/app.ts`)
- Auth routes → Auth controller: dispatches (evidence: `src/routes/authRoutes.ts`)
- Auth routes → Rate limiter: limits register login (evidence: `src/routes/authRoutes.ts`)
- User routes → JWT middleware: protects route (evidence: `src/routes/userRoutes.ts`)
- User routes → Profile controller: dispatches (evidence: `src/routes/userRoutes.ts`)
- Admin routes → JWT middleware: authenticates (evidence: `src/routes/adminRoutes.ts`)
- Admin routes → Role guard: checks role (evidence: `src/routes/adminRoutes.ts`)
- Admin routes → Admin controller: dispatches (evidence: `src/routes/adminRoutes.ts`)
- Health routes → Health controller: dispatches (evidence: `src/routes/healthRoutes.ts`)
- Auth controller → Auth validation: validates input (evidence: `src/controllers/authController.ts`)
- Auth controller → Account auth: registers and logs in (evidence: `src/controllers/authController.ts`)
- Auth controller → Refresh tokens: rotates or revokes (evidence: `src/controllers/authController.ts`)
- Profile controller → Profile service: loads profile (evidence: `src/controllers/userController.ts`)
- JWT middleware → JWT utilities: verifies access token (evidence: `README.md`)
- Account auth → Refresh tokens: creates refresh token (evidence: `src/services/authService.ts`)
- Account auth → JWT utilities: creates access token (evidence: `src/services/authService.ts`)
- Account auth → Prisma client: reads and writes users (evidence: `src/services/authService.ts`)
- Refresh tokens → Prisma client: stores token hashes (evidence: `src/services/refreshTokenService.ts`)
- Profile service → Prisma client: reads user data (evidence: `src/services/userService.ts`)
- User administration → Prisma client: queries users (evidence: `src/services/adminService.ts`)
- Health controller → Health check: uses health check (evidence: `src/controllers/healthController.ts`)
- Prisma client → PostgreSQL data: persists records (evidence: `src/config/prisma.ts`)
- PostgreSQL data → PostgreSQL: uses (evidence: `README.md`)
