Skip to content

codeprnv/aegis

Repository files navigation

🛡️ Aegis

Scalable MicroServices based Authentication Infrastructure built with Nx, Express, and TypeScript.

Nx TypeScript Express.js Zod

Aegis is a high-performance, resilient backend system designed for secure authentication operations. It leverages a modern monorepo architecture to ensure code modularity, type safety, and operational excellence.


🏗️ Architecture

The project follows a modular Nx Monorepo structure, separating concerns between application gateways and shared domain logic.

🚀 Applications

  • apps/api-gateway The central entry point for all client requests. It handles:

    • 🛡️ Security: Rate limiting, CORS configuration, and header sanitation.
    • 🔍 Observability: Request tracing (cls-rtracer) and access logging.
    • 🔑 Context: Authentication context extraction from tokens.
    • Health Checks: /gateway-health endpoint.
  • apps/iam-service The identity and access management service. It handles:

    • 🔐 Authentication: User registration, login, and secure password hashing (Argon2).
    • 🎫 Token Management: JWT issuance (Access & Refresh tokens).
    • 👤 User Management: Profile management and RBAC.

📚 Packages (packages/)

Core utilities shared across the platform:

  • middlewares/:
    • access-logger: Standardized request logging.
    • extractAuthContext: Decodes and injects user context into requests.
    • request-tracer: unique request ID generation for distributed tracing.
    • errorMiddleware: Centralized exception handling.
  • types/: shared TypeScript interfaces (e.g., process.env schema via Zod).
  • utils/: Shared logger instance (Pino).

🛠️ Tech Stack

  • Framework: Express.js
  • Monorepo Tooling: Nx
  • Language: TypeScript
  • Validation: Zod
  • Logging: Pino
  • Utilities: dotenv, cors, cookie-parser, express-limit.
  • Security: argon2 (Password Hashing).

⚡ Getting Started

Prerequisites

  • Node.js (v20+ recommended)
  • npm or yarn

1. Installation

npm install

2. Environment Setup

Create a .env file in the root directory. Ensure the following variables are defined (validated by libs/types/env.ts):

API_GATEWAY_PORT=8080
HOST=http://localhost
ORIGIN_HOST_1=http://localhost:3000
JWT_SECRET=your_super_secret_jwt_key
NODE_ENV=development

3. Running the Project

Start the development server (runs all applications in watch mode):

npm run dev

Or run the specific application:

npx nx serve api-gateway

🧪 Commands

Command Description
npm run dev Starts the development server for the entire workspace.
npx nx build api-gateway Builds the API Gateway for production.
npx jest apps/iam-service Runs unit tests for the IAM service.
npx nx graph Visualizes the project dependency graph.

Authors

About

A microservices based secure authentication system

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors