Skip to content

Latest commit

Β 

History

History
325 lines (248 loc) Β· 7.53 KB

File metadata and controls

325 lines (248 loc) Β· 7.53 KB

DevHub - Quick Reference Guide

πŸš€ Project Summary

DevHub is a full-stack web application for developers with authentication, profiles, AI chatbot, and more.


πŸ“š Tech Stack at a Glance

Frontend

  • React 18.3.1 - UI library
  • Vite 5.4.21 - Build tool
  • Tailwind CSS 3.4.15 - Styling
  • React Router DOM 6.28.0 - Routing
  • Lucide React - Icons

Backend

  • Node.js + Express 4.18.2 - Server
  • SQLite (Better-SQLite3) - Database
  • bcryptjs - Password hashing
  • Express-Session - Session management
  • OpenAI - AI chatbot
  • Multer - File uploads
  • Passport + Google OAuth - Authentication

πŸ“ Key File Locations

Frontend

src/
β”œβ”€β”€ components/        # Reusable UI components
β”‚   β”œβ”€β”€ Button.jsx
β”‚   β”œβ”€β”€ FormInput.jsx
β”‚   └── ErrorMessage.jsx
β”œβ”€β”€ pages/            # Page components
β”‚   β”œβ”€β”€ Home.jsx
β”‚   β”œβ”€β”€ Login.jsx
β”‚   β”œβ”€β”€ SignUp.jsx
β”‚   β”œβ”€β”€ Dashboard.jsx
β”‚   └── ProfileSettings.jsx
β”œβ”€β”€ context/          # React context
β”‚   └── AuthContext.jsx
β”œβ”€β”€ utils/            # Utilities
β”‚   β”œβ”€β”€ validation.js
β”‚   β”œβ”€β”€ constants.js
β”‚   └── helpers.js
└── App.jsx           # Root component

Backend

server/
β”œβ”€β”€ index.js          # Server entry point
β”œβ”€β”€ auth.js           # Auth routes
β”œβ”€β”€ profile.js        # Profile routes
β”œβ”€β”€ chatbot.js        # Chatbot routes
β”œβ”€β”€ history.js        # Navigation history routes
β”œβ”€β”€ db.js             # Database operations
β”œβ”€β”€ devhub.db         # SQLite database file
└── .env              # Environment variables

πŸ—„οΈ Database Schema

Tables

users - User accounts

  • id, email, username, password (hashed)
  • avatar_url, bio, location, social_links
  • created_at

sessions - User sessions

  • sid, sess, expired

navigation_history - User navigation

  • id, user_id, item_type, item_name, item_url, visited_at

chat_messages - Chatbot conversations

  • id, user_id, message, response, created_at

Database File: /home/pradhyum/project /Home page/server/devhub.db


πŸ” Environment Variables

Frontend (.env)

VITE_API_URL=http://localhost:5000

Backend (server/.env)

PORT=5000
FRONTEND_URL=http://localhost:5173
JWT_SECRET=your-secret-key-change-this
SESSION_SECRET=your-session-secret-change-this
GOOGLE_CLIENT_ID=your-google-client-id-here
GOOGLE_CLIENT_SECRET=your-google-client-secret-here
OPENAI_API_KEY=your-openai-api-key-here

⚑ Common Commands

Development

# Start backend (Terminal 1)
cd server
npm start

# Start frontend (Terminal 2)
npm run dev

Build

# Build frontend for production
npm run build

# Preview production build
npm run preview

Database

# View database contents
cd server
node view_db.js

# Backup database
cp devhub.db devhub.db.backup

🌐 API Endpoints

Authentication

  • POST /api/auth/signup - Create account
  • POST /api/auth/login - Login
  • GET /api/auth/verify - Verify session
  • POST /api/auth/logout - Logout

Profile

  • GET /api/profile - Get profile
  • PUT /api/profile - Update profile
  • POST /api/profile/avatar - Upload avatar

Chatbot

  • GET /api/chatbot/history - Get chat history
  • POST /api/chatbot/message - Send message

Navigation History

  • GET /api/history - Get history
  • POST /api/history - Add history entry

Health Check

  • GET /api/health - Server health

πŸ”§ Data Storage

Data Location
User accounts server/devhub.db β†’ users table
Sessions server/devhub.db β†’ sessions table
Chat history server/devhub.db β†’ chat_messages table
Navigation history server/devhub.db β†’ navigation_history table
User avatars public/uploads/avatars/
Config .env files

πŸ› Quick Troubleshooting

"Failed to fetch" Error

  1. Check backend is running: http://localhost:5000/api/health
  2. Verify VITE_API_URL in .env
  3. Check CORS settings in server/index.js

Session Not Persisting

  1. Ensure credentials: true in CORS config
  2. Check credentials: 'include' in fetch requests
  3. Verify session secret is set in server/.env

Database Errors

  1. Delete server/devhub.db and restart server
  2. Check migration code in server/db.js

Avatar Upload Fails

mkdir -p public/uploads/avatars

Chatbot Not Working

  1. Add OPENAI_API_KEY to server/.env
  2. Get key from https://platform.openai.com

πŸ“Š Code Quality Status

βœ… No Critical Errors Found

Checked:

  • βœ… All imports are valid
  • βœ… Database schema is correct
  • βœ… API routes are properly configured
  • βœ… Session management is working
  • βœ… CORS is configured correctly
  • βœ… File upload is configured
  • βœ… Environment variables are documented

Console.log Statements:

  • Present in server/profile.js for debugging profile updates
  • Present in server/db.js for database migration logging
  • Present in server/auth.js for session debugging
  • These are intentional and helpful for development

Recommendations:

  1. Consider using a proper logging library (Winston/Morgan) for production
  2. Remove or disable debug console.logs in production
  3. Add ESLint configuration file for code quality checks

πŸš€ Deployment Checklist

Before Deploying

  • Change all secrets in server/.env
  • Set NODE_ENV=production
  • Set cookie.secure = true in session config
  • Build frontend: npm run build
  • Update VITE_API_URL to production URL
  • Set up database backups
  • Configure proper CORS origins
  • Add rate limiting
  • Set up logging

Recommended Platforms

  • Frontend: Vercel, Netlify
  • Backend: Railway, Render, Heroku
  • Database: Consider PostgreSQL for production

πŸ“– Documentation Files

  1. DOCUMENTATION.md - Complete technical documentation
  2. README.md - Project overview
  3. walkthrough.md - Frontend simplification walkthrough
  4. implementation_plan.md - Simplification plan
  5. task.md - Task checklist

🎯 Key Features

Implemented

βœ… User registration and login
βœ… Session-based authentication
βœ… User profiles with avatars
βœ… Social links (GitHub, LinkedIn, Instagram, Website)
βœ… AI-powered chatbot
βœ… Navigation history tracking
βœ… Responsive design
βœ… Dark theme
βœ… Protected routes
βœ… Form validation

Configured (Requires API Keys)

βš™οΈ Google OAuth login
βš™οΈ OpenAI chatbot


πŸ’‘ Development Tips

Adding a New Page

  1. Create component in src/pages/
  2. Add route in src/App.jsx
  3. Wrap with <ProtectedRoute> if auth required

Adding a New API Endpoint

  1. Create route in appropriate file (server/auth.js, etc.)
  2. Add requireAuth middleware if auth required
  3. Update documentation

Adding a New Form

  1. Use FormInput component for fields
  2. Use Button component for submit
  3. Use validation functions from utils/validation.js
  4. Use ErrorMessage for error display

πŸ”— Useful Links


πŸ“ž Support

For issues or questions:

  1. Check DOCUMENTATION.md for detailed info
  2. Check troubleshooting section above
  3. Review server logs for errors
  4. Check browser console for frontend errors

Project Version: 1.0.0
Last Updated: November 26, 2024