πŸ“„ Authentication Microservice - Technical Architecture Documentation

Professional technical documentation showcasing microservices architecture

Authentication Microservice

Architecture Documentation

Developer: Lakshay Mahajan | Version: 1.0.0

⚑ Security Status: 33% improvement (50/100 β†’ 83/100).
πŸ—οΈ System Architecture Overview
Auth Architecture Diagram
🎯 Core Design Principles

πŸ”„ Reusability

Single authentication service powers multiple frontend applications, eliminating code duplication and ensuring consistency.

⚑ Performance

Asynchronous email processing ensures users don't wait for email delivery, improving response times.

πŸ›‘οΈ Security

JWT RS256 encryption, bcrypt password hashing, rate limiting, and secure cookie handling.

πŸ“ˆ Scalability

Event-driven architecture with AWS services allows horizontal scaling and reliable message processing.

Key Innovation: This architecture demonstrates system thinking by implementing a centralized authentication system with event-driven background processing.
βš™οΈ Technical Specifications
Technology Stack
Node.js 18+
Express.js
MongoDB
JWT (RS256)
AWS SNS/SQS
AWS Lambda
Docker
Google OAuth 2.0
GitHub Actions
πŸ›οΈ Architecture Patterns Implemented

Microservices Architecture

Single-responsibility service handling authentication for multiple client applications with clear service boundaries.

Event-Driven Design

Asynchronous message processing using AWS SNS/SQS for decoupled email notifications.

Repository Pattern

Clean separation between data access layer and business logic with dedicated service and controller layers.

Configuration Management

Environment-based configuration with secure secrets management and different settings for dev/prod.

πŸ”§ System Configuration

Authentication Methods:

Security Implementation:

🐳 Deployment Architecture

Containerization:

CI/CD Pipeline:

🌟 Key Features & Design Decisions
Authentication Features

πŸ”‘ Dual Authentication

Traditional & OAuth: Supports both email/password and Google OAuth 2.0, providing flexibility for different user preferences.

πŸͺ Cookie-Based Sessions

Secure & Persistent: Migrated from localStorage to secure httpOnly cookies, solving data persistence and security issues.

🎫 JWT Token Management

RS256 Encryption: Asymmetric key signing for enhanced security with 12-hour expiration time.

🚦 Rate Limiting

DDoS Protection: Configurable request limiting to prevent abuse and ensure service availability.

πŸ“§ Background Processing Architecture
Design Decision: Implemented asynchronous email processing to prevent user experience degradation. Users receive immediate authentication response while email notifications are processed in the background.

Email Processing Flow:

  1. Event Publication: Auth service publishes user events to AWS SNS topic
  2. Message Filtering: SQS queues receive filtered messages based on event type
  3. Lambda Processing: AWS Lambda functions triggered by SQS messages
  4. Email Delivery: Lambda functions handle email sending
πŸ—οΈ Code Organization & Best Practices

Project Structure Design:

πŸ›‘οΈ Security Design Decisions

Password Security

Bcrypt hashing with salt rounds, secure password validation.

Token Security

RSA-256 asymmetric encryption, proper key management, and 12-hour token expiration.

Request Security

Input validation, CORS protection, rate limiting.

Data Security

Secure cookie configuration, environment variable management, and proper error message handling.

⚠️ Known Limitations

Current System Constraints:

πŸ—ΊοΈ Roadmap & Future Enhancements

⚑ Active Development - Prioritized by Impact & Timeline:

High Priority (January 2025):

Medium Priority (February 2025):

Future Enhancements:

System Evolution: This service evolved from localStorage-based session management (with data persistence issues) to secure cookie-based authentication, solving real-world production problems encountered in previous projects.
πŸ”Œ API Endpoints & Integration Guide
Authentication Endpoints
POST /api/users/signup

Purpose: Register new user with email/password

Required Fields: name, email, password, username, business

Response: JWT token set as httpOnly cookie + user data

Events: Triggers 'user_registered' SNS message for welcome email

POST /api/users/login

Purpose: Authenticate existing user

Required Fields: email, password, business

Response: JWT token set as httpOnly cookie + user data

Events: Triggers 'user_loggedIn' SNS message for login notification

POST /api/users/logout

Purpose: Clear user session and invalidate token

Response: Success confirmation with cookie cleared

OAuth Endpoints
GET /api/auth/google/callback

Purpose: Google OAuth 2.0 callback handler

Process: Receives Google auth code, exchanges for user data

Response: JWT token set as httpOnly cookie + redirect to frontend

GET /api/auth/google/verify

Purpose: Verify JWT token validity

Response: Token status and user information

πŸ”— Integration Examples

Frontend Integration Pattern:

// Login Request Example
fetch('https://yourdomain.com/api/users/login', {
  method: 'POST',
  credentials: 'include', // Important for cookies
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    email: 'user@example.com',
    password: 'password123',
    business: 'resource-manager'
  })
})
πŸŽ›οΈ Configuration Requirements

Frontend CORS Configuration:

Cookie Domain Settings:

Integration Benefits: One-time integration effort provides authentication for unlimited client applications. Each new frontend requires only CORS configuration update, no code changes needed.
πŸ“Š Production Usage & Performance Metrics
Current Production Applications

πŸ—‚οΈ Resource Manager

Purpose: Developer resource management system

Features: Multi-link bookmarks, document uploads, tag-based search, organized collections

Authentication: Email/password and Google OAuth integration

πŸ“š Knowledge Store

Purpose: Book rental and management platform

Features: Catalog browsing, cart management, wishlist functionality, user profiles

Authentication: Seamless single sign-on across platform

πŸš€ Deployment & Infrastructure

Current Infrastructure:

Cost Optimization:

πŸ’‘ Key Learnings & Insights
Evolution Journey: From localStorage session management issues to production-ready cookie-based authentication with event-driven architecture. Each challenge solved contributed to a more robust, scalable system.

Technical Insights: