Services Overview

148 service files in backend/src/services/ (as of 2026-06, excluding co-located tests; 183 with tests), with matching interfaces in backend/src/interfaces/ (71 files). Each service encapsulates business logic for a domain entity, injected into routes via the DI container.

Under the persistence topology (I#2013), services add no new persistence: new Drizzle access lives in domain modules (currently lib/billing/, lib/file-operations/), which services and job processors consume. Existing direct DB access is allowlisted (ratcheted by scripts/check-persistence-topology.sh) and migrates on touch. See Persistence Topology and Service Layer Pattern.

DI Container

Services are created and wired in backend/src/services/create-services.ts (createProductionContainer()), then attached to the Hono context as c.var.services. The ServiceContainer (defined in interfaces/service-container.ts) has four slices: infrastructure, crossCutting, domain (domain modules), and services. Job processors receive a ProcessorContainer — a Pick of domain/infrastructure/crossCutting without the services slice (processors are peer clients of services, not callers). See Dependency Injection.

Key Services by Domain

Core Business

ServiceFilePurpose
BuildingsServicebuildings-service.tsBuilding CRUD, geometry, metadata
BuildingTechnologyServicebuilding-technology-service.tsBuilding technology data
ProjectServiceproject-service.tsProjects lifecycle
PhaseServicephase-service.tsProject phases
WorkflowPackageServiceworkflow-package-service.ts + workflow-package/Workflow packages (Auftragsübergabe)
SiteProtocolServicesite-protocol-service.ts, site-protocol-pdf.tsSite protocols + PDF export (PR#1994)

Scenarios, measures, and building components no longer have dedicated service files — their routes (scenarios.ts, scenario-measures.ts, measures.ts, building-components.ts) are served through the project/building stack.

CRM

ServiceFilePurpose
ContactServicecontact-service.tsContacts CRUD, claiming
CompanyServicecompany-service.tsCompanies management
ActivityService / TimelineServiceactivity-service.ts, timeline-service.tsActivity + timeline

Leads have no dedicated service — they mirror HubSpot Leads into hubspot_leads via the sync engine.

Finance & Billing

ServiceFilePurpose
QuoteServicequote-service.tsQuotes CRUD
QuoteFinanceServicequote-finance-service.tsFinancial Calculations for quotes
InvoiceServiceinvoice-service.tsInvoices generation
FinanceServicefinance-service.tsFinance operations
Billing suitebilling/ (14 files: invoices, operations, accounting, templates, settings, email, CAMT import)Billing domain (persistence in lib/billing/)
SevDesk suitesevdesk/sevDesk accounting bridge
RevenueServicerevenue/Revenue reporting
CatalogServicecatalog-service.tsProducts catalog
FundingApplicationServicefunding-application-service.tsFunding Applications
CommissionCalculatorcommission-calculator.tsContractor commissions

Documents & Files

ServiceFilePurpose
DocumentRequestServicedocument-request-service.ts, document-request-batch-service.tsDocuments request workflow
DocumentObtainingServicedocument-obtaining/Document Obtaining collection
DocumentTemplateServicedocument-template-service.ts + document-template/Document templates
FileServicefile-service.ts, bulk-file-service.tsFiles CAS upload/download (streams)
Collectionscollection-service.ts, file-collections-service.ts, file-collection-members-service.ts, entity-collection-links-service.ts, entity-file-link-service.ts, file-label-service.tsCollection-canonical file linkage (PR#1752)
PDF suitepdf-export-service.ts, pdf-template-service.ts, pdf-session-service.ts, pdf-combined-field-service.tsPDF Templates generation

Auth & Users

ServiceFilePurpose
AuthServiceauth-service.tsAuthentication, 2FA, password reset
UserServiceuser-service.tsUsers management
TokenServicetoken-service.tsToken operations
PortalServiceportal-service.ts + portal/ (access, downloads, forms, fulfillment, notifications, PDF)Portal

Automation & Scheduling

ServiceFilePurpose
WorkflowStateMachineworkflow-state-machine.tsWorkflows state transitions
Workflow config/templatesworkflow-config-service.ts, workflow-template-service.tsWorkflow configuration
TaskServicetask-service.tsTask management
EngagementTaskTemplateServiceengagement-task-template-service.tsEngagement task templates
AppointmentServiceappointment-service.tsAppointments scheduling
FulfillmentServicefulfillment-service.tsFulfillment chains
ResponsibilitiesServiceresponsibilities-service.tsResponsibility assignment

External Integrations & Dashboards

ServiceFile(s)Purpose
HubSpot suitehubspot/ (33 files incl. sync-engine/, event-handlers/, mapping/)HubSpot Integration sync
Entra suiteentra/ (auth, groups, sync)Azure Entra SSO + department/employee sync
FeedbackServicefeedback/Feedback System
Dashboardsdashboard-service.ts, dashboard/, admin-dashboard-service.ts, document-obtaining-dashboard-service.tsDashboards

Notifications dispatch lives in lib/notifications/ (with the BullMQ processor in lib/jobs/processors/notifications.ts); audit logging and departments are handled by middleware + the Entra sync rather than dedicated services.

Interface Pattern

Each service has a matching interface in backend/src/interfaces/ (same basename, no .interface suffix):

backend/src/interfaces/buildings-service.ts
backend/src/services/buildings-service.ts

The interface defines the contract; the service implements it. Routes depend on interfaces, not implementations.