A real-time CSV browser with role-based access control (RBAC) built with FastAPI and React.
./start.shThis launches a colorful interactive menu with 14 options:
- 🚀 Start Development/Production
- 🛑 Stop/Restart Containers
- 🔧 Rebuild/Clean
- 📊 View Logs/Status
- 💾 Database/Redis Shell
- 📚 Backup & Documentation
See INTERACTIVE_MENU_GUIDE.md for full details.
# Start development environment
make dev
# Or using docker-compose directly
docker-compose -f docker-compose.dev.yml up --build- Frontend: http://localhost:3000
- Backend API: http://localhost:8000/docs
- Default Login:
admin/admin123
For detailed Docker instructions, see DOCKER.md
- Authentication & Authorization: JWT-based authentication with role-based access control (Admin/User)
- Real-Time Updates: WebSocket integration for instant updates across all connected clients
- Admin Panel:
- Upload and delete CSV files
- Manage users (view and delete)
- View all uploaded files with metadata
- User Panel:
- Browse available CSV files
- View CSV contents in a table format
- Download CSV files
- Real-Time Sync: All clients receive instant updates when files are uploaded or deleted
- FastAPI - Modern Python web framework
- PostgreSQL - Relational database
- Redis - Caching and session management
- SQLAlchemy - ORM for database operations
- JWT - Token-based authentication
- WebSockets - Real-time communication
- React - UI library
- Vite - Build tool
- Tailwind CSS - Styling
- Axios - HTTP client
- React Router - Navigation
- Docker - Containerization
- Docker Compose - Multi-container orchestration
- Nginx - Production web server
csv-browser/
├── backend/
│ ├── app/
│ │ ├── api/ # API route handlers
│ │ │ ├── auth.py # Authentication endpoints
│ │ │ ├── admin.py # Admin-only endpoints
│ │ │ ├── csv.py # CSV file endpoints
│ │ │ └── websocket.py
│ │ ├── core/ # Core functionality
│ │ │ ├── config.py # Configuration
│ │ │ ├── database.py
│ │ │ ├── security.py # JWT & password hashing
│ │ │ └── deps.py # RBAC dependencies
│ │ ├── models/ # Database models
│ │ │ ├── user.py
│ │ │ └── csv_file.py
│ │ ├── schemas/ # Pydantic schemas
│ │ ├── services/ # Business logic
│ │ └── main.py # FastAPI application
│ ├── uploads/ # CSV file storage
│ ├── requirements.txt
│ └── init_db.py # Database initialization
├── frontend/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── contexts/ # React contexts (Auth)
│ │ ├── hooks/ # Custom hooks (WebSocket)
│ │ ├── pages/ # Page components
│ │ ├── services/ # API services
│ │ └── main.jsx
│ └── package.json
└── README.md
Prerequisites:
- Docker Engine 20.10+
- Docker Compose 2.0+
Quick Start:
# Development mode with hot-reload
make dev
# Production mode
make prod
# View logs
make logs
# Stop containers
make downSee DOCKER.md for detailed Docker instructions.
Prerequisites:
- Python 3.9+
- Node.js 18+
- PostgreSQL 12+
- Redis 6+ (optional)
Create a PostgreSQL database:
# Using psql
createdb csv_browser
# Or using PostgreSQL command line
psql -U postgres
CREATE DATABASE csv_browser;# Navigate to backend directory
cd backend
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Create .env file
cp .env.example .env
# Edit .env file with your database credentials
# DATABASE_URL=postgresql://username:password@localhost:5432/csv_browser
# Initialize database and create admin user
python init_db.py
# Run the backend server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000The backend will be running at http://localhost:8000
# Open a new terminal
# Navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Run the development server
npm run devThe frontend will be running at http://localhost:3000
After running init_db.py, an admin account is created:
- Username:
admin - Password:
admin123
Important: Change the admin password in production!
POST /api/auth/signup- Create new user accountPOST /api/auth/login- Login and get JWT token
GET /api/csv- Get all CSV filesGET /api/csv/{file_id}- Get CSV file content as JSONGET /api/csv/{file_id}/download- Download CSV file
POST /api/admin/csv/upload- Upload new CSV fileDELETE /api/admin/csv/{file_id}- Delete CSV fileGET /api/admin/users- Get all usersDELETE /api/admin/users/{user_id}- Delete user
WS /ws- WebSocket endpoint for real-time updates
- Sign Up: Create a new account at
/signup - Login: Sign in with your credentials
- Browse Files: View all available CSV files
- View Content: Click "View" to see the CSV data in a table
- Download: Download any CSV file for offline use
- Login: Use admin credentials
- Upload Files: Upload CSV files via the admin panel
- Manage Files: View and delete CSV files
- Manage Users: View and delete user accounts
- Real-Time Updates: All changes are broadcast to connected clients instantly
The application uses WebSockets to provide real-time updates:
- When an admin uploads a CSV file, all connected users see it immediately
- When an admin deletes a CSV file, it's removed from all users' views instantly
- No manual refresh required
- JWT Authentication: Secure token-based authentication
- Role-Based Access Control: Admin and User roles with different permissions
- Password Hashing: Passwords are hashed using bcrypt
- Protected Routes: Backend endpoints protected by FastAPI dependencies
- CORS Configuration: Configured for secure cross-origin requests
# Run with auto-reload
uvicorn app.main:app --reload
# Access API documentation
# Swagger UI: http://localhost:8000/docs
# ReDoc: http://localhost:8000/redoc# Run development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview-
Test Authentication:
- Sign up with a new user
- Login with admin credentials
- Verify JWT token is stored
-
Test CSV Upload (Admin):
- Upload a CSV file
- Verify it appears in the list
- Check real-time update in another browser tab
-
Test CSV Viewing (User):
- Login as regular user
- View CSV files
- Download a file
-
Test User Management (Admin):
- View all users
- Delete a user (except admin)
Database Connection Error:
- Verify PostgreSQL is running
- Check DATABASE_URL in .env file
- Ensure database exists
Import Errors:
- Activate virtual environment
- Reinstall dependencies:
pip install -r requirements.txt
WebSocket Connection Failed:
- Check if backend is running
- Verify CORS settings in main.py
API Connection Error:
- Verify backend is running on port 8000
- Check proxy configuration in vite.config.js
WebSocket Not Connecting:
- Check WebSocket URL in useWebSocket.js
- Verify backend WebSocket endpoint is accessible
- Set strong SECRET_KEY in environment variables
- Use production database credentials
- Enable HTTPS
- Configure proper CORS origins
- Use production ASGI server (uvicorn with workers)
- Build production bundle:
npm run build - Serve static files with nginx/Apache
- Configure environment variables
- Enable HTTPS
MIT License
Built as part of a full-stack development assignment.