How indrajit4444/secrets works
Project type and purpose
• This is a monolithic, server-rendered full-stack web application built on Node.js/Express.
• Purpose: Allow users to register/login (via local credentials or Google OAuth 2.0), submit secrets anonymously, and view secrets in a secured manner.
File structure
• Top-level files
• app.js – the Express application entry point (routes, middleware, server startup)
• package.json / package-lock.json – dependencies, scripts
• .gitignore
• Directories
• models/ – Mongoose model definitions (user schema)
• views/ – EJS templates for pages (home, login, register, secrets, submit) and partials (header/footer)
• public/css/ – static assets (styles.css)
• No dedicated “controllers” folder; routing and handler logic lives in app.js
• Key config built into app.js: Passport.js strategies for local (hash+salt) and Google OAuth 2.0
README for additional insights
• Confirms use of MongoDB for persistent storage
• Passport.js for authentication, with local hashing & salting plus Google OAuth 2.0
• No mention of additional microservices or external databases beyond Google OAuth and MongoDB
Main components
a. Client (User’s Web Browser)
• Sends HTTP(S) requests; renders HTML/CSS from EJS templates
b. Web Server (Express.js in app.js)
• Router/Controllers:
• / (home)
• /register → local signup (hash/salt)
• /login → local login
• /auth/google → OAuth handshake with Google
• /secrets → secure display
• /submit → posting new secrets
• Middleware: body-parser, express-session, Passport initialization
c. Authentication Module (Passport.js)
• Local Strategy: username/password with bcrypt hashing + salting
• Google OAuth 2.0 Strategy: external token exchange with Google’s OAuth endpoint
d. Persistence Layer (MongoDB via Mongoose)
• User model: schema includes OAuth IDs, hashed passwords, and an array or collection of secrets
e. External Service (Google OAuth 2.0 Provider)
• OAuth endpoints for user consenting and token issuance
f. Static Assets Server
• Serves CSS and any other public assets from /public
Relationships & data flows
• Browser → HTTP GET/POST → Express Router → Controllers
• In login/register flows: Express → Passport → Mongoose → MongoDB
• In Google OAuth flow: Express → Passport Google Strategy → Google OAuth API → Passport callback → Mongoose → MongoDB
• When fetching secrets: Express → Mongoose → MongoDB → Express → EJS render → Browser
Architectural patterns & design principles
• MVC-inspired separation (Models in /models, Views in /views, Controllers in app.js)
• Middleware pipeline (Express) for parsing, session handling, auth
• Single-process, event-driven JS server with clear layering
• Use of external identity provider (Google OAuth) to offload user credential management
Technologies & frameworks
• Node.js, Express.js, EJS (templating)
• Passport.js with passport-local and passport-google-oauth20 strategies
• MongoDB (hosted or local) accessed via Mongoose ODM
• bcrypt (or equivalent) for password hashing and salting
• express-session for session management
Elements to include for maximum clarity
• Clear component labels (e.g., “Express Server (app.js)”, “Passport Local Strategy”)
• Internal services (Express, Passport, Mongoose)
• External services (Google OAuth, MongoDB)
• Client and static assets
• Notes on critical middleware (sessions, body-parser) and security layers (hashing/salting)