# zokirs/onion-architecture architecture

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

- Interactive diagram: https://gitdiagram.com/zokirs/onion-architecture
- Repository: https://github.com/zokirs/onion-architecture

## Overview

This repository implements a company-and-employee management system with an API, a browser client, and IdentityServer-based identity features. The main API workflow routes company and employee requests through presentation controllers into application handlers or domain services, with persistence through repositories and Entity Framework. Authentication is handled both by API token services and by the identity-provider applications. The graph includes documented identity features, but their end-to-end wiring and the client’s API calls are not fully evidenced by the excerpts; those links are omitted or marked unverified.

Main entry points: [`CompanyEmployees.Presentation/Controllers/CompaniesController.cs`](https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.Presentation/Controllers/CompaniesController.cs) (Companies API), [`Repository/RepositoryManager.cs`](https://github.com/zokirs/onion-architecture/blob/master/Repository/RepositoryManager.cs) (Repository manager), [`Service/ServiceManager.cs`](https://github.com/zokirs/onion-architecture/blob/master/Service/ServiceManager.cs) (Service manager), [`CompanyEmployees.IDP/Quickstart/Account/AccountController.cs`](https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.IDP/Quickstart/Account/AccountController.cs) (Identity account)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["User interfaces"]
  node_companies_api["Companies API"]
  node_employees_api["Employees API"]
  node_client["Web client<br/>[HomeController.cs]"]
end

subgraph group_application["Application workflows"]
  node_company_workflows["Company workflows"]
  node_delete_notification["Deletion notification"]
end

subgraph group_domain["Domain services"]
  node_employee_service["Employee service<br/>[EmployeeService.cs]"]
  node_company_service["Company service<br/>[CompanyService.cs]"]
  node_service_manager["Service manager<br/>[ServiceManager.cs]"]
  node_authentication_service["API authentication"]
end

subgraph group_persistence["Persistence"]
  node_repository_manager["Repository manager"]
  node_company_repository["Company repository"]
  node_employee_repository["Employee repository"]
  node_database[("Application database")]
end

subgraph group_identity["Identity"]
  node_identity_user[("Identity user store<br/>[UserContext.cs]")]
  node_idp_account["Identity account"]
  node_idp_consent["Consent workflow"]
  node_idp_device["Device authorization"]
  node_idp_grants["User grants"]
  node_email_service["Email delivery<br/>[EmailSender.cs]"]
end

node_api_user(("API caller"))
node_browser_user(("Browser user"))

node_api_user -->|"requests"| node_companies_api
node_companies_api -->|"dispatches queries"| node_company_workflows
node_companies_api -->|"calls service"| node_company_service
node_companies_api -->|"publishes event"| node_delete_notification
node_api_user -->|"requests"| node_employees_api
node_employees_api -->|"calls service"| node_employee_service
node_employee_service -->|"uses repositories"| node_repository_manager
node_service_manager -->|"creates service"| node_company_service
node_service_manager -->|"creates service"| node_employee_service
node_service_manager -->|"creates service"| node_authentication_service
node_repository_manager -->|"creates repository"| node_company_repository
node_repository_manager -->|"creates repository"| node_employee_repository
node_repository_manager -->|"saves changes"| node_database
node_employee_repository -.->|"uses context"| node_database
node_company_repository -.->|"uses context"| node_database
node_browser_user -.->|"uses"| node_client
node_client -.->|"requests data"| node_companies_api
node_browser_user -.->|"signs in"| node_idp_account
node_idp_account -->|"manages users"| node_identity_user
node_idp_account -->|"sends email"| node_email_service

click node_companies_api "https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.Presentation/Controllers/CompaniesController.cs"
click node_employees_api "https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.Presentation/Controllers/EmployeesController.cs"
click node_client "https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.Client/Controllers/HomeController.cs"
click node_company_workflows "https://github.com/zokirs/onion-architecture/tree/master/Application/Handlers"
click node_delete_notification "https://github.com/zokirs/onion-architecture/blob/master/Application/Notifications/CompanyDeletedNotification.cs"
click node_employee_service "https://github.com/zokirs/onion-architecture/blob/master/Service/EmployeeService.cs"
click node_company_service "https://github.com/zokirs/onion-architecture/blob/master/Service/CompanyService.cs"
click node_service_manager "https://github.com/zokirs/onion-architecture/blob/master/Service/ServiceManager.cs"
click node_authentication_service "https://github.com/zokirs/onion-architecture/blob/master/Service/AuthenticationService.cs"
click node_repository_manager "https://github.com/zokirs/onion-architecture/blob/master/Repository/RepositoryManager.cs"
click node_company_repository "https://github.com/zokirs/onion-architecture/blob/master/Repository/CompanyRepository.cs"
click node_employee_repository "https://github.com/zokirs/onion-architecture/blob/master/Repository/EmployeeRepository.cs"
click node_database "https://github.com/zokirs/onion-architecture/blob/master/Repository/RepositoryContext.cs"
click node_identity_user "https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.IDP/Entities/UserContext.cs"
click node_idp_account "https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.IDP/Quickstart/Account/AccountController.cs"
click node_idp_consent "https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.IDP/Quickstart/Consent/ConsentController.cs"
click node_idp_device "https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.IDP/Quickstart/Device/DeviceController.cs"
click node_idp_grants "https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.IDP/Quickstart/Grants/GrantsController.cs"
click node_email_service "https://github.com/zokirs/onion-architecture/blob/master/EmailService/EmailSender.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_companies_api,node_employees_api,node_client,node_browser_user toneBlue
class node_company_workflows,node_delete_notification toneAmber
class node_employee_service,node_company_service,node_service_manager,node_authentication_service,node_api_user toneMint
class node_repository_manager,node_company_repository,node_employee_repository,node_database toneRose
class node_identity_user,node_idp_account,node_idp_consent,node_idp_device,node_idp_grants,node_email_service toneIndigo
```

## Components

### User interfaces

- [Companies API](https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.Presentation/Controllers/CompaniesController.cs): `CompanyEmployees.Presentation/Controllers/CompaniesController.cs`
- [Employees API](https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.Presentation/Controllers/EmployeesController.cs): `CompanyEmployees.Presentation/Controllers/EmployeesController.cs`
- [Web client](https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.Client/Controllers/HomeController.cs): `CompanyEmployees.Client/Controllers/HomeController.cs`

### Application workflows

- [Company workflows](https://github.com/zokirs/onion-architecture/tree/master/Application/Handlers): `Application/Handlers`
- [Deletion notification](https://github.com/zokirs/onion-architecture/blob/master/Application/Notifications/CompanyDeletedNotification.cs): `Application/Notifications/CompanyDeletedNotification.cs`

### Domain services

- [Employee service](https://github.com/zokirs/onion-architecture/blob/master/Service/EmployeeService.cs): `Service/EmployeeService.cs`
- [Company service](https://github.com/zokirs/onion-architecture/blob/master/Service/CompanyService.cs): `Service/CompanyService.cs`
- [Service manager](https://github.com/zokirs/onion-architecture/blob/master/Service/ServiceManager.cs): `Service/ServiceManager.cs`
- [API authentication](https://github.com/zokirs/onion-architecture/blob/master/Service/AuthenticationService.cs): `Service/AuthenticationService.cs`

### Persistence

- [Repository manager](https://github.com/zokirs/onion-architecture/blob/master/Repository/RepositoryManager.cs): `Repository/RepositoryManager.cs`
- [Company repository](https://github.com/zokirs/onion-architecture/blob/master/Repository/CompanyRepository.cs): `Repository/CompanyRepository.cs`
- [Employee repository](https://github.com/zokirs/onion-architecture/blob/master/Repository/EmployeeRepository.cs): `Repository/EmployeeRepository.cs`
- [Application database](https://github.com/zokirs/onion-architecture/blob/master/Repository/RepositoryContext.cs): `Repository/RepositoryContext.cs`

### Identity

- [Identity user store](https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.IDP/Entities/UserContext.cs): `CompanyEmployees.IDP/Entities/UserContext.cs`
- [Identity account](https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.IDP/Quickstart/Account/AccountController.cs): `CompanyEmployees.IDP/Quickstart/Account/AccountController.cs`
- [Consent workflow](https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.IDP/Quickstart/Consent/ConsentController.cs): `CompanyEmployees.IDP/Quickstart/Consent/ConsentController.cs`
- [Device authorization](https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.IDP/Quickstart/Device/DeviceController.cs): `CompanyEmployees.IDP/Quickstart/Device/DeviceController.cs`
- [User grants](https://github.com/zokirs/onion-architecture/blob/master/CompanyEmployees.IDP/Quickstart/Grants/GrantsController.cs): `CompanyEmployees.IDP/Quickstart/Grants/GrantsController.cs`
- [Email delivery](https://github.com/zokirs/onion-architecture/blob/master/EmailService/EmailSender.cs): `EmailService/EmailSender.cs`

### Other components

- **API caller**
- **Browser user**

## Connections

- API caller → Companies API: requests (evidence: `CompanyEmployees.Presentation/Controllers/CompaniesController.cs`)
- Companies API → Company workflows: dispatches queries (evidence: `CompanyEmployees.Presentation/Controllers/CompaniesController.cs`)
- Companies API → Company service: calls service (evidence: `CompanyEmployees.Presentation/Controllers/CompaniesController.cs`)
- Companies API → Deletion notification: publishes event (evidence: `CompanyEmployees.Presentation/Controllers/CompaniesController.cs`)
- API caller → Employees API: requests (evidence: `CompanyEmployees.Presentation/Controllers/EmployeesController.cs`)
- Employees API → Employee service: calls service (evidence: `CompanyEmployees.Presentation/Controllers/EmployeesController.cs`)
- Employee service → Repository manager: uses repositories (evidence: `Service/EmployeeService.cs`)
- Service manager → Company service: creates service (evidence: `Service/ServiceManager.cs`)
- Service manager → Employee service: creates service (evidence: `Service/ServiceManager.cs`)
- Service manager → API authentication: creates service (evidence: `Service/ServiceManager.cs`)
- Repository manager → Company repository: creates repository (evidence: `Repository/RepositoryManager.cs`)
- Repository manager → Employee repository: creates repository (evidence: `Repository/RepositoryManager.cs`)
- Repository manager → Application database: saves changes (evidence: `Repository/RepositoryManager.cs`)
- Employee repository → Application database: uses context
- Company repository → Application database: uses context
- Browser user → Web client: uses
- Web client → Companies API: requests data
- Browser user → Identity account: signs in
- Identity account → Identity user store: manages users (evidence: `CompanyEmployees.IDP/Quickstart/Account/AccountController.cs`)
- Identity account → Email delivery: sends email (evidence: `CompanyEmployees.IDP/Quickstart/Account/AccountController.cs`)
