Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

βš™οΈ Dynamic Filter System

A full-stack web application built for the Nomination Task Challenge to showcase backend efficiency, frontend responsiveness, and intelligent data handling.

This project demonstrates how to design a Dynamic Filtering System using FastAPI, PostgreSQL, Redis, and Next.js (React) β€” capable of handling 10,000+ records, supporting real-time dependent filters, and offering a fast, responsive UI.


πŸš€ Features

🧠 Intelligent Filtering

  • Supports filtering on all 50+ columns.
  • Dependent filter options: When a user applies one filter (e.g., price range), all other filters update dynamically to reflect valid options.
  • Realistic data generation with 10,000 records.

⚑ Performance Optimizations

  • PostgreSQL for structured and indexed data.
  • Redis caching to store and serve repeated queries efficiently.
  • Optimized query builder for dynamic WHERE clauses.

🧩 Backend (FastAPI)

  • RESTful APIs built with FastAPI.
  • primary endpoints:
    1. GET /data β†’ Returns filtered and paginated records.
    2. GET /filters β†’ Returns dynamic filter options based on current filters.
  • Scalable structure with clean modular code and dependency injection.

🎨 Frontend (Next.js + React)

  • Responsive and interactive UI built with Next.js and TailwindCSS.
  • DataTable with pagination, sorting, and search.
  • Dynamic filter panel that updates intelligently.
  • Smooth loading and transition effects with Framer Motion.

🧰 Tech Stack

Layer Technology
Frontend Next.js (React), TailwindCSS, Framer Motion
Backend FastAPI (Python)
Database PostgreSQL
Caching Redis

πŸ—‚οΈ Project Structure

πŸ“¦ Dynamic_filter_system
β”‚
β”œβ”€β”€ πŸ“ Backend
β”‚   β”œβ”€β”€ πŸ“ app
β”‚   β”‚   β”œβ”€β”€ πŸ“ api
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“ routes
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ data.py
β”‚   β”‚   β”‚   β”‚   └── filters.py
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   └── router.py
β”‚   β”‚   β”œβ”€β”€ πŸ“ core
β”‚   β”‚   β”‚   β”œβ”€β”€ config.py
β”‚   β”‚   β”‚   └── constants.py
β”‚   β”‚   β”œβ”€β”€ πŸ“ db
β”‚   β”‚   β”‚   └── connection.py
β”‚   β”‚   β”œβ”€β”€ πŸ“ middleware
β”‚   β”‚   β”‚   └── cors.py
β”‚   β”‚   β”œβ”€β”€ πŸ“ utils
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   β”œβ”€β”€ cache.py
β”‚   β”‚   β”‚   β”œβ”€β”€ json_encoder.py
β”‚   β”‚   β”‚   └── query_builder.py
β”‚   β”‚   └── main.py
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ πŸ“ frontend
|   β”œβ”€β”€ πŸ“ types
|   β”‚   β”œβ”€β”€ routes.d.ts
|   β”‚   └── validator.ts
|   β”œβ”€β”€ πŸ“ components
|   β”‚   β”œβ”€β”€ DataTable.js
|   β”‚   └── FilterPanel.js
|   β”œβ”€β”€ πŸ“ public
|   β”‚   β”œβ”€β”€ favicon.ico
|   β”‚   β”œβ”€β”€ file.svg
|   β”‚   β”œβ”€β”€ globe.svg
|   β”‚   β”œβ”€β”€ next.svg
|   β”‚   β”œβ”€β”€ vercel.svg
|   β”‚   └── window.svg
|   β”œβ”€β”€ πŸ“ src
|   β”‚   β”œβ”€β”€ πŸ“ pages
|   β”‚   β”‚   β”œβ”€β”€ πŸ“ api
|   β”‚   β”‚   β”‚   └── Dynamic_filter_sys_API.js
|   β”‚   β”‚   β”œβ”€β”€ _app.js
|   β”‚   β”‚   β”œβ”€β”€ _document.js
|   β”‚   β”‚   └── index.js
|   β”‚   └── πŸ“ styles
|   β”‚       └── globals.css
|   |
|   β”œβ”€β”€ .env.local.example
|   β”œβ”€β”€ .gitignore
|   β”œβ”€β”€ jsconfig.json
|   β”œβ”€β”€ next.config.mjs
|   β”œβ”€β”€ package-lock.json
|   β”œβ”€β”€ package.json
|   β”œβ”€β”€ postcss.config.mjs
|   └── README.md
|
β”œβ”€β”€ .env.example
β”œβ”€β”€ .gitignore
└── README.md

βš™οΈ Setup Instructions

πŸ—„οΈ Backend Setup (FastAPI)

  1. Clone the repository:

    git clone https://github.com/Jethva-Parthiv/Dynamic_Filter_System.git
    cd Dynamic_Filter_System/backend
    
  2. Create a virtual environment and install dependencies:

    python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt

  3. Configure environment variables in a .env file:

    DATABASE_URL=postgresql://user:password@localhost:5432/filters_db REDIS_URL=redis://localhost:6379

🧩 Database & Data Generation

Before running the backend, set up your PostgreSQL database and populate it with 10,000 records.

  1. Create Database psql -U youruser -d postgres;

    Once inside, create your project database:

    CREATE DATABASE your_DB; \q

  2. Run Schema

    Navigate to the backend/Data_Generation folder and run the schema:

    cd backend/Data_Generation psql -U youruser -d yourdb -f schema.sql

  3. Generate Data

    Update the credentials in data_gen.py:

    conn = psycopg2.connect(dbname='yourdb', user='youruser', password='yourpass', host='localhost', port=5432)

    Then run:

    python data_gen.py

This will insert 10,000+ random car records into your database in batches of 1,000.

  1. Run the FastAPI server:

    uvicorn app.main:app --reload

βš™οΈ Redis Connection Setup

Redis will be used for caching, rate limiting, or temporary filter results β€” boosting your API speed.

Install Redis & Dependencies

If you don’t have it installed:

πŸͺŸ Windows (via WSL or Scoop) sudo apt update && sudo apt install redis-server sudo service redis-server start

or

scoop install redis
redis-server

🐧 Linux / macOS sudo apt install redis-server sudo systemctl enable redis-server sudo systemctl start redis-server

Verify Redis Connection

Run in terminal: redis-cli ping

Expected output: PONG

Configure environment variable for Redis in a .env file:

REDIS_URL=redis://localhost:<port>
# Example
    REDIS_URL=redis://localhost:6379

🧭 Frontend Setup (Next.js)

1. Change to the frontend directory
```bash
cd ../frontend
```

2. Install dependencies
```bash
npm install
```

3. Create .env.local (example)
```env
NEXT_PUBLIC_API_URL=http://localhost:8000
```

4. Run the development server
```bash
npm run dev
```

=============================================================================

πŸ“Š API Endpoints

1️⃣ /data

  • Method: GET
  • Description: Fetch filtered and paginated data.
  • Query Parameters:
    • filters: JSON string of filters
    • limit: Number of records per page
    • offset: Starting record index
  • Example:
    GET /data?filters={"brand":"Toyota","fuel_type":"Petrol"}&limit=20&offset=0
    

2️⃣ /filters

  • Method: GET
  • Description: Fetch dynamic filter options based on currently applied filters.
  • Example:
    GET /filters?filters={"price_range":[10000,30000]}
    

πŸ’Ύ Caching Logic (Redis)

  • Each unique filter combination is hashed and stored in Redis.
  • Repeated requests serve instantly from cache.
  • Automatic cache invalidation when database updates occur.

🌐 Frontend Highlights

  • Real-time filter updates using React hooks and memoization.
  • Responsive DataTable with pagination and sorting.
  • Smooth animations with Framer Motion.

🧠 Learning Outcomes

  • Efficient query building and dynamic data handling.
  • Full-stack integration between FastAPI and Next.js.
  • Scalable architecture design with caching and pagination.
  • Clean, modular, and production-ready codebase.

πŸ† Project Showcase

  • Goal: Demonstrate a real-world scalable filtering system for large datasets.
  • Keywords: FastAPI Β· PostgreSQL Β· Redis Β· Next.js Β· Dynamic Filters Β· Pagination Β· Performance Optimization

πŸ‘¨β€πŸ’» Author

  • Name: Parthiv Jethva
  • Role: Computer Science Student Β· Backend & Full-Stack Developer - Python
  • GitHub Profile: Jethva-Parthiv
  • Contact: Email

πŸ“« Get in Touch

  • Feel free to reach out for collaborations or inquiries!

About

πŸš€ Dynamic Filter System β€” A full-stack project demonstrating intelligent and scalable dynamic filtering with FastAPI, PostgreSQL, Redis caching, and Next.js. Features include dependent filters, pagination, responsive UI, and optimized backend queries for handling large datasets.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages