A secure file-sharing web application built using FastAPI, PostgreSQL, and Cloudinary that supports role-based access. Ops users can upload files, while Client users can view and download shared files. The system includes JWT-based authentication, email verification, and secure download logging.
- 🔐 User Roles (
OpsandClient) - 📤 File Upload to Cloudinary (restricted to
Ops) - 📥 Download Access for
Clientusers - ✅ JWT Authentication
- 📧 Email Verification via Mailtrap or SMTP
- 📊 Download Logs for admin auditing
- 📂 Supports
.docx,.pptx,.xlsxfile types - 🛡️ Role-based Access Control (RBAC)
.
├── app/
│ ├── main.py
│ ├── models.py
│ ├── routes/
│ │ ├── client.py
│ │ └── files.py
│ ├── auth.py
│ ├── database.py
│ ├── schemas.py
│ └── utils.py
├── .env
├── .gitignore
├── requirements.txt
└── README.md
pip install -r requirements.txtCreate a .env file in the root of the project with the following values:
DATABASE_URL=postgresql://username:password@localhost:5432/your_db_nameSECRET_KEY=your_secret_key
EMAIL_FROM=your_mailtrap_email@example.com
EMAIL_PASSWORD=your_mailtrap_password
SMTP_SERVER=smtp.mailtrap.io
SMTP_PORT=587
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
🔑 Tip: Use Mailtrap for safe email testing and Cloudinary for file hosting.
Make sure PostgreSQL is running. Then run the following once to initialize:
from app.database import Base, engine
Base.metadata.create_all(bind=engine)Or add this snippet temporarily to main.py for auto-creation of tables on server start.
uvicorn app.main:app --reloadServer will start at: http://127.0.0.1:8000
POST /signup– Register user (clientorops)POST /login– Login and receive JWT token
| Endpoint | Method | Role | Description |
|---|---|---|---|
/upload |
POST | ops |
Upload file to Cloudinary |
/files |
GET | client |
List all available files |
/download/{file_id} |
GET | client |
Download specific file |
/logs |
GET | ops |
View all download logs |
/verify?email=email |
GET | any |
Verifies email from email link |
- Only
Opsusers can upload files. - Only
Clientusers can view and download. - Files are securely hosted on Cloudinary and linked through signed URLs.
- Download logs are recorded for every client file download.
- Email verification is required to access protected routes.
- Sign up via
/signup - You’ll receive a verification link via email
- Once verified, log in using
/loginto receive a JWT - Use the JWT in headers:
Authorization: Bearer <token>
- FastAPI
- SQLAlchemy + PostgreSQL
- Cloudinary SDK
- Mailtrap (SMTP)
- JWT Auth
- Pydantic
- Uvicorn