# Tech Stack Selector -- Postgres + Neo4j Knowledge Graph This project provides a **price-focused technology stack selector**.\ It uses a **Postgres relational database** for storing technologies and pricing, and builds a **Neo4j knowledge graph** to support advanced queries like: > *"Show me all backend, frontend, and cloud technologies that fit a > \$10-\$50 budget."* ------------------------------------------------------------------------ ## πŸ“Œ 1. Database Schema (Postgres) The schema is designed to ensure **data integrity** and **price-tier-driven recommendations**. ### Core Tables - **`price_tiers`** -- Foundation table for price categories (tiers like *Free*, *Low*, *Medium*, *Enterprise*). - **Category-Specific Tables** -- Each technology domain has its own table: - `frontend_technologies` - `backend_technologies` - `cloud_technologies` - `database_technologies` - `testing_technologies` - `mobile_technologies` - `devops_technologies` - `ai_ml_technologies` - **`tools`** -- Central table for business/productivity tools with: - `name`, `category`, `description` - `primary_use_cases` - `popularity_score` - Pricing fields: `monthly_cost_usd`, `setup_cost_usd`, `license_cost_usd`, `training_cost_usd`, `total_cost_of_ownership_score` - Foreign key to `price_tiers` All category tables reference `price_tiers(id)` ensuring **referential integrity**. ------------------------------------------------------------------------ ## 🧱 2. Migration Files Your migrations are structured as follows: 1. **`001_schema.sql`** -- Creates all tables, constraints, indexes. 2. **`002_tools_migration.sql`** -- Adds `tools` table and full-text search indexes. 3. **`003_tools_pricing_migration.sql`** -- Adds cost-related fields to `tools` and links to `price_tiers`. Run them in order: ``` bash psql -U -d -f sql/001_schema.sql psql -U -d -f sql/002_tools_migration.sql psql -U -d -f sql/003_tools_pricing_migration.sql ``` ------------------------------------------------------------------------ ## πŸ•ΈοΈ 3. Neo4j Knowledge Graph Design We map relational data into a graph for semantic querying. ### Node Types - **Technology** β†’ `{name, category, description, popularity_score}` - **Category** β†’ `{name}` - **PriceTier** β†’ `{tier_name, min_price, max_price}` ### Relationships - `(Technology)-[:BELONGS_TO]->(Category)` - `(Technology)-[:HAS_PRICE_TIER]->(PriceTier)` Example graph: (:Technology {name:"NodeJS"})-[:BELONGS_TO]->(:Category {name:"Backend"}) (:Technology {name:"NodeJS"})-[:HAS_PRICE_TIER]->(:PriceTier {tier_name:"Medium"}) ------------------------------------------------------------------------ ## πŸ”„ 4. ETL (Extract β†’ Transform β†’ Load) Use a Python ETL script to pull from Postgres and load into Neo4j. ### Example Script ``` python from neo4j import GraphDatabase import psycopg2 pg_conn = psycopg2.connect(host="localhost", database="techstack", user="user", password="pass") pg_cur = pg_conn.cursor() driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password")) def insert_data(tx, tech_name, category, price_tier): tx.run(""" MERGE (c:Category {name: $category}) MERGE (t:Technology {name: $tech}) ON CREATE SET t.category = $category MERGE (p:PriceTier {tier_name: $price_tier}) MERGE (t)-[:BELONGS_TO]->(c) MERGE (t)-[:HAS_PRICE_TIER]->(p) """, tech=tech_name, category=category, price_tier=price_tier) pg_cur.execute("SELECT name, category, tier_name FROM tools JOIN price_tiers ON price_tiers.id = tools.price_tier_id") rows = pg_cur.fetchall() with driver.session() as session: for name, category, tier in rows: session.write_transaction(insert_data, name, category, tier) pg_conn.close() driver.close() ``` ------------------------------------------------------------------------ ## πŸ” 5. Querying the Knowledge Graph ### Find technologies in a price range: ``` cypher MATCH (t:Technology)-[:HAS_PRICE_TIER]->(p:PriceTier) WHERE p.min_price >= 10 AND p.max_price <= 50 RETURN t.name, p.tier_name ORDER BY p.min_price ASC ``` ### Find technologies for a specific domain: ``` cypher MATCH (t:Technology)-[:BELONGS_TO]->(c:Category) WHERE c.name = "Backend" RETURN t.name, t.popularity_score ORDER BY t.popularity_score DESC ``` ------------------------------------------------------------------------ ## πŸ—‚οΈ 6. Suggested Project Structure techstack-selector/ β”œβ”€β”€ sql/ β”‚ β”œβ”€β”€ 001_schema.sql β”‚ β”œβ”€β”€ 002_tools_migration.sql β”‚ └── 003_tools_pricing_migration.sql β”œβ”€β”€ etl/ β”‚ └── postgres_to_neo4j.py β”œβ”€β”€ api/ β”‚ └── app.py (Flask/FastAPI server for exposing queries) β”œβ”€β”€ docs/ β”‚ └── README.md ------------------------------------------------------------------------ ## πŸš€ 7. API Layer (Optional) You can wrap Neo4j queries inside a REST/GraphQL API. Example response: ``` json { "price_range": [10, 50], "technologies": [ {"name": "NodeJS", "category": "Backend", "tier": "Medium"}, {"name": "React", "category": "Frontend", "tier": "Medium"} ] } ``` ------------------------------------------------------------------------ ## βœ… Summary This README covers: - Postgres schema with pricing and foreign keys - Migration execution steps - Neo4j graph model - Python ETL script - Example Cypher queries - Suggested folder structure This setup enables **price-driven technology recommendations** with a clear path for building APIs and AI-powered analytics.