Skip to content

Latest commit

 

History

History
210 lines (146 loc) · 8.09 KB

README.md

File metadata and controls

210 lines (146 loc) · 8.09 KB

Egypt Metro Backend API (Django)

License Python Django

Overview

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.


Features

Passenger Features

  • 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 Features

  • 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.

Technologies Used

  • 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)

Installation

Prerequisites

  • 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

Steps

  1. Clone the Repository

    git clone https://github.com/Egypt-Metro/backend.git
    cd backend
  2. Set Up Virtual Environment

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install Dependencies

    pip install -r requirements.txt
  4. 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
  5. Apply Migrations

    python manage.py migrate
  6. Create Superuser

    python manage.py createsuperuser
  7. Run the Server

    python manage.py runserver
  8. Access the API:

    • API Base URL: http://127.0.0.1:8000
    • Admin Panel: http://127.0.0.1:8000/admin/

API Endpoints

Authentication Endpoints

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.

Metro Stations Endpoints

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.

Route and Trip Planning

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.

Train Schedules

Method Endpoint Description
GET /api/schedules/ Get the current train schedules.
GET /api/schedules/{train_id}/ Get schedule details for a specific train.

User Management

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.

Ticketing

Method Endpoint Description
POST /api/tickets/ Create a new ticket based on the route selected.
GET /api/tickets/{ticket_id}/ Get ticket details.

Miscellaneous Endpoints

Method Endpoint Description
GET /health/ Health check for the API.

API Documentation

Interactive API documentation is available:


Deployment

The project is deployed using Render. To deploy:

  1. Configure Environment Variables on Render.
  2. Use the provided PostgreSQL database settings.
  3. Deploy the Django app with the necessary build and start commands.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Contact

For inquiries, please reach out to Ahmed Nassar: