# dheer2005/busbooking_backend architecture

> Architecture diagram of the GitHub repository dheer2005/busbooking_backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dheer2005/busbooking_backend
- Repository: https://github.com/dheer2005/busbooking_backend

## Overview

##### Project type and purpose
- This is a .NET 8.0 back-end RESTful web API (monolithic) for a bus-booking system.
- It exposes endpoints (Controllers) to let clients (web or mobile) search routes, book seats, process payments, manage users, feedback, ratings, etc.
- The project uses ASP.NET Core MVC, Entity Framework Core for data access, and code-first migrations to an RDBMS.

##### File-structure analysis
- Top-level: Program.cs (app entry), appsettings.json (configuration), BusBooking.sln/.csproj
- Controllers/ : ASP.NET Core API controllers for each domain (Admin, Bus, Booking, Payment, Schedule, User, Location)
- DTO/ : Data Transfer Objects for incoming requests and outgoing responses
- Context/BusBookingDbContext.cs : EF Core DbContext managing DbSets for domain Models
- Models/ : EF Core entity classes (Booking, Bus, User, Payment, Feedback, Schedule, etc.)
- Migrations/ : Code-first EF migrations defining/updating database schema
- Properties/PublishProfiles & launchSettings.json : Deployment and launch configurations

a. Clients
- Web or mobile application(s) invoking HTTP(s) requests
b. API Layer
- ASP.NET Core Host & Middleware (routing, authentication, logging)
- Controllers (BookingController, BusController, etc.)
- DTO mapping and model validation
c. Business/Service layer (implicit inside Controllers or factored out in future)
d. Data Access
- EF Core DbContext (BusBookingDbContext)
- Entity Models & Migrations
e. External services
- Payment Gateway (called by PaymentController)
- Optional: Email/SMS notification service for booking confirmations
f. Database
- Relational database (e.g., SQL Server) storing tables for Users, Buses, Bookings, Payments, etc.
g. Configuration & Infrastructure
- appsettings.json (connection strings, logging levels, API keys)
- Publish profiles for deployment targets

##### Interactions and data flow
- Client → HTTP Request → ASP.NET Core Middleware → Matching Controller
- Controller → Validate & Map DTO → (Optional Service Layer) → DbContext
- DbContext → SQL commands → Database
- PaymentController → External Payment Gateway API → Payment status → DbContext
- Controller → Map entities to ResponseDTO → HTTP Response → Client

##### Architectural patterns & principles
- Layered architecture: Presentation (Controllers) → Business logic → Data access
- RESTful API patterns: resource-based endpoints, HTTP verbs
- Dependency Injection: DbContext, configuration, logging injected via Program.cs
- Code-first migrations for database versioning
- DTOs to decouple external contracts from domain models

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Infrastructure & Configuration
    subgraph "Infrastructure & Config"
        Config1["appsettings.json"]:::infra
        Config2["appsettings.Development.json"]:::infra
        LaunchSettings["launchSettings.json"]:::infra
        PublishProfiles["PublishProfiles"]:::infra
    end

    %% Entry Point
    subgraph "Entry Point"
        Program["Program.cs"]:::internal
    end

    Program --> Config1
    Program --> Config2
    Program --> LaunchSettings
    Program --> PublishProfiles

    %% API Layer
    subgraph "API Layer"
        subgraph "Controllers"
            AdminC["AdminController"]:::internal
            BookingC["BookingController"]:::internal
            BusC["BusController"]:::internal
            LocationC["LocationController"]:::internal
            PaymentC["PaymentController"]:::internal
            ScheduleC["ScheduleController"]:::internal
            UserC["UserController"]:::internal
        end

        subgraph "DTOs"
            BookingDTO["BookingDTO"]:::internal
            BookingResDTO["BookingResponseDTO"]:::internal
            BusDTO["BusDTO"]:::internal
            BusRatingDTO["BusRatingDTO"]:::internal
            FeedbackDTO["FeedbackDTO"]:::internal
            LocationDTO["LocationDTO"]:::internal
            LocationDropDTO["LocationDropdownDto"]:::internal
            LoginReqDTO["LoginRequestDTO"]:::internal
            PassengerDTO["PassengerDTO"]:::internal
            PaymentDTO["PaymentDTO"]:::internal
            RegisterUserDTO["RegisterUserDTO"]:::internal
            ScheduleDTO["ScheduleDTO"]:::internal
            ScheduleResDTO["ScheduleResultDTO"]:::internal
        end
    end

    Program --> AdminC
    Program --> BookingC
    Program --> BusC
    Program --> LocationC
    Program --> PaymentC
    Program --> ScheduleC
    Program --> UserC

    AdminC --> BookingDTO
    BookingC --> BookingDTO
    BookingC --> BookingResDTO
    BusC --> BusDTO
    BusC --> BusRatingDTO
    LocationC --> LocationDTO
    LocationC --> LocationDropDTO
    UserC --> LoginReqDTO
    UserC --> RegisterUserDTO
    ScheduleC --> ScheduleDTO
    ScheduleC --> ScheduleResDTO
    PaymentC --> PaymentDTO
    BookingC --> PassengerDTO
    FeedbackDTO---AdminC

    %% Data Access
    subgraph "Data Access"
        DbContext["BusBookingDbContext"]:::internal
        MigrationsFolder["Migrations"]:::internal
        subgraph "Entity Models"
            AdminM["Admin"]:::internal
            BookingM["Booking"]:::internal
            BusM["Bus"]:::internal
            BusRatingM["BusRating"]:::internal
            FeedbackM["Feedback"]:::internal
            LocationM["Location"]:::internal
            PassengerM["Passenger"]:::internal
            PaymentM["Payment"]:::internal
            ScheduleM["Schedule"]:::internal
            StateCitiesM["StateWiseCities"]:::internal
            UserM["User"]:::internal
        end
    end

    BookingC --> DbContext
    AdminC --> DbContext
    BusC --> DbContext
    LocationC --> DbContext
    PaymentC --> DbContext
    ScheduleC --> DbContext
    UserC --> DbContext

    DbContext --> MigrationsFolder
    DbContext --> AdminM
    DbContext --> BookingM
    DbContext --> BusM
    DbContext --> BusRatingM
    DbContext --> FeedbackM
    DbContext --> LocationM
    DbContext --> PassengerM
    DbContext --> PaymentM
    DbContext --> ScheduleM
    DbContext --> StateCitiesM
    DbContext --> UserM

    %% External Services
    subgraph "External Services"
        PaymentGW["Payment Gateway"]:::external
        Notification["Email/SMS Service"]:::external
    end

    PaymentC -->|"POST /payments"| PaymentGW
    BookingC -->|"Send confirmation"| Notification

    %% Database
    subgraph "Database"
        DB["SQL Database"]:::db
    end

    DbContext -->|"SQL Commands"| DB

    %% Click Events
    click Program "https://github.com/dheer2005/busbooking_backend/blob/main/Program.cs"
    click Config1 "https://github.com/dheer2005/busbooking_backend/blob/main/appsettings.json"
    click Config2 "https://github.com/dheer2005/busbooking_backend/blob/main/appsettings.Development.json"
    click LaunchSettings "https://github.com/dheer2005/busbooking_backend/blob/main/Properties/launchSettings.json"
    click PublishProfiles "https://github.com/dheer2005/busbooking_backend/tree/main/Properties/PublishProfiles"
    click AdminC "https://github.com/dheer2005/busbooking_backend/blob/main/Controllers/AdminController.cs"
    click BookingC "https://github.com/dheer2005/busbooking_backend/blob/main/Controllers/BookingController.cs"
    click BusC "https://github.com/dheer2005/busbooking_backend/blob/main/Controllers/BusController.cs"
    click LocationC "https://github.com/dheer2005/busbooking_backend/blob/main/Controllers/LocationController.cs"
    click PaymentC "https://github.com/dheer2005/busbooking_backend/blob/main/Controllers/PaymentController.cs"
    click ScheduleC "https://github.com/dheer2005/busbooking_backend/blob/main/Controllers/ScheduleController.cs"
    click UserC "https://github.com/dheer2005/busbooking_backend/blob/main/Controllers/UserController.cs"
    click BookingDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/BookingDTO.cs"
    click BookingResDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/BookingResponseDTO.cs"
    click BusDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/BusDTO.cs"
    click BusRatingDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/BusRatingDTO.cs"
    click FeedbackDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/FeedbackDTO.cs"
    click LocationDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/LocationDTO.cs"
    click LocationDropDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/LocationDropdownDto.cs"
    click LoginReqDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/LoginRequestDTO.cs"
    click PassengerDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/PassengerDTO.cs"
    click PaymentDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/PaymentDTO.cs"
    click RegisterUserDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/RegisterUserDTO.cs"
    click ScheduleDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/ScheduleDTO.cs"
    click ScheduleResDTO "https://github.com/dheer2005/busbooking_backend/blob/main/DTO/ScheduleResultDTO.cs"
    click DbContext "https://github.com/dheer2005/busbooking_backend/blob/main/Context/BusBookingDbContext.cs"
    click MigrationsFolder "https://github.com/dheer2005/busbooking_backend/tree/main/Migrations"
    click AdminM "https://github.com/dheer2005/busbooking_backend/blob/main/Models/Admin.cs"
    click BookingM "https://github.com/dheer2005/busbooking_backend/blob/main/Models/Booking.cs"
    click BusM "https://github.com/dheer2005/busbooking_backend/blob/main/Models/Bus.cs"
    click BusRatingM "https://github.com/dheer2005/busbooking_backend/blob/main/Models/BusRating.cs"
    click FeedbackM "https://github.com/dheer2005/busbooking_backend/blob/main/Models/Feedback.cs"
    click LocationM "https://github.com/dheer2005/busbooking_backend/blob/main/Models/Location.cs"
    click PassengerM "https://github.com/dheer2005/busbooking_backend/blob/main/Models/Passenger.cs"
    click PaymentM "https://github.com/dheer2005/busbooking_backend/blob/main/Models/Payment.cs"
    click ScheduleM "https://github.com/dheer2005/busbooking_backend/blob/main/Models/Schedule.cs"
    click StateCitiesM "https://github.com/dheer2005/busbooking_backend/blob/main/Models/StateWiseCities.cs"
    click UserM "https://github.com/dheer2005/busbooking_backend/blob/main/Models/User.cs"

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#000;
    classDef db fill:#90EE90,stroke:#000;
    classDef external fill:#FFA500,stroke:#000;
    classDef infra fill:#D3D3D3,stroke:#000;
```
