# shashirajraja/train-ticket-reservation-system architecture

> Architecture diagram of the GitHub repository shashirajraja/train-ticket-reservation-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shashirajraja/train-ticket-reservation-system
- Repository: https://github.com/shashirajraja/train-ticket-reservation-system

## Overview

##### Project Type and Purpose
- This is a web-based full-stack application built using Java (J2EE), Servlets, JDBC, HTML/CSS/Bootstrap, and Oracle as the database.
- The purpose is to allow users to search train schedules, check seat availability, book tickets online, view booking history, and perform various profile operations, while administrators can manage trains (add/update/cancel) and oversee user activity.

##### Analyzing the File Structure
- The top-level directories of note are:
– WebContent: Contains the static HTML files (views) used in the application such as AdminLogin.html, UserLogin.html, Payment.html etc. It also holds the WEB-INF directory which contains configuration files (web.xml), libraries (like ojdbc8.jar) and deployment descriptors.
– src: This contains the Java source code organized by packages:
- beans: Classes modeling domain objects (AdminBean, TrainBean, UserBean, etc.).
- constant: Definitions for response codes and user roles.
- service & service/impl: Business logic classes where interfaces (e.g., TrainService, UserService, BookingService) are defined and implemented.
- servlets: The Controller layer which handles HTTP requests (e.g., AdminLogin, BookTrainFwd) and directs them to the service layer.
- utility: Utility classes like DBUtil and TrainUtil that likely encapsulate JDBC connectivity and possibly other common operations.
– Configuration files: pom.xml for Maven build, application.properties for configuration, and several Eclipse-specific files that guide project setup.

##### Key Architectural Choices
- The project follows a Model-View-Controller (MVC) architecture:
– The “Model” is represented by JavaBeans (in the beans package) which encapsulate the application data.
– The “View” is implemented with static HTML pages within WebContent along with CSS styling and Bootstrap.
– The “Controller” is implemented via Servlets which process requests, interact with the service layer, and route responses.
- The Service Layer abstracts business logic and database operations are managed using JDBC, facilitated by utility classes.
- The use of Maven (pom.xml) indicates dependency management and build automation.
- The deployment container is Apache Tomcat (configured to run on port 8083).

##### Instructional Elements

- At the top: Client Web Browser accessing WebContent (HTML/CSS/Bootstrap).
- Middle Tier:
– Presentation/Controller Layer: Servlets in WebContent/WEB-INF configured via web.xml.
– Business Logic Layer: Service interfaces and implementations.
– Utility/DAO Components for JDBC operations.
- Bottom Tier: Oracle Database (including the ADMIN, CUSTOMER, TRAIN, and HISTORY tables).
- Optional: A side element for the Payment Gateway simulation.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client/Presentation Layer
    subgraph "Client/Presentation Layer"
        AdminLogin["AdminLogin.html"]:::client
        UserLogin["UserLogin.html"]:::client
        Payment["Payment.html"]:::client
    end

    %% Controller Layer
    subgraph "Controller Layer"
        Servlets["Servlets (Controller)"]:::controller
        AdminServlet["AdminLogin Servlet"]:::controller
        BookServlet["BookTrainFwd Servlet"]:::controller
        Servlets --> AdminServlet
        Servlets --> BookServlet
    end

    %% Model Layer
    subgraph "Model Layer"
        Beans["JavaBeans (Domain Models)"]:::model
        AdminBean["AdminBean"]:::model
        TrainBean["TrainBean"]:::model
        UserBean["UserBean"]:::model
        Beans --> AdminBean
        Beans --> TrainBean
        Beans --> UserBean
    end

    %% Business/Service Layer
    subgraph "Business/Service Layer"
        ServiceInterfaces["Service Interfaces"]:::service
        BookingService["BookingService"]:::service
        TrainService["TrainService"]:::service
        UserService["UserService"]:::service
        ServiceInterfaces --> BookingService
        ServiceInterfaces --> TrainService
        ServiceInterfaces --> UserService

        ServiceImpl["Service Implementations"]:::service
        BookingServiceImpl["BookingServiceImpl"]:::service
        TrainServiceImpl["TrainServiceImpl"]:::service
        UserServiceImpl["UserServiceImpl"]:::service
        ServiceImpl --> BookingServiceImpl
        ServiceImpl --> TrainServiceImpl
        ServiceImpl --> UserServiceImpl
    end

    %% Data Access/Utility Layer
    subgraph "Data Access/Utility Layer"
        Utility["Utility Classes (DAO)"]:::utility
        DBUtil["DBUtil"]:::utility
        TrainUtil["TrainUtil"]:::utility
        Utility --> DBUtil
        Utility --> TrainUtil
    end

    %% Configuration/Deployment
    subgraph "Configuration/Deployment"
        WebXML["web.xml"]:::config
        Pom["pom.xml"]:::config
        AppProps["application.properties"]:::config
    end

    %% Database Layer
    subgraph "Database Layer"
        OracleDB["Oracle Database (ADMIN,CUSTOMER,TRAIN,HISTORY)"]:::database
    end

    %% Deployment Environment
    subgraph "Deployment Environment"
        Tomcat["Apache Tomcat (Port8083)"]:::external
        Maven["Maven Build System"]:::external
    end

    %% Interactions between Layers
    AdminLogin -->|"submitLogin"| AdminServlet
    UserLogin -->|"submitLogin"| BookServlet
    AdminServlet -->|"invokeService"| BookingService
    BookServlet -->|"invokeService"| TrainService
    BookingService -->|"callDBUtil"| DBUtil
    TrainService -->|"callDBUtil"| TrainUtil
    DBUtil -->|"query/update"| OracleDB
    TrainUtil -->|"processData"| OracleDB
    AdminServlet -->|"retrieveModel"| AdminBean
    BookServlet -->|"retrieveModel"| TrainBean
    TrainServiceImpl -->|"updateModel"| UserBean

    %% External Payment Interaction
    Payment -->|"simulatePayment"| Tomcat

    %% Deployment - Configuration
    Tomcat -->|"deployUsing"| WebXML
    Maven -->|"triggerBuild"| Pom

    %% Click Events
    click AdminLogin "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/WebContent/AdminLogin.html"
    click UserLogin "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/WebContent/UserLogin.html"
    click Payment "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/WebContent/Payment.html"
    click Servlets "https://github.com/shashirajraja/train-ticket-reservation-system/tree/master/src/com/shashi/servlets"
    click AdminServlet "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/servlets/AdminLogin.java"
    click BookServlet "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/servlets/BookTrainFwd.java"
    click Beans "https://github.com/shashirajraja/train-ticket-reservation-system/tree/master/src/com/shashi/beans"
    click AdminBean "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/beans/AdminBean.java"
    click TrainBean "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/beans/TrainBean.java"
    click UserBean "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/beans/UserBean.java"
    click BookingService "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/service/BookingService.java"
    click TrainService "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/service/TrainService.java"
    click UserService "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/service/UserService.java"
    click BookingServiceImpl "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/service/impl/BookingServiceImpl.java"
    click TrainServiceImpl "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/service/impl/TrainServiceImpl.java"
    click UserServiceImpl "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/service/impl/UserServiceImpl.java"
    click DBUtil "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/utility/DBUtil.java"
    click TrainUtil "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/com/shashi/utility/TrainUtil.java"
    click WebXML "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/WebContent/WEB-INF/web.xml"
    click Pom "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/pom.xml"
    click AppProps "https://github.com/shashirajraja/train-ticket-reservation-system/blob/master/src/application.properties"

    %% Styles
    classDef client fill:#cfe2f3,stroke:#0b5394,stroke-width:2px;
    classDef controller fill:#d9ead3,stroke:#38761d,stroke-width:2px;
    classDef model fill:#fff2cc,stroke:#bf9000,stroke-width:2px;
    classDef service fill:#ead1dc,stroke:#b85450,stroke-width:2px;
    classDef utility fill:#d9d2e9,stroke:#674ea7,stroke-width:2px;
    classDef config fill:#f9cb9c,stroke:#e69138,stroke-width:2px;
    classDef database fill:#ffe599,stroke:#bf9000,stroke-width:2px;
    classDef external fill:#c9daf8,stroke:#1155cc,stroke-width:2px;
```
