Skip to content

yash08123/Phoenix-IMF-Gadget-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Upraised Backend API

A RESTful API built with Node.js, Express, TypeScript, and Prisma for managing gadgets and user authentication.

Features

  • 🔐 JWT-based Authentication & Authorization
  • 👤 User Management (Agents & Admins)
  • 🔧 Gadget Management System
  • 📝 PostgreSQL Database with Prisma ORM
  • 🚀 TypeScript Support
  • ⚡ Fast Development Setup

Prerequisites

  • Node.js (v14 or higher)
  • PostgreSQL Database
  • npm or yarn package manager

Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Language: TypeScript
  • ORM: Prisma
  • Database: PostgreSQL
  • Authentication: JWT (JSON Web Tokens)

Getting Started

  1. Clone the repository:
git clone <repository-url>
cd upraised
  1. Install dependencies:
npm install
  1. Set up environment variables: Create a .env file in the root directory with the following variables:
DATABASE_URL="postgresql://username:password@localhost:5432/database_name"
JWT_SECRET="your-jwt-secret"
PORT=3000
  1. Generate Prisma client and run migrations:
npm run prisma:generate
npm run prisma:migrate
  1. Start the development server:
npm run dev

Available Scripts

  • npm run dev - Start development server with hot-reload
  • npm run build - Build the project for production
  • npm start - Start production server
  • npm run prisma:generate - Generate Prisma client
  • npm run prisma:migrate - Run database migrations

API Endpoints

Authentication

  • POST /api/auth/register - Register a new user
  • POST /api/auth/login - Login user

Gadgets

  • GET /api/gadgets - Get all gadgets
  • GET /api/gadgets/:id - Get a specific gadget
  • POST /api/gadgets - Create a new gadget
  • PUT /api/gadgets/:id - Update a gadget
  • DELETE /api/gadgets/:id - Delete a gadget

Data Models

User

  • id: UUID
  • username: String (unique)
  • password: String (hashed)
  • role: Enum (AGENT, ADMIN)
  • createdAt: DateTime
  • updatedAt: DateTime

Gadget

  • id: UUID
  • codename: String (unique)
  • name: String
  • status: Enum (Available, Deployed, Destroyed, Decommissioned)
  • decommissionedAt: DateTime (optional)
  • createdAt: DateTime
  • updatedAt: DateTime

Security Features

  • Password hashing using bcrypt
  • JWT-based authentication
  • Role-based access control
  • Environment variables for sensitive data

Error Handling

The API includes a centralized error handling middleware that processes all errors and returns appropriate HTTP status codes and error messages.

Development

The project uses ts-node-dev for development, which provides hot-reload functionality. The TypeScript configuration is set up to ensure type safety throughout the application.

Releases

No releases published

Packages

No packages published