# justinmajetich/airbnb_clone architecture

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

- Interactive diagram: https://gitdiagram.com/justinmajetich/airbnb_clone
- Repository: https://github.com/justinmajetich/airbnb_clone

## Overview

##### Project type and purpose
- This is a Python-based backend console application (the “HBnB console”) that exposes a CLI for creating, reading, updating, and deleting (CRUD) instances of Airbnb-style models.
- It uses JSON serialization to persist model instances to a file and supports an alternative dot-notation command syntax.

##### Main components
a. Console Interface Layer
- console.py – the entry point, command loop, and parser.
- Command Parser – dispatches commands (create, show, destroy, all, update, quit) to the application core.
b. Application Core Layer
- Models Package (models/)
– base_model.py – BaseModel class (id, created_at, updated_at, to_dict(), save()).
– amenity.py, city.py, place.py, review.py, state.py, user.py – domain entities inheriting from BaseModel.
- Storage Engine (models/engine/file_storage.py)
– FileStorage class – keeps an in-memory dictionary of all objects, serializes to JSON on disk (file.json), and reloads on startup.
c. Persistence Layer
- JSON File (file.json) – the flat file used for storing serialized objects.
- File System – read/write operations performed by FileStorage.save() and FileStorage.reload().
d. Supporting Artifacts
- web_static/ – static HTML/CSS pages (staged for front-end preview but not served by this console).
- tests/ – unit tests validating models and file storage behavior.

##### Relationships and data flows
- Console Interface Layer → Application Core Layer
(user types a command)
- Models ↔ Storage Engine
- Models call storage.new(self) and storage.save() in BaseModel.save().
- FileStorage maintains dict<“ClassName.id”, object> and calls to_dict() on each model, then writes JSON.
- Storage Engine ↔ JSON File
- FileStorage.save() → writes JSON to disk.
- FileStorage.reload() → reads JSON, instantiates model objects via **kwargs and BaseModel.
- (Optional) Console Interface → web_static

##### Architectural patterns and design principles
- Layered architecture: CLI Layer → Application Layer (Models + Storage) → Infrastructure (File System).
- Single Responsibility:
- console.py only handles user I/O.
- Models encapsulate data and behavior.
- FileStorage encapsulates persistence logic.
- Factory/Registry pattern: FileStorage acts as a registry of all model instances.
- Serialization/Deserialization: JSON-based persistence.

##### Elements to ensure clarity
- Clear, unique labels on each component.
- A brief note (in a corner) listing technologies: Python 3, JSON, unittest, console (cmd module or custom loop).

## Diagram (Mermaid)

```mermaid
flowchart TD
    title[[HBnB Console Architecture Diagram]]

    subgraph "Console Interface Layer"
        CLI["Console Interface<br/>(console.py)"]:::code
        Parser["Command Parser"]:::code
    end

    subgraph "Application Core Layer"
        subgraph "Models Package"
            BM["BaseModel"]:::code
            Am["Amenity"]:::code
            Ci["City"]:::code
            Pl["Place"]:::code
            Re["Review"]:::code
            St["State"]:::code
            Us["User"]:::code
        end
        subgraph "Storage Engine"
            FS["FileStorage"]:::code
        end
    end

    subgraph "Persistence Layer"
        JSONFile[(file.json)]:::persistence
        FileSystem["File System"]:::artifact
    end

    subgraph "Supporting Artifacts"
        WebStatic["web_static/"]:::artifact
    end

    subgraph "Unit Tests"
        TM["tests/test_models/"]:::artifact
        TFS["test_file_storage.py"]:::artifact
    end

    CLI -->|"parse_command()"| Parser
    Parser -->|"invoke_model_operation()"| BM
    BM -->|"save()"| FS
    FS -->|"write JSON"| JSONFile
    FS -->|"reload()"| JSONFile
    JSONFile -->|"loaded objects"| FS
    FS -->|"new(self)"| BM

    CLI -.->|"planned preview"| WebStatic
    TM -.->|"tests models"| BM
    TFS -.->|"tests storage"| FS

    classDef code fill:#DDEEFF,stroke:#000,stroke-width:1px
    classDef persistence fill:#CCFFCC,stroke:#000,stroke-width:1px
    classDef artifact fill:#EEEEEE,stroke:#666,stroke-width:1px

    click CLI "https://github.com/justinmajetich/airbnb_clone/blob/master/console.py"
    click Parser "https://github.com/justinmajetich/airbnb_clone/blob/master/console.py"
    click BM "https://github.com/justinmajetich/airbnb_clone/blob/master/models/base_model.py"
    click Am "https://github.com/justinmajetich/airbnb_clone/blob/master/models/amenity.py"
    click Ci "https://github.com/justinmajetich/airbnb_clone/blob/master/models/city.py"
    click Pl "https://github.com/justinmajetich/airbnb_clone/blob/master/models/place.py"
    click Re "https://github.com/justinmajetich/airbnb_clone/blob/master/models/review.py"
    click St "https://github.com/justinmajetich/airbnb_clone/blob/master/models/state.py"
    click Us "https://github.com/justinmajetich/airbnb_clone/blob/master/models/user.py"
    click FS "https://github.com/justinmajetich/airbnb_clone/blob/master/models/engine/file_storage.py"
    click WebStatic "https://github.com/justinmajetich/airbnb_clone/tree/master/web_static/"
    click TM "https://github.com/justinmajetich/airbnb_clone/tree/master/tests/test_models/"
    click TFS "https://github.com/justinmajetich/airbnb_clone/blob/master/tests/test_models/test_engine/test_file_storage.py"
```
