Skip to main content

Overview

The PC Fix backend is a RESTful API built with Express 5, featuring a modular architecture organized by domain. It uses Prisma 6 as the ORM for PostgreSQL database access and implements industry-standard security practices.
The API is deployed on Railway and serves as the data layer for the Astro frontend.

Core Technologies

Express 5.2.1

Modern web application framework with async middleware support

Prisma 6.18

Type-safe ORM with automatic migrations and client generation

PostgreSQL

Robust relational database hosted on Railway

TypeScript 5.9

End-to-end type safety from database to API responses

Project Structure

Server Setup

server.ts

src/server.ts

Middleware Stack

Authentication Middleware

src/shared/middlewares/authMiddleware.ts

Rate Limiting Middleware

src/shared/middlewares/rateLimitMiddleware.ts

Error Handling Middleware

src/shared/middlewares/errorMiddleware.ts

Upload Middleware (Cloudinary)

src/shared/middlewares/uploadMiddleware.ts

Module Structure (Example: Products)

Routes

src/modules/products/products.routes.ts

Controller

src/modules/products/products.controller.ts

Service

src/modules/products/products.service.ts

Prisma Client Setup

src/shared/database/prismaClient.ts

Background Jobs (Cron Service)

src/shared/services/cron.service.ts

API Modules Overview

  • User registration and login
  • JWT token generation and refresh
  • Google OAuth integration
  • Password reset functionality
  • Token blacklisting
  • CRUD operations for products
  • Filtering, searching, pagination
  • Image upload to Cloudinary
  • Soft delete functionality
  • Featured products
  • Hierarchical category structure
  • Parent-child relationships
  • Category-based product filtering
  • Order creation and management
  • Payment processing (MercadoPago)
  • Order status workflow
  • Shipping integration (Zipnova)
  • Invoice generation
  • Add/remove items
  • Update quantities
  • Abandoned cart tracking
  • Cart persistence
  • Support ticket creation
  • Admin ticket management
  • Service items catalog
  • Response system
  • Sales analytics
  • Revenue reports
  • Product performance metrics
  • User statistics

Security Features

JWT Authentication

Stateless authentication with access and refresh tokens

Password Hashing

Bcrypt hashing with salt rounds for secure password storage

Rate Limiting

Protection against brute force and DDoS attacks

Helmet.js

HTTP header security (XSS, clickjacking, etc.)

CORS

Configurable cross-origin resource sharing

Input Validation

Zod schema validation on all endpoints

Testing

src/modules/products/products.test.ts

Next Steps

Database Schema

Explore the Prisma schema

Frontend

Connect to the Astro frontend

Deployment

Deploy to Railway