# indrajit4444/secrets architecture

> Architecture diagram of the GitHub repository indrajit4444/secrets, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/indrajit4444/secrets
- Repository: https://github.com/indrajit4444/secrets

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser["Client Browser"]:::client
    Browser -->|"GET /, POST /login, /register"| ExpressServer
    Browser -->|"GET CSS"| StaticAssets

    %% Static Assets
    StaticAssets["Static Assets (CSS)"]:::assets
    click CSS "https://github.com/indrajit4444/secrets/blob/main/public/css/styles.css"

    %% Server Layer
    subgraph "Express Application"
        direction TB
        ExpressServer["Express Server (app.js)"]:::server
        Middleware["Middleware: body-parser, express-session"]:::server
        PassportLocal["Passport Local Strategy"]:::auth
        PassportGoogle["Passport Google OAuth2 Strategy"]:::auth
        Routes["Routes (/ , /register, /login, /auth/google, /secrets, /submit)"]:::server

        ExpressServer -->|uses| Middleware
        ExpressServer -->|initializes| PassportLocal
        ExpressServer -->|initializes| PassportGoogle
        ExpressServer -->|defines| Routes
    end
    click ExpressServer "https://github.com/indrajit4444/secrets/blob/main/app.js"
    click PassportLocal "https://github.com/indrajit4444/secrets/blob/main/app.js"
    click PassportGoogle "https://github.com/indrajit4444/secrets/blob/main/app.js"

    %% Views & Templates
    subgraph "Views (EJS Templates)"
        direction TB
        Home["Home Page"]:::view
        Login["Login Page"]:::view
        Register["Register Page"]:::view
        SecretsPage["Secrets Display Page"]:::view
        SubmitPage["Submit Secret Page"]:::view
        Header["Header Partial"]:::view
        Footer["Footer Partial"]:::view

        Routes -->|renders| Home
        Routes -->|renders| Login
        Routes -->|renders| Register
        Routes -->|renders| SecretsPage
        Routes -->|renders| SubmitPage
        Home --> Header
        Home --> Footer
        Login --> Header
        Login --> Footer
        Register --> Header
        Register --> Footer
        SecretsPage --> Header
        SecretsPage --> Footer
        SubmitPage --> Header
        SubmitPage --> Footer
    end
    click Home "https://github.com/indrajit4444/secrets/blob/main/views/home.ejs"
    click Login "https://github.com/indrajit4444/secrets/blob/main/views/login.ejs"
    click Register "https://github.com/indrajit4444/secrets/blob/main/views/register.ejs"
    click SecretsPage "https://github.com/indrajit4444/secrets/blob/main/views/secrets.ejs"
    click SubmitPage "https://github.com/indrajit4444/secrets/blob/main/views/submit.ejs"
    click Header "https://github.com/indrajit4444/secrets/blob/main/views/partials/header.ejs"
    click Footer "https://github.com/indrajit4444/secrets/blob/main/views/partials/footer.ejs"

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        UserModel["Mongoose User Model"]:::model
        MongoDB["MongoDB"]:::db
        UserModel -->|CRUD via Mongoose| MongoDB
    end
    click UserModel "https://github.com/indrajit4444/secrets/blob/main/models/user.js"

    %% External Services
    GoogleOAuth["Google OAuth 2.0"]:::external
    ExpressServer -->|OAuth token exchange| GoogleOAuth
    GoogleOAuth -->|callback| ExpressServer

    %% Additional Config Files
    Configs["Config & Scripts"]:::config
    Configs --> Package
    Configs --> PackageLock
    Configs --> GitIgnore
    click Package "https://github.com/indrajit4444/secrets/blob/main/package.json"
    click PackageLock "https://github.com/indrajit4444/secrets/blob/main/package-lock.json"
    click GitIgnore "https://github.com/indrajit4444/secrets/blob/main/.gitignore"

    %% Response flows
    ExpressServer -->|"EJS Rendered HTML"| Browser
    MongoDB -->|query results| ExpressServer

    %% Style Definitions
    classDef client fill:#cccccc,stroke:#333,stroke-width:1px
    classDef server fill:#add8e6,stroke:#333,stroke-width:1px
    classDef auth fill:#87cefa,stroke:#333,stroke-width:1px
    classDef db fill:#90ee90,stroke:#333,stroke-width:1px
    classDef external fill:#ffa500,stroke:#333,stroke-width:1px
    classDef assets fill:#ffff99,stroke:#333,stroke-width:1px
    classDef view fill:#e6e6fa,stroke:#333,stroke-width:1px
    classDef model fill:#98fb98,stroke:#333,stroke-width:1px
    classDef config fill:#f0e68c,stroke:#333,stroke-width:1px
```
