The Egypt Metro Backend is a robust API, bussiness logic, metro administration for managing and operating the Egypt Metro platform. Built with Django and Django REST Framework (DRF), it provides seamless user authentication, metro station data, real-time train schedules, and AI-powered features such as crowd prediction and route optimization. The backend integrates with Flutter (frontend) and AI models, delivering a scalable and efficient solution.
- User Authentication: Registration, login, profile management, and JWT support.
- Station Management: Nearest station lookup, station list, and trip details.
- Route and Trip Planning: Manage metro routes, count number of stations, and calculate ticket prices.
- Train Schedules: Provide real-time schedule data, including arrival times and GPS-tracked train locations.
- Crowd Management: Use AI to predict crowd levels on trains and provide recommendations for less crowded options.
- User Profiles: Manage user accounts, including registration, login, subscription types, and payment options.
- Ticketing: Generate tickets based on selected routes.
- Subscription Management: Users can subscribe to different metro plans.
- Real-Time Updates: Supports extensions for real-time data (e.g., train locations, crowd levels).
- Extensible Design: Modular architecture for scalable development.
- API Documentation: Interactive docs with Swagger and ReDoc.
- Health Check: Ensure the backend service is operational.
- Admin Dashboard: Track revenue, sales, and station performance in real-time.
- Fault Reporting: Allow admins to view, respond to, and track the status of user-reported issues.
- Revenue and Sales Tracking: Monitor ticket sales and subscription renewals for each metro line and station.
- 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)
- Python: Version 3.9+
- Django: Version 4.x+
- PostgreSQL (recommended for production)
- Swagger & ReDoc: For API documentation
- Docker: For containerized deployment (optional)
- Poetry or Pip: For managing dependencies
- Channels: for real-time updates
-
Clone the Repository
git clone https://github.com/Egypt-Metro/backend.git cd backend
-
Set Up 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 and add the following:SECRET_KEY=<your-secret-key> DEBUG=True # Set to False in production DB_NAME=<your-db-name> DB_USER=<your-db-user> DB_PASSWORD=<your-db-password> DB_HOST=<your-db-host> DB_PORT=5432
-
Apply Migrations
python manage.py migrate
-
Create Superuser
python manage.py createsuperuser
-
Run the Server
python manage.py runserver
-
Access the API:
- API Base URL:
http://127.0.0.1:8000
- Admin Panel:
http://127.0.0.1:8000/admin/
- API Base URL:
Method | Endpoint | Description |
---|---|---|
POST | /api/users/register/ |
Register a new user. |
POST | /api/users/login/ |
Login to get JWT tokens. |
POST | /api/users/token/refresh/ |
Refresh access token. |
GET | /api/users/profile/ |
Retrieve user profile. |
PATCH | /api/users/profile/update/ |
Update user profile. |
Method | Endpoint | Description |
---|---|---|
GET | /api/stations/list/ |
List all metro stations. |
GET | /api/stations/trip/<start_station_id>/<end_station_id>/ |
Get trip details between two stations. |
GET | /api/stations/nearest/ |
Get the nearest metro station. |
Method | Endpoint | Description |
---|---|---|
GET | /api/routes/ |
Get available routes and their respective details (stations, trip duration, price). |
GET | /api/routes/{start_station}/{end_station}/ |
Get a route between two stations, including trip details and fare. |
Method | Endpoint | Description |
---|---|---|
GET | /api/schedules/ |
Get the current train schedules. |
GET | /api/schedules/{train_id}/ |
Get schedule details for a specific train. |
Method | Endpoint | Description |
---|---|---|
POST | /api/users/register/ |
Register a new user. |
POST | /api/users/login/ |
Login a user. |
GET | /api/users/{user_id}/ |
Get user profile information. |
Method | Endpoint | Description |
---|---|---|
POST | /api/tickets/ |
Create a new ticket based on the route selected. |
GET | /api/tickets/{ticket_id}/ |
Get ticket details. |
Method | Endpoint | Description |
---|---|---|
GET | /health/ |
Health check for the API. |
Interactive API documentation is available:
- Swagger UI: https://backend-54v5.onrender.com/swagger/
- ReDoc: https://backend-54v5.onrender.com/redoc/
- Swagger JSON: https://backend-54v5.onrender.com/swagger.json
The project is deployed using Render. To deploy:
- Configure Environment Variables on Render.
- Use the provided PostgreSQL database settings.
- Deploy the Django app with the necessary build and start commands.
This project is licensed under the MIT License. See the LICENSE file for details.
For inquiries, please reach out to Ahmed Nassar:
- Email: [email protected]
- GitHub: AhmedNassar7