express-train-server

Stars
0
Committers
2

Train Service Management System

Overview

The Train Service Management System is a backend application designed to handle train services, user management, wallet integration, and ticketing. Built with Node.js, Express, and TypeScript, this system uses MongoDB and Mongoose for data persistence. It supports user authentication, station and train management, wallet transactions, and ticket purchases. The project follows a modular architecture for maintainability and scalability.

Features

  • User Management: Register, log in, and manage users with JWT authentication and password hashing using bcrypt.

  • Station Management: Create, update, and retrieve station information.

  • Train Management: Manage train schedules, including stops and timings.

  • Wallet Integration: Add funds, check balance, and maintain transaction history.

  • Ticketing System: Purchase tickets with wallet balance, calculate fares based on train stops.

Technologies

  • Node.js: JavaScript runtime for building scalable server-side applications.

  • Express: Web framework for Node.js to build RESTful APIs.

  • TypeScript: Adds static types to JavaScript, improving code quality and maintainability.

  • MongoDB: NoSQL database for flexible and scalable data storage.

  • Mongoose: ODM library for MongoDB to simplify data modeling and validation.

  • Prettier: Code formatter to ensure consistent code style.

  • ESLint: Linter to identify and fix problems in the code.

Project Setup

  1. Clone the Repository
git clone https://github.com/iibrahim70/express-train-server.git
cd express-train-server
  1. Install Dependencies
pnpm i
  1. Configuration

    Create a .env file in the root directory with the following environment variables:

NODE_ENV=development
PORT=5000
DATABASE_URL=yourMongoDbDatabaseUrl
COLLECTION_NAME=yourCollectionName
BCRYPT_SALT_ROUNDS=10
JWT_ACCESS_SECRET=yourJwtAccessSecret
JWT_EXPIRES_IN=1h
  1. Build the Project
pnpm start
  1. Run the Project
pnpm start:dev

Endpoints

User Management

  • POST api/v1/users/register: Register a new user.

  • POST api/v1/users/login: Log in an existing user.

Station Management

  • GET /api/v1/stations: Retrieve stations information.

  • GET /api/v1/stations/:stationId: Retrieve station information.

  • POST /api/v1/stations/create-station: Create a new station.

  • PATCH /api/v1/stations/update-station/:stationId: Update station information.

Train Management

  • GET /api/v1/trains/: Retrieve trains schedule information.

  • GET /api/v1/trains/:trainId: Retrieve train schedule information.

  • POST /api/v1/trains/create-train: Create a new train schedule.

  • PATCH /api/v1/trains/update-train:trainId: Update train schedule information.

Wallet Integration

  • GET /api/v1/wallets: Retrieve the user's wallet balance.

  • POST /api/v1/wallets/add-funds: Add funds to the user's wallet.

Ticketing System

  • POST /api/v1/tickets/calculate-price: Calculate the price of a ticket based on provided details.

  • POST /api/v1/tickets/purchase: Purchase a ticket using wallet balance.

Code Quality

  • Prettier: Code formatting rules are enforced by Prettier.

  • ESLint: Linting rules are enforced by ESLint.

  • TypeScript: Adds static types to JavaScript, improving code quality and maintainability.

Contact

For any questions or issues, please reach out to Click Here.


Related Projects