A modern, responsive commenting system with unlimited nesting levels, real-time interactions, and admin features. Built with React, FastAPI, and Docker.
- Unlimited Nested Comments: Support for infinite comment threading with visual hierarchy
- Real-time Interactions: Upvoting, editing, and deleting comments
- User Authentication: JWT-based authentication with role-based access control
- Admin Privileges: Admin users can moderate all comments
- Responsive Design: Optimized for desktop, tablet, and mobile devices
- Smooth Animations: Framer Motion animations for enhanced user experience
- Comment Sorting: Sort by date, upvotes, or number of replies
- Collapsible Threads: Expand/collapse comment threads for better navigation
- User Avatars: Dynamic avatar generation for users
- Time Formatting: Smart relative time display (e.g., "2h ago", "3d ago")
- Toast Notifications: Real-time feedback for user actions
- Loading States: Skeleton loading animations
- Error Handling: Comprehensive error handling and user feedback
- RESTful API: Well-documented FastAPI backend
- Database: SQLite with SQLAlchemy ORM
- Authentication: JWT tokens with bcrypt password hashing
- CORS Support: Configured for cross-origin requests
- Docker Support: Full containerization with Docker Compose
- Responsive UI: Tailwind CSS with custom animations
- Framework: FastAPI with SQLAlchemy ORM
- Database: SQLite (easily configurable for PostgreSQL/MySQL)
- Authentication: JWT with bcrypt password hashing
- API Documentation: Auto-generated OpenAPI/Swagger docs
- CORS: Configured for frontend integration
- Framework: React 18 with Vite
- Styling: Tailwind CSS with custom components
- Animations: Framer Motion for smooth transitions
- State Management: React Context API
- HTTP Client: Axios with interceptors
- Notifications: React Hot Toast
-- Users Table
CREATE TABLE users (
id VARCHAR PRIMARY KEY,
name VARCHAR NOT NULL,
email VARCHAR UNIQUE NOT NULL,
avatar VARCHAR,
hashed_password VARCHAR NOT NULL,
is_admin BOOLEAN DEFAULT FALSE,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Comments Table
CREATE TABLE comments (
id INTEGER PRIMARY KEY,
text VARCHAR NOT NULL,
upvotes INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
user_id VARCHAR REFERENCES users(id),
parent_id INTEGER REFERENCES comments(id)
);- Docker and Docker Compose
- Node.js 18+ (for local development)
- Python 3.11+ (for local development)
-
Clone the repository
git clone <repository-url> cd nested-comments-system
-
Start the application
docker-compose up --build
-
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
python seed_data.py
uvicorn main:app --reloadcd frontend
npm install
npm run dev- Admin User:
- Email:
admin@example.com - Password:
admin123
- Email:
- Regular User:
- Email:
liam.joshi.1@example.com - Password:
password123
- Email:
- Users can register with any email
- Admin users can be created through the API endpoint
/admin/create-admin - Password requirements: Minimum 6 characters
POST /auth/register- Register a new userPOST /auth/login- Login userGET /auth/me- Get current user info
GET /comments- Get all comments with sorting optionsPOST /comments- Create a new commentPUT /comments/{id}- Update a commentDELETE /comments/{id}- Delete a commentPUT /comments/{id}/upvote- Upvote a comment
POST /admin/create-admin- Create admin user (admin only)
sort_by:created_at,upvotes,repliesorder:asc,desc
- Clean Interface: Minimalist design with focus on content
- Visual Hierarchy: Clear nesting with indentation and borders
- Responsive Layout: Mobile-first design approach
- Accessibility: Keyboard navigation and screen reader support
- Page Transitions: Smooth fade-in animations
- Comment Interactions: Hover effects and micro-interactions
- Loading States: Skeleton loaders and progress indicators
- Toast Notifications: Non-intrusive feedback system
- Primary: Blue gradient (#3b82f6 to #1e40af)
- Success: Green (#10b981)
- Warning: Yellow (#f59e0b)
- Error: Red (#ef4444)
- Neutral: Gray scale for text and backgrounds
nested-comments-system/
βββ backend/
β βββ main.py # FastAPI application
β βββ seed_data.py # Database seeding
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Backend container
βββ frontend/
β βββ src/
β β βββ components/ # React components
β β βββ contexts/ # React contexts
β β βββ services/ # API services
β β βββ App.jsx # Main application
β βββ package.json # Node dependencies
β βββ Dockerfile # Frontend container
βββ docker-compose.yml # Development setup
βββ docker-compose.prod.yml # Production setup
βββ README.md # This file
- main.py: FastAPI application with all routes
- seed_data.py: Database seeding with sample data
- Models: User and Comment SQLAlchemy models
- Authentication: JWT token handling and password hashing
- App.jsx: Main application component
- AuthPage.jsx: Login/register interface
- CommentSystem.jsx: Main comment interface
- CommentItem.jsx: Individual comment component
- CommentForm.jsx: Comment creation/editing form
- SortControls.jsx: Comment sorting interface
- AuthContext: User authentication state
- CommentContext: Comments and interactions state
- Local Storage: Persistent authentication tokens
docker-compose up --build -d
# View logs
docker-compose logs -f
# Stop services
docker-compose downCreate a .env file for production:
SECRET_KEY=your-secret-key-here
DATABASE_URL=sqlite:///./comments.db
CORS_ORIGINS=http://localhost:3000,https://yourdomain.com-
Authentication Flow
- Register new user
- Login with credentials
- Logout functionality
-
Comment Operations
- Create top-level comments
- Reply to comments (nesting)
- Edit own comments
- Delete own comments
- Upvote comments
-
Admin Features
- Admin login
- Delete any comment
- Create admin users
-
UI/UX Testing
- Responsive design on different screen sizes
- Animation smoothness
- Loading states
- Error handling
Use the interactive API documentation at http://localhost:8000/docs to test endpoints.
- Database: SQLite (default), easily configurable for PostgreSQL/MySQL
- Authentication: JWT with configurable expiration
- CORS: Configurable origins for security
- Logging: Structured logging for debugging
- API Base URL: Configurable in
src/services/api.js - Theme: Customizable in
tailwind.config.js - Animations: Configurable in component files
- Database Indexing: Proper indexes on foreign keys
- Query Optimization: Efficient comment tree building
- Caching: Consider Redis for session management
- Rate Limiting: Implement for production use
- Code Splitting: Lazy loading for better performance
- Image Optimization: WebP format for avatars
- Bundle Size: Tree shaking and minification
- Caching: Service worker for offline support
- Password Hashing: bcrypt with salt rounds
- JWT Tokens: Secure token generation and validation
- Session Management: Automatic token refresh
- Input Validation: Pydantic models for data validation
- CORS Configuration: Restricted origins
- Rate Limiting: Prevent abuse (implement in production)
- Input Sanitization: XSS protection
- SQL Injection: SQLAlchemy ORM protection
-
Database Connection Issues
# Check if database file exists ls -la backend/comments.db # Recreate database rm backend/comments.db python backend/seed_data.py
-
Frontend Build Issues
# Clear node modules and reinstall rm -rf frontend/node_modules cd frontend && npm install
-
Docker Issues
# Clean Docker cache docker system prune -a # Rebuild containers docker-compose down docker-compose up --build
Enable debug logging:
# In backend/main.py
import logging
logging.basicConfig(level=logging.DEBUG)- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- FastAPI for the excellent Python web framework
- React for the powerful frontend library
- Tailwind CSS for the utility-first CSS framework
- Framer Motion for smooth animations
- Lucide React for beautiful icons
Built with β€οΈ for Inter IIT Tech Meet 14.0 Dev Team Task