# mohammdpc/paylense-backend architecture

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

- Interactive diagram: https://gitdiagram.com/mohammdpc/paylense-backend
- Repository: https://github.com/mohammdpc/paylense-backend

## Overview

PayLense is an authentication backend. Its main workflow accepts auth requests, then handles signup and contact verification, sign-in with optional two-factor checks, token refresh, and logout. The auth service coordinates identity, persisted account/device/token state, OTP generation and delivery, and card handling. The README gives no further product detail; links below are limited to relationships visible in the excerpts or SOURCE INDEX, so unsampled behavior is not expanded.

Main entry points: [`src/PayLense.Infrastructure/Services/AuthService.cs`](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/AuthService.cs) (Auth orchestration), [`src/PayLense.Infrastructure/DependencyInjection.cs`](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/DependencyInjection.cs) (Service registration), [`src/PayLense.Infrastructure/Persistence/AppDbContext.cs`](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Persistence/AppDbContext.cs) (Auth data context), [`src/PayLense.Infrastructure/Services/OtpService.cs`](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/OtpService.cs) (OTP lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entry"]
  node_auth_controller["Auth endpoints<br/>[AuthController.cs]"]
  node_exception_middleware["Exception handling"]
  node_program["API startup<br/>[Program.cs]"]
end

subgraph group_application["Application contracts"]
  node_auth_contract["Auth contract<br/>[IAuthService.cs]"]
  node_auth_dtos["Auth requests<br/>[AuthDtos.cs]"]
  node_jwt_settings["JWT settings<br/>[JwtSettings.cs]"]
  node_card_validator["Card validation<br/>[CardValidator.cs]"]
end

subgraph group_auth["Authentication services"]
  node_auth_service["Auth orchestration<br/>[AuthService.cs]"]
  node_otp_service["OTP lifecycle<br/>[OtpService.cs]"]
  node_otp_sender["OTP delivery"]
  node_token_service["Token operations<br/>[TokenService.cs]"]
  node_card_encryptor["Card encryption<br/>[CardEncryptor.cs]"]
end

subgraph group_data["Identity and persistence"]
  node_identity_user["Identity user<br/>[ApplicationUser.cs]"]
  node_db_context[("Auth data context<br/>[AppDbContext.cs]")]
  node_di_config["Service registration"]
end

subgraph group_domain["Domain models"]
  node_domain_entities["Account entities<br/>[Entities]"]
  node_otp_purpose["OTP purposes<br/>[OtpPurpose.cs]"]
  node_app_exception["Application errors<br/>[AppException.cs]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_auth_controller
node_auth_controller -->|"invokes"| node_auth_contract
node_di_config -->|"registers"| node_auth_service
node_auth_service -->|"implements"| node_auth_contract
node_auth_service -->|"accepts and returns"| node_auth_dtos
node_auth_service -->|"manages users"| node_identity_user
node_auth_service -->|"reads and writes"| node_db_context
node_auth_service -->|"generates and verifies"| node_otp_service
node_auth_service -->|"sends codes"| node_otp_sender
node_auth_service -->|"creates and hashes"| node_token_service
node_auth_service -->|"encrypts cards"| node_card_encryptor
node_auth_service -->|"validates cards"| node_card_validator
node_auth_service -->|"uses settings"| node_jwt_settings
node_otp_service -->|"reads and writes"| node_db_context
node_db_context -->|"maps identity"| node_identity_user
node_db_context -->|"maps entities"| node_domain_entities
node_exception_middleware -->|"handles errors"| node_app_exception
node_program -->|"configures"| node_exception_middleware
node_di_config -->|"configures"| node_db_context
node_di_config -->|"registers"| node_token_service
node_di_config -->|"registers"| node_otp_service
node_di_config -->|"registers"| node_card_encryptor
node_di_config -->|"registers"| node_otp_sender

click node_auth_controller "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.API/Controllers/AuthController.cs"
click node_exception_middleware "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.API/Middleware/ExceptionMiddleware.cs"
click node_program "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.API/Program.cs"
click node_auth_contract "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Application/Interfaces/IAuthService.cs"
click node_auth_dtos "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Application/DTOs/Auth/AuthDtos.cs"
click node_jwt_settings "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Application/Common/JwtSettings.cs"
click node_auth_service "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/AuthService.cs"
click node_otp_service "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/OtpService.cs"
click node_otp_sender "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/ConsoleOtpSender.cs"
click node_token_service "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/TokenService.cs"
click node_card_encryptor "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/CardEncryptor.cs"
click node_card_validator "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Application/Common/CardValidator.cs"
click node_identity_user "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Identity/ApplicationUser.cs"
click node_db_context "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Persistence/AppDbContext.cs"
click node_di_config "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/DependencyInjection.cs"
click node_domain_entities "https://github.com/mohammdpc/paylense-backend/tree/main/src/PayLense.Domain/Entities"
click node_otp_purpose "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Domain/Enums/OtpPurpose.cs"
click node_app_exception "https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Domain/Exceptions/AppException.cs"

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_auth_controller,node_exception_middleware,node_program,node_client toneBlue
class node_auth_contract,node_auth_dtos,node_jwt_settings,node_card_validator toneAmber
class node_auth_service,node_otp_service,node_otp_sender,node_token_service,node_card_encryptor toneMint
class node_identity_user,node_db_context,node_di_config toneRose
class node_domain_entities,node_otp_purpose,node_app_exception toneIndigo
```

## Components

### API entry

- [Auth endpoints](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.API/Controllers/AuthController.cs): `src/PayLense.API/Controllers/AuthController.cs`
- [Exception handling](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.API/Middleware/ExceptionMiddleware.cs): `src/PayLense.API/Middleware/ExceptionMiddleware.cs`
- [API startup](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.API/Program.cs): `src/PayLense.API/Program.cs`

### Application contracts

- [Auth contract](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Application/Interfaces/IAuthService.cs): `src/PayLense.Application/Interfaces/IAuthService.cs`
- [Auth requests](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Application/DTOs/Auth/AuthDtos.cs): `src/PayLense.Application/DTOs/Auth/AuthDtos.cs`
- [JWT settings](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Application/Common/JwtSettings.cs): `src/PayLense.Application/Common/JwtSettings.cs`
- [Card validation](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Application/Common/CardValidator.cs): `src/PayLense.Application/Common/CardValidator.cs`

### Authentication services

- [Auth orchestration](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/AuthService.cs): `src/PayLense.Infrastructure/Services/AuthService.cs`
- [OTP lifecycle](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/OtpService.cs): `src/PayLense.Infrastructure/Services/OtpService.cs`
- [OTP delivery](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/ConsoleOtpSender.cs): `src/PayLense.Infrastructure/Services/ConsoleOtpSender.cs`
- [Token operations](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/TokenService.cs): `src/PayLense.Infrastructure/Services/TokenService.cs`
- [Card encryption](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Services/CardEncryptor.cs): `src/PayLense.Infrastructure/Services/CardEncryptor.cs`

### Identity and persistence

- [Identity user](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Identity/ApplicationUser.cs): `src/PayLense.Infrastructure/Identity/ApplicationUser.cs`
- [Auth data context](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/Persistence/AppDbContext.cs): `src/PayLense.Infrastructure/Persistence/AppDbContext.cs`
- [Service registration](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Infrastructure/DependencyInjection.cs): `src/PayLense.Infrastructure/DependencyInjection.cs`

### Domain models

- [Account entities](https://github.com/mohammdpc/paylense-backend/tree/main/src/PayLense.Domain/Entities): `src/PayLense.Domain/Entities`
- [OTP purposes](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Domain/Enums/OtpPurpose.cs): `src/PayLense.Domain/Enums/OtpPurpose.cs`
- [Application errors](https://github.com/mohammdpc/paylense-backend/blob/main/src/PayLense.Domain/Exceptions/AppException.cs): `src/PayLense.Domain/Exceptions/AppException.cs`

### Other components

- **API client**

## Connections

- API client → Auth endpoints: sends requests (evidence: `src/PayLense.API/Controllers/AuthController.cs`)
- Auth endpoints → Auth contract: invokes (evidence: `src/PayLense.API/Controllers/AuthController.cs`)
- Service registration → Auth orchestration: registers (evidence: `src/PayLense.Infrastructure/DependencyInjection.cs`)
- Auth orchestration → Auth contract: implements (evidence: `src/PayLense.Infrastructure/Services/AuthService.cs`)
- Auth orchestration → Auth requests: accepts and returns (evidence: `src/PayLense.Infrastructure/Services/AuthService.cs`)
- Auth orchestration → Identity user: manages users (evidence: `src/PayLense.Infrastructure/Services/AuthService.cs`)
- Auth orchestration → Auth data context: reads and writes (evidence: `src/PayLense.Infrastructure/Services/AuthService.cs`)
- Auth orchestration → OTP lifecycle: generates and verifies (evidence: `src/PayLense.Infrastructure/Services/AuthService.cs`)
- Auth orchestration → OTP delivery: sends codes (evidence: `src/PayLense.Infrastructure/Services/AuthService.cs`)
- Auth orchestration → Token operations: creates and hashes (evidence: `src/PayLense.Infrastructure/Services/AuthService.cs`)
- Auth orchestration → Card encryption: encrypts cards (evidence: `src/PayLense.Infrastructure/Services/AuthService.cs`)
- Auth orchestration → Card validation: validates cards (evidence: `src/PayLense.Infrastructure/Services/AuthService.cs`)
- Auth orchestration → JWT settings: uses settings (evidence: `src/PayLense.Infrastructure/Services/AuthService.cs`)
- OTP lifecycle → Auth data context: reads and writes (evidence: `src/PayLense.Infrastructure/Services/OtpService.cs`)
- Auth data context → Identity user: maps identity (evidence: `src/PayLense.Infrastructure/Persistence/AppDbContext.cs`)
- Auth data context → Account entities: maps entities (evidence: `src/PayLense.Infrastructure/Persistence/AppDbContext.cs`)
- Exception handling → Application errors: handles errors (evidence: `src/PayLense.API/Middleware/ExceptionMiddleware.cs`)
- API startup → Exception handling: configures (evidence: `src/PayLense.API/Program.cs`)
- Service registration → Auth data context: configures (evidence: `src/PayLense.Infrastructure/DependencyInjection.cs`)
- Service registration → Token operations: registers (evidence: `src/PayLense.Infrastructure/DependencyInjection.cs`)
- Service registration → OTP lifecycle: registers (evidence: `src/PayLense.Infrastructure/DependencyInjection.cs`)
- Service registration → Card encryption: registers (evidence: `src/PayLense.Infrastructure/DependencyInjection.cs`)
- Service registration → OTP delivery: registers (evidence: `src/PayLense.Infrastructure/DependencyInjection.cs`)
