Sign inSign up

jjimenezc/teslo-shop

By jjimenezc

•Updated about 1 year ago

Image
0

978

jjimenezc/teslo-shop repository overview

⁠Teslo Shop API

A production-ready e-commerce REST API built with NestJS, featuring authentication, product management, file uploads, and real-time messaging capabilities.

⁠Quick Start

# Pull and run the image
docker pull your-registry/teslo-shop:latest
docker run -p 3000:3000 -e PORT=3000 your-registry/teslo-shop:latest

⁠What is Teslo Shop?

Teslo Shop is a comprehensive e-commerce backend API built with NestJS and TypeScript. It provides a complete solution for online store management with modern web technologies and best practices.

⁠Key Features
  • 🔐 Authentication & Authorization - JWT-based authentication with role-based access control
  • 📦 Product Management - Complete CRUD operations for products with image support
  • 📁 File Upload System - Secure file handling and static asset serving
  • 💬 Real-time Messaging - WebSocket integration for live communication
  • 📊 API Documentation - Auto-generated Swagger/OpenAPI documentation
  • 🌱 Database Seeding - Built-in data seeding for development and testing
  • 🔍 Data Validation - Comprehensive input validation and sanitization
  • 🏗️ TypeORM Integration - Database abstraction with PostgreSQL support

⁠Environment Variables

The following environment variables are required to configure the application:

VariableDescriptionRequiredDefaultExample
PORTApplication port✅30003000
APP_VERSIONApplication version for tracking❌-1.0.1
STAGEDeployment stage (affects SSL settings)✅devdev, prod
DB_HOSTPostgreSQL database host✅-localhost, db
DB_PORTPostgreSQL database port✅54325432
DB_NAMEPostgreSQL database name✅-TesloDB
DB_USERNAMEPostgreSQL database username✅-postgres
DB_PASSWORDPostgreSQL database password✅-MySecr3tPassWord@as2
JWT_SECRETSecret key for JWT token signing✅-Est3EsMISE3Dsecreto32s...
HOST_APIBase URL for API (used for file URLs)✅-http://localhost:3000/api
⁠Environment Variables Notes
  • SSL Configuration: When STAGE=prod, the application automatically enables SSL for database connections
  • JWT Security: Use a strong, unique JWT_SECRET in production (minimum 32 characters recommended)
  • Database: The application uses PostgreSQL and requires all database connection variables
  • File URLs: HOST_API is used to generate complete URLs for uploaded files

⁠API Endpoints

  • API Base: /api
  • Documentation: /api (Swagger UI)
  • Health Check: /api/seed (also serves as data seeding endpoint)

⁠Multi-stage Build

This image uses a multi-stage Docker build for optimal production deployment:

  • Development stage: Full development environment with hot reload
  • Builder stage: Compiles TypeScript to JavaScript
  • Production stage: Minimal runtime image with only necessary dependencies

⁠Supported Tags

  • latest - Latest stable release
  • dev - Development build with hot reload capabilities
  • x.x.x - Specific version tags

⁠Usage Examples

⁠Development Mode
docker run -p 3000:3000 \
  -e PORT=3000 \
  -e STAGE=dev \
  -e DB_HOST=localhost \
  -e DB_PORT=5432 \
  -e DB_NAME=TesloDB \
  -e DB_USERNAME=postgres \
  -e DB_PASSWORD=MySecr3tPassWord@as2 \
  -e JWT_SECRET=Est3EsMISE3Dsecreto32s \
  -e HOST_API=http://localhost:3000/api \
  -v $(pwd):/app \
  -v /app/node_modules \
  your-registry/teslo-shop:dev
⁠Production Mode
docker run -d \
  --name teslo-shop \
  -p 3000:3000 \
  -e PORT=3000 \
  -e APP_VERSION=1.0.0 \
  -e STAGE=prod \
  -e DB_HOST=your-db-host \
  -e DB_PORT=5432 \
  -e DB_NAME=TesloDB \
  -e DB_USERNAME=postgres \
  -e DB_PASSWORD=your-secure-password \
  -e JWT_SECRET=your-super-secure-jwt-secret-key \
  -e HOST_API=https://your-domain.com/api \
  your-registry/teslo-shop:latest
⁠With Docker Compose
version: '3.8'
services:
  teslo-shop:
    image: your-registry/teslo-shop:latest
    ports:
      - "3000:3000"
    environment:
      - PORT=3000
      - APP_VERSION=1.0.0
      - STAGE=prod
      - DB_HOST=postgres
      - DB_PORT=5432
      - DB_NAME=TesloDB
      - DB_USERNAME=postgres
      - DB_PASSWORD=MySecr3tPassWord@as2
      - JWT_SECRET=Est3EsMISE3Dsecreto32s
      - HOST_API=http://localhost:3000/api
    depends_on:
      - postgres
  
  postgres:
    image: postgres:14.3
    environment:
      - POSTGRES_DB=TesloDB
      - POSTGRES_PASSWORD=MySecr3tPassWord@as2
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

volumes:
  postgres_data:
⁠Environment File (.env)
# Application Configuration
PORT=3000
APP_VERSION=1.0.1
STAGE=dev

# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=TesloDB
DB_USERNAME=postgres
DB_PASSWORD=MySecr3tPassWord@as2

# Security
JWT_SECRET=Est3EsMISE3Dsecreto32s

# API Configuration
HOST_API=http://localhost:3000/api

⁠Technology Stack

  • Framework: NestJS 8.x
  • Runtime: Node.js 19 (Alpine Linux)
  • Language: TypeScript
  • Database: PostgreSQL (via TypeORM)
  • Authentication: JWT with Passport
  • Documentation: Swagger/OpenAPI
  • WebSockets: Socket.IO
  • Validation: class-validator & class-transformer

⁠Health Check

The application exposes a health check endpoint at /api/seed which can be used to verify the service is running correctly.

⁠Security Features

  • Input validation and sanitization
  • JWT token-based authentication
  • Role-based authorization
  • Secure file upload handling
  • CORS configuration
  • Environment-based configuration
  • SSL support for production databases

⁠File Upload Support

The application supports secure file uploads for product images with:

  • Automatic file validation (jpg, jpeg, png, gif)
  • UUID-based file naming
  • Static file serving
  • Configurable upload paths

⁠License

This project is licensed under UNLICENSED.

⁠Support

For issues and questions, please refer to the project repository or contact the development team.

Tag summary

Content type

Image

Digest

sha256:7bac1d97a…

Size

65.6 MB

Last updated

about 1 year ago

docker pull jjimenezc/teslo-shop