Skip to content

Backend Overview ​

The backend is a NestJS API serving the web frontend and mobile app. It handles authentication, multi-tenant data access, real-time communication, and asynchronous processing pipelines for audio transcription, document analysis, and AI-powered data extraction.

High-Level Architecture ​

Module Map ​

The backend is organized into domain modules, each owning its controller, service, DTOs, and Mongoose schemas.

ModulePurposeKey Collections
DraftsNotes β€” the central intake for user contentdrafts
ConversationsChat threads + messagesconversations, messages
ParseStructured records extracted by AIparseresults
FieldsAgricultural field boundaries (geo polygons)fields
AttachmentsImages, PDFs, documents (S3)attachments
Call LogsAudio recordings + transcription metadatacalllogs
UsersUser profiles + company membershipsusers
CompaniesMulti-tenant organizationscompanies
WorkspacesWorkspace schemas for structured dataworkspaces
TranscriptionSpeech-to-text provider orchestrationβ€”
ProcessAI parsing pipeline (preprocessing, intent, extraction)β€”
QueueBullMQ job processorsβ€”
RealtimeSocket.IO WebSocket gatewayβ€”
FirebaseFirebase Auth integrationβ€”

Request Lifecycle ​

Every HTTP request passes through a layered guard system before reaching business logic:

Key Decorators ​

DecoratorPurpose
@Public()Skip all auth guards
@CompanyRequired()Enforce company membership
@CompanyRoles([...])Require specific roles (admin, manager, worker)
@CurrentUserProfile()Inject the resolved UserDocumentPopulated

Multi-Tenancy ​

Every domain entity extends CompanyAwareBase and is automatically scoped to the user's companies. See Multi-Tenancy Architecture for the full model.