Skip to content

Sharath-shetty28/KnowledgeFlow-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

80 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ KnowledgeFlow AI ✨

A lightweight full-stack notes application built with PERN(React, Express, Node.js, and PostgreSQL), designed to be responsive and installable as a Progressive Web App (PWA). The application features JWT-based authentication, SSO login, and automatically sends a welcome email when users sign in.

The backend API is secured with rate limiting powered by Upstash Redis, ensuring reliability and protection against abuse. The project follows a clean, well-structured folder architecture to support scalability and long-term maintainability.

A CI/CD pipeline is integrated to automatically build, test, and deploy the application on every push, enabling fast and reliable releases with minimal manual intervention.


Key features

  • PERN Stack: Full-stack application using PostgreSQL, Express, React, and Node.js.
  • Responsive Design: Optimized for 100% of screen sizes, including mobile, tablet, and desktop.
  • PWA Installable: Progressive Web App installable with <1s load time for quick access.
  • JWT Authentication: Secures 100% of API endpoints with JSON Web Tokens.
  • SSO Login: Supports Google Sign-in for quick user sign-in.
  • Welcome Email: Automatically sends emails to 100% of new users upon signup.
  • API Rate Limiting: Limits API calls to 100 requests per 15 minutes per user using Upstash Redis.
  • Clean Folder Structure: Organized into <10 main folders, ensuring maintainable and scalable code.
  • CI/CD pipeline is integrated to automatically build, test, and deploy the application.

Demo

image image

Tech stack

  • Frontend: React (Vite)
  • Backend: Node.js, Express
  • Database: PostgreSQL(Neon DB)
  • Rate limiting & cache: Upstash Redis (serverless Redis)
  • Email Sending: Resend
  • CI/CD: Github Actions
  • Deployment: Render

Prerequisites

  • Node.js v16+
  • npm
  • Neon DB connection
  • Upstash Redis REST/URL & token (for rate limiting)

Quick start (development)

1. Clone repository

git clone https://github.com/<your-username>/KnowledgeFlowAI.git
cd KnowledgeFlowAI

2. Install dependencies

# from repo root (if repo has packages separated)
cd backend && npm install
cd frontend && npm install

3. Environment variables

Create .env files in backend/ and frontend/ as needed. Example variables for backend/.env:

PORT=5001
DATABASE_URL="url_of_noen_db"
UPSTASH_REDIS_REST_URL=https://usX1-web-..../
UPSTASH_REDIS_REST_TOKEN=your_upstash_token

Security note: Never commit .env files or secrets to git. Use repository secrets for CI/CD.

4. Run in development

# backend
cd backend
npm run dev

# frontend
cd frontend
npm run dev

Open http://localhost:5173 (Vite default) or port shown by your dev server.


Production build

  • Build frontend: cd frontend && npm run build and deploy the dist/build folder to your static host.
  • Deploy backend to your chosen provider, set environment variables and point frontend VITE_API_URL to the production backend.

Important implementation notes

Rate limiting with Upstash Redis

  • The backend uses a middleware that uses Upstash Redis REST API to store counters per IP or per API key.

  • A simple sliding-window or fixed-window algorithm is recommended:

    • increment the counter for key = rate_limit:${ip} on each request
    • set TTL to the window size (e.g., 60 seconds)
    • block requests when the counter exceeds the allowed requests
  • Upstash has a simple REST endpoint; use the official client or plain HTTP fetch for serverless environments.


Folder structure (clean, suggested)

notesboardapp/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ prisma/
β”‚   β”‚   β”‚   β”œβ”€β”€ migrations/
β”‚   β”‚   |   └── schema.prisma
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ server.js
β”‚   β”‚   β”œβ”€β”€ app.js           # app entry            
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   β”œβ”€β”€ note.route.js
β”‚   β”‚   |   └── user.route.js
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”‚   β”œβ”€β”€ note.controller.js
β”‚   β”‚   |   └── user.controller.js
β”‚   β”‚   β”œβ”€β”€ emails/
β”‚   β”‚   β”‚   └── emailHandlers.js
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ note.service.js
β”‚   β”‚   |   └── User.service.js
β”‚   β”‚   β”œβ”€β”€ repositories/
β”‚   β”‚   β”‚   β”œβ”€β”€ note.repo.js
β”‚   β”‚   |   └── User.repo.js
β”‚   β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”‚   β”œβ”€β”€ rateLimiter.js  # Upstash Redis integration
β”‚   β”‚   |   └── authUser.js
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   β”œβ”€β”€ db.js 
β”‚   β”‚   |   └── upstash.js
β”‚   β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”‚   └── generateToken.js
β”‚   └── .env

β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   β”œβ”€β”€ favicon.ico      # PWA manifest
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ main.jsx
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   β”œβ”€β”€ noteServices.js
β”‚   β”‚   β”œβ”€β”€ idb.js   #localstorage
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€  Navbar.jsx
β”‚   β”‚   β”‚   └──  NoteCard.jsx
β”‚   β”‚   β”‚   └── NotesNotFound.jsx
β”‚   β”‚   β”‚   └── RateLimitedUI.jsx
β”‚   β”‚   β”‚   └── GoogleSignInButton.jsx
β”‚   β”‚   β”‚   └── ProtectedRoute.jsx
β”‚   β”‚   β”œβ”€β”€ context/
β”‚   β”‚   β”‚   └── AuthContext.jsx
β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”œβ”€β”€ axios.js
β”‚   β”‚   β”‚   └── utils.js
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ CreatePage.jsx
β”‚   β”‚   β”‚   └── HomePage.jsx
β”‚   β”‚   β”‚   └── NoteDetailPage.jsx
β”‚   β”‚   β”‚   └── LoginPage.jsx
β”‚   β”‚   β”‚   └── SignUppage.jsx
β”‚   └── .env
β”œβ”€β”€ README.md       
└── .gitignore

API endpoints (suggested)

  • POST /api/auth/signup - create a new user

  • POST /api/auth/login - login to existing account

  • POST /api/auth/google-login - login using a Google account

  • GET /api/auth/is-auth - validating a user

  • POST /api/auth/logout - user logout

  • POST /api/notes - create note

  • GET /api/notes - list notes for user

  • PUT /api/notes/:id - update note

  • DELETE /api/notes/:id - delete note

Each endpoint should be protected by rate-limiter middleware.


Testing

  • Tested all controllers, services, and API endpoints using Postman to ensure correct functionality and responses.
  • Verified authentication flows, including JWT and SSO, and ensured API rate limits were properly enforced.
  • Checked email notifications for welcome emails on signup.

Deployment tips

  • Use environment secrets for DB, Upstash, and Brevo credentials.
  • Use HTTPS for the service worker and sync to function properly in production.

Contributing

  1. Fork the project
  2. Create a feature branch feature/your-feature
  3. Open a PR with a clear description

Releases

No releases published

Packages

 
 
 

Contributors

Languages