# twoody/hotel architecture

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

- Interactive diagram: https://gitdiagram.com/twoody/hotel
- Repository: https://github.com/twoody/hotel

## Overview

##### Main System Components
- Frontend Application:
- Located primarily in the “src” directory.
- Contains core Vue.js components, views (e.g., Home, Login, Booking details, admin dashboards), and assets.
- Uses Vite (with vite.config.js) and Vitest (for unit testing in vitest.config.js) in its development/testing setup.
- Integrates the “teahub” UI components library (as mentioned in the README) for shared component usage.
- Firebase Hosting & Cloud Services:
- Firebase configuration files like firebase.json, firestore.rules, and firestore.indexes.json indicate that Firebase is used for hosting the client application.
- Cloud Functions reside in the “functions” folder (using Firebase Cloud Functions) and handle backend logic.
- Database & Migration System:
- Firestore is used as the NoSQL database. The project includes custom migration scripts, migration templates (in src/migrations/template.js), and shell scripts (in scripts/) to execute migrations. This part of the system ensures schema updates and data transformations.
- CI/CD and Deployment:
- GitHub workflows under “.github/workflows” reveal automated deployment on merges to the main branch.
- Deployment is tied to Firebase, making hosting a managed part of the architecture.
- Testing and Linting:
- Multiple test directories (like “tests/unit”) and ESLint configurations indicate that testing and code quality are essential parts of the system.

##### Understand the Relationships and Data Flows
- The Vue.js Frontend communicates with Firebase – either directly via the Firebase client (observed in src/firebase.js) or indirectly through Cloud Functions (in the “functions” folder).
- Firebase exclusively hosts the application’s static content along with dynamic functionalities served by Cloud Functions.
- Firestore acts as the central data store. The frontend and backend (migration scripts and functions) interact with it to read and write data.
- The Firestore migration subsystem reads data from Firestore, creates backups, applies schema changes, and (if necessary) performs rollbacks. This subsystem is critical to ensuring data consistency across schema updates.
- CI/CD processes (triggered by GitHub Actions) are responsible for automated deployment after build steps and code merges.

##### Important Architectural Patterns & Design Principles
- Component-Based Design: The frontend is modular with components (buttons, accordions, navigation, forms, etc.) that are isolated for reusability, as evidenced by directories like “src/components” and “attic/src/components.”
- Separation of Concerns: There’s a clear separation between frontend (user interface), backend (cloud functions), and database operations (Firestore with migration tools).
- Automation and Environment Safety: The migration system illustrates batch processing, environmental safeguards (using emulator in development), and rollback capabilities, ensuring robust data management.
- DevOps Integration: With GitHub workflows triggering production deployments and hosting commands documented in the README, continuous integration and deployment are integral to the architecture.

##### Additional Specific Details
- External dependencies (e.g., the integration with the teahub library and external Firebase services).
- Important notes from the README about Firebase “costly mistakes” and performance considerations. It’s helpful to annotate areas where batching is important (e.g., migration operations with commit thresholds).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    Client["User Device"]:::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Vue.js Frontend Application"]:::frontend
        Vite["Vite & Vitest Configuration"]:::development
        Teahub["teahub UI Components"]:::frontend
        Hosp["Firebase Hosting & Cloud Config"]:::cloud
    end

    %% Backend and Database Layer
    subgraph "Backend Services"
        CF["Firebase Cloud Functions"]:::backend
        FD["Firestore Database"]:::database
            FD_A["Firebase Admin"]:::database
        Migration["Migration System"]:::backend
            subgraph "Migration Subsystem"
                MT["Migration Template"]:::backend
                MS1["migrate-firestore.sh"]:::backend
                MS2["migration-run.sh"]:::backend
                MS3["migration-rollback.sh"]:::backend
            end
        CICD["CI/CD Pipeline"]:::ci
    end

    %% Development Tools
    subgraph "Development Tools"
        Test["Testing (tests/)"]:::testing
        ESL["ESLint (.eslintrc.js)"]:::testing
        ESL_FC["Functions ESLint (functions/.eslintrc.js)"]:::testing
    end

    %% Connections and Data Flows
    Client -->|"InteractsViaBrowser"| FE
    FE -->|"BuiltUsing"| Vite
    FE -->|"Utilizes"| Teahub
    FE -->|"ServedBy"| Hosp
    FE -->|"Calls"| CF
    CF -->|"PerformsDataOpsOn"| FD
    FD_A -.-> FD
    FD -->|"SchemaUpdate/Backup"| Migration
    CICD -->|"DeploysTo"| Hosp
    CICD -->|"Triggers"| CF
    Test -->|"Validates"| FE
    ESL -->|"Lints"| FE
    ESL_FC -->|"Lints"| CF

    %% Additional Internal Flow
    Vite -->|"BuildProcess"| FE

    %% Click Events for Component Mapping
    click FE "https://github.com/twoody/hotel/tree/main/src/"
    click Vite "https://github.com/twoody/hotel/blob/main/vite.config.js"
    click Teahub "https://github.com/twoody/hotel/tree/main/attic/src/components"
    click Hosp "https://github.com/twoody/hotel/blob/main/firebase.json"
    click CF "https://github.com/twoody/hotel/blob/main/functions/index.js"
    click FD "https://github.com/twoody/hotel/blob/main/src/firebase.js"
    click FD_A "https://github.com/twoody/hotel/blob/main/src/firebaseAdmin.js"
    click MT "https://github.com/twoody/hotel/blob/main/src/migrations/template.js"
    click MS1 "https://github.com/twoody/hotel/blob/main/scripts/migrate-firestore.sh"
    click MS2 "https://github.com/twoody/hotel/blob/main/scripts/migration-run.sh"
    click MS3 "https://github.com/twoody/hotel/blob/main/scripts/migration-rollback.sh"
    click CICD "https://github.com/twoody/hotel/tree/main/.github/workflows/"
    click Test "https://github.com/twoody/hotel/tree/main/tests/"
    click ESL "https://github.com/twoody/hotel/blob/main/ .eslintrc.js"
    click ESL_FC "https://github.com/twoody/hotel/blob/main/functions/.eslintrc.js"

    %% Styles
    classDef external fill:#FAD,stroke:#333,stroke-width:2px;
    classDef frontend fill:#BBF,stroke:#333,stroke-width:2px;
    classDef development fill:#DDf,stroke:#333,stroke-width:2px;
    classDef cloud fill:#CCF,stroke:#333,stroke-width:2px;
    classDef backend fill:#CFC,stroke:#333,stroke-width:2px;
    classDef database fill:#FFC,stroke:#333,stroke-width:2px;
    classDef ci fill:#FC9,stroke:#333,stroke-width:2px;
    classDef testing fill:#CFF,stroke:#333,stroke-width:2px;
```
