A modern, secure file storage application that leverages Telegram's infrastructure for storing and managing files. Built with React (frontend) and Express.js (backend), featuring JWT authentication and a Progressive Web App (PWA) interface.
- Secure File Storage: Files are stored directly on Telegram's servers, ensuring high availability and security.
- User Authentication: JWT-based authentication with Telegram session management.
- File Management: Upload, download, and organize files in folders.
- Cross-Platform: Works on desktop and mobile via PWA.
- Real-time Sync: Offline support with IndexedDB for local caching.
- Responsive UI: Built with Tailwind CSS and Framer Motion for smooth animations.
- React 19 with TypeScript
- Vite for build tooling
- Tailwind CSS for styling
- React Router for navigation
- Framer Motion for animations
- IndexedDB (via idb-keyval) for offline storage
- PWA with Service Worker
- Express.js with Node.js
- Telegram API (gram.js) for file operations
- MongoDB with Mongoose for metadata storage
- JWT for authentication
- Multer for file uploads
- CORS and security middleware
- Node.js >= 18.0.0
- MongoDB database (local or cloud, e.g., MongoDB Atlas)
- Telegram API credentials (get from my.telegram.org)
-
Clone the repository:
git clone https://github.com/kiran-venugopal/TGramDrive.git cd TGramDrive -
Install dependencies:
npm install
-
Set up environment variables (see below).
Create a .env file in the server/ directory with the following variables:
PORT=3000
TELEGRAM_API_ID=your_telegram_api_id
TELEGRAM_API_HASH=your_telegram_api_hash
MONGODB_URI=mongodb://localhost:27017/tgramdrive
JWT_SECRET=your_jwt_secret_key
SESSION_ENCRYPTION_KEY=your_session_encryption_key- Go to my.telegram.org and log in with your phone number.
- Click on "Create application" (or use an existing one).
- Fill in the required fields (App title, Short name, etc.).
- Copy the
api_idandapi_hashto your.envfile.
Important: Use production API credentials, not test credentials. Test credentials (api_id starting with small numbers like 12345) only work with test phone numbers and have limitations. Production credentials allow login with any real Telegram phone number.
MONGODB_URI: Use your MongoDB connection string.JWT_SECRET: A strong, random string for signing JWT tokens.SESSION_ENCRYPTION_KEY: A 32-character key for encrypting Telegram sessions.
cd client
npm run devOpens at http://localhost:5173
cd server
npm run devRuns on http://localhost:3000 with nodemon for auto-restart.
-
Start the backend:
cd server npm run dev -
In a new terminal, start the frontend:
cd client npm run dev -
Open
http://localhost:5173in your browser.
The frontend will proxy API requests to the backend.
-
Build the entire project:
npm run build
This installs client dependencies, builds the frontend to
client/dist, and installs server dependencies. -
Start the production server:
npm start
Runs on
http://localhost:3000.
The backend is an Express.js server that acts as a bridge between the frontend and Telegram's API:
- Authentication Routes (
/api/auth): Handle user login/logout using Telegram sessions. - File Routes (
/api/files): Manage file operations (upload, download, list) via Telegram API. - Folder Routes (
/api/folders): Organize files into folders using MongoDB metadata. - Client Manager: Maintains Telegram client instances per user session.
- Database Models: Store user info, file/folder mappings in MongoDB.
- User uploads a file via frontend.
- Backend receives the file and uploads it to Telegram using the user's session.
- File metadata (Telegram message ID, size, etc.) is stored in MongoDB.
- Downloads retrieve the file from Telegram and stream it to the user.
- All routes are protected with JWT middleware.
- Telegram sessions are encrypted and stored securely.
- CORS is configured to allow the frontend origin.
-
Login Process:
- User enters phone number on frontend.
- Backend sends verification code via Telegram API.
- User enters code; backend creates a Telegram session.
- JWT token is issued and stored in HTTP-only cookies.
-
Session Management:
- Telegram sessions are encrypted and stored in the database.
- JWT tokens expire and require re-authentication.
-
Logout:
- Destroys the Telegram session and clears the JWT token.
POST /api/auth/send-code- Send verification codePOST /api/auth/verify-code- Verify code and loginPOST /api/auth/logout- Logout user
GET /api/files/drives- List user's Telegram chats/drivesGET /api/files/:driveId- List files in a drivePOST /api/files/upload- Upload a fileGET /api/files/download/:fileId- Download a file
GET /api/folders- List user's foldersPOST /api/folders- Create a folderPUT /api/folders/:id- Update folderDELETE /api/folders/:id- Delete folder
Problem: Login only works for one specific phone number.
Solution: This usually occurs when using test API credentials instead of production ones. Test API credentials (api_id around 12345) only work with test phone numbers. Get production API credentials from my.telegram.org as described above.
Problem: "PHONE_CODE_INVALID" error.
Solution: The verification code may have expired (5 minutes) or been entered incorrectly. Request a new code.
Problem: "SESSION_PASSWORD_NEEDED" error.
Solution: The account has 2FA enabled. Enter your password when prompted.
Problem: Files larger than 2GB fail to upload.
Solution: Telegram has a 2GB per file limit. Split large files or use compression.
Problem: Upload fails with network errors.
Solution: Check your internet connection and try again. The app has retry logic built-in.
Problem: "Invalid session" errors.
Solution: Clear browser cookies and local storage, then log in again.
Problem: MongoDB connection errors.
Solution: Verify your MONGODB_URI is correct and the database is accessible.
- Fork the repository.
- Create a feature branch:
git checkout -b feature-name - Make your changes and test thoroughly.
- Commit:
git commit -m 'Add feature' - Push:
git push origin feature-name - Open a Pull Request.
ISC License - see LICENSE file for details.
If you encounter issues:
- Check the Vercel function logs for backend errors.
- Ensure all environment variables are set correctly.
- Verify Telegram API credentials are valid.
For questions, open an issue on GitHub.