How sambhavbalki-codes/auth-system works
Purpose and entry points
This is a Node.js backend centered on user authentication and session management. The process entry point is server.js, which initializes the application exported from src/app.js.
HTTP application boundary
src/app.js composes the web application: middleware, route registration, and error/request handling belong at this boundary. Authentication-facing HTTP endpoints are mounted through src/routes/auth.routes.js, keeping transport routing separate from business handlers.
Authentication flow
src/routes/auth.routes.js maps authentication requests to src/controllers/auth.controller.js. The controller is the primary orchestration layer for registration, login, logout, and/or session validation: it accepts HTTP input, invokes persistence models, and emits HTTP responses.
Identity persistence
src/models/user.model.js defines the durable user identity boundary. It owns user records and credentials/profile fields used by authentication. Controllers should access user data through this model rather than embedding database operations in routes.
Session persistence
src/models/session.model.js represents authenticated session state separately from user identity. The expected control flow is: authenticate a user through user.model, create or look up session state through session.model, then return or clear session information through the auth controller.
Configuration and database infrastructure
src/config/config.js centralizes runtime configuration, likely including environment-derived application and credential settings. src/config/database.js establishes the database connection used by src/models/user.model.js and src/models/session.model.js. This is the key external-service boundary: the application depends on a configured persistent database.
Runtime structure
The runtime is JavaScript/Node.js, with dependencies and execution scripts defined in package.json. Startup control flows from server.js → src/app.js → route registration → controllers → models/database; response flow returns in reverse through the HTTP application layer.
Main entry points: database.js Database Connection · auth.controller.js Auth Controller · server.js Server Entry · app.js Application Composition
Components 10
Node.js Runtime
- Package Scripts & Dependencies · Defines runtime dependencies and execution scripts.
package.json - Server Entry
server.js
HTTP Application
- Application Composition · Composes middleware, routes, and request/error handling.
src/app.js - Auth Routes
src/routes/auth.routes.js
Authentication
- Auth Controller · Handles registration, login, logout, and session validation.
src/controllers/auth.controller.js
Persistence
- User Model · Owns durable user records and credentials.
src/models/user.model.js - Session Model · Owns authenticated session state separately from identities.
src/models/session.model.js - Runtime Configuration · Provides environment-derived application and credential settings.
src/config/config.js - Database Connection · Establishes the persistent database connection.
src/config/database.js
Other components
- Persistent Database
Connections 10
- Package Scripts & Dependencies → Server Entry: runs
- Server Entry → Application Composition: initializes
- Application Composition → Auth Routes: mounts
- Auth Routes → Auth Controller: maps requests to
- Auth Controller → User Model: authenticates users
- Auth Controller → Session Model: creates, validates, clears sessions
- Runtime Configuration → Database Connection: configures
- Database Connection → Persistent Database: connects to
- User Model → Database Connection: uses
- Session Model → Database Connection: uses