Hey there! Iโm Yatharth Kumar Saxena, and over the last 30 days, I hand-crafted a zero-compromise authentication system for modern production use cases โ featuring secure login, strict device binding, rate limiters, and complete audit logging. After 296 commits and 4500+ lines of code, I'm opening it up for the world. Letโs build together.
- ๐ Introduction
- ๐ Core Highlights
- ๐งฉ Current Architecture
- ๐๏ธ Folder Structure
- ๐งโ๐ป Open Contribution Areas
- ๐ค How to Contribute
- โ๏ธ Tech Stack & Principles
- ๐ฏ Final Takeaway
This is the open-source counterpart to my private Strict Authentication Service. While the original repository was focused on internal implementation and experimentation, this one is about collaboration, innovation, and collective engineering.
โSystem fails. Design survives.โ โ YKS
This isnโt just login/signup โ itโs a full-blown auth engine with enterprise readiness.
- ๐ JWT-based stateless sessions (access & refresh)
- ๐ Admin-only protected routes (with
ADMxxxxxprefix) - ๐ต Strict device policy: Only one device per user, one user per device
- โฑ๏ธ Request tracking (
requestCount,lastRequestAt) per device - ๐ Auto-expiry & re-allocation of device slots if inactive
- ๐ Full logout (DB + cookies + logs)
- ๐งพ Structured audit logging (with
SYSTEM,USER,ADMIN) - ๐ซ Rate limiting for login/signup/change-password
- ๐ Cookie & header-based token response (double fallback)
โ ๏ธ Dynamic field validation (regex + length-based)
Design Principles:
โ๏ธ SOLID ยท โ๏ธ DRY ยท โ๏ธ KISS ยท โ๏ธ YAGNI
Patterns in Play:
๐งฑ Singleton ยท ๐ญ Factory ยท ๐งฌ Strategy ยท ๐ Chain of Responsibility
This system is modular, testable, and microservice-ready โ designed with scalability and readability in mind.
๐ง Session Management Note:
- A user can only stay logged in from one device at a time.
- If they log in from another device, the previous session is invalidated.
- Each device is uniquely tied to only one user at any point in time.
Total files: 60+ (excluding
node_modules)
| ๐ Folder | ๐ท๏ธ Description |
|---|---|
configs/ |
โ Application configs (env, auth, cookie, token, HTTP codes, regex, etc.) |
controllers/ |
๐ฎ Express route handlers โ directly handle incoming HTTP requests |
middlewares/ |
๐ก๏ธ Role guards, device parsers, rate-limiters, access control checks |
rate-limiters/ |
๐ Route-based in-memory limiter logic and dynamic Prisma-based limiter service |
services/ |
๐ง Core business logic โ login, registration, ID generation, validation, logout |
utils/ |
๐งฐ Helper utilities โ logs, token, cookie, validators, device utils, etc. |
clients/ |
๐ข๏ธ Prisma clients โ handles public.prisma and private.prisma connections |
routers/ |
๐ Route layer โ Express router-level mappings for all APIs |
cron-jobs/ |
โฑ๏ธ Time-based background jobs (e.g., cleanup, expiry, stale sessions) |
internal/ |
๐ฐ๏ธ Internal API call handlers (service-to-service calls if extended later) |
README.md |
๐งญ You are here โ full repo structure, purpose, and setup instructions |
Each module has its own README.md inside the folder for context and usage.
Hereโs what weโre actively looking to build or improve:
- After sign-up, users remain
isActive: falseuntil OTP verification. - Implement 6-digit OTP with a 30s expiry & retry logic.
- Ideal: Plug this as a strategy module or plug-in service.
- One-time token/email flow.
- TTL-based token expiry or OTP-based verification.
- Ensure rate limit + log tracking.
- Plug in
winstonorpino. - Add traceIDs, log rotation, and transport options.
- In-memory cache for device/user lookups.
- Graceful shutdown handling.
- Add Prometheus metrics integration (optional).
- Strict validator improvements
- Mongoose index improvements (e.g., TTL)
- Controller decoupling or route modularization
๐ Must follow design principles & architecture style.
- Fork โ clone โ
git checkout -b feature/your-feature - Run
npm installโ rename.env.sampleโ.env - Make your changes with clear commit messages
- Open a PR โ mention issue number and design rationale
- Donโt forget unit tests for new logic
| Layer | Tech |
|---|---|
| ๐ Backend | Node.js + Express.js |
| ๐ง DB | PostgreSQL (Prisma ORM) |
| ๐ Auth | JWT (stateless), cookie fallback |
| ๐ Logs | Console + audit logs (JSON-ready) |
| โฑ๏ธ Limiting | User + Device rate limiters |
| โป๏ธ Cleanup | Cron jobs (expired logs, stale users) |
This project started as my personal dive into enterprise-grade authentication systems. Now, itโs yours too.
Whether itโs your first PR or a production-grade refactor โ welcome aboard.
Letโs build a fortress of security โ the clean way. ๐
โ Yatharth Kumar Saxena