# snowflake-labs/sfguide-getting-started-with-cortex-analyst architecture

> Architecture diagram of the GitHub repository snowflake-labs/sfguide-getting-started-with-cortex-analyst, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst
- Repository: https://github.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst

## Overview

##### Project type and purpose
- This repository is a demo/quickstart for “Cortex Analyst” working on top of Snowflake. It provides sample Python scripts (for streaming and batch demos), SQL DDL/DML scripts to create and load Snowflake objects, and sample CSV data for ingestion. The goal is to show how to load data into Snowflake, configure Cortex Analyst, and run simple analytics.

##### File structure
- Top‑level demo scripts:
- cortex_analyst_sis_demo_app.py (batch or “SIS” demo)
- cortex_analyst_streaming_demo.py (streaming demo)
- SQL scripts for Snowflake schema & data setup:
- create_snowflake_objects.sql (DDL: tables, streams, tasks)
- cortex_search_create.sql (perhaps search/index setup)
- load_data.sql (ingests CSV files)
- data/ folder with sample CSVs (daily_revenue.csv, product.csv, region.csv)
- revenue_timeseries.yaml (configuration for Cortex timeseries analytics)
- requirements.txt (Python dependencies)

##### README for insights
- Confirms this is a Quickstart guide: you first run the SQL to set up schema & load data, then run the Python demos to connect to Snowflake (and Cortex Analyst), and execute analytics/stream processing.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Local Developer Workstation
    subgraph "Local Developer Workstation" 
        direction TB
        req["requirements.txt"]:::local
        SQL_SETUP["create_snowflake_objects.sql"]:::document
        SQL_SEARCH["cortex_search_create.sql"]:::document
        SQL_LOAD["load_data.sql"]:::document
        CSV1["daily_revenue.csv"]:::data
        CSV2["product.csv"]:::data
        CSV3["region.csv"]:::data
        YAML["revenue_timeseries.yaml"]:::document
        BatchApp["cortex_analyst_sis_demo_app.py"]:::process
        StreamApp["cortex_analyst_streaming_demo.py"]:::process
    end

    %% Snowflake Cloud Platform
    subgraph "Snowflake Cloud Platform" 
        direction TB
        Tables["Snowflake Tables"]:::snowflake
        Streams["Snowflake Streams"]:::snowflake
        Tasks["Snowflake Tasks"]:::snowflake
    end

    %% Cortex Analyst Service
    Cortex["Cortex Analyst Service"]:::external

    %% Data Flow: Batch/ELT
    CSV1 -->|reads| SQL_LOAD
    CSV2 -->|reads| SQL_LOAD
    CSV3 -->|reads| SQL_LOAD
    SQL_LOAD -->|INSERT via snowflake-connector| Tables
    SQL_SETUP -->|DDL: create tables, streams, tasks| Tables
    SQL_SETUP --> Streams
    SQL_SETUP --> Tasks
    SQL_SEARCH -->|create indexes| Tables

    %% Python Demo Apps
    BatchApp -->|queries & inserts| Tables
    BatchApp -->|uses config| YAML
    StreamApp -->|reads CDC| Streams
    StreamApp -->|invokes tasks| Tasks
    StreamApp -->|writes new events| Tables

    %% Cortex Calls
    BatchApp -->|POST /timeseries| Cortex
    StreamApp -->|POST /timeseries| Cortex
    Cortex -->|returns results| BatchApp
    Cortex -->|returns results| StreamApp

    %% Styling
    classDef local fill:#e5ffe5,stroke:#333
    classDef snowflake fill:#e5f0ff,stroke:#333
    classDef external fill:#ffe5cc,stroke:#333
    classDef document fill:#fff2cc,stroke:#333,stroke-dasharray: 2 2
    classDef data fill:#f0fff0,stroke:#333,stroke-dasharray: 2 2
    classDef process fill:#e0ffe0,stroke:#333

    %% Click Events
    click BatchApp "https://github.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst/blob/main/cortex_analyst_sis_demo_app.py"
    click StreamApp "https://github.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst/blob/main/cortex_analyst_streaming_demo.py"
    click SQL_SETUP "https://github.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst/blob/main/create_snowflake_objects.sql"
    click SQL_SEARCH "https://github.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst/blob/main/cortex_search_create.sql"
    click SQL_LOAD "https://github.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst/blob/main/load_data.sql"
    click CSV1 "https://github.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst/blob/main/data/daily_revenue.csv"
    click CSV2 "https://github.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst/blob/main/data/product.csv"
    click CSV3 "https://github.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst/blob/main/data/region.csv"
    click YAML "https://github.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst/blob/main/revenue_timeseries.yaml"
    click req "https://github.com/snowflake-labs/sfguide-getting-started-with-cortex-analyst/blob/main/requirements.txt"
```
