# ancyr-academy/webinaires architecture

> Architecture diagram of the GitHub repository ancyr-academy/webinaires, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ancyr-academy/webinaires
- Repository: https://github.com/ancyr-academy/webinaires

## Overview

1. **Overall shape**
   - This is a NestJS TypeScript backend organized around two main business areas: **users** and **webinaires**.
   - The code follows a **ports-and-adapters / hexagonal** style: controllers and use-case services depend on interfaces in `ports`, while concrete persistence and infrastructure live in `adapters`.

2. **Application composition**
   - The runtime entrypoint is `src/main.ts`, which boots the Nest app.
   - `src/core/app.module.ts`, `src/core/common.module.ts`, and `src/core/main.module.ts` are the top-level composition points that wire together the feature modules.
   - Feature modules are split into `src/users/user.module.ts` and `src/webinaires/webinaire.module.ts`.

3. **HTTP boundary**
   - Inbound requests are handled by controllers under `src/webinaires/controllers` and the core app controller.
   - Cross-cutting request handling includes:
     - `src/core/auth.guard.ts` for authentication/authorization checks
     - `src/core/pipes/zod-validation.pipe.ts` for schema-based validation
   - The web layer is thin; it delegates business operations to commands and query handlers.

4. **Users subsystem**
   - The users domain has:
     - `src/users/entities/user.entity.ts` as the domain model
     - `src/users/ports/user-repository.interface.ts` as the persistence contract
     - `src/users/services/authenticator.ts` as the main domain/application service around user identity/auth
   - There are two repository adapters:
     - `src/users/adapters/in-memory-user-repository.ts` for tests/local isolation
     - `src/users/adapters/mongo/mongo-user-repository.ts` for MongoDB persistence

5. **Webinaires subsystem**
   - The webinaires domain is the core business area and contains:
     - `webinaire.entity.ts` and `participation.entity.ts`
     - repository interfaces for webinaires and participations
     - a set of domain-specific exceptions describing rule violations
   - It supports two aggregates or concepts:
     - **webinaire**: the event/session itself
     - **participation**: a user’s seat reservation/attendance relation

6. **Use-case layer**
   - Business operations are modeled explicitly as commands and queries:
     - Commands: `organize-webinaire`, `reserve-seat`, `cancel-seat`, `change-dates`, `change-seats`, `cancel-webinaire`
     - Query: `get-webinaire-by-id`
   - This suggests a CQRS-like separation: commands mutate state, queries read it.
   - Controllers likely invoke these use cases directly, keeping orchestration out of the HTTP layer.

7. **Domain rules and error boundaries**
   - The `src/webinaires/exceptions` folder contains the main business invariants:
     - seat limits and overbooking
     - reservation conflicts
     - missing webinaire/participation records
     - update constraints such as “too early” or “update forbidden”
   - These exceptions form a clear boundary between valid command execution and rejected business actions, which is important for diagramming failure paths.

8. **Infrastructure adapters**
   - Persistence is implemented with MongoDB adapters under `src/users/adapters/mongo` and `src/webinaires/adapters/mongo`.
   - There are parallel in-memory adapters for users, webinaires, and participations, which implies the same domain logic can run against multiple backing stores.
   - There is also a mailer port plus `src/core/adapters/in-memory-mailer.ts`, indicating outbound notifications are abstracted even if no production mail provider is shown here.

9. **Shared kernel**
   - `src/shared` contains base abstractions used across features:
     - `entity.ts`
     - `exception.ts`
     - `executable.ts`
   - This is the shared domain/application foundation that the feature modules build on.

10. **Testing strategy**
   - The repository has strong test coverage at multiple levels:
     - unit tests beside commands/services/adapters
     - Mongo integration tests for repositories
     - end-to-end tests under `src/tests`
   - The E2E setup uses Docker-managed infrastructure (`src/tests/setup/docker-compose.yml`, `docker-manager.ts`, `global-setup.ts`, `global-teardown.ts`), so architecture diagrams should include an external test Mongo service as part of verification, not production runtime.

11. **Test data and fixtures**
   - `src/tests/fixtures` and `src/tests/seeds` define reusable test users, webinaires, and participations.
   - This supports scenario-driven E2E flows such as organizing a webinaire, reserving a seat, changing seats/dates, and canceling.

12. **Important runtime boundaries to show in a diagram**
   - Incoming HTTP request -> controller -> auth/validation -> command/query -> domain entities/rules -> repository/mail ports -> concrete adapter.
   - Separate the **user domain** from the **webinaire domain**, with shared infrastructure underneath.
   - Show MongoDB as the persistence boundary, in-memory adapters as alternate/test implementations, and Docker as the integration-test support layer.

13. **What this repo is not**
   - Despite the generic Nest README, this is not a boilerplate app anymore; it is a domain-oriented backend centered on scheduling and seat management for webinaires, with explicit business rules and persistence abstractions.

Main entry points: [`src/webinaires/commands/organize-webinaire.ts`](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/commands/organize-webinaire.ts) (Commands), [`src/core/common.module.ts`](https://github.com/ancyr-academy/webinaires/blob/main/src/core/common.module.ts) (Common module), [`src/webinaires/controllers/webinaire.controller.ts`](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/controllers/webinaire.controller.ts) (Web controllers), [`src/webinaires/ports/webinaire-repository.interface.ts`](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/ports/webinaire-repository.interface.ts) (Webinaire ports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_src_main(("main<br/>bootstrap<br/>[main.ts]"))
end

subgraph group_core["Core"]
  node_src_core_main_module["Main module<br/>composition<br/>[main.module.ts]"]
  node_src_core_app_module["App module<br/>[app.module.ts]"]
  node_src_core_common_module["Common module<br/>[common.module.ts]"]
  node_src_core_auth_guard{{"Auth guard<br/>[auth.guard.ts]"}}
  node_src_core_zod_pipe{{"Validation pipe"}}
  node_src_core_mailer_port["Mailer port"]
  node_src_core_in_memory_mailer[("Memory mailer<br/>adapter")]
end

subgraph group_users["Users"]
  node_src_users_entity{{"User<br/>domain entity<br/>[user.entity.ts]"}}
  node_src_users_port["User repo<br/>port"]
  node_src_users_authenticator["Authenticator<br/>[authenticator.ts]"]
  node_src_users_in_memory_repo[("Memory users<br/>adapter")]
  node_src_users_mongo_repo[("Mongo users<br/>adapter")]
  node_src_users_module["Users module<br/>[user.module.ts]"]
end

subgraph group_webinaires["Webinaires"]
  node_src_web_controllers["Web controllers<br/>http controllers"]
  node_src_web_commands["Commands"]
  node_src_web_query["Webinaire query<br/>use-case query"]
  node_src_web_entities{{"Webinaire model<br/>domain"}}
  node_src_web_ports["Webinaire ports"]
  node_src_web_in_memory_repos[("Memory repos<br/>adapter")]
  node_src_web_mongo_repos[("Mongo repos<br/>adapter")]
  node_src_web_exceptions["Rule exceptions<br/>domain errors"]
  node_src_web_module["Webinaires module"]
end

subgraph group_tests["Tests"]
  node_src_tests_setup["Test setup<br/>e2e harness<br/>[docker-manager.ts]"]
end

node_src_shared["Shared base<br/>[entity.ts]"]

node_src_main -->|"boots"| node_src_core_main_module
node_src_core_main_module -->|"composes"| node_src_core_app_module
node_src_core_app_module -->|"imports"| node_src_core_common_module
node_src_core_common_module -->|"provides"| node_src_core_auth_guard
node_src_core_common_module -->|"provides"| node_src_core_zod_pipe
node_src_core_common_module -->|"defines"| node_src_core_mailer_port
node_src_core_common_module -->|"adapts"| node_src_core_in_memory_mailer
node_src_users_module -->|"wires"| node_src_users_authenticator
node_src_users_authenticator -->|"uses"| node_src_users_entity
node_src_users_authenticator -->|"depends on"| node_src_users_port
node_src_users_port -.->|"implemented by"| node_src_users_in_memory_repo
node_src_users_port -.->|"implemented by"| node_src_users_mongo_repo
node_src_web_module -->|"exposes"| node_src_web_controllers
node_src_web_module -->|"wires"| node_src_web_commands
node_src_web_module -->|"wires"| node_src_web_query
node_src_web_controllers -->|"uses"| node_src_core_auth_guard
node_src_web_controllers -->|"uses"| node_src_core_zod_pipe
node_src_web_controllers -->|"invokes"| node_src_web_commands
node_src_web_controllers -->|"invokes"| node_src_web_query
node_src_web_commands -->|"mutates"| node_src_web_entities
node_src_web_commands -->|"depends on"| node_src_web_ports
node_src_web_commands -->|"notifies"| node_src_core_mailer_port
node_src_web_ports -.->|"implemented by"| node_src_web_in_memory_repos
node_src_web_ports -.->|"implemented by"| node_src_web_mongo_repos
node_src_web_commands -->|"raises"| node_src_web_exceptions
node_src_web_query -->|"reads through"| node_src_web_ports
node_src_shared -.->|"base for"| node_src_users_entity
node_src_shared -.->|"base for"| node_src_web_entities
node_src_tests_setup -.->|"verifies"| node_src_web_mongo_repos
node_src_tests_setup -.->|"verifies"| node_src_users_mongo_repo
node_src_tests_setup -.->|"uses"| node_src_core_in_memory_mailer

click node_src_main "https://github.com/ancyr-academy/webinaires/blob/main/src/main.ts"
click node_src_core_main_module "https://github.com/ancyr-academy/webinaires/blob/main/src/core/main.module.ts"
click node_src_core_app_module "https://github.com/ancyr-academy/webinaires/blob/main/src/core/app.module.ts"
click node_src_core_common_module "https://github.com/ancyr-academy/webinaires/blob/main/src/core/common.module.ts"
click node_src_core_auth_guard "https://github.com/ancyr-academy/webinaires/blob/main/src/core/auth.guard.ts"
click node_src_core_zod_pipe "https://github.com/ancyr-academy/webinaires/blob/main/src/core/pipes/zod-validation.pipe.ts"
click node_src_core_mailer_port "https://github.com/ancyr-academy/webinaires/blob/main/src/core/ports/mailer.interface.ts"
click node_src_core_in_memory_mailer "https://github.com/ancyr-academy/webinaires/blob/main/src/core/adapters/in-memory-mailer.ts"
click node_src_shared "https://github.com/ancyr-academy/webinaires/blob/main/src/shared/entity.ts"
click node_src_users_entity "https://github.com/ancyr-academy/webinaires/blob/main/src/users/entities/user.entity.ts"
click node_src_users_port "https://github.com/ancyr-academy/webinaires/blob/main/src/users/ports/user-repository.interface.ts"
click node_src_users_authenticator "https://github.com/ancyr-academy/webinaires/blob/main/src/users/services/authenticator.ts"
click node_src_users_in_memory_repo "https://github.com/ancyr-academy/webinaires/blob/main/src/users/adapters/in-memory-user-repository.ts"
click node_src_users_mongo_repo "https://github.com/ancyr-academy/webinaires/blob/main/src/users/adapters/mongo/mongo-user-repository.ts"
click node_src_users_module "https://github.com/ancyr-academy/webinaires/blob/main/src/users/user.module.ts"
click node_src_web_controllers "https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/controllers/webinaire.controller.ts"
click node_src_web_commands "https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/commands/organize-webinaire.ts"
click node_src_web_query "https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/queries/get-webinaire-by-id.ts"
click node_src_web_entities "https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/entities/webinaire.entity.ts"
click node_src_web_ports "https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/ports/webinaire-repository.interface.ts"
click node_src_web_in_memory_repos "https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/adapters/in-memory-webinaire-repository.ts"
click node_src_web_mongo_repos "https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/adapters/mongo/mongo-webinaire-repository.ts"
click node_src_web_exceptions "https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/exceptions/webinaire-not-found.ts"
click node_src_web_module "https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/webinaire.module.ts"
click node_src_tests_setup "https://github.com/ancyr-academy/webinaires/blob/main/src/tests/setup/docker-manager.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_src_main toneBlue
class node_src_core_main_module,node_src_core_app_module,node_src_core_common_module,node_src_core_auth_guard,node_src_core_zod_pipe,node_src_core_mailer_port,node_src_core_in_memory_mailer toneAmber
class node_src_users_entity,node_src_users_port,node_src_users_authenticator,node_src_users_in_memory_repo,node_src_users_mongo_repo,node_src_users_module toneMint
class node_src_web_controllers,node_src_web_commands,node_src_web_query,node_src_web_entities,node_src_web_ports,node_src_web_in_memory_repos,node_src_web_mongo_repos,node_src_web_exceptions,node_src_web_module toneRose
class node_src_tests_setup toneIndigo
class node_src_shared toneNeutral
```

## Components

### Runtime

Nest bootstrapping and app composition

- [main](https://github.com/ancyr-academy/webinaires/blob/main/src/main.ts): bootstrap · Starts the Nest application · `src/main.ts`

### Core

Cross-cutting application infrastructure

- [Main module](https://github.com/ancyr-academy/webinaires/blob/main/src/core/main.module.ts): composition · Top-level application wiring · `src/core/main.module.ts`
- [App module](https://github.com/ancyr-academy/webinaires/blob/main/src/core/app.module.ts): module · Application module assembly · `src/core/app.module.ts`
- [Common module](https://github.com/ancyr-academy/webinaires/blob/main/src/core/common.module.ts): module · Shared cross-cutting providers · `src/core/common.module.ts`
- [Auth guard](https://github.com/ancyr-academy/webinaires/blob/main/src/core/auth.guard.ts): guard · Request authentication/authorization boundary · `src/core/auth.guard.ts`
- [Validation pipe](https://github.com/ancyr-academy/webinaires/blob/main/src/core/pipes/zod-validation.pipe.ts): pipe · Schema-based request validation · `src/core/pipes/zod-validation.pipe.ts`
- [Mailer port](https://github.com/ancyr-academy/webinaires/blob/main/src/core/ports/mailer.interface.ts): port · Outbound notification contract · `src/core/ports/mailer.interface.ts`
- [Memory mailer](https://github.com/ancyr-academy/webinaires/blob/main/src/core/adapters/in-memory-mailer.ts): adapter · Test/in-memory mail delivery adapter · `src/core/adapters/in-memory-mailer.ts`

### Users

User identity and persistence

- [User](https://github.com/ancyr-academy/webinaires/blob/main/src/users/entities/user.entity.ts): domain entity · User identity model · `src/users/entities/user.entity.ts`
- [User repo](https://github.com/ancyr-academy/webinaires/blob/main/src/users/ports/user-repository.interface.ts): port · User persistence contract · `src/users/ports/user-repository.interface.ts`
- [Authenticator](https://github.com/ancyr-academy/webinaires/blob/main/src/users/services/authenticator.ts): service · User identity and auth service · `src/users/services/authenticator.ts`
- [Memory users](https://github.com/ancyr-academy/webinaires/blob/main/src/users/adapters/in-memory-user-repository.ts): adapter · In-memory user repository · `src/users/adapters/in-memory-user-repository.ts`
- [Mongo users](https://github.com/ancyr-academy/webinaires/blob/main/src/users/adapters/mongo/mongo-user-repository.ts): adapter · MongoDB user repository · `src/users/adapters/mongo/mongo-user-repository.ts`
- [Users module](https://github.com/ancyr-academy/webinaires/blob/main/src/users/user.module.ts): module · User feature composition · `src/users/user.module.ts`

### Webinaires

Event scheduling and seat management

- [Web controllers](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/controllers/webinaire.controller.ts): http controllers · HTTP entrypoints for webinaire flows · `src/webinaires/controllers/webinaire.controller.ts`
- [Commands](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/commands/organize-webinaire.ts): use-case commands · State-changing business operations · `src/webinaires/commands/organize-webinaire.ts`
- [Webinaire query](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/queries/get-webinaire-by-id.ts): use-case query · Reads webinaire details by id · `src/webinaires/queries/get-webinaire-by-id.ts`
- [Webinaire model](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/entities/webinaire.entity.ts): domain · Webinaire and participation entities · `src/webinaires/entities/webinaire.entity.ts`
- [Webinaire ports](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/ports/webinaire-repository.interface.ts): ports · Repository contracts for webinaires and participations · `src/webinaires/ports/webinaire-repository.interface.ts`
- [Memory repos](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/adapters/in-memory-webinaire-repository.ts): adapter · In-memory webinaire and participation repositories · `src/webinaires/adapters/in-memory-webinaire-repository.ts`
- [Mongo repos](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/adapters/mongo/mongo-webinaire-repository.ts): adapter · MongoDB webinaire and participation repositories · `src/webinaires/adapters/mongo/mongo-webinaire-repository.ts`
- [Rule exceptions](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/exceptions/webinaire-not-found.ts): domain errors · Business invariant and update constraint failures · `src/webinaires/exceptions/webinaire-not-found.ts`
- [Webinaires module](https://github.com/ancyr-academy/webinaires/blob/main/src/webinaires/webinaire.module.ts): module · Webinaire feature composition · `src/webinaires/webinaire.module.ts`

### Tests

End-to-end and integration verification

- [Test setup](https://github.com/ancyr-academy/webinaires/blob/main/src/tests/setup/docker-manager.ts): e2e harness · Docker-managed integration test environment · `src/tests/setup/docker-manager.ts`

### Other components

- [Shared base](https://github.com/ancyr-academy/webinaires/blob/main/src/shared/entity.ts): shared · Common entity, exception, and executable abstractions · `src/shared/entity.ts`

## Connections

- main → Main module: boots · Bootstraps the application module
- Main module → App module: composes · Top-level module assembly
- App module → Common module: imports · Shares cross-cutting providers
- Common module → Auth guard: provides · Exports request guard
- Common module → Validation pipe: provides · Exports validation pipe
- Common module → Mailer port: defines · Declares outbound mail contract
- Common module → Memory mailer: adapts · In-memory mail implementation
- Users module → Authenticator: wires · User service composition
- Authenticator → User: uses · Operates on user domain model
- Authenticator → User repo: depends on · Reads/writes users through port
- User repo → Memory users: implemented by · Test-friendly persistence
- User repo → Mongo users: implemented by · MongoDB persistence
- Webinaires module → Web controllers: exposes · HTTP layer for webinaire actions
- Webinaires module → Commands: wires · Command handlers for mutations
- Webinaires module → Webinaire query: wires · Query handler for reads
- Web controllers → Auth guard: uses · Protects HTTP endpoints
- Web controllers → Validation pipe: uses · Validates incoming payloads
- Web controllers → Commands: invokes · Delegates mutations to commands
- Web controllers → Webinaire query: invokes · Delegates reads to query
- Commands → Webinaire model: mutates · Applies business rules to aggregates
- Commands → Webinaire ports: depends on · Persists through repository contracts
- Commands → Mailer port: notifies · Can trigger outbound mail
- Webinaire ports → Memory repos: implemented by · In-memory persistence
- Webinaire ports → Mongo repos: implemented by · MongoDB persistence
- Commands → Rule exceptions: raises · Signals business rule violations
- Webinaire query → Webinaire ports: reads through · Loads webinaire data via port
- Shared base → User: base for · Shared abstractions underpin entities
- Shared base → Webinaire model: base for · Shared abstractions underpin entities
- Test setup → Mongo repos: verifies · Integration tests against MongoDB adapters
- Test setup → Mongo users: verifies · Integration tests against MongoDB adapters
- Test setup → Memory mailer: uses · Test harness mailer stub
