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.
| Module | Purpose | Key Collections |
|---|---|---|
| Drafts | Notes β the central intake for user content | drafts |
| Conversations | Chat threads + messages | conversations, messages |
| Parse | Structured records extracted by AI | parseresults |
| Fields | Agricultural field boundaries (geo polygons) | fields |
| Attachments | Images, PDFs, documents (S3) | attachments |
| Call Logs | Audio recordings + transcription metadata | calllogs |
| Users | User profiles + company memberships | users |
| Companies | Multi-tenant organizations | companies |
| Workspaces | Workspace schemas for structured data | workspaces |
| Transcription | Speech-to-text provider orchestration | β |
| Process | AI parsing pipeline (preprocessing, intent, extraction) | β |
| Queue | BullMQ job processors | β |
| Realtime | Socket.IO WebSocket gateway | β |
| Firebase | Firebase Auth integration | β |
Request Lifecycle β
Every HTTP request passes through a layered guard system before reaching business logic:
Key Decorators β
| Decorator | Purpose |
|---|---|
@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.
Related Pages β
- Drafts (Notes) β the central data intake module
- Module Relationships β how modules connect
- Queues & Processing β async pipelines
- Main chat weather (Open-Meteo) & search result IDs β
get_weather, field ID resolution, semantic searchidfix