HiCrew Backend is a comprehensive RESTful API for managing virtual airline operations. Built with Node.js, Express, Prisma ORM, and MySQL/MariaDB, it provides complete functionality for pilot management, fleet operations, flight tracking, and administration systems.
- π Authentication & Authorization - JWT-based auth with role-based permissions
- π¨β
βοΈ Pilot Management - Complete pilot profiles with IVAO/VATSIM integration βοΈ Fleet Management - Aircraft, routes, and fleet administration- π Flight Operations - Flight planning, tracking, and reporting
- π Gamification - Medals, ranks, and achievement system
- π Multi-airline Support - Configurable for different virtual airlines
- π§ Email Integration - Automated notifications and communications
- π ACARS Integration - Compatible with HiACARS flight tracking
- π Administration Panel - Complete backend for admin operations
- π³ Docker Support - Easy deployment with Docker containers
- Node.js (v16 or higher)
- npm or yarn
- MySQL or MariaDB (v10.5+)
- Git
-
Clone the repository:
git clone https://github.com/alejandro-diazro/HiCrewBackend.git cd HiCrewBackend -
Install dependencies:
npm install
-
Configure environment variables:
# Copy the example environment file cp .env.example .env # Edit the .env file with your configuration nano .env # or use your preferred editor
-
Set up the database:
# Generate Prisma client npx prisma generate # Run database migrations npx prisma migrate dev
-
Seed the database (optional but recommended):
# Add initial data and configuration node seed.js # Add airports data (optional - adds worldwide airports) node airports.js
-
Start the server:
# Development mode npm run dev # Production mode npm start
The API will be available at http://localhost:8000 (or your configured port).
# Server Configuration
PORT=8000
# Database Configuration
DATABASE_URL="mysql://username:password@localhost:3306/hicrew"
# JWT Security
JWT_SECRET=your_very_secure_jwt_secret_here
# Email Configuration (for notifications)
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password
EMAIL_NAME=HiCrew
# Frontend URL (for CORS and email links)
FRONTEND_URL=http://localhost:3000
# Airline Configuration
ICAO_AIRLINE="HCW" # Your airline's ICAO code# Install MySQL or MariaDB locally
# Create database
mysql -u root -p
CREATE DATABASE hicrew;# Use the provided docker-compose file
docker-compose up -dnpm start # Start production server
npm run dev # Start development server with nodemon
npm run prisma:migrate # Run database migrations
npm run prisma:generate # Generate Prisma clientPOST /api/auth/register- Register new pilotPOST /api/auth/login- Pilot loginPOST /api/auth/forgot-password- Password reset requestPOST /api/auth/reset-password- Reset password
GET /api/pilots- List all pilotsGET /api/pilots/:id- Get pilot detailsPUT /api/pilots/:id- Update pilot profileDELETE /api/pilots/:id- Delete pilot
GET /api/aircraft- List aircraft typesGET /api/fleet- List airline fleetPOST /api/fleet- Add aircraft to fleetPUT /api/fleet/:id- Update fleet aircraftDELETE /api/fleet/:id- Remove from fleet
GET /api/flights- List flightsPOST /api/flights- Create new flightGET /api/routes- List available routesPOST /api/routes- Create new route
GET /api/permissions- List permissionsPOST /api/permissions- Assign permissionsGET /api/config- Get airline configurationPUT /api/config- Update configuration
GET /api/airports- List airportsGET /api/medals- List medals/achievementsGET /api/ranks- List pilot ranksGET /api/simulators- List supported simulators
For complete API documentation, see the /docs endpoint when the server is running.
HiCrewBackend/
βββ config/ # Database and app configuration
βββ controllers/ # Business logic controllers
βββ middleware/ # Authentication and validation middleware
β βββ auth.js # JWT authentication
β βββ permissions.js # Role-based permissions
βββ models/ # Data models (if using additional ORMs)
βββ prisma/ # Prisma ORM configuration
β βββ schema.prisma # Database schema
β βββ migrations/ # Database migration files
βββ routes/ # API route definitions
β βββ auth.js # Authentication routes
β βββ pilots.js # Pilot management
β βββ fleet.js # Fleet operations
β βββ flights.js # Flight operations
β βββ ... # Other route files
βββ utils/ # Utility functions
β βββ email.js # Email sending utilities
βββ .env.example # Environment configuration template
βββ docker-compose.yml # Docker setup for database
βββ seed.js # Database seeding script
βββ airports.js # Airport data import script
βββ cronJobs.js # Scheduled tasks
βββ server.js # Main application entry point
For easy development setup with Docker:
# Start the database container
docker-compose up -d
# The database will be available at localhost:3306
# Default credentials are in docker-compose.ymlThis backend is designed to work with the HiCrew Frontend:
- Start the backend (this repository)
- Configure the frontend to point to this API
- Update CORS settings in the backend for your frontend URL
You can test the API using:
- Postman - Import the API collection (if available)
- curl - Command line testing
- Frontend - Direct integration testing
Example test request:
# Test server health
curl http://localhost:8000/api/health
# Login example
curl -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"pilot@example.com","password":"password"}'Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow existing code conventions
- Add tests for new features
- Update documentation as needed
- Ensure all migrations are reversible
- Test with both MySQL and MariaDB if possible
- JWT Authentication - Secure token-based authentication
- Password Hashing - bcrypt for secure password storage
- Input Validation - Comprehensive request validation
- CORS Configuration - Proper cross-origin resource sharing
- Environment Variables - Sensitive data stored securely
The database uses Prisma ORM with the following main entities:
- Pilots - User accounts and profiles
- Airlines - Virtual airline configurations
- Aircraft - Aircraft types and specifications
- Fleet - Airline fleet management
- Routes - Flight routes and schedules
- Flights - Individual flight records
- Permissions - Role-based access control
- Medals & Ranks - Gamification system
Database connection fails:
# Check your DATABASE_URL in .env
# Ensure MySQL/MariaDB is running
# Verify database exists and credentials are correctPrisma errors:
# Regenerate Prisma client
npx prisma generate
# Reset database (CAUTION: This will delete all data)
npx prisma migrate resetPort already in use:
# Change PORT in .env file
# Or kill the process using the port
lsof -ti:8000 | xargs killThis project is licensed under the MIT License - see the LICENSE file for details.
Developed by Alejandro DΓaz
- HiCrew Frontend - React frontend application
- HiACARS - Flight tracking software
Ready to manage your virtual airline?
- Setup the database
- Configure your
.env - Run migrations and seed data
- Connect your frontend
- Take off! π
- Create a
.envfile in the root directory based on the example below:DATABASE_URL="mysql://hicrew_user:hicrew_password@localhost:3306/hicrew" JWT_SECRET="your_jwt_secret_here"
- Replace
hicrew_user,hicrew_password, andyour_jwt_secret_herewith your own secure credentials.
- Create a
- Apply database migrations:
- Initialize the database schema with Prisma:
npx prisma migrate dev --name init
- Initialize the database schema with Prisma:
- Seed permissions (optional):
- Run the seed script to populate the
Permissiontable with default permissions:node seed.js
- Run the seed script to populate the
- Clone the repository (as above).
- Install dependencies (as above).
- Set up Docker:
- Ensure Docker and Docker Compose are installed.
- Create or use the provided
docker-compose.ymlfile to set up MariaDB:version: '3.8' services: mariadb: image: mariadb:10.5 environment: MYSQL_ROOT_PASSWORD: root_password MYSQL_DATABASE: hicrew MYSQL_USER: hicrew_user MYSQL_PASSWORD: hicrew_password ports: - "3306:3306" volumes: - mariadb_data:/var/lib/mysql volumes: mariadb_data:
- Start the MariaDB container:
docker-compose up -d
- Configure environment variables:
- Update
.envto point to the Docker-hosted MariaDB:DATABASE_URL="mysql://hicrew_user:hicrew_password@mariadb:3306/hicrew" JWT_SECRET="your_jwt_secret_here"
- Update
- Apply migrations and seed:
- Run the migrations and seed script as described in the Local Setup.
- Database: Ensure MariaDB is running and accessible via the
DATABASE_URL. - JWT: Set a secure
JWT_SECRETfor signing authentication tokens. - Permissions: The
seed.jsscript populates permissions likeVIEW_PILOTS,MANAGE_FLIGHTS,MANAGE_PILOTS, andADMIN. Modifyseed.jsto add custom permissions if needed.
- Start the server:
The API will be available at
npm start
http://localhost:8000. - Verify the server:
- Open
http://localhost:8000/pilotsin a browser or Postman to see the public list of pilots (no authentication required).
- Open
| Method | Endpoint | Description | Authentication |
|---|---|---|---|
| POST | /auth/register |
Register a new pilot | None |
| POST | /auth/login |
Log in and obtain a JWT token | None |
| GET | /pilots |
List pilots (limited fields) | None |
| GET | /pilots/authenticated |
List pilots (more fields) | JWT token |
| GET | /pilots/admin |
List all pilots with full details | JWT token, ADMIN |
-
Register a pilot:
- Method:
POST - URL:
http://localhost:8000/auth/register - Body (JSON):
{ "email": "test@example.com", "password": "password123", "firstName": "John", "lastName": "Doe", "birthDate": "1990-01-01", "callsign": "TST123", "ivaoId": "123456", "vatsimId": "654321" } - Response: Returns pilot details and a JWT token (no permissions assigned by default).
- Method:
-
Log in:
- Method:
POST - URL:
http://localhost:8000/auth/login - Body (JSON):
{ "email": "test@example.com", "password": "password123" } - Response: Returns pilot details and a JWT token.
- Method:
-
Access admin route:
- Method:
GET - URL:
http://localhost:8000/pilots/admin - Headers:
Authorization: Bearer <jwt_token> - Note: Requires a pilot with
ADMINpermission. Assign it manually if needed:INSERT INTO pilot_permissions (pilot_id, permission_id) VALUES (1, (SELECT id FROM Permission WHERE name = 'ADMIN'));
- Method:
hicrew-backend/
βββ middleware/ # Authentication and permission middlewares
β βββ auth.js # JWT authentication middleware
β βββ permissions.js # Permission checking middleware
βββ prisma/ # Prisma schema and migrations
β βββ schema.prisma # Database schema
β βββ migrations/ # Migration files
βββ routes/ # API route handlers
β βββ auth.js # Authentication routes (register, login)
β βββ pilots.js # Pilot management routes
βββ .env # Environment variables (not tracked)
βββ .gitignore # Git ignore file
βββ docker-compose.yml # Docker configuration for MariaDB
βββ package.json # Node.js dependencies and scripts
βββ seed.js # Script to seed permissions
βββ index.js # Entry point
βββ README.md # Project documentation
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature). - Commit your changes (
git commit -m 'Add your feature'). - Push to the branch (
git push origin feature/your-feature). - Open a Pull Request.
Please ensure your code follows the project's coding style and includes tests where applicable. Report issues or suggest features via the Issues page.
This project is licensed under the MIT License (LICENSE). You are free to use, modify, and distribute this software, as long as you include the license and copyright notice.