# crowafrica/crow-backend architecture

> Architecture diagram of the GitHub repository crowafrica/crow-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/crowafrica/crow-backend
- Repository: https://github.com/crowafrica/crow-backend

## Overview

#### Purpose and Runtime
Crow Elite is a NestJS/Node.js backend for brand–creator collaborations: identity onboarding, creator discovery, campaigns, applications, contracts, messaging, reviews, and escrow payments. The HTTP server starts in `src/main.ts`; root composition is `src/app.module.ts`. Swagger is exposed at `/api/docs`.

#### API and Module Boundary
Feature modules follow Nest’s controller → service → persistence pattern. Controllers expose REST endpoints and services own use-case logic:
- `src/creators/creators.controller.ts`, `src/creators/creators.service.ts`
- `src/campaigns/campaigns.controller.ts`, `src/campaigns/campaigns.service.ts`
- `src/applications/applications.controller.ts`, `src/applications/applications.service.ts`

DTOs at feature boundaries validate/shape requests, including campaign creation/search and application or invitation actions.

#### Identity, Access, and Onboarding
Authentication supports registration, OTP verification, login, role-specific onboarding, JWT sessions, and Google OAuth. `src/auth/auth.controller.ts` delegates these flows to `src/auth/auth.service.ts`. Request protection is split between JWT, Google, and role guards in `src/auth/guards/jwt-auth.guard.ts`, `src/auth/guards/google-auth.guard.ts`, and `src/auth/guards/roles.guard.ts`. User identity is propagated through `src/common/decorators/current-user.decorator.ts`.

#### Collaboration Lifecycle
Brands create and manage campaigns; creators discover campaigns and apply, while brands can invite creators. The applications module is the lifecycle junction between campaign and creator records, with request contracts in `src/applications/dto/apply-campaign.dto.ts` and `src/applications/dto/invite-creator.dto.ts`. Contracts add milestones to accepted work, through `src/contracts/contracts.service.ts` and `src/contracts/dto/create-milestone.dto.ts`.

#### Engagement and Trust
Post-collaboration interactions are modeled as messages and reviews:
- `src/messages/messages.controller.ts`, `src/messages/messages.service.ts`
- `src/reviews/reviews.controller.ts`, `src/reviews/reviews.service.ts`
These are separate domain modules rather than part of the application workflow service, allowing messaging, reputation, and contract state to evolve independently.

#### Persistence and External Services
PostgreSQL is the system of record, accessed via the shared Prisma integration in `src/prisma/prisma.module.ts` and `src/prisma/prisma.service.ts`; schema and migration history are in `prisma/schema.prisma` and `prisma/migrations/`. Cloudinary provides uploaded-file/image storage through `src/cloudinary/cloudinary.module.ts` and `src/cloudinary/cloudinary.service.ts`. Email-related delivery is isolated in `src/mail/mail.module.ts` and `src/mail/mail.service.ts`.

#### Payments and Operational Deployment
Escrow funding is exposed as a dedicated payments domain, separated from contracts: `src/payments/payments.controller.ts`, `src/payments/payments.service.ts`, and `src/payments/dto/fund-escrow.dto.ts`. Local infrastructure is represented by `docker-compose.yml`; Render deployment configuration is in `render.yaml`. Cross-cutting error normalization is centralized in `src/common/filters/all-exceptions.filter.ts`.

Main entry points: [`src/app.module.ts`](https://github.com/crowafrica/crow-backend/blob/main/src/app.module.ts) (App module), [`src/prisma/prisma.service.ts`](https://github.com/crowafrica/crow-backend/blob/main/src/prisma/prisma.service.ts) (Prisma data access), [`src/applications/applications.service.ts`](https://github.com/crowafrica/crow-backend/blob/main/src/applications/applications.service.ts) (Applications & invites), [`src/auth/auth.controller.ts`](https://github.com/crowafrica/crow-backend/blob/main/src/auth/auth.controller.ts) (Auth API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_bootstrap{{"Nest bootstrap<br/>entrypoint<br/>[main.ts]"}}
  node_app_module["App module<br/>composition root<br/>[app.module.ts]"]
  node_deployment["Container &amp; Render deploy<br/>operations<br/>[docker-compose.yml]"]
end

subgraph group_identity["Identity &amp; Access"]
  node_auth_api["Auth API<br/>controller + service<br/>[auth.controller.ts]"]
  node_access_controls["Access controls<br/>guards + decorator<br/>[jwt-auth.guard.ts]"]
end

subgraph group_collaboration["Collaboration"]
  node_creators["Creators<br/>feature module"]
  node_campaigns["Campaigns<br/>feature module"]
  node_applications["Applications &amp; invites<br/>lifecycle module"]
  node_contracts["Contracts &amp; milestones<br/>feature module"]
  node_payments["Escrow payments<br/>feature module"]
end

subgraph group_engagement["Engagement"]
  node_messages["Messages<br/>feature module"]
  node_reviews["Reviews<br/>feature module<br/>[reviews.service.ts]"]
end

subgraph group_platform["Platform Services"]
  node_prisma[("Prisma data access<br/>shared persistence<br/>[prisma.service.ts]")]
  node_postgres[("PostgreSQL<br/>system of record<br/>[schema.prisma]")]
  node_cloudinary["Cloudinary integration<br/>external storage adapter"]
  node_mail["Mail delivery<br/>external delivery adapter<br/>[mail.service.ts]"]
  node_exception_filter["Exception normalization<br/>global filter"]
end

node_bootstrap -->|"boots"| node_app_module
node_bootstrap -->|"installs"| node_exception_filter
node_app_module -->|"composes"| node_auth_api
node_app_module -->|"composes"| node_creators
node_app_module -->|"composes"| node_campaigns
node_app_module -->|"composes"| node_applications
node_app_module -->|"composes"| node_contracts
node_app_module -->|"composes"| node_payments
node_app_module -->|"composes"| node_messages
node_app_module -->|"composes"| node_reviews
node_auth_api -->|"uses"| node_access_controls
node_auth_api -->|"persists identities"| node_prisma
node_creators -->|"reads and writes"| node_prisma
node_campaigns -->|"reads and writes"| node_prisma
node_applications -->|"links creators"| node_creators
node_applications -->|"links campaigns"| node_campaigns
node_applications -->|"persists lifecycle"| node_prisma
node_contracts -->|"follows acceptance"| node_applications
node_contracts -->|"persists contracts"| node_prisma
node_payments -->|"funds escrow for"| node_contracts
node_payments -->|"persists funding"| node_prisma
node_messages -->|"persists conversations"| node_prisma
node_reviews -->|"persists reputation"| node_prisma
node_prisma -->|"accesses"| node_postgres
node_creators -->|"stores uploads"| node_cloudinary
node_auth_api -->|"sends OTP email"| node_mail
node_deployment -.->|"deploys"| node_bootstrap

click node_bootstrap "https://github.com/crowafrica/crow-backend/blob/main/src/main.ts"
click node_app_module "https://github.com/crowafrica/crow-backend/blob/main/src/app.module.ts"
click node_auth_api "https://github.com/crowafrica/crow-backend/blob/main/src/auth/auth.controller.ts"
click node_access_controls "https://github.com/crowafrica/crow-backend/blob/main/src/auth/guards/jwt-auth.guard.ts"
click node_creators "https://github.com/crowafrica/crow-backend/blob/main/src/creators/creators.service.ts"
click node_campaigns "https://github.com/crowafrica/crow-backend/blob/main/src/campaigns/campaigns.service.ts"
click node_applications "https://github.com/crowafrica/crow-backend/blob/main/src/applications/applications.service.ts"
click node_contracts "https://github.com/crowafrica/crow-backend/blob/main/src/contracts/contracts.service.ts"
click node_payments "https://github.com/crowafrica/crow-backend/blob/main/src/payments/payments.service.ts"
click node_messages "https://github.com/crowafrica/crow-backend/blob/main/src/messages/messages.service.ts"
click node_reviews "https://github.com/crowafrica/crow-backend/blob/main/src/reviews/reviews.service.ts"
click node_prisma "https://github.com/crowafrica/crow-backend/blob/main/src/prisma/prisma.service.ts"
click node_postgres "https://github.com/crowafrica/crow-backend/blob/main/prisma/schema.prisma"
click node_cloudinary "https://github.com/crowafrica/crow-backend/blob/main/src/cloudinary/cloudinary.service.ts"
click node_mail "https://github.com/crowafrica/crow-backend/blob/main/src/mail/mail.service.ts"
click node_exception_filter "https://github.com/crowafrica/crow-backend/blob/main/src/common/filters/all-exceptions.filter.ts"
click node_deployment "https://github.com/crowafrica/crow-backend/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_bootstrap,node_app_module,node_deployment toneBlue
class node_auth_api,node_access_controls toneAmber
class node_creators,node_campaigns,node_applications,node_contracts,node_payments toneMint
class node_messages,node_reviews toneRose
class node_prisma,node_postgres,node_cloudinary,node_mail,node_exception_filter toneIndigo
```

## Components

### Runtime

- [Nest bootstrap](https://github.com/crowafrica/crow-backend/blob/main/src/main.ts): entrypoint · Starts HTTP server and Swagger docs. · `src/main.ts`
- [App module](https://github.com/crowafrica/crow-backend/blob/main/src/app.module.ts): composition root · Composes feature and shared modules. · `src/app.module.ts`
- [Container & Render deploy](https://github.com/crowafrica/crow-backend/blob/main/docker-compose.yml): operations · Local Compose infrastructure and Render deployment. · `docker-compose.yml`

### Identity & Access

- [Auth API](https://github.com/crowafrica/crow-backend/blob/main/src/auth/auth.controller.ts): controller + service · Registration, OTP, login, onboarding, JWT, and Google OAuth. · `src/auth/auth.controller.ts`
- [Access controls](https://github.com/crowafrica/crow-backend/blob/main/src/auth/guards/jwt-auth.guard.ts): guards + decorator · JWT, Google, role enforcement, and current-user propagation. · `src/auth/guards/jwt-auth.guard.ts`

### Collaboration

- [Creators](https://github.com/crowafrica/crow-backend/blob/main/src/creators/creators.service.ts): feature module · Creator profiles and discovery use cases. · `src/creators/creators.service.ts`
- [Campaigns](https://github.com/crowafrica/crow-backend/blob/main/src/campaigns/campaigns.service.ts): feature module · Brand campaign creation, management, and search. · `src/campaigns/campaigns.service.ts`
- [Applications & invites](https://github.com/crowafrica/crow-backend/blob/main/src/applications/applications.service.ts): lifecycle module · Junction for creator applications and brand invitations. · `src/applications/applications.service.ts`
- [Contracts & milestones](https://github.com/crowafrica/crow-backend/blob/main/src/contracts/contracts.service.ts): feature module · Accepted work contracts and milestone creation. · `src/contracts/contracts.service.ts`
- [Escrow payments](https://github.com/crowafrica/crow-backend/blob/main/src/payments/payments.service.ts): feature module · Dedicated escrow funding domain. · `src/payments/payments.service.ts`

### Engagement

- [Messages](https://github.com/crowafrica/crow-backend/blob/main/src/messages/messages.service.ts): feature module · Independent collaboration messaging. · `src/messages/messages.service.ts`
- [Reviews](https://github.com/crowafrica/crow-backend/blob/main/src/reviews/reviews.service.ts): feature module · Independent reputation and review domain. · `src/reviews/reviews.service.ts`

### Platform Services

- [Prisma data access](https://github.com/crowafrica/crow-backend/blob/main/src/prisma/prisma.service.ts): shared persistence · Shared database client integration. · `src/prisma/prisma.service.ts`
- [PostgreSQL](https://github.com/crowafrica/crow-backend/blob/main/prisma/schema.prisma): system of record · `prisma/schema.prisma`
- [Cloudinary integration](https://github.com/crowafrica/crow-backend/blob/main/src/cloudinary/cloudinary.service.ts): external storage adapter · Uploaded-file and image storage. · `src/cloudinary/cloudinary.service.ts`
- [Mail delivery](https://github.com/crowafrica/crow-backend/blob/main/src/mail/mail.service.ts): external delivery adapter · `src/mail/mail.service.ts`
- [Exception normalization](https://github.com/crowafrica/crow-backend/blob/main/src/common/filters/all-exceptions.filter.ts): global filter · `src/common/filters/all-exceptions.filter.ts`

## Connections

- Nest bootstrap → App module: boots
- Nest bootstrap → Exception normalization: installs
- App module → Auth API: composes
- App module → Creators: composes
- App module → Campaigns: composes
- App module → Applications & invites: composes
- App module → Contracts & milestones: composes
- App module → Escrow payments: composes
- App module → Messages: composes
- App module → Reviews: composes
- Auth API → Access controls: uses
- Auth API → Prisma data access: persists identities
- Creators → Prisma data access: reads and writes
- Campaigns → Prisma data access: reads and writes
- Applications & invites → Creators: links creators
- Applications & invites → Campaigns: links campaigns
- Applications & invites → Prisma data access: persists lifecycle
- Contracts & milestones → Applications & invites: follows acceptance
- Contracts & milestones → Prisma data access: persists contracts
- Escrow payments → Contracts & milestones: funds escrow for
- Escrow payments → Prisma data access: persists funding
- Messages → Prisma data access: persists conversations
- Reviews → Prisma data access: persists reputation
- Prisma data access → PostgreSQL: accesses
- Creators → Cloudinary integration: stores uploads
- Auth API → Mail delivery: sends OTP email
- Container & Render deploy → Nest bootstrap: deploys
