# johnny890122/house-rent-591 architecture

> Architecture diagram of the GitHub repository johnny890122/house-rent-591, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/johnny890122/house-rent-591
- Repository: https://github.com/johnny890122/house-rent-591

## Overview

##### Project Type and Purpose
- This is a full-stack, serverless web application for aggregating and displaying house-rent listings (house-rent-591).
- It includes a React single-page frontend, AWS Lambda–based backend/API functions, a crawler service to scrape or ingest data, and MongoDB as the primary datastore.

##### Main Components
a. Frontend (frontend/)
- A React SPA (public/index.html + src/*) served as static assets (static.json).
- Interacts over HTTPS with the backend API (via AWS API Gateway or similar).
b. Backend/API Functions (functions/)
- AWS Lambda functions defined in functions/ and configured via package.json & requirements.txt.
- Expose a RESTful interface for CRUD operations on listings, user actions, etc.
c. Data Store (services/mongo.py + data_sources/ + auth/)
- MongoDB Atlas clusters (data_sources/Cluster0/config.json).
- Custom user metadata (auth/custom_user_data.json) and auth providers (auth/providers.json).
d. Crawler Service (services/crawler/)
- A SAM-defined Lambda (app.py + template.yaml + samconfig.toml) that periodically scrapes or ingests listings.
- Reads data_sources configs and writes to MongoDB.
e. Eventing and Scheduling (triggers/ + sync/)
- AWS EventBridge rules (triggers/aws_event_bus.json) or CloudWatch Events to kick off Lambdas (crawler, sync).
- sync/ for one-off or bulk sync tasks.
f. Configuration and Secrets (functions/config.json + services/secrets_manager.py + root_config.json + environments/)
- Environment-specific settings (development.json, production.json, etc.).
- AWS Secrets Manager integration for credentials.
g. Deployment (Procfile, package.json)
- Procfile suggests possible Heroku deployment or AWS EB; package.json scripts orchestrate build and deploy.

##### Component Relationships and Data Flow
- User’s browser retrieves static React assets (frontend/public) from the CDN or S3.
- React app calls API Gateway endpoints.
- API Gateway routes requests to Lambda functions (functions/).
- Lambdas use services/secrets_manager.py to fetch credentials, then read/write to MongoDB (services/mongo.py).
- On a schedule or event bus trigger, the crawler Lambda runs, scrapes data according to data_sources configs, and writes new listings to MongoDB.
- A separate sync Lambda may aggregate or normalize data on demand.
- Auth flows either use Cognito or a custom solution reading auth/providers.json and custom_user_data.json.

##### Architectural Patterns and Principles
- Serverless microservices: each Lambda is a focused service (API, crawler, sync).
- Event-driven design: EventBridge (or CloudWatch Events) to decouple crawler/sync triggers from processing logic.
- Clear separation of concerns: Frontend vs. API vs. data ingestion vs. storage.
- Environment-based configuration and secrets management.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        Browser["📱 Browser (React SPA)"]:::client
    end

    %% API Layer
    subgraph "API Layer"
        APIGW["☁️ API Gateway"]:::aws
        Functions["🔷 Lambda Functions"]:::lambda
    end

    %% Worker Layer
    subgraph "Worker Layer"
        EventBus["☁️ EventBridge (Event Bus)"]:::aws
        Crawler["🔷 Crawler Lambda"]:::lambda
        SyncLambda["🔷 Sync Lambda"]:::lambda
    end

    %% Data Layer
    subgraph "Data Layer"
        MongoDB["🗄️ MongoDB Atlas"]:::db
        SecretsMgr["☁️ AWS Secrets Manager"]:::aws
    end

    %% Configuration Layer
    subgraph "Configuration Management"
        RootConfig["📄 root_config.json"]:::config
        Envs["📄 environments/*.json"]:::config
        Deployment["📄 Procfile / static.json / package.json / .env.default"]:::config
    end

    %% Connections
    Browser -->|"HTTPS"| APIGW
    APIGW -->|Invoke| Functions
    Functions -->|Uses| SecretsMgr
    SecretsMgr -->|Provides creds| Functions
    Functions -->|Read/Write| MongoDB

    EventBus -->|Trigger| Crawler
    Crawler -->|Scrape & Write| MongoDB
    Crawler -->|Reads configs| MongoDB
    EventBus -->|Trigger| SyncLambda
    SyncLambda -->|Read/Write| MongoDB

    %% Config flows
    RootConfig -->|Env settings| Browser
    Envs -->|Build & Deploy| Browser
    RootConfig -->|Env settings| Functions
    Envs -->|Env overrides| Functions
    RootConfig -->|Env settings| Crawler
    Envs -->|Env overrides| Crawler

    %% Click Events
    click Browser "https://github.com/johnny890122/house-rent-591/tree/main/frontend/"
    click Browser "https://github.com/johnny890122/house-rent-591/blob/main/frontend/public/index.html"
    click Browser "https://github.com/johnny890122/house-rent-591/blob/main/frontend/src/index.js"
    click Browser "https://github.com/johnny890122/house-rent-591/blob/main/frontend/src/App.js"
    click Functions "https://github.com/johnny890122/house-rent-591/tree/main/functions/"
    click Functions "https://github.com/johnny890122/house-rent-591/blob/main/functions/config.json"
    click Functions "https://github.com/johnny890122/house-rent-591/blob/main/package.json"
    click MongoDB "https://github.com/johnny890122/house-rent-591/blob/main/services/mongo.py"
    click MongoDB "https://github.com/johnny890122/house-rent-591/blob/main/data_sources/Cluster0/config.json"
    click MongoDB "https://github.com/johnny890122/house-rent-591/blob/main/auth/custom_user_data.json"
    click MongoDB "https://github.com/johnny890122/house-rent-591/blob/main/auth/providers.json"
    click SecretsMgr "https://github.com/johnny890122/house-rent-591/blob/main/services/secrets_manager.py"
    click Crawler "https://github.com/johnny890122/house-rent-591/tree/main/services/crawler/"
    click Crawler "https://github.com/johnny890122/house-rent-591/blob/main/services/crawler/app.py"
    click Crawler "https://github.com/johnny890122/house-rent-591/blob/main/services/crawler/template.yaml"
    click Crawler "https://github.com/johnny890122/house-rent-591/blob/main/services/crawler/samconfig.toml"
    click Crawler "https://github.com/johnny890122/house-rent-591/blob/main/services/crawler/requirements.txt"
    click EventBus "https://github.com/johnny890122/house-rent-591/blob/main/triggers/aws_event_bus.json"
    click SyncLambda "https://github.com/johnny890122/house-rent-591/blob/main/sync/config.json"
    click RootConfig "https://github.com/johnny890122/house-rent-591/blob/main/root_config.json"
    click Envs "https://github.com/johnny890122/house-rent-591/blob/main/environments/development.json"
    click Envs "https://github.com/johnny890122/house-rent-591/blob/main/environments/qa.json"
    click Envs "https://github.com/johnny890122/house-rent-591/blob/main/environments/production.json"
    click Envs "https://github.com/johnny890122/house-rent-591/blob/main/environments/testing.json"
    click Envs "https://github.com/johnny890122/house-rent-591/blob/main/environments/no-environment.json"
    click Deployment "https://github.com/johnny890122/house-rent-591/tree/main/Procfile"
    click Deployment "https://github.com/johnny890122/house-rent-591/blob/main/static.json"
    click Deployment "https://github.com/johnny890122/house-rent-591/blob/main/package.json"
    click Deployment "https://github.com/johnny890122/house-rent-591/blob/main/.env.default"

    %% Styles
    classDef client fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1;
    classDef lambda fill:#C8E6C9,stroke:#2E7D32,color:#2E7D32;
    classDef aws fill:#FFE0B2,stroke:#EF6C00,color:#EF6C00;
    classDef db fill:#D1C4E9,stroke:#512DA8,color:#512DA8;
    classDef config fill:#F0F4C3,stroke:#827717,color:#827717;
```
