# javier13g/backendrealstate architecture

> Architecture diagram of the GitHub repository javier13g/backendrealstate, 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/javier13g/backendrealstate
- Repository: https://github.com/javier13g/backendrealstate

## Overview

##### Project type and purpose
- This is a backend API project built with NestJS (a Node.js framework), using Prisma as the ORM and MongoDB as the data store.
- It exposes RESTful HTTP endpoints (controllers) for authentication (JWT), user management, roles, and status‐user management.

##### File structure
- Top-level folders & files:
- src/ : all application code
- prisma/ : Prisma schema & client generation
- test/ : end‐to‐end tests
- Inside src/ you see distinct NestJS modules:
- auth/
- users/
- roles/
- status-user/
- common/ (shared filters)
- prisma/ (PrismaService & module)
- Core NestJS files: app.module.ts (root module), main.ts (bootstrap), app.service, app.controller.
- Configuration files for TypeScript, ESLint, Nest CLI, Prettier, and package.json scripts.

##### README
- Confirms NestJS + Prisma + MongoDB + JWT stack.

a. Main components:
- HTTP Client (e.g., browser or mobile app)
- NestJS API Server
– API Gateway / Entry Point (main.ts)
– Controllers (AuthController, UsersController, RolesController, StatusUserController, AppController)
– Services (AuthService, UsersService, RolesService, StatusUserService, AppService)
– Shared/Common Filters (e.g., HTTP exception filter)
– Prisma Module & PrismaService (database access abstraction)
- MongoDB Database
- External JWT lib (used by AuthService, but part of the API server)
b. Relationships & interactions:
1. Client → NestJS HTTP Listener
2. HTTP Request routed to appropriate Controller
3. Controller calls its Service
4. Service uses PrismaService to query/update MongoDB
5. PrismaService translates service calls into MongoDB operations
6. DB returns results → Service applies business logic → Controller returns HTTP response
7. Auth flows: incoming credentials → AuthService verifies via Prisma → issues JWT → client stores token for subsequent calls
c. Architectural patterns & principles:
- Modular monolith: each feature (auth, users, roles, status‐user) is its own Nest module
- Layered architecture: Controller (entry point) → Service (business logic) → Repository/ORM (Prisma) → Database
- Dependency Injection: modules import/supply PrismaService and share common filters
- DTOs for input validation (in each module’s dto folder)
d. Technologies & frameworks:
- NestJS (framework; modules, controllers, services)
- TypeScript (language)
- Prisma ORM (PrismaService, schema.prisma)
- MongoDB (NoSQL document store)
- JWT (stateless authentication)

## Diagram (Mermaid)

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

    %% Entry Point and Root Module
    Client --> Entrypoint["API Gateway / Entry Point"]:::api
    Entrypoint --> AppModule["AppModule"]:::biz

    %% API Controllers grouped by AppModule
    AppModule --> AppController["AppController"]:::api
    AppModule --> AuthModule["Auth Module"]:::biz
    AppModule --> UsersModule["Users Module"]:::biz
    AppModule --> RolesModule["Roles Module"]:::biz
    AppModule --> StatusUserModule["StatusUser Module"]:::biz

    %% App Controller & Service
    AppController --> AppService["AppService"]:::biz
    AppService --> PrismaService

    %% Auth Module
    subgraph "Auth Module"
        AuthController["AuthController"]:::api
        AuthService["AuthService"]:::biz
    end
    AuthModule --> AuthController
    AuthController --> AuthService
    AuthService --> PrismaService

    %% Users Module
    subgraph "Users Module"
        UsersController["UsersController"]:::api
        UsersService["UsersService"]:::biz
        UsersDTO["Users DTO"]:::data
    end
    UsersModule --> UsersController
    UsersController --> UsersDTO
    UsersController --> UsersService
    UsersService --> PrismaService

    %% Roles Module
    subgraph "Roles Module"
        RolesController["RolesController"]:::api
        RolesService["RolesService"]:::biz
        RolesDTO["Roles DTO"]:::data
    end
    RolesModule --> RolesController
    RolesController --> RolesDTO
    RolesController --> RolesService
    RolesService --> PrismaService

    %% Status-User Module
    subgraph "StatusUser Module"
        StatusUserController["StatusUserController"]:::api
        StatusUserService["StatusUserService"]:::biz
        StatusUserDTO["StatusUser DTO"]:::data
    end
    StatusUserModule --> StatusUserController
    StatusUserController --> StatusUserDTO
    StatusUserController --> StatusUserService
    StatusUserService --> PrismaService

    %% Common & Shared
    subgraph "Common Shared"
        HTTPExceptionFilter["HTTPExceptionFilter"]:::biz
        PaginationUtil["Pagination Utils"]:::data
    end
    AppModule --> HTTPExceptionFilter
    UsersService --> PaginationUtil
    RolesService --> PaginationUtil
    StatusUserService --> PaginationUtil

    %% Prisma Layer
    subgraph "Prisma Module" 
        PrismaModule["PrismaModule"]:::data
        PrismaService["PrismaService"]:::data
        Schema["schema.prisma"]:::data
    end
    PrismaModule --> PrismaService
    Schema --> PrismaService
    AppService --> PrismaService

    %% Database
    PrismaService --> MongoDB["MongoDB Database"]:::external

    %% Styles
    classDef api fill:#D0E6FF,stroke:#0366d6;
    classDef biz fill:#D5F5E3,stroke:#28a745;
    classDef data fill:#FFE5B4,stroke:#d9822b;
    classDef external fill:#E2E2E2,stroke:#6c757d;

    %% Click Events
    click Entrypoint "https://github.com/javier13g/backendrealstate/blob/main/src/main.ts"
    click AppModule "https://github.com/javier13g/backendrealstate/blob/main/src/app.module.ts"
    click AppController "https://github.com/javier13g/backendrealstate/blob/main/src/app.controller.ts"
    click AppService "https://github.com/javier13g/backendrealstate/blob/main/src/app.service.ts"
    click AuthModule "https://github.com/javier13g/backendrealstate/blob/main/src/auth/auth.module.ts"
    click AuthController "https://github.com/javier13g/backendrealstate/blob/main/src/auth/auth.controller.ts"
    click AuthService "https://github.com/javier13g/backendrealstate/blob/main/src/auth/auth.service.ts"
    click UsersModule "https://github.com/javier13g/backendrealstate/blob/main/src/users/users.module.ts"
    click UsersController "https://github.com/javier13g/backendrealstate/blob/main/src/users/users.controller.ts"
    click UsersService "https://github.com/javier13g/backendrealstate/blob/main/src/users/users.service.ts"
    click UsersDTO "https://github.com/javier13g/backendrealstate/blob/main/src/users/dto/users.dto.ts"
    click RolesModule "https://github.com/javier13g/backendrealstate/blob/main/src/roles/roles.module.ts"
    click RolesController "https://github.com/javier13g/backendrealstate/blob/main/src/roles/roles.controller.ts"
    click RolesService "https://github.com/javier13g/backendrealstate/blob/main/src/roles/roles.service.ts"
    click RolesDTO "https://github.com/javier13g/backendrealstate/blob/main/src/roles/dto/roles.dto.ts"
    click StatusUserModule "https://github.com/javier13g/backendrealstate/blob/main/src/status-user/status-user.module.ts"
    click StatusUserController "https://github.com/javier13g/backendrealstate/blob/main/src/status-user/status-user.controller.ts"
    click StatusUserService "https://github.com/javier13g/backendrealstate/blob/main/src/status-user/status-user.service.ts"
    click StatusUserDTO "https://github.com/javier13g/backendrealstate/blob/main/src/status-user/dto/status-user.dto.ts"
    click HTTPExceptionFilter "https://github.com/javier13g/backendrealstate/blob/main/src/common/filters/http-exception.filter.ts"
    click PrismaModule "https://github.com/javier13g/backendrealstate/blob/main/src/prisma/prisma.module.ts"
    click PrismaService "https://github.com/javier13g/backendrealstate/blob/main/src/prisma/prisma.service.ts"
    click Schema "https://github.com/javier13g/backendrealstate/blob/main/prisma/schema.prisma"
    click PaginationUtil "https://github.com/javier13g/backendrealstate/blob/main/src/utils/pagination.utils.ts"
```
