# mateusz-bogacz-collegiumwitelona/spcrm_backend architecture

> Architecture diagram of the GitHub repository mateusz-bogacz-collegiumwitelona/spcrm_backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mateusz-bogacz-collegiumwitelona/spcrm_backend
- Repository: https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend

## Overview

SPCRM is a backend CRM for a steel-trading business. The main workflow is an authenticated user request entering the REST API, being validated and mapped, handled by a domain service, and returned as a response; business operations also read and update CRM records. Distinct capabilities include sales and invoicing, product inventory, user and company management, tasks, analytics, and scheduled email/cleanup work. The sampled sources confirm representative controller-to-service calls, authentication, persistence in event handling, and SMTP delivery; many other subsystem links are omitted where their wiring was not sampled.

Main entry points: [`Api/Program.cs`](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Api/Program.cs) (API host), [`Infrastructure/AppDbContext.cs`](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Infrastructure/AppDbContext.cs) (CRM database), [`Api/Controllers/DealController.cs`](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Api/Controllers/DealController.cs) (Deal endpoints), [`Api/Controllers/UserController.cs`](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Api/Controllers/UserController.cs) (User endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_api_app["API host<br/>[Program.cs]"]
  node_user_ctl["User endpoints<br/>[UserController.cs]"]
  node_company_ctl["Company endpoints"]
  node_deal_ctl["Deal endpoints<br/>[DealController.cs]"]
  node_auth_svc["Authentication<br/>[AuthServices.cs]"]
  node_validators["Request validation"]
  node_mappers["Request mapping"]
end

subgraph group_crm["CRM operations"]
  node_company_svc["Company services<br/>[CompanyServices.cs]"]
  node_contact_svc["Contact services<br/>[ContactServices.cs]"]
  node_deal_svc["Deal services<br/>[DealServices.cs]"]
  node_offer_svc["Offer services<br/>[OfferServices.cs]"]
  node_product_svc["Product inventory<br/>[ProductSevices.cs]"]
  node_invoice_svc["Invoices and payments<br/>[InvoiceService.cs]"]
  node_task_svc["Task services<br/>[TaskServices.cs]"]
  node_analytics_svc["Analytics"]
end

subgraph group_domain["Domain workflow"]
  node_state{{"Deal and task states"}}
  node_deal_event["Deal completion event"]
  node_event_handler["Invoice event handler"]
end

subgraph group_data["Persistence and reports"]
  node_db[("CRM database<br/>[AppDbContext.cs]")]
  node_pdf["PDF generation"]
end

subgraph group_integrations["Async integrations"]
  node_workers["Scheduled workers"]
  node_email_sender["Email delivery"]
  node_smtp["SMTP server"]
  node_redis[("Redis cache")]
end

node_user(("CRM user"))

node_user -->|"sends requests"| node_api_app
node_api_app -->|"routes requests"| node_user_ctl
node_api_app -->|"routes requests"| node_company_ctl
node_api_app -->|"routes requests"| node_deal_ctl
node_api_app -->|"validates requests"| node_validators
node_user_ctl -->|"calls identity"| node_auth_svc
node_user_ctl -->|"maps requests"| node_mappers
node_user_ctl -->|"calls services"| node_company_svc
node_company_ctl -->|"maps requests"| node_mappers
node_company_ctl -->|"calls services"| node_company_svc
node_company_ctl -->|"gets company deals"| node_deal_svc
node_deal_ctl -->|"maps requests"| node_mappers
node_deal_ctl -->|"calls services"| node_deal_svc
node_deal_ctl -->|"adds deal task"| node_task_svc
node_deal_ctl -->|"changes status"| node_state
node_deal_svc -->|"raises event"| node_deal_event
node_event_handler -->|"handles event"| node_deal_event
node_event_handler -->|"creates invoice"| node_db
node_event_handler -->|"sends invoice email"| node_email_sender
node_invoice_svc -->|"reads and writes"| node_db
node_product_svc -->|"reads and writes"| node_db
node_offer_svc -->|"reads and writes"| node_db
node_task_svc -->|"reads and writes"| node_db
node_analytics_svc -->|"reads records"| node_db
node_analytics_svc -->|"generates reports"| node_pdf
node_workers -->|"dispatches email"| node_email_sender
node_email_sender -->|"sends mail"| node_smtp
node_api_app -.->|"configures cache"| node_redis

click node_api_app "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Api/Program.cs"
click node_user_ctl "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Api/Controllers/UserController.cs"
click node_company_ctl "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Api/Controllers/CompanyController.cs"
click node_deal_ctl "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Api/Controllers/DealController.cs"
click node_auth_svc "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/AuthServices.cs"
click node_validators "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/tree/main/Api/Validators/Validators"
click node_mappers "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/tree/main/Api/Mappers"
click node_company_svc "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/CompanyServices.cs"
click node_contact_svc "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/ContactServices.cs"
click node_deal_svc "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/DealServices.cs"
click node_offer_svc "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/OfferServices.cs"
click node_product_svc "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/ProductSevices.cs"
click node_invoice_svc "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/InvoiceService.cs"
click node_task_svc "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/TaskServices.cs"
click node_analytics_svc "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/AnalyticsService.cs"
click node_state "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Domain/State/DealStateMachine.cs"
click node_deal_event "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Domain/Events/DealCompletedEvent.cs"
click node_event_handler "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Handlers/DealCompletedEventHandler.cs"
click node_db "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Infrastructure/AppDbContext.cs"
click node_pdf "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Infrastructure/Pdf/AnalyticsPdfGenerator.cs"
click node_workers "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Worker/Workers/InvoiceEmailWorker.cs"
click node_email_sender "https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Email/SmtpEmailService.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_api_app,node_user_ctl,node_company_ctl,node_deal_ctl,node_auth_svc,node_validators,node_mappers,node_user toneBlue
class node_company_svc,node_contact_svc,node_deal_svc,node_offer_svc,node_product_svc,node_invoice_svc,node_task_svc,node_analytics_svc toneAmber
class node_state,node_deal_event,node_event_handler toneMint
class node_db,node_pdf toneRose
class node_workers,node_email_sender,node_smtp,node_redis toneIndigo
```

## Components

### API and identity

- [API host](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Api/Program.cs): `Api/Program.cs`
- [User endpoints](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Api/Controllers/UserController.cs): `Api/Controllers/UserController.cs`
- [Company endpoints](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Api/Controllers/CompanyController.cs): `Api/Controllers/CompanyController.cs`
- [Deal endpoints](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Api/Controllers/DealController.cs): `Api/Controllers/DealController.cs`
- [Authentication](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/AuthServices.cs): `Services/Services/AuthServices.cs`
- [Request validation](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/tree/main/Api/Validators/Validators): `Api/Validators/Validators`
- [Request mapping](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/tree/main/Api/Mappers): `Api/Mappers`

### CRM operations

- [Company services](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/CompanyServices.cs): `Services/Services/CompanyServices.cs`
- [Contact services](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/ContactServices.cs): `Services/Services/ContactServices.cs`
- [Deal services](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/DealServices.cs): `Services/Services/DealServices.cs`
- [Offer services](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/OfferServices.cs): `Services/Services/OfferServices.cs`
- [Product inventory](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/ProductSevices.cs): `Services/Services/ProductSevices.cs`
- [Invoices and payments](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/InvoiceService.cs): `Services/Services/InvoiceService.cs`
- [Task services](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/TaskServices.cs): `Services/Services/TaskServices.cs`
- [Analytics](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Services/AnalyticsService.cs): `Services/Services/AnalyticsService.cs`

### Domain workflow

- [Deal and task states](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Domain/State/DealStateMachine.cs): `Domain/State/DealStateMachine.cs`
- [Deal completion event](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Domain/Events/DealCompletedEvent.cs): `Domain/Events/DealCompletedEvent.cs`
- [Invoice event handler](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Services/Handlers/DealCompletedEventHandler.cs): `Services/Handlers/DealCompletedEventHandler.cs`

### Persistence and reports

- [CRM database](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Infrastructure/AppDbContext.cs): `Infrastructure/AppDbContext.cs`
- [PDF generation](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Infrastructure/Pdf/AnalyticsPdfGenerator.cs): `Infrastructure/Pdf/AnalyticsPdfGenerator.cs`

### Async integrations

- [Scheduled workers](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Worker/Workers/InvoiceEmailWorker.cs): `Worker/Workers/InvoiceEmailWorker.cs`
- [Email delivery](https://github.com/mateusz-bogacz-collegiumwitelona/spcrm_backend/blob/main/Email/SmtpEmailService.cs): `Email/SmtpEmailService.cs`
- **SMTP server**
- **Redis cache**

### Other components

- **CRM user**

## Connections

- CRM user → API host: sends requests
- API host → User endpoints: routes requests
- API host → Company endpoints: routes requests
- API host → Deal endpoints: routes requests
- API host → Request validation: validates requests
- User endpoints → Authentication: calls identity
- User endpoints → Request mapping: maps requests
- User endpoints → Company services: calls services
- Company endpoints → Request mapping: maps requests
- Company endpoints → Company services: calls services
- Company endpoints → Deal services: gets company deals
- Deal endpoints → Request mapping: maps requests
- Deal endpoints → Deal services: calls services
- Deal endpoints → Task services: adds deal task
- Deal endpoints → Deal and task states: changes status
- Deal services → Deal completion event: raises event
- Invoice event handler → Deal completion event: handles event
- Invoice event handler → CRM database: creates invoice
- Invoice event handler → Email delivery: sends invoice email
- Invoices and payments → CRM database: reads and writes
- Product inventory → CRM database: reads and writes
- Offer services → CRM database: reads and writes
- Task services → CRM database: reads and writes
- Analytics → CRM database: reads records
- Analytics → PDF generation: generates reports
- Scheduled workers → Email delivery: dispatches email
- Email delivery → SMTP server: sends mail
- API host → Redis cache: configures cache
