# turb0xx/phonehub-backend architecture

> Architecture diagram of the GitHub repository turb0xx/phonehub-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/turb0xx/phonehub-backend
- Repository: https://github.com/turb0xx/phonehub-backend

## Overview

PhoneHub is a phone-inventory and point-of-sale API. Requests enter product, sale, invoice, or user/token endpoints; services apply business rules and use repositories to access relational state. The sale workflow checks product stock and user activity, reduces inventory, records the sale, and supports annulment and daily cash-close reporting. Product inventory ingress and invoice/user management are separate capabilities. The sampled files establish several service-to-repository calls; other subsystem links are shown only where the source index or API excerpts support them.

Main entry points: [`PhoneHub.Infrastructure/Repositories/SaleRepository.cs`](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/SaleRepository.cs) (Sale repository), [`PhoneHub.Services/Services/SaleService.cs`](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/SaleService.cs) (Sale service), [`PhoneHub.Infrastructure/Repositories/ProductRepository.cs`](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/ProductRepository.cs) (Product repository), [`PhoneHub.Services/Services/UserService.cs`](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/UserService.cs) (User service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_products_api["Products API"]
  node_sales_api["Sales API<br/>[SaleController.cs]"]
  node_invoices_api["Invoices API"]
  node_users_api["Users API<br/>[UserController.cs]"]
  node_tokens_api["Token API<br/>[TokenController.cs]"]
end

subgraph group_domain["Business Services"]
  node_product_service["Product service<br/>[ProductService.cs]"]
  node_sale_service["Sale service<br/>[SaleService.cs]"]
  node_invoice_service["Invoice service<br/>[InvoiceService.cs]"]
end

subgraph group_persistence["Persistence"]
  node_product_repo["Product repository"]
  node_sale_repo["Sale repository<br/>[SaleRepository.cs]"]
  node_invoice_repo["Invoice repository"]
  node_unit_of_work["Unit of work<br/>[UnitOfWork.cs]"]
  node_ef_context["EF context<br/>[PhoneHubContext.cs]"]
  node_dapper_context["Dapper context<br/>[DapperContext.cs]"]
  node_sale_queries["Sale queries<br/>[SaleQueries.cs]"]
end

subgraph group_identity["Identity"]
  node_user_service["User service<br/>[UserService.cs]"]
  node_user_repo["User repository<br/>[UserRepository.cs]"]
  node_passwords["Password service<br/>[PasswordService.cs]"]
end

node_client(("API client"))
node_database[("Relational database")]

node_client -->|"requests"| node_products_api
node_client -->|"requests"| node_sales_api
node_client -->|"requests"| node_invoices_api
node_client -->|"requests"| node_users_api
node_client -->|"requests"| node_tokens_api
node_products_api -->|"delegates"| node_product_service
node_sales_api -->|"delegates"| node_sale_service
node_invoices_api -->|"delegates"| node_invoice_service
node_users_api -->|"delegates"| node_user_service
node_tokens_api -->|"authenticates"| node_user_service
node_product_service -->|"accesses"| node_product_repo
node_product_service -->|"checks sales"| node_sale_repo
node_sale_service -->|"checks stock"| node_product_repo
node_sale_service -->|"records sales"| node_sale_repo
node_sale_service -->|"checks user"| node_user_repo
node_user_service -->|"manages users"| node_user_repo
node_user_service -->|"uses passwords"| node_passwords
node_invoice_service -.->|"accesses"| node_invoice_repo
node_product_repo -->|"uses"| node_ef_context
node_sale_repo -->|"uses"| node_ef_context
node_invoice_repo -->|"uses"| node_ef_context
node_product_repo -->|"queries"| node_dapper_context
node_sale_repo -->|"queries"| node_dapper_context
node_invoice_repo -->|"queries"| node_dapper_context
node_sale_repo -->|"selects SQL"| node_sale_queries
node_ef_context -.->|"reads/writes"| node_database
node_dapper_context -.->|"executes SQL"| node_database

click node_products_api "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Api/Controllers/ProductController.cs"
click node_sales_api "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Api/Controllers/SaleController.cs"
click node_invoices_api "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Api/Controllers/InvoiceController.cs"
click node_users_api "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Api/Controllers/UserController.cs"
click node_tokens_api "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Api/Controllers/TokenController.cs"
click node_product_service "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/ProductService.cs"
click node_sale_service "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/SaleService.cs"
click node_invoice_service "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/InvoiceService.cs"
click node_user_service "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/UserService.cs"
click node_product_repo "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/ProductRepository.cs"
click node_sale_repo "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/SaleRepository.cs"
click node_invoice_repo "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/InvoiceRepository.cs"
click node_user_repo "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/UserRepository.cs"
click node_unit_of_work "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/UnitOfWork.cs"
click node_ef_context "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Data/PhoneHubContext.cs"
click node_dapper_context "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Data/DapperContext.cs"
click node_sale_queries "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Queries/SaleQueries.cs"
click node_passwords "https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/PasswordService.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_products_api,node_sales_api,node_invoices_api,node_users_api,node_tokens_api,node_client toneBlue
class node_product_service,node_sale_service,node_invoice_service,node_database toneAmber
class node_product_repo,node_sale_repo,node_invoice_repo,node_unit_of_work,node_ef_context,node_dapper_context,node_sale_queries toneMint
class node_user_service,node_user_repo,node_passwords toneRose
```

## Components

### HTTP API

- [Products API](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Api/Controllers/ProductController.cs): `PhoneHub.Api/Controllers/ProductController.cs`
- [Sales API](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Api/Controllers/SaleController.cs): `PhoneHub.Api/Controllers/SaleController.cs`
- [Invoices API](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Api/Controllers/InvoiceController.cs): `PhoneHub.Api/Controllers/InvoiceController.cs`
- [Users API](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Api/Controllers/UserController.cs): `PhoneHub.Api/Controllers/UserController.cs`
- [Token API](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Api/Controllers/TokenController.cs): `PhoneHub.Api/Controllers/TokenController.cs`

### Business Services

- [Product service](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/ProductService.cs): `PhoneHub.Services/Services/ProductService.cs`
- [Sale service](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/SaleService.cs): `PhoneHub.Services/Services/SaleService.cs`
- [Invoice service](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/InvoiceService.cs): `PhoneHub.Services/Services/InvoiceService.cs`

### Persistence

- [Product repository](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/ProductRepository.cs): `PhoneHub.Infrastructure/Repositories/ProductRepository.cs`
- [Sale repository](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/SaleRepository.cs): `PhoneHub.Infrastructure/Repositories/SaleRepository.cs`
- [Invoice repository](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/InvoiceRepository.cs): `PhoneHub.Infrastructure/Repositories/InvoiceRepository.cs`
- [Unit of work](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/UnitOfWork.cs): `PhoneHub.Infrastructure/Repositories/UnitOfWork.cs`
- [EF context](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Data/PhoneHubContext.cs): `PhoneHub.Infrastructure/Data/PhoneHubContext.cs`
- [Dapper context](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Data/DapperContext.cs): `PhoneHub.Infrastructure/Data/DapperContext.cs`
- [Sale queries](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Queries/SaleQueries.cs): `PhoneHub.Infrastructure/Queries/SaleQueries.cs`

### Identity

- [User service](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/UserService.cs): `PhoneHub.Services/Services/UserService.cs`
- [User repository](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Infrastructure/Repositories/UserRepository.cs): `PhoneHub.Infrastructure/Repositories/UserRepository.cs`
- [Password service](https://github.com/turb0xx/phonehub-backend/blob/main/PhoneHub.Services/Services/PasswordService.cs): `PhoneHub.Services/Services/PasswordService.cs`

### Other components

- **API client**
- **Relational database**

## Connections

- API client → Products API: requests (evidence: `PhoneHub.Api/Controllers/ProductController.cs`)
- API client → Sales API: requests (evidence: `PhoneHub.Api/Controllers/SaleController.cs`)
- API client → Invoices API: requests (evidence: `PhoneHub.Api/Controllers/InvoiceController.cs`)
- API client → Users API: requests (evidence: `PhoneHub.Api/Controllers/UserController.cs`)
- API client → Token API: requests (evidence: `PhoneHub.Api/Controllers/TokenController.cs`)
- Products API → Product service: delegates (evidence: `PhoneHub.Api/Controllers/ProductController.cs`)
- Sales API → Sale service: delegates (evidence: `PhoneHub.Api/Controllers/SaleController.cs`)
- Invoices API → Invoice service: delegates (evidence: `PhoneHub.Api/Controllers/InvoiceController.cs`)
- Users API → User service: delegates (evidence: `PhoneHub.Api/Controllers/UserController.cs`)
- Token API → User service: authenticates (evidence: `PhoneHub.Api/Controllers/TokenController.cs`)
- Product service → Product repository: accesses (evidence: `PhoneHub.Services/Services/ProductService.cs`)
- Product service → Sale repository: checks sales (evidence: `PhoneHub.Services/Services/ProductService.cs`)
- Sale service → Product repository: checks stock (evidence: `PhoneHub.Services/Services/SaleService.cs`)
- Sale service → Sale repository: records sales (evidence: `PhoneHub.Services/Services/SaleService.cs`)
- Sale service → User repository: checks user (evidence: `PhoneHub.Services/Services/SaleService.cs`)
- User service → User repository: manages users (evidence: `PhoneHub.Services/Services/UserService.cs`)
- User service → Password service: uses passwords (evidence: `PhoneHub.Services/Services/UserService.cs`)
- Invoice service → Invoice repository: accesses
- Product repository → EF context: uses (evidence: `PhoneHub.Infrastructure/Repositories/ProductRepository.cs`)
- Sale repository → EF context: uses (evidence: `PhoneHub.Infrastructure/Repositories/SaleRepository.cs`)
- Invoice repository → EF context: uses (evidence: `PhoneHub.Infrastructure/Repositories/InvoiceRepository.cs`)
- Product repository → Dapper context: queries (evidence: `PhoneHub.Infrastructure/Repositories/ProductRepository.cs`)
- Sale repository → Dapper context: queries (evidence: `PhoneHub.Infrastructure/Repositories/SaleRepository.cs`)
- Invoice repository → Dapper context: queries (evidence: `PhoneHub.Infrastructure/Repositories/InvoiceRepository.cs`)
- Sale repository → Sale queries: selects SQL (evidence: `PhoneHub.Infrastructure/Repositories/SaleRepository.cs`)
- EF context → Relational database: reads/writes
- Dapper context → Relational database: executes SQL
