How ancyr-academy/webinaires works
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: organize-webinaire.ts Commands · common.module.ts Common module · webinaire.controller.ts Web controllers · webinaire-repository.interface.ts Webinaire ports
Components 25
Core
Cross-cutting application infrastructure
- Main module · Top-level application wiring
src/core/main.module.ts - App module · Application module assembly
src/core/app.module.ts - Common module · Shared cross-cutting providers
src/core/common.module.ts - Auth guard · Request authentication/authorization boundary
src/core/auth.guard.ts - Validation pipe · Schema-based request validation
src/core/pipes/zod-validation.pipe.ts - Mailer port · Outbound notification contract
src/core/ports/mailer.interface.ts - Memory mailer · Test/in-memory mail delivery adapter
src/core/adapters/in-memory-mailer.ts
Users
User identity and persistence
- User · User identity model
src/users/entities/user.entity.ts - User repo · User persistence contract
src/users/ports/user-repository.interface.ts - Authenticator · User identity and auth service
src/users/services/authenticator.ts - Memory users · In-memory user repository
src/users/adapters/in-memory-user-repository.ts - Mongo users · MongoDB user repository
src/users/adapters/mongo/mongo-user-repository.ts - Users module · User feature composition
src/users/user.module.ts
Webinaires
Event scheduling and seat management
- Web controllers · HTTP entrypoints for webinaire flows
src/webinaires/controllers/webinaire.controller.ts - Commands · State-changing business operations
src/webinaires/commands/organize-webinaire.ts - Webinaire query · Reads webinaire details by id
src/webinaires/queries/get-webinaire-by-id.ts - Webinaire model · Webinaire and participation entities
src/webinaires/entities/webinaire.entity.ts - Webinaire ports · Repository contracts for webinaires and participations
src/webinaires/ports/webinaire-repository.interface.ts - Memory repos · In-memory webinaire and participation repositories
src/webinaires/adapters/in-memory-webinaire-repository.ts - Mongo repos · MongoDB webinaire and participation repositories
src/webinaires/adapters/mongo/mongo-webinaire-repository.ts - Rule exceptions · Business invariant and update constraint failures
src/webinaires/exceptions/webinaire-not-found.ts - Webinaires module · Webinaire feature composition
src/webinaires/webinaire.module.ts
Tests
End-to-end and integration verification
- Test setup · Docker-managed integration test environment
src/tests/setup/docker-manager.ts
Other components
- Shared base · Common entity, exception, and executable abstractions
src/shared/entity.ts
Connections 31
- 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