# naliyev02/identity-service architecture

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

- Interactive diagram: https://gitdiagram.com/naliyev02/identity-service
- Repository: https://github.com/naliyev02/identity-service

## Overview

This is an ASP.NET identity service for registration, authentication, account recovery, session management, and role/permission administration. The primary flow is a client request through an API controller, dispatched with MediatR to an application feature, which applies identity rules and uses persistence or security abstractions. The graph also preserves user administration, RBAC, verification email, and token/session concerns. Relationships involving unsampled handlers are included only where the SOURCE INDEX names the dependency; optional email delivery is marked unverified.

Main entry points: [`src/Identity.Application/Features/Authentication`](https://github.com/naliyev02/identity-service/tree/main/src/Identity.Application/Features/Authentication) (Authentication features), [`src/Identity.Infrastructure/Persistence/AppDbContext.cs`](https://github.com/naliyev02/identity-service/blob/main/src/Identity.Infrastructure/Persistence/AppDbContext.cs) (Identity database context), [`src/Identity.API/Controllers/UsersController.cs`](https://github.com/naliyev02/identity-service/blob/main/src/Identity.API/Controllers/UsersController.cs) (Users API), [`src/Identity.Application/Features/Roles`](https://github.com/naliyev02/identity-service/tree/main/src/Identity.Application/Features/Roles) (Role features)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_auth_api["Authentication API<br/>[AuthController.cs]"]
  node_users_api["Users API<br/>[UsersController.cs]"]
  node_roles_api["Roles API<br/>[RolesController.cs]"]
  node_sessions_api["Sessions API"]
end

subgraph group_application["Application workflows"]
  node_auth_features["Authentication features<br/>[Authentication]"]
  node_user_features["User features<br/>[Users]"]
  node_role_features["Role features<br/>[Roles]"]
  node_permission_features["Permission queries<br/>[Permissions]"]
  node_session_services["Session services"]
  node_persistence_ports["Persistence contracts"]
  node_email_port["Email sender contract<br/>[IEmailSender.cs]"]
  node_security_ports["Token contracts"]
end

subgraph group_domain["Identity domain"]
  node_user_domain["User and session model<br/>[User.cs]"]
  node_role_domain["Role and permission model<br/>[Role.cs]"]
  node_email_domain["Verification token model"]
end

subgraph group_infrastructure["Infrastructure"]
  node_repositories["Entity repositories<br/>[Repositories]"]
  node_database[("Identity database context<br/>[AppDbContext.cs]")]
  node_email_delivery["Email delivery<br/>[SmtpEmailSender.cs]"]
  node_token_security["Token implementations"]
end

node_client(("API client"))

node_client -->|"sends auth requests"| node_auth_api
node_client -->|"sends user requests"| node_users_api
node_client -->|"sends role requests"| node_roles_api
node_client -->|"sends session requests"| node_sessions_api
node_auth_api -->|"dispatches commands"| node_auth_features
node_users_api -->|"dispatches queries"| node_user_features
node_users_api -->|"dispatches role assignment"| node_role_features
node_roles_api -->|"dispatches role requests"| node_role_features
node_sessions_api -->|"dispatches session actions"| node_auth_features
node_auth_features -->|"uses session repository"| node_persistence_ports
node_auth_features -->|"locates current session"| node_session_services
node_auth_features -->|"uses user entity"| node_user_domain
node_repositories -->|"queries and updates"| node_database
node_database -->|"maps entities"| node_user_domain
node_database -->|"maps entities"| node_role_domain
node_database -->|"maps entities"| node_email_domain
node_auth_features -.->|"may send verification mail"| node_email_port
node_email_port -.->|"may deliver email"| node_email_delivery
node_auth_features -.->|"uses token services"| node_security_ports
node_user_features -.->|"uses persistence contracts"| node_persistence_ports
node_role_features -.->|"uses persistence contracts"| node_persistence_ports

click node_auth_api "https://github.com/naliyev02/identity-service/blob/main/src/Identity.API/Controllers/AuthController.cs"
click node_users_api "https://github.com/naliyev02/identity-service/blob/main/src/Identity.API/Controllers/UsersController.cs"
click node_roles_api "https://github.com/naliyev02/identity-service/blob/main/src/Identity.API/Controllers/RolesController.cs"
click node_sessions_api "https://github.com/naliyev02/identity-service/blob/main/src/Identity.API/Controllers/SessionsController.cs"
click node_auth_features "https://github.com/naliyev02/identity-service/tree/main/src/Identity.Application/Features/Authentication"
click node_user_features "https://github.com/naliyev02/identity-service/tree/main/src/Identity.Application/Features/Users"
click node_role_features "https://github.com/naliyev02/identity-service/tree/main/src/Identity.Application/Features/Roles"
click node_permission_features "https://github.com/naliyev02/identity-service/tree/main/src/Identity.Application/Features/Permissions"
click node_session_services "https://github.com/naliyev02/identity-service/blob/main/src/Identity.Application/Services/CurrentSessionLocator.cs"
click node_persistence_ports "https://github.com/naliyev02/identity-service/blob/main/src/Identity.Application/Abstractions/Persistence/ISessionRepository.cs"
click node_email_port "https://github.com/naliyev02/identity-service/blob/main/src/Identity.Application/Abstractions/Messaging/IEmailSender.cs"
click node_security_ports "https://github.com/naliyev02/identity-service/blob/main/src/Identity.Application/Abstractions/Security/IAccessTokenIssuer.cs"
click node_user_domain "https://github.com/naliyev02/identity-service/blob/main/src/Identity.Domain/User/Entities/User.cs"
click node_role_domain "https://github.com/naliyev02/identity-service/blob/main/src/Identity.Domain/Role/Entities/Role.cs"
click node_email_domain "https://github.com/naliyev02/identity-service/blob/main/src/Identity.Domain/User/Entities/EmailVerificationToken.cs"
click node_repositories "https://github.com/naliyev02/identity-service/tree/main/src/Identity.Infrastructure/Persistence/Repositories"
click node_database "https://github.com/naliyev02/identity-service/blob/main/src/Identity.Infrastructure/Persistence/AppDbContext.cs"
click node_email_delivery "https://github.com/naliyev02/identity-service/blob/main/src/Identity.Infrastructure/Email/SmtpEmailSender.cs"
click node_token_security "https://github.com/naliyev02/identity-service/blob/main/src/Identity.Infrastructure/Security/JwtAccessTokenIssuer.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_api,node_users_api,node_roles_api,node_sessions_api,node_client toneBlue
class node_auth_features,node_user_features,node_role_features,node_permission_features,node_session_services,node_persistence_ports,node_email_port,node_security_ports toneAmber
class node_user_domain,node_role_domain,node_email_domain toneMint
class node_repositories,node_database,node_email_delivery,node_token_security toneRose
```

## Components

### HTTP API

- [Authentication API](https://github.com/naliyev02/identity-service/blob/main/src/Identity.API/Controllers/AuthController.cs): `src/Identity.API/Controllers/AuthController.cs`
- [Users API](https://github.com/naliyev02/identity-service/blob/main/src/Identity.API/Controllers/UsersController.cs): `src/Identity.API/Controllers/UsersController.cs`
- [Roles API](https://github.com/naliyev02/identity-service/blob/main/src/Identity.API/Controllers/RolesController.cs): `src/Identity.API/Controllers/RolesController.cs`
- [Sessions API](https://github.com/naliyev02/identity-service/blob/main/src/Identity.API/Controllers/SessionsController.cs): `src/Identity.API/Controllers/SessionsController.cs`

### Application workflows

- [Authentication features](https://github.com/naliyev02/identity-service/tree/main/src/Identity.Application/Features/Authentication): `src/Identity.Application/Features/Authentication`
- [User features](https://github.com/naliyev02/identity-service/tree/main/src/Identity.Application/Features/Users): `src/Identity.Application/Features/Users`
- [Role features](https://github.com/naliyev02/identity-service/tree/main/src/Identity.Application/Features/Roles): `src/Identity.Application/Features/Roles`
- [Permission queries](https://github.com/naliyev02/identity-service/tree/main/src/Identity.Application/Features/Permissions): `src/Identity.Application/Features/Permissions`
- [Session services](https://github.com/naliyev02/identity-service/blob/main/src/Identity.Application/Services/CurrentSessionLocator.cs): `src/Identity.Application/Services/CurrentSessionLocator.cs`
- [Persistence contracts](https://github.com/naliyev02/identity-service/blob/main/src/Identity.Application/Abstractions/Persistence/ISessionRepository.cs): `src/Identity.Application/Abstractions/Persistence/ISessionRepository.cs`
- [Email sender contract](https://github.com/naliyev02/identity-service/blob/main/src/Identity.Application/Abstractions/Messaging/IEmailSender.cs): `src/Identity.Application/Abstractions/Messaging/IEmailSender.cs`
- [Token contracts](https://github.com/naliyev02/identity-service/blob/main/src/Identity.Application/Abstractions/Security/IAccessTokenIssuer.cs): `src/Identity.Application/Abstractions/Security/IAccessTokenIssuer.cs`

### Identity domain

- [User and session model](https://github.com/naliyev02/identity-service/blob/main/src/Identity.Domain/User/Entities/User.cs): `src/Identity.Domain/User/Entities/User.cs`
- [Role and permission model](https://github.com/naliyev02/identity-service/blob/main/src/Identity.Domain/Role/Entities/Role.cs): `src/Identity.Domain/Role/Entities/Role.cs`
- [Verification token model](https://github.com/naliyev02/identity-service/blob/main/src/Identity.Domain/User/Entities/EmailVerificationToken.cs): `src/Identity.Domain/User/Entities/EmailVerificationToken.cs`

### Infrastructure

- [Entity repositories](https://github.com/naliyev02/identity-service/tree/main/src/Identity.Infrastructure/Persistence/Repositories): `src/Identity.Infrastructure/Persistence/Repositories`
- [Identity database context](https://github.com/naliyev02/identity-service/blob/main/src/Identity.Infrastructure/Persistence/AppDbContext.cs): `src/Identity.Infrastructure/Persistence/AppDbContext.cs`
- [Email delivery](https://github.com/naliyev02/identity-service/blob/main/src/Identity.Infrastructure/Email/SmtpEmailSender.cs): `src/Identity.Infrastructure/Email/SmtpEmailSender.cs`
- [Token implementations](https://github.com/naliyev02/identity-service/blob/main/src/Identity.Infrastructure/Security/JwtAccessTokenIssuer.cs): `src/Identity.Infrastructure/Security/JwtAccessTokenIssuer.cs`

### Other components

- **API client**

## Connections

- API client → Authentication API: sends auth requests (evidence: `src/Identity.API/Controllers/AuthController.cs`)
- API client → Users API: sends user requests (evidence: `src/Identity.API/Controllers/UsersController.cs`)
- API client → Roles API: sends role requests (evidence: `src/Identity.API/Controllers/RolesController.cs`)
- API client → Sessions API: sends session requests (evidence: `src/Identity.API/Controllers/SessionsController.cs`)
- Authentication API → Authentication features: dispatches commands (evidence: `src/Identity.API/Controllers/AuthController.cs`)
- Users API → User features: dispatches queries (evidence: `src/Identity.API/Controllers/UsersController.cs`)
- Users API → Role features: dispatches role assignment (evidence: `src/Identity.API/Controllers/UsersController.cs`)
- Roles API → Role features: dispatches role requests (evidence: `src/Identity.API/Controllers/RolesController.cs`)
- Sessions API → Authentication features: dispatches session actions (evidence: `src/Identity.API/Controllers/SessionsController.cs`)
- Authentication features → Persistence contracts: uses session repository (evidence: `src/Identity.Application/Features/Authentication/Commands/RevokeMySession/RevokeMySessionHandler.cs`)
- Authentication features → Session services: locates current session (evidence: `src/Identity.Application/Features/Authentication/Commands/RevokeMySession/RevokeMySessionHandler.cs`)
- Authentication features → User and session model: uses user entity (evidence: `src/Identity.API/Controllers/AuthController.cs`)
- Entity repositories → Identity database context: queries and updates (evidence: `src/Identity.Infrastructure/Persistence/Repositories/SessionRepository.cs`)
- Identity database context → User and session model: maps entities (evidence: `src/Identity.Infrastructure/Persistence/AppDbContext.cs`)
- Identity database context → Role and permission model: maps entities (evidence: `src/Identity.Infrastructure/Persistence/AppDbContext.cs`)
- Identity database context → Verification token model: maps entities (evidence: `src/Identity.Infrastructure/Persistence/AppDbContext.cs`)
- Authentication features → Email sender contract: may send verification mail
- Email sender contract → Email delivery: may deliver email
- Authentication features → Token contracts: uses token services (evidence: `src/Identity.Application/Features/Authentication/Commands/Login/LoginHandler.cs`)
- User features → Persistence contracts: uses persistence contracts
- Role features → Persistence contracts: uses persistence contracts
