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:
companiesmirrors the HubSpot Company object (objectTypeId0-2,companyConfiginservices/hubspot/sync-engine/entity-configs.ts).hubspotIdis for sync round-tripping only — internal references join oncompanies.id(UUID PK).
Source Files
| Layer | Path |
|---|---|
| Schema | backend/src/db/schema.ts (companies) |
| Routes | backend/src/routes/companies.ts |
| Service | backend/src/services/company-service.ts |
| Pages | frontend/src/pages/CompaniesPage.tsx, frontend/src/pages/CompanyDetailPage.tsx |
| Queries | frontend/src/lib/queries/companyQueries.ts |
Database Tables
| Table | Purpose |
|---|---|
companies | Main entity — name, domain, address, business info, HubSpot sync, hierarchy |
contact_companies | M2M join with Contacts (role, isPrimary, start/end dates) |
partner_agreements | KOP commission rate Renewa earns from a contractor company (dealType eb/kop/external, rate, validity window) |
Key Fields
| Field | Type | Notes |
|---|---|---|
name | varchar(255) | Company name (required) |
domain, website | varchar | Web presence |
email, phone | varchar | Primary contact info |
industry | varchar | Business sector |
legalForm | varchar(50) | Legal form (Rechtsform) |
annualRevenue | decimal | Revenue figure |
numberOfEmployees | integer | Company size |
taxId | varchar | Tax identification (USt-IdNr) |
isVatDeductible | boolean | VAT deduction eligibility |
companyType | varchar | RENEWA classification (Kategorie) |
classification | varchar | Internal classification |
priority, potential | varchar | Business priority and potential |
organizationalLevel | varchar(50) | Organisationsebene |
parentCompanyId | uuid | Self-referencing hierarchy |
hierarchyLevel, hierarchyPath | int/varchar | Hierarchy navigation |
trades, tradeLabels | text | Semicolon-separated trade specializations |
letterhead, importantNotes, aboutUs, linkedinCompanyPage, foundedYear | varchar/text | Additional business info |
fastbillId | varchar(100) | FastBill integration ID |
hubspotId | varchar(100) | HubSpot company ID (unique) |
recordOwnerContactId | uuid FK | Read-only sync mirror of the HubSpot record owner (resolved to a contact via hubspot_owners; sync layer is the sole writer) |
hubspotProperties | jsonb | Raw HubSpot property bag |
hubspotPipeline, hubspotPipelineStage, hubspotSchemaVersion, lastSyncedAt | varchar/timestamp | Sync metadata |
isActive | boolean | RENEWA business flag (enabled/disabled) |
archived, archivedAt, deletedAt, archiveReason, mergedIntoHubspotId | various | HubSpot 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:
parentCompanyIdpoints to the parent companyhierarchyLevel(0 = root) andhierarchyPathenable efficient tree queries- Used to model corporate structures (holding → subsidiary → branch)
HubSpot Sync
- Synced from HubSpot CRM companies via HubSpot Integration
hubspotCompanyTypemaps to HubSpot’s type field (PROSPECT, PARTNER, VENDOR, etc.)lifecycleStageandleadStatustrack 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)
Related Pages
Contacts | Projects | Buildings | HubSpot Integration | Leads | Database Architecture