# bsvalues/bsbcintelligentvalues architecture

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

- Interactive diagram: https://gitdiagram.com/bsvalues/bsbcintelligentvalues
- Repository: https://github.com/bsvalues/bsbcintelligentvalues

## Overview

##### Project Type and Purpose
- This is a full-stack, AI-powered real-estate analytics platform.
- It combines:
- A React/TypeScript frontend (“client/”) for interactive dashboards and visualizations.
- A Node/TypeScript backend (“server/”) providing REST endpoints and AI orchestration.
- Multiple Python FastAPI microservices (“microservices/”) for domain-specific logic (property, market, spatial, analytics).
- An Apache Airflow ETL pipeline (“etl/”) for real-time data ingestion.
- A PostgreSQL database (configured via Drizzle) for persistent storage.
- ML components for valuation and forecasting.

##### File Structure
- Top-level directories:
- client/ → React SPA with Vite, TypeScript, Shadcn UI, hooks, components.
- server/ → Express-style API controllers, middleware, services, AI connectors, routing.
- microservices/ → Python FastAPI services, each in its own subfolder (analytics, market, property, spatial).
- etl/ → Airflow configuration and DAGs for data pipelines.
- agents/ → In-house agent framework and implementations for AI orchestration.
- data/ → Vector memory persistence.
- shared/ → Shared schema definitions.
- Configuration and tooling:
- GitHub Actions workflows (.github/).
- Docker/Nix config (replit.nix).
- Testing harness (jest.config.cjs, tests/).
- Drizzle ORM config (drizzle.config.ts).

##### Extract Architecture Insights from README
- ETL pipeline reads from MLS, county, tax sources → Airflow → PostgreSQL.
- FastAPI microservices expose domain APIs on /docs.
- React UI calls both Node server and microservices (via server as API gateway).
- Machine Learning modules run inside analytics microservice and server-side services.
- Geospatial analysis uses Turf.js, Leaflet in the frontend.

a. Main Components
- Data Sources: External MLS, Tax, GIS, Weather feeds.
- ETL Layer: Apache Airflow (etl/dags).
- Primary Database: PostgreSQL (initialized via microservices/init_database.py).
- API Gateway / BFF: Node/TypeScript server (server/).
- Microservices Cluster: FastAPI apps (property, market, spatial, analytics).
- AI Orchestration: Custom Agent framework (agents/) invoked by server.
- Frontend: React SPA (client/) with visualization & mapping.
- Storage: Vector store (data/vector_memory.json), shared schemas.

b. Relationships & Data Flows
1. Data Sources → Airflow DAGs → PostgreSQL
2. Frontend ↔ API Gateway (server)
3. API Gateway ↔ Microservices (HTTP calls to each FastAPI service)
4. API Gateway ↔ Agent Framework (in-process calls into agents/)
5. Microservices ↔ PostgreSQL
6. Frontend ↔ Direct Microservices “/docs” endpoints for swagger if needed
7. Frontend ↔ WebSocket or polling (optional) for real-time updates

c. Architectural Patterns & Principles
- Microservices for separation of concerns and independent scaling
- BFF/Gateway pattern: Node server unifies calls and handles auth, caching, AI coordination
- ETL orchestration for data hygiene and scheduling
- Agent-based AI orchestration for complex multi-step workflows
- Shared schema module to enforce contract between services and frontend

d. Key Technologies & Libraries
- Frontend: React, TypeScript, Vite, Shadcn UI, Leaflet, Turf.js, Recharts, D3
- Backend Gateway: Node.js, TypeScript, Express-style routing, OpenAPI (server/openapi.ts)
- Microservices: Python, FastAPI, SQLAlchemy, mlflow (analytics), uvicorn
- ETL: Apache Airflow
- Database: PostgreSQL, Drizzle ORM
- AI/ML: scikit-learn, NumPy, Pandas, OpenAI connectors
- DevOps: GitHub Actions, Docker/Nix

##### Essential Details, Avoid Over-Simplification
- Don’t just lump “Backend” together—distinguish ETL, API Gateway, AI Agents, microservices.
- Shared schema and how both server and client import it.
- Airflow DAG → Microservices data handshake (if analytics microservice consumes preprocessed data).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Sources
    subgraph "External Data Sources" 
        direction TB
        MLS["MLS Feed"]:::external
        Tax["Tax Records"]:::external
        GIS["GIS Data"]:::external
        Weather["Weather API"]:::external
    end

    %% ETL Layer
    subgraph "ETL Layer" 
        direction TB
        Airflow["Apache Airflow"]:::process
        AirflowCfg["airflow.cfg"]:::config
        DAG["real_estate_data_pipeline.py"]:::process
    end

    %% Database
    subgraph "Database & Storage"
        direction TB
        Postgres["PostgreSQL"]:::database
        DrizzleCfg["drizzle.config.ts"]:::config
        VectorStore["Vector Store\n(vector_memory.json)"]:::storage
    end

    %% API Gateway & Agents
    subgraph "API Gateway & AI Agents"
        direction TB
        APIGateway["Node.js API Gateway\n(server/)"]:::api
        Agents["AI Agent Framework\n(agents/)"]:::agent
        SharedSchema["Shared Schema\n(shared/schema.ts)"]:::config
    end

    %% Microservices Cluster
    subgraph "FastAPI Microservices"
        direction TB
        CommonUtils["Common Utils & DB Init\n(microservices/common/)"]:::service
        InitDB["Init DB Script\n(microservices/init_database.py)"]:::service
        PropSvc["Property Service\n(app.py)"]:::service
        MarketSvc["Market Service\n(app.py)"]:::service
        SpatialSvc["Spatial Service\n(app.py)"]:::service
        AnalyticsSvc["Analytics Service\n(app.py)"]:::service
        Predictor["market_predictor.py"]:::service
        DataQuality["data_quality.py"]:::service
        MLflow["mlflow_tracker.py"]:::service
        Launch["Launcher Scripts\n(microservices/launch.py,\nrun_services.py,\ninit_and_run.py)"]:::service
    end

    %% Frontend
    subgraph "Frontend"
        direction TB
        Client["React SPA (client/)"]:::frontend
    end

    %% CI/CD and Testing
    subgraph "CI/CD & Testing"
        direction TB
        GHActions["GitHub Actions\n(.github/workflows/)"]:::tooling
        Jest["Jest Config\n(jest.config.cjs)"]:::tooling
        Tests["Integration Tests\n(tests/)"]:::tooling
    end

    %% Data flows
    MLS --> Airflow
    Tax --> Airflow
    GIS --> Airflow
    Weather --> Airflow

    Airflow -->|"loads data"| Postgres
    DAG --> Airflow

    Postgres --> CommonUtils
    CommonUtils --> InitDB
    InitDB --> Postgres

    APIGateway -->|queries| Postgres
    APIGateway -->|calls| PropSvc
    APIGateway -->|calls| MarketSvc
    APIGateway -->|calls| SpatialSvc
    APIGateway -->|calls| AnalyticsSvc
    APIGateway --> Agents

    PropSvc -->|reads/writes| Postgres
    MarketSvc -->|reads/writes| Postgres
    SpatialSvc -->|reads/writes| Postgres
    AnalyticsSvc -->|reads/writes| Postgres

    AnalyticsSvc --> Predictor
    AnalyticsSvc --> DataQuality
    AnalyticsSvc --> MLflow

    Client -->|REST API| APIGateway
    Client -->|Swagger Docs| PropSvc
    Client -->|Swagger Docs| MarketSvc
    Client -->|Swagger Docs| SpatialSvc
    Client -->|Swagger Docs| AnalyticsSvc

    Client -->|vector queries| VectorStore

    APIGateway --> SharedSchema
    Client --> SharedSchema

    GHActions -->|CI/CD pipelines| APIGateway
    GHActions --> Client
    Jest --> APIGateway
    Tests --> APIGateway

    Launch --> PropSvc
    Launch --> MarketSvc
    Launch --> SpatialSvc
    Launch --> AnalyticsSvc

    %% Click Events
    click Client "https://github.com/bsvalues/bsbcintelligentvalues/tree/main/client/"
    click APIGateway "https://github.com/bsvalues/bsbcintelligentvalues/tree/main/server/"
    click AirflowCfg "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/etl/airflow.cfg"
    click DAG "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/etl/dags/real_estate_data_pipeline.py"
    click PropSvc "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/microservices/property/app.py"
    click MarketSvc "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/microservices/market/app.py"
    click SpatialSvc "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/microservices/spatial/app.py"
    click AnalyticsSvc "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/microservices/analytics/app.py"
    click Predictor "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/microservices/analytics/market_predictor.py"
    click DataQuality "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/microservices/analytics/data_quality.py"
    click MLflow "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/microservices/analytics/mlflow_tracker.py"
    click CommonUtils "https://github.com/bsvalues/bsbcintelligentvalues/tree/main/microservices/common/"
    click InitDB "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/microservices/init_database.py"
    click Launch "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/microservices/launch.py"
    click Agents "https://github.com/bsvalues/bsbcintelligentvalues/tree/main/agents/"
    click VectorStore "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/data/vector_memory.json"
    click DrizzleCfg "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/drizzle.config.ts"
    click SharedSchema "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/shared/schema.ts"
    click GHActions "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/.github/workflows/ci.yml"
    click GHActions "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/.github/workflows/ci-cd.yml"
    click Jest "https://github.com/bsvalues/bsbcintelligentvalues/blob/main/jest.config.cjs"
    click Tests "https://github.com/bsvalues/bsbcintelligentvalues/tree/main/tests/"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef process fill:#ff9,stroke:#333,stroke-width:1px
    classDef database fill:#9ff,stroke:#333,stroke-width:1px
    classDef storage fill:#9f9,stroke:#333,stroke-width:1px
    classDef api fill:#f99,stroke:#333,stroke-width:1px
    classDef agent fill:#fcf,stroke:#333,stroke-width:1px
    classDef service fill:#cff,stroke:#333,stroke-width:1px
    classDef frontend fill:#ccf,stroke:#333,stroke-width:1px
    classDef config fill:#eee,stroke:#333,stroke-width:1px
    classDef tooling fill:#ddd,stroke:#333,stroke-width:1px
```
