Companies

Organizations in the system — partner firms, client companies, contractors, subcontractors. Synced with HubSpot Integration and linked to Contacts via a many-to-many relationship.

HubSpot mirror: companies mirrors the HubSpot Company object (objectTypeId 0-2, companyConfig in services/hubspot/sync-engine/entity-configs.ts). hubspotId is for sync round-tripping only — internal references join on companies.id (UUID PK).

Source Files

LayerPath
Schemabackend/src/db/schema.ts (companies)
Routesbackend/src/routes/companies.ts
Servicebackend/src/services/company-service.ts
Pagesfrontend/src/pages/CompaniesPage.tsx, frontend/src/pages/CompanyDetailPage.tsx
Queriesfrontend/src/lib/queries/companyQueries.ts

Database Tables

TablePurpose
companiesMain entity — name, domain, address, business info, HubSpot sync, hierarchy
contact_companiesM2M join with Contacts (role, isPrimary, start/end dates)
partner_agreementsKOP commission rate Renewa earns from a contractor company (dealType eb/kop/external, rate, validity window)

Key Fields

FieldTypeNotes
namevarchar(255)Company name (required)
domain, websitevarcharWeb presence
email, phonevarcharPrimary contact info
industryvarcharBusiness sector
legalFormvarchar(50)Legal form (Rechtsform)
annualRevenuedecimalRevenue figure
numberOfEmployeesintegerCompany size
taxIdvarcharTax identification (USt-IdNr)
isVatDeductiblebooleanVAT deduction eligibility
companyTypevarcharRENEWA classification (Kategorie)
classificationvarcharInternal classification
priority, potentialvarcharBusiness priority and potential
organizationalLevelvarchar(50)Organisationsebene
parentCompanyIduuidSelf-referencing hierarchy
hierarchyLevel, hierarchyPathint/varcharHierarchy navigation
trades, tradeLabelstextSemicolon-separated trade specializations
letterhead, importantNotes, aboutUs, linkedinCompanyPage, foundedYearvarchar/textAdditional business info
fastbillIdvarchar(100)FastBill integration ID
hubspotIdvarchar(100)HubSpot company ID (unique)
recordOwnerContactIduuid FKRead-only sync mirror of the HubSpot record owner (resolved to a contact via hubspot_owners; sync layer is the sole writer)
hubspotPropertiesjsonbRaw HubSpot property bag
hubspotPipeline, hubspotPipelineStage, hubspotSchemaVersion, lastSyncedAtvarchar/timestampSync metadata
isActivebooleanRENEWA business flag (enabled/disabled)
archived, archivedAt, deletedAt, archiveReason, mergedIntoHubspotIdvariousHubSpot archive/merge status + soft delete

Relationships

Company *──* Contacts (via contact_companies)
Company *──0..1 Company (parent -- self-referencing hierarchy)
Company *──* Projects (via contacts and roles)

Company Hierarchy

Companies support a self-referencing tree structure:

  • parentCompanyId points to the parent company
  • hierarchyLevel (0 = root) and hierarchyPath enable efficient tree queries
  • Used to model corporate structures (holding subsidiary branch)

HubSpot Sync

  • Synced from HubSpot CRM companies via HubSpot Integration
  • hubspotCompanyType maps to HubSpot’s type field (PROSPECT, PARTNER, VENDOR, etc.)
  • lifecycleStage and leadStatus track the HubSpot sales pipeline
  • Association config in backend/src/routes/admin/hubspot-association-config.ts

HubSpot-Tracked Relationships

Relationships HubSpot tracks against companies (e.g., primary_company, contractor, property_management, invoice_recipient) are not FK columns — they are polymorphic rows in hubspot_associations, read via getAssociationsByRenewaName(role, ...) with the internal_name → role mapping in RENEWA_ROLE_BINDINGS. Spec: docs/superpowers/specs/2026-05-08-hubspot-association-infrastructure-design.md. The contact_companies junction (employment-style contact↔company links) predates this and remains.

Features

  • Company hierarchy with parent/child relationships and tree navigation
  • HubSpot sync for CRM data including lifecycle and classification
  • Trade tracking for contractor/craftsman specializations
  • Contact associations with role metadata (employee, consultant, board member)
  • RENEWA classification system (type, classification, priority, potential)

Contacts | Projects | Buildings | HubSpot Integration | Leads | Database Architecture