# thewizardshell/doctorchat-api architecture

> Architecture diagram of the GitHub repository thewizardshell/doctorchat-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thewizardshell/doctorchat-api
- Repository: https://github.com/thewizardshell/doctorchat-api

## Overview

##### Main Components
- Client/External Interface: Represent how clients (such as web/mobile or API consumers) interact with the system via HTTP requests.
- Core Application: The NestJS server itself, which is constructed around the application module (“app.module.ts”) that aggregates all the feature modules.
- Feature Modules:
- Auth Module – handles authentication and authorization (contains auth.controller.ts, auth.service.ts).
- Chat Module – likely handles chat communications (with its own controller and service).
- Citas Module – manages appointments or similar “citas” functionality.
- Informes Module – responsible for reports or medical/informative outputs.
- Domain/Entities Layer: Organized by domains (User, Doctor, AI) with repositories, interfaces, and tests. This layer underpins the persistence logic.
- Use Cases: Separate “use_cases” directory encapsulates business logic for commands like “register-user”, “register-doctor”, “register-cita”, and handling responses from AI integrations.
- External Services/Integrations:
- Firebase Service – under “src/services/firebase” with its own firebase configuration.
- Possibility of external integrations (like external chat systems, AI-based response processing) add up here.

##### Relationships and Interactions
- Within each module, indicate that Controllers delegate business logic to Services.
- Services, in turn, interact with the Data/Entities layer (through repositories) and trigger Use Cases when more elaborate business rules are processed.
- A link from the Use Cases layer back to Services or directly to Entities to represent data persistence or additional logic.
- Firebase as an External Integration component that is accessed by its dedicated service (firebase.service.ts).

##### Architectural Patterns and Design Principles
- Modular architecture with a clear separation between controllers (handling input/output), services (acting as business logic handlers), and repositories/entities (managing data and persistence).
- Use of a use case pattern where individual business operations are encapsulated in dedicated files.
- If applicable, illustrate any dependency injection patterns used by NestJS, where the AppModule orchestrates dependencies.

##### Relevant Technologies
- Node.js as the runtime environment.
- TypeScript for strong typing.
- NestJS as the primary framework.
- Firebase for some parts of the service layer.
- Testing frameworks (indicated in the “test” and “jest.e2e.json”) for validating endpoints and business logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    EC["External Clients"]:::external
    HTTP["HTTP Layer (API Gateway)"]:::core
    Core["NestJS Core (App Module)"]:::core

    EC --> HTTP
    HTTP --> Core

    subgraph "Feature Modules"
        subgraph "Auth Module"
            AM["Auth Module"]:::module
            AController["Auth Controller"]:::controller
            AService["Auth Service"]:::service
            AM --> AController
            AM --> AService
            AController -->|"calls"| AService
        end

        subgraph "Chat Module"
            CM["Chat Module"]:::module
            CController["Chat Controller"]:::controller
            CService["Chat Service"]:::service
            CM --> CController
            CM --> CService
            CController -->|"calls"| CService
        end

        subgraph "Citas Module"
            CIM["Citas Module"]:::module
            CIController["Citas Controller"]:::controller
            CIService["Citas Service"]:::service
            CIM --> CIController
            CIM --> CIService
            CIController -->|"calls"| CIService
        end

        subgraph "Informes Module"
            IM["Informes Module"]:::module
            IController["Informes Controller"]:::controller
            IService["Informes Service"]:::service
            IM --> IController
            IM --> IService
            IController -->|"calls"| IService
        end
    end

    Core --> AM
    Core --> CM
    Core --> CIM
    Core --> IM

    AService --> UC["Use Cases"]:::usecase
    CService --> UC
    CIService --> UC
    IService --> UC

    subgraph "Domain / Entities"
        UD["User Domain"]:::entity
        DD["Doctor Domain"]:::entity
        AD["AI Domain"]:::entity
    end

    UC --> UD
    UC --> DD
    UC --> AD

    subgraph "Firebase Integration"
        FBsvc["Firebase Service"]:::integration
        FBcfg["Firebase Config"]:::integration
        FBsvc -->|"config"| FBcfg
    end

    CService -->|"integrates"| FBsvc

    %% Click Events
    click Core "https://github.com/thewizardshell/doctorchat-api/blob/master/src/app.module.ts"
    click AM "https://github.com/thewizardshell/doctorchat-api/tree/master/src/auth"
    click AController "https://github.com/thewizardshell/doctorchat-api/blob/master/src/auth/auth.controller.ts"
    click AService "https://github.com/thewizardshell/doctorchat-api/blob/master/src/auth/auth.service.ts"
    click CM "https://github.com/thewizardshell/doctorchat-api/tree/master/src/chat"
    click CController "https://github.com/thewizardshell/doctorchat-api/blob/master/src/chat/chat.controller.ts"
    click CService "https://github.com/thewizardshell/doctorchat-api/blob/master/src/chat/chat.service.ts"
    click CIM "https://github.com/thewizardshell/doctorchat-api/tree/master/src/citas"
    click CIController "https://github.com/thewizardshell/doctorchat-api/blob/master/src/citas/citas.controller.ts"
    click CIService "https://github.com/thewizardshell/doctorchat-api/blob/master/src/citas/citas.service.ts"
    click IM "https://github.com/thewizardshell/doctorchat-api/tree/master/src/informes"
    click IController "https://github.com/thewizardshell/doctorchat-api/blob/master/src/informes/informes.controller.ts"
    click IService "https://github.com/thewizardshell/doctorchat-api/blob/master/src/informes/informes.service.ts"
    click UD "https://github.com/thewizardshell/doctorchat-api/tree/master/src/entities/user"
    click DD "https://github.com/thewizardshell/doctorchat-api/tree/master/src/entities/doctor"
    click AD "https://github.com/thewizardshell/doctorchat-api/tree/master/src/entities/ai"
    click UC "https://github.com/thewizardshell/doctorchat-api/tree/master/src/use_cases"
    click FBsvc "https://github.com/thewizardshell/doctorchat-api/blob/master/src/services/firebase/firebase.service.ts"
    click FBcfg "https://github.com/thewizardshell/doctorchat-api/blob/master/src/firebaseConfig.ts"

    %% Styles
    classDef external fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef core fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef module fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef controller fill:#fdebd0,stroke:#d35400,stroke-width:2px;
    classDef service fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef usecase fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef entity fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef integration fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
