# rocketseat-education/05-nest-clean architecture

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

- Interactive diagram: https://gitdiagram.com/rocketseat-education/05-nest-clean
- Repository: https://github.com/rocketseat-education/05-nest-clean

## Overview

This is a NestJS backend API for a Q&A forum. Its principal user workflow is account creation/authentication, posting questions, receiving answers and comments, and selecting a best answer; attachments and read notifications are additional capabilities. The graph reflects the documented API and the sampled module/repository wiring. Most controllers and use cases were not sampled, so their internal call paths are left unverified rather than inferred.

Main entry points: [`src/infra/http/controllers`](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/infra/http/controllers) (HTTP endpoints), [`src/infra/database/prisma/repositories`](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/infra/database/prisma/repositories) (Prisma repositories), [`src/domain/forum/application/use-cases`](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/forum/application/use-cases) (Forum use cases), [`src/domain/forum/enterprise/entities`](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/forum/enterprise/entities) (Forum entities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP and access"]
  node_http["HTTP endpoints"]
  node_auth["Authentication"]
end

subgraph group_forum["Forum domain"]
  node_forum_cases["Forum use cases"]
  node_forum_entities["Forum entities"]
  node_forum_events["Forum events"]
  node_forum_repos["Forum repository contracts"]
  node_core["Core primitives"]
end

subgraph group_notifications["Notifications"]
  node_notification_cases["Notification use cases"]
  node_notification_subscribers["Event subscribers"]
  node_notification_entities["Notification entity<br/>[notification.ts]"]
  node_notification_repo["Notification repository contract"]
end

subgraph group_infrastructure["Persistence and integrations"]
  node_database_module["Database wiring<br/>[database.module.ts]"]
  node_prisma_repos["Prisma repositories"]
  node_prisma["Prisma client<br/>[prisma.service.ts]"]
  node_postgres[("PostgreSQL")]
  node_cache[("Redis cache")]
  node_uploader["Upload service<br/>[r2-storage.ts]"]
  node_object_storage[("R2 object storage")]
  node_app["Application modules<br/>[app.module.ts]"]
  node_events_module["Event wiring<br/>[events.module.ts]"]
end

node_student(("Forum user"))

node_student -->|"uses API"| node_http
node_http -.->|"authenticates"| node_auth
node_http -.->|"dispatches to"| node_forum_cases
node_http -.->|"dispatches to"| node_notification_cases
node_forum_cases -.->|"uses contracts"| node_forum_repos
node_forum_cases -.->|"uses entities"| node_forum_entities
node_forum_entities -->|"uses primitives"| node_core
node_forum_entities -->|"raises events"| node_forum_events
node_database_module -->|"binds implementations"| node_prisma_repos
node_database_module -->|"provides client"| node_prisma
node_prisma_repos -->|"uses client"| node_prisma
node_prisma_repos -->|"implements contracts"| node_forum_repos
node_prisma -->|"persists data"| node_postgres
node_prisma_repos -->|"uses cache"| node_cache
node_notification_subscribers -.->|"handles events"| node_forum_events
node_notification_subscribers -.->|"triggers notification"| node_notification_cases
node_notification_cases -.->|"uses contract"| node_notification_repo
node_notification_repo -->|"stores entity"| node_notification_entities
node_notification_repo -->|"implemented by"| node_prisma_repos
node_forum_cases -.->|"requests uploads"| node_uploader
node_uploader -->|"uploads objects"| node_object_storage
node_app -->|"registers module"| node_http
node_app -->|"registers module"| node_events_module

click node_http "https://github.com/rocketseat-education/05-nest-clean/tree/main/src/infra/http/controllers"
click node_auth "https://github.com/rocketseat-education/05-nest-clean/tree/main/src/infra/auth"
click node_forum_cases "https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/forum/application/use-cases"
click node_forum_entities "https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/forum/enterprise/entities"
click node_forum_events "https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/forum/enterprise/events"
click node_forum_repos "https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/forum/application/repositories"
click node_core "https://github.com/rocketseat-education/05-nest-clean/tree/main/src/core"
click node_notification_cases "https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/notification/application/use-cases"
click node_notification_subscribers "https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/notification/application/subscribers"
click node_notification_entities "https://github.com/rocketseat-education/05-nest-clean/blob/main/src/domain/notification/enterprise/entities/notification.ts"
click node_notification_repo "https://github.com/rocketseat-education/05-nest-clean/blob/main/src/domain/notification/application/repositories/notifications-repository.ts"
click node_database_module "https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/database/database.module.ts"
click node_prisma_repos "https://github.com/rocketseat-education/05-nest-clean/tree/main/src/infra/database/prisma/repositories"
click node_prisma "https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/database/prisma/prisma.service.ts"
click node_cache "https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/cache/redis/redis-cache-repository.ts"
click node_uploader "https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/storage/r2-storage.ts"
click node_app "https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/app.module.ts"
click node_events_module "https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/events/events.module.ts"

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_http,node_auth,node_student toneBlue
class node_forum_cases,node_forum_entities,node_forum_events,node_forum_repos,node_core toneAmber
class node_notification_cases,node_notification_subscribers,node_notification_entities,node_notification_repo toneMint
class node_database_module,node_prisma_repos,node_prisma,node_postgres,node_cache,node_uploader,node_object_storage,node_app,node_events_module toneRose
```

## Components

### HTTP and access

- [HTTP endpoints](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/infra/http/controllers): `src/infra/http/controllers`
- [Authentication](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/infra/auth): `src/infra/auth`

### Forum domain

- [Forum use cases](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/forum/application/use-cases): `src/domain/forum/application/use-cases`
- [Forum entities](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/forum/enterprise/entities): `src/domain/forum/enterprise/entities`
- [Forum events](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/forum/enterprise/events): `src/domain/forum/enterprise/events`
- [Forum repository contracts](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/forum/application/repositories): `src/domain/forum/application/repositories`
- [Core primitives](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/core): `src/core`

### Notifications

- [Notification use cases](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/notification/application/use-cases): `src/domain/notification/application/use-cases`
- [Event subscribers](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/domain/notification/application/subscribers): `src/domain/notification/application/subscribers`
- [Notification entity](https://github.com/rocketseat-education/05-nest-clean/blob/main/src/domain/notification/enterprise/entities/notification.ts): `src/domain/notification/enterprise/entities/notification.ts`
- [Notification repository contract](https://github.com/rocketseat-education/05-nest-clean/blob/main/src/domain/notification/application/repositories/notifications-repository.ts): `src/domain/notification/application/repositories/notifications-repository.ts`

### Persistence and integrations

- [Database wiring](https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/database/database.module.ts): `src/infra/database/database.module.ts`
- [Prisma repositories](https://github.com/rocketseat-education/05-nest-clean/tree/main/src/infra/database/prisma/repositories): `src/infra/database/prisma/repositories`
- [Prisma client](https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/database/prisma/prisma.service.ts): `src/infra/database/prisma/prisma.service.ts`
- **PostgreSQL**
- [Redis cache](https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/cache/redis/redis-cache-repository.ts): `src/infra/cache/redis/redis-cache-repository.ts`
- [Upload service](https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/storage/r2-storage.ts): `src/infra/storage/r2-storage.ts`
- **R2 object storage**
- [Application modules](https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/app.module.ts): `src/infra/app.module.ts`
- [Event wiring](https://github.com/rocketseat-education/05-nest-clean/blob/main/src/infra/events/events.module.ts): `src/infra/events/events.module.ts`

### Other components

- **Forum user**

## Connections

- Forum user → HTTP endpoints: uses API (evidence: `README.md`)
- HTTP endpoints → Authentication: authenticates
- HTTP endpoints → Forum use cases: dispatches to
- HTTP endpoints → Notification use cases: dispatches to
- Forum use cases → Forum repository contracts: uses contracts (evidence: `src/domain/forum/application/use-cases/authenticate-student.ts`)
- Forum use cases → Forum entities: uses entities
- Forum entities → Core primitives: uses primitives (evidence: `src/domain/forum/enterprise/entities/question.ts`)
- Forum entities → Forum events: raises events (evidence: `src/domain/forum/enterprise/entities/question.ts`)
- Database wiring → Prisma repositories: binds implementations (evidence: `src/infra/database/database.module.ts`)
- Database wiring → Prisma client: provides client (evidence: `src/infra/database/database.module.ts`)
- Prisma repositories → Prisma client: uses client (evidence: `src/infra/database/prisma/repositories/prisma-questions-repository.ts`)
- Prisma repositories → Forum repository contracts: implements contracts (evidence: `src/infra/database/database.module.ts`)
- Prisma client → PostgreSQL: persists data (evidence: `README.md`)
- Prisma repositories → Redis cache: uses cache (evidence: `src/infra/database/prisma/repositories/prisma-questions-repository.ts`)
- Event subscribers → Forum events: handles events
- Event subscribers → Notification use cases: triggers notification
- Notification use cases → Notification repository contract: uses contract
- Notification repository contract → Notification entity: stores entity (evidence: `src/domain/notification/application/repositories/notifications-repository.ts`)
- Notification repository contract → Prisma repositories: implemented by (evidence: `src/infra/database/database.module.ts`)
- Forum use cases → Upload service: requests uploads
- Upload service → R2 object storage: uploads objects (evidence: `src/infra/storage/r2-storage.ts`)
- Application modules → HTTP endpoints: registers module (evidence: `src/infra/app.module.ts`)
- Application modules → Event wiring: registers module (evidence: `src/infra/app.module.ts`)
