DEV Community

Chitra Shinde
Chitra Shinde

Posted on

Bus Ticket Booking App | Angular 18 + .NET API


Image description

In this blog, I’ll walk you through building a Bus Ticket Booking App using Angular 18 for the front end and .NET API for the back end. This full-stack application allows users to search for bus routes, check seat availability, and book tickets seamlessly. If you prefer a video tutorial, you can watch my step-by-step guide here: Watch the full video.

Overview

The Bus Ticket Booking App provides users with a streamlined way to search, book, and manage bus tickets across various routes. In this app, Angular handles the dynamic front-end user interface, while the .NET API efficiently manages the back-end logic, database interactions, and real-time seat availability.

  • You can explore the live version of the Bus Ticket Booking App here.


Image description

Click here to visit the live app

Why Angular 18 and .NET?

  • Angular 18: The latest Angular version introduces improved performance, streamlined code, and a more responsive user interface, making it ideal for high-traffic applications like ticket booking.

  • .NET API: With its strong framework and robust security features, .NET enables efficient and secure data handling. It seamlessly connects with databases, allowing real-time updates on bus schedules and booking statuses.

Features of the App

1. User Authentication:
Users can register and log in to access their accounts, view their booking history, and manage their profiles.

2. Search for Routes:
Users can search for buses by entering the departure and arrival cities and selecting their desired date of travel. The app fetches real-time bus schedules from the database.

3. Real-Time Seat Availability:
The app provides users with a visual representation of seat availability, making it easy to choose and book specific seats.

4. Booking and Payment:
Once users select their seats, they proceed to the payment gateway, where they can securely pay for their tickets.

5. Responsive Design:
The app is fully responsive, ensuring a smooth user experience across desktop, tablet, and mobile devices.

Image description

Tech Stack

Front-End:

  • Angular 18: Standalone components, better rendering performance, and modularity.
  • Bootstrap: For responsive design and layout.
  • TypeScript: For strong typing and structured code.

Back-End:

  • .NET API: Manages the business logic, interacts with the database, and ensures secure user authentication and payment processing.
  • You can explore the API Endpoints for Bus Ticket Booking App here.
  • Entity Framework: Used for database interactions, enabling real-time updates for seat availability and bookings.

Database:

  • SQL Server: To store user data, bus schedules, bookings, and payment information.

  • Step-by-Step Guide

1. Setting Up the Angular 18 Project
Start by setting up an Angular 18 project. Use Angular CLI to initialize the app, set up components, and design the UI with Bootstrap.

ng new bus-ticket-booking-app
Enter fullscreen mode Exit fullscreen mode

Create components for the following:

  • Search Form
  • Seat Selection
  • User Authentication

2. Integrating the .NET API

Image description

Click here to Explore the detailed API documentation for the Bus Ticket Booking App

The .NET API handles user data, booking information, and interacts with the SQL database. Here’s a simplified flow:

  1. User Registration and Authentication: The API validates user credentials and manages sessions.
  2. Route Search and Seat Availability: Fetches real-time data from the database.
  3. Booking and Payment Processing: Ensures secure payment through an integrated gateway.

3. Connecting Front-End with Back-End
Using **HTTPClient **in Angular, connect the front-end to the .NET API to send requests and handle responses. For example, the bus search form sends a request to the API to retrieve available buses based on user input.

this.http.get('api/buses', { params: { from: 'cityA', to: 'cityB', date: '2024-08-20' }})
  .subscribe(response => { /* handle response */ });
Enter fullscreen mode Exit fullscreen mode

4. Handling User Authentication
With the JWT (JSON Web Token) approach, the .NET API issues tokens upon successful login. Angular then stores the token in local storage and includes it in headers for future requests to the API.

5. Implementing Seat Selection
Use a dynamic layout in Angular to represent available and booked seats. The selection is sent to the .NET API to ensure the chosen seats are reserved and updated in real-time in the database.

6. Deploying the App
After development, deploy the front end and back end separately. The front end can be hosted using platforms like Netlify or Vercel, while the back end can be hosted on Azure or AWS.

Challenges and Learnings
Throughout the development of this app, I faced challenges with integrating Angular with .NET, specifically handling async data. However, with proper use of services and observables, I was able to ensure seamless communication between the front end and back end.

Conclusion
This Bus Ticket Booking App showcases how Angular 18 and .NET API can be combined to build a full-stack, real-time application. The application demonstrates essential features such as user authentication, real-time data handling, and secure payment gateways, all wrapped in a responsive and user-friendly interface.

Check out the full video tutorial for a complete walk-through of the project: Watch here.

Top comments (0)