# queirozcarlos/chatbot-saas- architecture

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

- Interactive diagram: https://gitdiagram.com/queirozcarlos/chatbot-saas-
- Repository: https://github.com/queirozcarlos/chatbot-saas-

## Overview

##### Project type and purpose
- This is a Spring Boot–based backend application providing RESTful APIs for a sales chatbot SaaS.
- Key responsibilities include user authentication (JWT), product management, sales recording, report generation, and notifications.

##### File structure
- Layered, monolithic architecture under src/main/java/com/sistema/chatbot:
– config: CORS, JSON, OpenAPI, exception handling
– security: filter, token service, global security configs
– controller: REST endpoints (AuthenticationController, Chatbot-related, ProductController, SaleController, ReportController, NotificationController, UserController)
– service: business logic (UserService, ProductService, SaleService, ReportService, NotificationService, JwtService, AuthorizationService, TokenService)
– repository: Spring Data JPA interfaces to persistence (UserRepository, ProductRepository, SaleRepository, ReportRepository, NotificationRepository)
– model/dto: domain entities + data‐transfer objects
- Resources: application.properties (DB, JWT, logging configs)
- Tests: basic startup test

##### README insights
- Title “ChatBot-SaaS” confirms a SaaS offering around chatbot‐driven sales assistance.

a. Main components
1. External Client(s): Browser/mobile UI or messaging platform (e.g., WhatsApp, Telegram)
2. API Layer: Spring Boot REST Controllers
3. Security Layer: JWT filter, SecurityConfigurations
4. Service Layer: Business logic services
5. Persistence Layer: Spring Data repositories
6. Database: Relational DB (e.g., PostgreSQL/MySQL)
7. Logging/Monitoring: local log files (logs/chatbot-vendas.log) or external ELK
8. Notification Channel: e-mail or push (could be external SMTP or push gateway)
b. Relationships and data flow
– User/Client → HTTP(S) → AuthenticationController → JwtService → returns JWT
– User/Client (with JWT) → Chat/Product/Sale/Report/Notification Controllers
– Each Controller → Service Layer → Repository → Database
– Errors bubble up to GlobalExceptionHandler → HTTP error responses
– Upon events (sale completed) Service triggers NotificationService → external notification channel
– All components emit logs to log files/monitoring system
c. Architectural patterns & design principles
– Layered architecture (Controller → Service → Repository)
– Dependency Injection via Spring
– Separation of concerns: config, security, API, business logic, persistence
– Exception handling centralized in GlobalExceptionHandler
– DTOs to decouple API contracts from domain models
– JWT-based stateless authentication
d. Key technologies
– Framework: Spring Boot, Spring MVC, Spring Security, Spring Data JPA
– Data interchange: JSON (customized via JacksonConfig)
– API docs: OpenAPI/Swagger (OpenApiConfig)
– Build: Maven (pom.xml, mvnw)
– Logging: SLF4J/Logback (application.properties)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Entity
    Client["External Client"]:::external

    %% Application Entry
    Entry["ChatbotVendasApplication"]:::app

    %% Layers
    subgraph "API Layer"
        AuthController["AuthenticationController"]:::controller
        ProductController["ProductController"]:::controller
        SaleController["SaleController"]:::controller
        ReportController["ReportController"]:::controller
        NotificationController["NotificationController"]:::controller
        UserController["UserController"]:::controller
    end

    subgraph "Security Layer"
        SecurityFilter["SecurityFilter"]:::security
        SecurityConfig["SecurityConfigurations"]:::security
        TokenServiceSec["TokenService"]:::security
        JwtService["JwtService"]:::security
        AuthzService["AuthorizationService"]:::security
    end

    subgraph "Service Layer"
        UserService["UserService"]:::service
        ProductService["ProductService"]:::service
        SaleService["SaleService"]:::service
        ReportService["ReportService"]:::service
        NotificationService["NotificationService"]:::service
    end

    subgraph "Repository Layer"
        UserRepo["UserRepository"]:::repository
        ProductRepo["ProductRepository"]:::repository
        SaleRepo["SaleRepository"]:::repository
        ReportRepo["ReportRepository"]:::repository
        NotificationRepo["NotificationRepository"]:::repository
    end

    Database["Database"]:::database
    ChatPlatform["Chat Platform"]:::external
    SMTP["SMTP/Push Gateway"]:::external
    Logger["Logging / Monitoring"]:::monitoring
    GlobalException["GlobalExceptionHandler"]:::error

    %% Startup
    Entry --> AuthController
    Entry --> SecurityConfig
    Entry --> SecurityFilter
    Entry --> UserService
    Entry --> UserRepo

    %% Client Requests
    Client -->|"auth request"| AuthController
    Client -->|"secured request"| ProductController
    Client -->|"secured request"| SaleController
    Client -->|"secured request"| ReportController
    Client -->|"secured request"| NotificationController
    Client -->|"secured request"| UserController

    %% Security Flow
    AuthController --> JwtService
    AuthController --> TokenServiceSec
    AuthController --> AuthzService
    ProductController --> SecurityFilter
    SaleController --> SecurityFilter
    ReportController --> SecurityFilter
    NotificationController --> SecurityFilter
    UserController --> SecurityFilter

    %% Controller to Service
    AuthController --> UserService
    ProductController --> ProductService
    SaleController --> SaleService
    ReportController --> ReportService
    NotificationController --> NotificationService
    UserController --> UserService

    %% Service to Repo
    UserService --> UserRepo
    ProductService --> ProductRepo
    SaleService --> SaleRepo
    ReportService --> ReportRepo
    NotificationService --> NotificationRepo

    %% Persistence
    UserRepo --> Database
    ProductRepo --> Database
    SaleRepo --> Database
    ReportRepo --> Database
    NotificationRepo --> Database

    %% Notifications
    SaleService --> NotificationService
    NotificationService --> SMTP
    NotificationService --> ChatPlatform

    %% Errors and Logging
    AuthController --> GlobalException
    ProductController --> GlobalException
    SaleController --> GlobalException
    ReportController --> GlobalException
    NotificationController --> GlobalException
    UserController --> GlobalException
    AuthController --> Logger
    ProductController --> Logger
    SaleController --> Logger
    ReportController --> Logger
    NotificationController --> Logger
    UserController --> Logger
    SecurityFilter --> Logger
    SecurityConfig --> Logger
    JwtService --> Logger
    TokenServiceSec --> Logger
    AuthzService --> Logger
    UserService --> Logger
    ProductService --> Logger
    SaleService --> Logger
    ReportService --> Logger
    NotificationService --> Logger
    UserRepo --> Logger
    ProductRepo --> Logger
    SaleRepo --> Logger
    ReportRepo --> Logger
    NotificationRepo --> Logger
    Database --> Logger
    SMTP --> Logger
    ChatPlatform --> Logger

    %% Click Events
    click AuthController "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/controller/AuthenticationController.java"
    click ProductController "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/controller/ProductController.java"
    click SaleController "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/controller/SaleController.java"
    click ReportController "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/controller/ReportController.java"
    click NotificationController "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/controller/NotificationController.java"
    click UserController "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/controller/UserController.java"
    click SecurityConfig "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/security/SecurityConfigurations.java"
    click SecurityFilter "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/security/SecurityFilter.java"
    click TokenServiceSec "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/security/TokenService.java"
    click JwtService "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/service/JwtService.java"
    click AuthzService "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/service/AuthorizationService.java"
    click UserService "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/service/UserService.java"
    click ProductService "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/service/ProductService.java"
    click SaleService "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/service/SaleService.java"
    click ReportService "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/service/ReportService.java"
    click NotificationService "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/service/NotificationService.java"
    click UserRepo "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/repository/UserRepository.java"
    click ProductRepo "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/repository/ProductRepository.java"
    click SaleRepo "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/repository/SaleRepository.java"
    click ReportRepo "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/repository/ReportRepository.java"
    click NotificationRepo "https://github.com/queirozcarlos/chatbot-saas-/blob/main/src/main/java/com/sistema/chatbot/repository/NotificationRepository.java"

    %% Styles
    classDef controller fill:#E3F2FD,stroke:#90CAF9;
    classDef service fill:#BBDEFB,stroke:#64B5F6;
    classDef repository fill:#E8EAF6,stroke:#7986CB;
    classDef security fill:#FFF3E0,stroke:#FFB74D,stroke-dasharray: 5 5;
    classDef database fill:#C8E6C9,stroke:#66BB6A,stroke-dasharray: 2 2;
    classDef external fill:#FFE0B2,stroke:#FFA726;
    classDef monitoring fill:#F5F5F5,stroke:#BDBDBD,stroke-dasharray: 4 2;
    classDef error fill:#FFEBEE,stroke:#E57373,stroke-dasharray: 4 2;
    classDef app fill:#E1BEE7,stroke:#BA68C8,stroke-dasharray: 3 3;
```
