# 20225scorpion/backend_hotel architecture

> Architecture diagram of the GitHub repository 20225scorpion/backend_hotel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/20225scorpion/backend_hotel
- Repository: https://github.com/20225scorpion/backend_hotel

## Overview

Hotel Asturias API is a FastAPI backend for hotel operations and staff accounts. Users register or log in to obtain a token; protected requests resolve that token to a user before reaching operational endpoints. The main domain stages are room and guest management, stays, income and expenses, reporting, and audit/history. SQLAlchemy models persist the domain records. The source index identifies the router dependencies, but several router implementations were not excerpted, so their detailed calls are not asserted here.

Main entry points: [`main.py`](https://github.com/20225scorpion/backend_hotel/blob/main/main.py) (FastAPI app), [`database.py`](https://github.com/20225scorpion/backend_hotel/blob/main/database.py) (SQLAlchemy setup), [`routers/hospedajes.py`](https://github.com/20225scorpion/backend_hotel/blob/main/routers/hospedajes.py) (Stays API), [`routers/habitaciones.py`](https://github.com/20225scorpion/backend_hotel/blob/main/routers/habitaciones.py) (Rooms API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_app["FastAPI app<br/>[main.py]"]
end

subgraph group_security["Identity and access"]
  node_auth_handler["Token and passwords<br/>[auth_handler.py]"]
  node_bearer["Bearer verification<br/>[auth_bearer.py]"]
  node_roles["Role checks<br/>[role_checker.py]"]
  node_dependencies["Request dependencies<br/>[deps.py]"]
end

subgraph group_operations["Hotel operations"]
  node_rooms_api["Rooms API<br/>[habitaciones.py]"]
  node_guests_api["Guests API<br/>[huespedes.py]"]
  node_stays_api["Stays API<br/>[hospedajes.py]"]
  node_income_api["Income API<br/>[ingresos.py]"]
  node_expenses_api["Expenses API<br/>[gastos.py]"]
  node_reports_api["Reports API<br/>[reportes.py]"]
  node_audit_api["Audit API<br/>[auditoria.py]"]
end

subgraph group_persistence["Persistence"]
  node_database["SQLAlchemy setup<br/>[database.py]"]
  node_users["User records<br/>[user_model.py]"]
  node_rooms["Room records"]
  node_guests["Guest records<br/>[huesped_model.py]"]
  node_stays["Stay records<br/>[hospedaje_model.py]"]
  node_income["Income records<br/>[ingreso_model.py]"]
  node_expenses["Expense records<br/>[gasto_model.py]"]
  node_taxes["Tax records<br/>[impuesto_model.py]"]
  node_audit["Audit records<br/>[auditoria_model.py]"]
  node_deleted["Deletion records"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_rooms_api
node_app -->|"mounts routes"| node_guests_api
node_app -->|"mounts routes"| node_income_api
node_app -->|"mounts routes"| node_expenses_api
node_app -->|"mounts routes"| node_stays_api
node_app -->|"mounts routes"| node_reports_api
node_app -->|"mounts routes"| node_audit_api
node_app -->|"hashes and issues"| node_auth_handler
node_app -->|"queries and writes"| node_users
node_app -->|"records login"| node_audit
node_app -->|"protects profile"| node_bearer
node_app -->|"checks privileged routes"| node_roles
node_dependencies -->|"verifies token"| node_bearer
node_dependencies -->|"resolves account"| node_users
node_bearer -->|"uses signing settings"| node_auth_handler
node_roles -->|"depends on verification"| node_bearer
node_database -->|"provides model base"| node_users
node_database -->|"provides model base"| node_rooms
node_database -->|"provides model base"| node_stays
node_database -->|"provides model base"| node_income
node_database -->|"provides model base"| node_audit
node_database -->|"provides model base"| node_deleted
node_rooms_api -->|"uses request access"| node_dependencies
node_rooms_api -->|"queries and updates"| node_rooms
node_rooms_api -->|"records changes"| node_audit
node_rooms_api -->|"records removals"| node_deleted
node_guests_api -.->|"uses request access"| node_dependencies
node_guests_api -.->|"manages guests"| node_guests
node_stays_api -.->|"uses request access"| node_dependencies
node_stays_api -.->|"manages stays"| node_stays
node_stays_api -.->|"uses room records"| node_rooms
node_stays_api -.->|"uses guest records"| node_guests
node_stays_api -.->|"records stay income"| node_income
node_income_api -.->|"manages income"| node_income
node_expenses_api -.->|"manages expenses"| node_expenses
node_reports_api -.->|"reads income"| node_income
node_reports_api -.->|"reads expenses"| node_expenses
node_reports_api -.->|"reads stays"| node_stays
node_reports_api -.->|"reads rooms"| node_rooms
node_audit_api -.->|"reads audit history"| node_audit
node_audit_api -.->|"reads deletion history"| node_deleted

click node_app "https://github.com/20225scorpion/backend_hotel/blob/main/main.py"
click node_rooms_api "https://github.com/20225scorpion/backend_hotel/blob/main/routers/habitaciones.py"
click node_guests_api "https://github.com/20225scorpion/backend_hotel/blob/main/routers/huespedes.py"
click node_stays_api "https://github.com/20225scorpion/backend_hotel/blob/main/routers/hospedajes.py"
click node_income_api "https://github.com/20225scorpion/backend_hotel/blob/main/routers/ingresos.py"
click node_expenses_api "https://github.com/20225scorpion/backend_hotel/blob/main/routers/gastos.py"
click node_reports_api "https://github.com/20225scorpion/backend_hotel/blob/main/routers/reportes.py"
click node_audit_api "https://github.com/20225scorpion/backend_hotel/blob/main/routers/auditoria.py"
click node_auth_handler "https://github.com/20225scorpion/backend_hotel/blob/main/auth/auth_handler.py"
click node_bearer "https://github.com/20225scorpion/backend_hotel/blob/main/auth/auth_bearer.py"
click node_roles "https://github.com/20225scorpion/backend_hotel/blob/main/auth/role_checker.py"
click node_dependencies "https://github.com/20225scorpion/backend_hotel/blob/main/deps.py"
click node_database "https://github.com/20225scorpion/backend_hotel/blob/main/database.py"
click node_users "https://github.com/20225scorpion/backend_hotel/blob/main/models/user_model.py"
click node_rooms "https://github.com/20225scorpion/backend_hotel/blob/main/models/habitacion_model.py"
click node_guests "https://github.com/20225scorpion/backend_hotel/blob/main/models/huesped_model.py"
click node_stays "https://github.com/20225scorpion/backend_hotel/blob/main/models/hospedaje_model.py"
click node_income "https://github.com/20225scorpion/backend_hotel/blob/main/models/ingreso_model.py"
click node_expenses "https://github.com/20225scorpion/backend_hotel/blob/main/models/gasto_model.py"
click node_taxes "https://github.com/20225scorpion/backend_hotel/blob/main/models/impuesto_model.py"
click node_audit "https://github.com/20225scorpion/backend_hotel/blob/main/models/auditoria_model.py"
click node_deleted "https://github.com/20225scorpion/backend_hotel/blob/main/models/registro_eliminado_model.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_client toneBlue
class node_auth_handler,node_bearer,node_roles,node_dependencies toneAmber
class node_rooms_api,node_guests_api,node_stays_api,node_income_api,node_expenses_api,node_reports_api,node_audit_api toneMint
class node_database,node_users,node_rooms,node_guests,node_stays,node_income,node_expenses,node_taxes,node_audit,node_deleted toneRose
```

## Components

### API entry

- [FastAPI app](https://github.com/20225scorpion/backend_hotel/blob/main/main.py): `main.py`

### Identity and access

- [Token and passwords](https://github.com/20225scorpion/backend_hotel/blob/main/auth/auth_handler.py): `auth/auth_handler.py`
- [Bearer verification](https://github.com/20225scorpion/backend_hotel/blob/main/auth/auth_bearer.py): `auth/auth_bearer.py`
- [Role checks](https://github.com/20225scorpion/backend_hotel/blob/main/auth/role_checker.py): `auth/role_checker.py`
- [Request dependencies](https://github.com/20225scorpion/backend_hotel/blob/main/deps.py): `deps.py`

### Hotel operations

- [Rooms API](https://github.com/20225scorpion/backend_hotel/blob/main/routers/habitaciones.py): `routers/habitaciones.py`
- [Guests API](https://github.com/20225scorpion/backend_hotel/blob/main/routers/huespedes.py): `routers/huespedes.py`
- [Stays API](https://github.com/20225scorpion/backend_hotel/blob/main/routers/hospedajes.py): `routers/hospedajes.py`
- [Income API](https://github.com/20225scorpion/backend_hotel/blob/main/routers/ingresos.py): `routers/ingresos.py`
- [Expenses API](https://github.com/20225scorpion/backend_hotel/blob/main/routers/gastos.py): `routers/gastos.py`
- [Reports API](https://github.com/20225scorpion/backend_hotel/blob/main/routers/reportes.py): `routers/reportes.py`
- [Audit API](https://github.com/20225scorpion/backend_hotel/blob/main/routers/auditoria.py): `routers/auditoria.py`

### Persistence

- [SQLAlchemy setup](https://github.com/20225scorpion/backend_hotel/blob/main/database.py): `database.py`
- [User records](https://github.com/20225scorpion/backend_hotel/blob/main/models/user_model.py): `models/user_model.py`
- [Room records](https://github.com/20225scorpion/backend_hotel/blob/main/models/habitacion_model.py): `models/habitacion_model.py`
- [Guest records](https://github.com/20225scorpion/backend_hotel/blob/main/models/huesped_model.py): `models/huesped_model.py`
- [Stay records](https://github.com/20225scorpion/backend_hotel/blob/main/models/hospedaje_model.py): `models/hospedaje_model.py`
- [Income records](https://github.com/20225scorpion/backend_hotel/blob/main/models/ingreso_model.py): `models/ingreso_model.py`
- [Expense records](https://github.com/20225scorpion/backend_hotel/blob/main/models/gasto_model.py): `models/gasto_model.py`
- [Tax records](https://github.com/20225scorpion/backend_hotel/blob/main/models/impuesto_model.py): `models/impuesto_model.py`
- [Audit records](https://github.com/20225scorpion/backend_hotel/blob/main/models/auditoria_model.py): `models/auditoria_model.py`
- [Deletion records](https://github.com/20225scorpion/backend_hotel/blob/main/models/registro_eliminado_model.py): `models/registro_eliminado_model.py`

### Other components

- **API client**

## Connections

- API client → FastAPI app: sends requests (evidence: `main.py`)
- FastAPI app → Rooms API: mounts routes (evidence: `main.py`)
- FastAPI app → Guests API: mounts routes (evidence: `main.py`)
- FastAPI app → Income API: mounts routes (evidence: `main.py`)
- FastAPI app → Expenses API: mounts routes (evidence: `main.py`)
- FastAPI app → Stays API: mounts routes (evidence: `main.py`)
- FastAPI app → Reports API: mounts routes (evidence: `main.py`)
- FastAPI app → Audit API: mounts routes (evidence: `main.py`)
- FastAPI app → Token and passwords: hashes and issues (evidence: `main.py`)
- FastAPI app → User records: queries and writes (evidence: `main.py`)
- FastAPI app → Audit records: records login (evidence: `main.py`)
- FastAPI app → Bearer verification: protects profile (evidence: `main.py`)
- FastAPI app → Role checks: checks privileged routes (evidence: `main.py`)
- Request dependencies → Bearer verification: verifies token (evidence: `deps.py`)
- Request dependencies → User records: resolves account (evidence: `deps.py`)
- Bearer verification → Token and passwords: uses signing settings (evidence: `auth/auth_bearer.py`)
- Role checks → Bearer verification: depends on verification (evidence: `auth/role_checker.py`)
- SQLAlchemy setup → User records: provides model base (evidence: `models/user_model.py`)
- SQLAlchemy setup → Room records: provides model base (evidence: `models/habitacion_model.py`)
- SQLAlchemy setup → Stay records: provides model base (evidence: `models/hospedaje_model.py`)
- SQLAlchemy setup → Income records: provides model base (evidence: `models/ingreso_model.py`)
- SQLAlchemy setup → Audit records: provides model base (evidence: `models/auditoria_model.py`)
- SQLAlchemy setup → Deletion records: provides model base (evidence: `models/registro_eliminado_model.py`)
- Rooms API → Request dependencies: uses request access (evidence: `routers/habitaciones.py`)
- Rooms API → Room records: queries and updates (evidence: `routers/habitaciones.py`)
- Rooms API → Audit records: records changes (evidence: `routers/habitaciones.py`)
- Rooms API → Deletion records: records removals (evidence: `routers/habitaciones.py`)
- Guests API → Request dependencies: uses request access (evidence: `routers/huespedes.py`)
- Guests API → Guest records: manages guests (evidence: `routers/huespedes.py`)
- Stays API → Request dependencies: uses request access (evidence: `routers/hospedajes.py`)
- Stays API → Stay records: manages stays (evidence: `routers/hospedajes.py`)
- Stays API → Room records: uses room records (evidence: `routers/hospedajes.py`)
- Stays API → Guest records: uses guest records (evidence: `routers/hospedajes.py`)
- Stays API → Income records: records stay income (evidence: `routers/hospedajes.py`)
- Income API → Income records: manages income (evidence: `routers/ingresos.py`)
- Expenses API → Expense records: manages expenses (evidence: `routers/gastos.py`)
- Reports API → Income records: reads income (evidence: `routers/reportes.py`)
- Reports API → Expense records: reads expenses (evidence: `routers/reportes.py`)
- Reports API → Stay records: reads stays (evidence: `routers/reportes.py`)
- Reports API → Room records: reads rooms (evidence: `routers/reportes.py`)
- Audit API → Audit records: reads audit history (evidence: `routers/auditoria.py`)
- Audit API → Deletion records: reads deletion history (evidence: `routers/auditoria.py`)
