Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

42 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AuthLab API

Node.js TypeScript Express MongoDB Jest Docker MIT License


πŸ” Overview

AuthLab API is a robust authentication service built with Node.js, TypeScript, and Express. It provides secure user registration, login, and JWT-based authentication with comprehensive testing and Docker support.


✨ Features

  • πŸ”’ JWT-based authentication with refresh tokens
  • πŸ‘€ User registration and login
  • πŸ›‘οΈ Password hashing with bcrypt
  • πŸ“Š Input validation with Joi
  • 🚦 Rate limiting and security headers
  • πŸ“š Swagger API documentation
  • πŸ§ͺ Comprehensive testing (unit & integration)
  • 🐳 Docker containerization
  • πŸ”„ CI/CD ready
  • ☁️ SST for ECS deploy in AWS

πŸ—οΈ Project Structure

auth-lab/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app.ts                 # Express app configuration
β”‚   β”œβ”€β”€ index.ts               # Application entry point
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ database.ts        # MongoDB connection
β”‚   β”‚   └── env.ts             # Environment configuration
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ auth.controller.ts # Authentication logic
β”‚   β”‚   └── user.controller.ts # User management
β”‚   β”œβ”€β”€ middlewares/
β”‚   β”‚   β”œβ”€β”€ auth.middleware.ts # JWT verification
β”‚   β”‚   └── validate.middleware.ts # Input validation
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── user.model.ts      # User schema
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ auth.routes.ts     # Auth endpoints
β”‚   β”‚   └── user.routes.ts     # User endpoints
β”‚   β”œβ”€β”€ validations/
β”‚   β”‚   β”œβ”€β”€ auth.validation.ts # Auth validation schemas
β”‚   β”‚   └── user.validation.ts # User validation schemas
β”‚   β”œβ”€β”€ types/
β”‚   β”‚   └── express.d.ts       # Type definitions
β”‚   └── docs/
β”‚       └── openapi.yaml       # API documentation
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ unit/                  # Unit tests
β”‚   β”œβ”€β”€ integration/           # Integration tests
β”‚   └── setup.ts               # Test configuration
β”œβ”€β”€ Dockerfile                 # Docker configuration
└── docker-compose.yml         # Multi-container setup

πŸš€ Getting Started

Prerequisites

  • Node.js 20+
  • MongoDB
  • npm or yarn

1. Clone & Install

git clone https://github.com/Veras-D/auth-lab.git
cd auth-lab
npm install

2. Environment Setup

cp .env.example .env

Configure your environment variables:

NODE_ENV=development
PORT=3000
MONGODB_URI=mongodb://localhost:27017/auth-db
JWT_SECRET=your-jwt-secret
JWT_REFRESH_SECRET=your-refresh-secret
JWT_EXPIRES_IN=15m
JWT_REFRESH_EXPIRES_IN=7d

3. Start Development Server

npm run dev

The API will be available at http://localhost:3000


πŸ“š API Documentation

Interactive API documentation is available at /api-docs when the server is running.

Core Endpoints

Method Endpoint Description
POST /api/users/register Register new user
POST /api/users/login User login
GET /api/auth/profile Get user profile
POST /api/auth/logout User logout
POST /api/auth/token/refresh Refresh JWT token
GET /api/users Get all users
PUT /api/users/:id Update user
DELETE /api/users/:id Delete user

πŸ§ͺ Testing

Run All Tests

npm test

Unit Tests

npm run test:unit

Integration Tests

npm run test:integration

Test Coverage

npm run test:coverage

Watch Mode

npm run test:watch

🐳 Docker Deployment

Build and Run

npm run docker:build
npm run docker:run

Development with Docker Compose

npm run docker:dev

Production with Docker Compose

npm run docker:prod

πŸš€ Deploy to Render

  1. Fork this repository
  2. Connect your GitHub account to Render
  3. Create a new Web Service
  4. Configure environment variables
  5. Deploy automatically on git push

Render Configuration

  • Build Command: npm run build
  • Start Command: npm start
  • Environment: Node.js
  • Instance Type: Free tier compatible

πŸ“¦ Available Scripts

Script Description
dev Start development server
build Build TypeScript to JavaScript
start Start production server
test Run all tests
test:unit Run unit tests only
test:integration Run integration tests only
test:watch Run tests in watch mode
test:coverage Generate test coverage report
test:ci Run tests for CI/CD
lint Run ESLint
docker:build Build Docker image
docker:run Run Docker container

πŸ› οΈ Technologies

  • Node.js - Runtime environment
  • TypeScript - Type safety
  • Express - Web framework
  • MongoDB - Database
  • Mongoose - ODM
  • JWT - Authentication
  • bcrypt - Password hashing
  • Joi - Input validation
  • Jest - Testing framework
  • Swagger - API documentation
  • Docker - Containerization

πŸ”’ Security Features

  • Password hashing with bcrypt
  • JWT token authentication
  • Rate limiting
  • CORS protection
  • Security headers with Helmet
  • Input validation and sanitization

πŸ“„ License

MIT


β˜• Support

Ko-Fi


Β© 2025 VERAS. All rights reserved.

About

Auth API is a robust authentication service built with Node.js, TypeScript, and Express. It provides secure user registration, login, and JWT-based authentication with comprehensive testing and Docker support.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages