# bichotas-season/bibliosoftb architecture

> Architecture diagram of the GitHub repository bichotas-season/bibliosoftb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bichotas-season/bibliosoftb
- Repository: https://github.com/bichotas-season/bibliosoftb

## Overview

##### Project Type and Purpose
- This is a standalone Spring Boot microservice (“Módulo Préstamos”) that exposes a REST API for managing library book loans: registering loans, tracking statuses, calculating fines for overdue returns, and handling returns.
- It uses JWT for security, Swagger/OpenAPI for documentation, and MongoDB (via Spring Data) for persistence.

##### High-Level Components
a. Clients
- Front-end SPA or any HTTP client (e.g. Postman)
- Other backend services (e.g. Student or Book modules) via the ApiClient
b. API Layer
- CorsConfig – enforces allowed origins (FRONTEND_URL)
- SecurityConfig + JwtAuthenticationFilter – configures Spring Security filter chain for JWT auth
- SwaggerConfig – exposes /swagger-ui for API docs
c. Controller Layer
- PrestamoController – maps HTTP endpoints (`/prestamos`, `/prestamos-prestados`, etc.) to service methods
d. Service Layer
- PrestamoService – core business logic (create, update, delete, calculate fines)
- TaskScheduledService – scheduled jobs (e.g. periodic overdue check/fine update)
- ApiClient – outbound REST client to student/book validation services
e. Repository Layer
- PrestamoRepository – Spring Data MongoDB interface for CRUD operations on Prestamo documents
f. Data Model
- Prestamo entity (loan document)
- DTOs: DevolucionDTO (return payload), PrestamoVencidoDTO (overdue notices)
g. Persistence
- MongoDB database (configured via SPRING_DATA_MONGODB_URI)
h. Infrastructure & Config
- application.properties / application-dev/prod.properties – environment-specific settings
- Docker (optional) – containerization

##### Relationships and Data Flows
- Clients → HTTP(S) → CorsConfig → JwtAuthenticationFilter → PrestamoController
- PrestamoController → PrestamoService → PrestamoRepository → MongoDB
- PrestamoService ↔ ApiClient → External Student/Book modules (validate availability, student eligibility)
- TaskScheduledService (cron) → PrestamoService → PrestamoRepository → MongoDB (update overdue fines)
- SwaggerConfig exposes metadata → clients

##### Architectural Patterns & Design Principles
- Layered architecture (Controller → Service → Repository)
- Filter chain for cross-cutting concerns (CORS, Security)
- DTOs for inbound/outbound data segregation
- Scheduled tasks for asynchronous/periodic processing
- External API client abstraction for decoupling from other modules

9. At the bottom or side, note configuration sources (application-*.properties, environment variables).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Inbound Traffic
    subgraph "Inbound Traffic"
        Client["Client (SPA / Postman)"]:::external
    end

    %% API / Security / Docs
    subgraph "API / Security / Docs"
        Cors["CorsConfig"]:::config
        Sec["SecurityConfig"]:::config
        Jwt["JwtAuthenticationFilter"]:::config
        Swagger["SwaggerConfig"]:::config
    end

    %% Controllers
    subgraph "Controllers"
        Controller["PrestamoController"]:::controller
    end

    %% Business Logic
    subgraph "Business Logic"
        PrestamoService["PrestamoService"]:::service
        TaskService["TaskScheduledService"]:::service
        ApiClient["ApiClient"]:::service
    end

    %% Domain Model
    subgraph "Domain Model"
        Entity["Prestamo"]:::entity
        DTO1["DevolucionDTO"]:::entity
        DTO2["PrestamoVencidoDTO"]:::entity
        Ex["PrestamosException"]:::entity
    end

    %% Data Access
    subgraph "Data Access"
        Repo["PrestamoRepository"]:::repository
    end

    %% Persistence
    subgraph "Persistence"
        Mongo["MongoDB"]:::database
    end

    %% External Integrations
    subgraph "External Integrations"
        Student["Student Service"]:::external
        Book["Book Service"]:::external
    end

    %% Configuration Files
    subgraph "Configuration Files"
        Props1["application.properties"]:::config
        Props2["application-dev.properties"]:::config
        Props3["application-prod.properties"]:::config
    end

    %% Scheduled Trigger
    Cron(("Cron Timer")):::cron

    %% Connections
    Client -->|"HTTP Request"| Cors --> Sec --> Jwt --> Controller
    Swagger -->|"Swagger UI /swagger-ui"| Controller
    Controller -->|"calls"| PrestamoService
    PrestamoService -->|"uses"| ApiClient
    Cron -.->|"Scheduled Trigger"| TaskService
    TaskService -->|"invokes"| PrestamoService
    PrestamoService -->|"DB Read/Write"| Repo
    TaskService -->|"DB Read/Write"| Repo
    Repo -->|"CRUD ops"| Mongo
    ApiClient -->|"External REST Call"| Student
    ApiClient -->|"External REST Call"| Book

    %% Click Events
    click Client "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/ModuloPrestamosApplication.java"
    click Cors "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/config/CorsConfig.java"
    click Sec "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/config/SecurityConfig.java"
    click Jwt "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/config/JwtAuthenticationFilter.java"
    click Swagger "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/config/SwaggerConfig.java"
    click Controller "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/controller/PrestamoController.java"
    click PrestamoService "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/service/PrestamoService.java"
    click TaskService "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/service/TaskScheduledService.java"
    click ApiClient "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/service/ApiClient.java"
    click Repo "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/repository/PrestamoRepository.java"
    click Entity "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/entity/Prestamo.java"
    click DTO1 "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/entity/dto/DevolucionDTO.java"
    click DTO2 "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/entity/dto/PrestamoVencidoDTO.java"
    click Ex "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/java/com/bichotas/moduloprestamos/exception/PrestamosException.java"
    click Props1 "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/resources/application.properties"
    click Props2 "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/resources/application-dev.properties"
    click Props3 "https://github.com/bichotas-season/bibliosoftb/blob/main/src/main/resources/application-prod.properties"

    %% Styles
    classDef config fill:#a0c4ff,stroke:#000,stroke-width:1px
    classDef controller fill:#69dbf1,stroke:#000,stroke-width:1px
    classDef service fill:#caffbf,stroke:#000,stroke-width:1px
    classDef repository fill:#ffadad,stroke:#000,stroke-width:1px
    classDef database fill:#8ccf7f,stroke:#000,stroke-width:1px
    classDef external fill:#d3d3d3,stroke:#000,stroke-width:1px
    classDef entity fill:#ffe5a8,stroke:#000,stroke-width:1px
    classDef cron stroke-dasharray: 5 5,fill:none,stroke:#555,stroke-width:1px
```
