Scalable MicroServices based Authentication Infrastructure built with Nx, Express, and TypeScript.
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.
The project follows a modular Nx Monorepo structure, separating concerns between application gateways and shared domain logic.
-
apps/api-gatewayThe 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-healthendpoint.
-
apps/iam-serviceThe 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.
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.envschema via Zod).utils/: Sharedloggerinstance (Pino).
- Framework: Express.js
- Monorepo Tooling: Nx
- Language: TypeScript
- Validation: Zod
- Logging: Pino
- Utilities:
dotenv,cors,cookie-parser,express-limit. - Security:
argon2(Password Hashing).
- Node.js (v20+ recommended)
- npm or yarn
npm installCreate 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=developmentStart the development server (runs all applications in watch mode):
npm run devOr run the specific application:
npx nx serve api-gateway| 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. |
- Built with 💖 by @codeprnv