- Overview
- Related Projects
- Features
- API Documentation
- API Endpoints
- Technology Stack
- Installation
- Deployment
- Contributing
- Contact
The Egypt Metro Backend API provides a robust infrastructure for managing and operating the Egypt Metro platform. It serves as the central system for user authentication, station management, trip details, ticketing, subscriptions, payments, and real-time train information. The API is designed to support millions of daily passengers with high reliability and scalability.
- Frontend (Mobile App): https://github.com/Egypt-Metro/frontend - Flutter-based mobile application
- AI Models: https://github.com/Egypt-Metro/ai - Machine learning models for crowd management.
User Authentication and Profile Management
: Secure user registration, login, and profile management.Station Management
: Nearest station lookup and station list.Trip Details
: Provide trip route, number of stations, ticket price, and average time.Real-Time Train Details
: Provide real-time schedule data, including arrival times and crowd data for each car in train.User Profiles
: Manage user accounts, including registration, login, subscription types, and payment options.Online Ticketing
: Buy and generate tickets online with QR codes for easy scanning at metro gates.Online Subscription
: Subscribe to or renew metro plans online.Payment Options
: Users can pay via credit/debit cards, e-wallets, or other payment gateways.Chatbot Support
: 24/7 AI-powered chatbot to answer questions, guide users, and connect with customer service.Real-Time Updates
: Supports extensions for real-time data (e.g., train locations, crowd levels).
Admin Dashboard
: Track sales and revenue for each line and station in real-time.Fault Reporting
: Allow admins to view, respond to, and track the status of user-reported issues.
Interactive API documentation is available at:
- Swagger UI: https://backend-54v5.onrender.com/swagger/
- ReDoc: https://backend-54v5.onrender.com/redoc/
- Swagger JSON: https://backend-54v5.onrender.com/swagger.json
- API Schema: https://backend-54v5.onrender.com/api/schema/
- API Docs: https://backend-54v5.onrender.com/api/docs/
- Backend Framework: Django
- API: Django REST Framework
- Database: PostgreSQL (hosted on Render)
- Authentication: JWT (JSON Web Token), Django Allauth
- Documentation: Swagger (DRF-YASG), ReDoc
- Profiling: Silk (development only)
- Real-time Features: WebSockets (optional, for live updates like train location or crowds)
The API provides 60 endpoints across 9 categories. Below is a summary of the main endpoints:
Method | Endpoint | Description |
---|---|---|
GET | /api/users/login/ |
User authentication |
GET | /api/users/register/ |
New user registration |
GET | /api/users/profile/ |
Get user profile |
GET | /api/users/profile/update/ |
Update user profile |
GET | /api/users/token/refresh/ |
Refresh authentication token |
GET | /api/auth/password/reset/request/ |
Request password reset |
GET | /api/auth/password/reset/confirm/ |
Confirm password reset |
GET | /api/auth/password/reset/validate/ |
Validate password reset token |
Method | Endpoint | Description |
---|---|---|
GET | /api/stations/list/ |
List all stations |
GET | /api/stations/nearest/ |
Find nearest stations |
GET | /api/stations/trip/{start_station_id}/{end_station_id}/ |
Get trip details between stations |
Method | Endpoint | Description |
---|---|---|
GET | /api/trains/ |
List all trains |
GET | /api/trains/{train_id}/ |
Get train details |
GET | /api/trains/get-schedules/ |
Get train schedules |
GET | /api/trains/{train_id}/crowd-status/ |
Get crowd status for a train |
GET | /api/trains/{train_id}/update-crowd-level/ |
Update crowd level information |
GET | /api/trains/{train_id}/update-location/ |
Update train location |
GET | /api/trains/{train_id}/station-schedule/ |
Get station schedule for a train |
GET | /api/trains/debug/ |
Debug information for trains |
Method | Endpoint | Description |
---|---|---|
GET | /api/routes/find/ |
Find optimal routes between stations |
Method | Endpoint | Description |
---|---|---|
GET | /api/tickets/ |
List user tickets |
GET | /api/tickets/{ticket_id}/ |
Get ticket details |
GET | /api/tickets/purchase-with-wallet/ |
Purchase ticket using wallet |
GET | /api/tickets/{ticket_id}/validate_entry/ |
Validate ticket for entry |
GET | /api/tickets/{ticket_id}/validate_exit/ |
Validate ticket for exit |
GET | /api/tickets/{ticket_id}/upgrade/ |
Upgrade ticket |
GET | /api/tickets/{ticket_id}/upgrade-with-wallet/ |
Upgrade ticket using wallet |
GET | /api/tickets/sync/ |
Synchronize tickets |
GET | /api/tickets/types/ |
List ticket types |
GET | /api/tickets/validate-scan/ |
Validate ticket scan |
GET | /api/tickets/pending-upgrades/ |
List pending ticket upgrades |
GET | /api/tickets/dashboard/ |
Ticket dashboard |
GET | /api/tickets/gate-status/ |
Get gate status |
GET | /api/tickets/hardware-status/ |
Get hardware status |
GET | /api/tickets/scanner/process/ |
Process scanner information |
Method | Endpoint | Description |
---|---|---|
GET | /api/tickets/subscriptions/ |
List user subscriptions |
GET | /api/tickets/subscriptions/{subscription_id}/ |
Get subscription details |
GET | /api/tickets/subscriptions/active/ |
Get active subscriptions |
GET | /api/tickets/subscriptions/purchase-with-wallet/ |
Purchase subscription using wallet |
GET | /api/tickets/subscriptions/recommend/ |
Get subscription recommendations |
GET | /api/tickets/subscriptions/{subscription_id}/cancel/ |
Cancel subscription |
GET | /api/tickets/subscriptions/{subscription_id}/qr_code/ |
Get subscription QR code |
GET | /api/tickets/subscriptions/{subscription_id}/validate_station/ |
Validate subscription at station |
Method | Endpoint | Description |
---|---|---|
GET | /api/wallet/wallet/my_wallet/ |
Get user wallet |
GET | /api/wallet/wallet/add_funds/ |
Add funds to wallet |
GET | /api/wallet/wallet/withdraw_funds/ |
Withdraw funds from wallet |
GET | /api/wallet/transactions/ |
List wallet transactions |
GET | /api/wallet/transactions/{transaction_id}/ |
Get transaction details |
GET | /api/wallet/transactions/recent/ |
Get recent transactions |
GET | /api/wallet/transactions/filter/ |
Filter transactions |
GET | /api/wallet/payment-methods/ |
List payment methods |
GET | /api/wallet/payment-methods/{payment_method_id}/ |
Get payment method details |
GET | /api/wallet/payment-methods/{payment_method_id}/set_default/ |
Set default payment method |
Method | Endpoint | Description |
---|---|---|
GET | /health/ |
System health check |
- Framework: Django 5.1.3
- API Framework: Django REST Framework 3.14.0
- Database: PostgreSQL 15.4
- Cache: Redis
- Task Queue: Celery
- Web Server: Gunicorn with Nginx
- Authentication: JWT (JSON Web Tokens)
- Security: HTTPS, CORS, Input Validation
- Password Hashing: Argon2
- Rate Limiting: Django-ratelimit
- Machine Learning Integration: REST API to AI services
- Crowd Management Models: Integration with Python-based ML models
- Payment Gateway Integration: Multiple payment providers
- Digital Wallet: Custom implementation with transaction history
- Subscription Management: Recurring payment handling
- Deployment: Render
- Containerization: Docker 20.10.24
- CI/CD: GitHub Actions
- Monitoring: Prometheus with Grafana
- Logging: ELK Stack (Elasticsearch, Logstash, Kibana)
- Testing: Pytest, Django Test Framework
- API Documentation: Swagger, ReDoc
- Code Quality: Black, Flake8, isort
- Type Checking: mypy
- Python 3.12+
- PostgreSQL 15.4+
- Redis (optional, for caching and Celery)
- Git
-
Clone the repository
git clone https://github.com/Egypt-Metro/backend.git cd backend
-
Create and activate virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
Create a
.env
file in the root directory with the following variables:SECRET_KEY=your_secret_key DEBUG=True DATABASE_URL=postgres://user:password@localhost:5432/egypt_metro ALLOWED_HOSTS=localhost,127.0.0.1
-
Run migrations
python manage.py migrate
-
Create superuser (admin)
python manage.py createsuperuser
-
Start development server
python manage.py runserver
-
Access the API:
- API:
http://127.0.0.1:8000/
- Admin interface:
http://127.0.0.1:8000/admin/
- API documentation:
http://127.0.0.1:8000/swagger/
- API:
The API is deployed on Render at https://backend-54v5.onrender.com/
For deployment to your own Render instance:
- Create a new Web Service on Render
- Connect to your GitHub repository
- Set the following:
- Build Command:
pip install -r requirements.txt && python manage.py collectstatic --noinput && python manage.py migrate
- Start Command:
gunicorn config.wsgi:application
- Build Command:
- Add the required environment variables
- Deploy the service
We welcome contributions to the Egypt Metro Backend! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
For inquiries, Feel free to reach out Me:
- Email: [email protected]
- GitHub: AhmedNassar7
© 2025 Egypt Metro. All rights reserved.