# thynkzone/pnc-social architecture

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

- Interactive diagram: https://gitdiagram.com/thynkzone/pnc-social
- Repository: https://github.com/thynkzone/pnc-social

## Overview

##### Project type and purpose
- This is a full-stack Java web application: a workplace social networking platform (“P&C”).
- Backend: Java/JSP/Servlets running on Apache Tomcat, using JDBC to talk to MySQL.
- Frontend: JSP pages, HTML5/CSS3, JavaScript, jQuery.
- Purpose: user management, social graph, content sharing, gamification, real-time notifications, admin tools, strong security.

##### File structure
- Top level:
- java/com/thynkzone/jsp/… – backend classes (database access, hashing, encryption, utilities).
- WEB-INF/web.xml + META-INF/MANIFEST.MF – servlet mappings, deployment descriptor.
- Patterns:
- Traditional MVC-ish: JSPs as views + Java utility classes invoked via scriptlets or custom tags.
- Single Tomcat WAR deployable module.
- Config & build:
- No explicit build script in repo (Maven optional).
- Sensitive configs (DB creds, security keys) under WEB-INF/secured/ (gitignored).

##### README for additional insights
- Tech stack reconfirmed (Tomcat, MySQL, BCrypt, AES, reCAPTCHA).
- Security features: CSRF tokens, prepared statements, input sanitization.
- External dependencies: email service (SMTP), Google reCAPTCHA.
- Data model: 8+ database tables (users, posts, comments, likes, notifications, ranks, reports).

##### Components
a. Main Components
– Browser/UI (JSP pages, JS and CSS)
– Web Server / Application Server (Apache Tomcat)
– Servlet Container + JSP Engine
– Business Logic Layer (Java classes in com.thynkzone.jsp)
– Data Access Layer (db.java)
– MySQL Database
– External Services: SMTP Mail Server, Google reCAPTCHA endpoint
– (Optional) File Storage for user uploads (e.g., external file server or cloud storage)
– Security Modules (BCrypt, AES encryption, CSRF filter)

b. Relationships and Interactions
1. User’s browser sends HTTP(S) request → Apache Tomcat
2. Tomcat consults web.xml → dispatch to JSP/Servlet
3. JSP invokes Java utility classes (business logic)
4. Business logic layer calls db.java → JDBC → MySQL
5. Results flow back through layers → JSP view → HTTP response
6. For file uploads: JSP forwards to storage module → saved externally
7. For email notifications: business logic calls SMTP server
8. For CAPTCHA: frontend requests token → backend verifies with Google API
9. Session cookie management, CSRF token checks at filter layer

c. Architectural Patterns & Design Principles
– Layered architecture (Presentation → Business Logic → Data Access)
– Security-first: encryption, hashing, prepared statements, token filters
– Modular utility classes for reuse (hashing, encoding, image processing)
– WAR-based monolith deploy
– MVC flavor: JSPs = Views, Java classes = Controllers/Models

d. Key Technologies/Frameworks
– Java Servlets & JSP on Apache Tomcat
– JDBC for MySQL connectivity
– BCrypt, SHA-512, AES for security
– Google reCAPTCHA v2/v3
– HTML5/CSS3/jQuery for client UI

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Browser Layer
    subgraph "Client Browser" 
        direction TB
        BrowserUI["Browser/UI<br/>(JSP, HTML, CSS, JS)"]:::frontend
        SessionCookie["Session Cookie/CSRF Token"]:::security
    end

    %% Web Container Layer
    subgraph "Apache Tomcat<br/>(Web Server & Servlet Container)" 
        direction TB
        WebXML["web.xml<br/>(Servlet Mappings)"]:::server
        JSPContainer["JSP Engine<br/>& Servlet Container"]:::server
        Manifest["MANIFEST.MF"]:::server
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        JSPViews["JSP Pages & Static Assets"]:::frontend
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer<br/>(Java Utility & Controllers)"
        direction TB
        BizLogic["com.thynkzone.jsp Classes<br/>(Rancook, Rund, af, millionaize, move2…)"]:::server
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        DBLayer["db.java<br/>(JDBC Interface)"]:::data
    end

    %% Database
    MySQLDB["MySQL Database"]:::data

    %% External Services
    subgraph "External Services"
        direction TB
        SMTP["SMTP Mail Server"]:::external
        ReCAPTCHAV2["Google reCAPTCHA V2"]:::external
        ReCAPTCHAV3["Google reCAPTCHA V3"]:::external
        FileStorage["External File Storage"]:::external
    end

    %% Security Modules
    subgraph "Security Modules"
        direction TB
        BCrypt["BCrypt (bcrypt.java, bsalt.java)"]:::security
        AES["AES Encryption (encdecry.java)"]:::security
        Hasher["Hash Utilities (hasher.java, hasherfast.java)"]:::security
        CSRFFilter["CSRF Filter (cf.java)"]:::security
    end

    %% Flow Connections
    BrowserUI -->|HTTPS Request| WebXML
    BrowserUI -->|Includes Token| SessionCookie
    WebXML -->|Dispatch| JSPContainer
    JSPContainer -->|Render| JSPViews
    JSPViews -->|Calls| BizLogic
    BizLogic -->|JDBC Calls| DBLayer
    DBLayer -->|SQL Queries| MySQLDB
    BizLogic -->|Send Email via SMTP| SMTP
    BizLogic -->|Verify CAPTCHA| ReCAPTCHAV2
    BizLogic -->|Verify CAPTCHA| ReCAPTCHAV3
    JSPViews -->|File Upload| FileStorage
    WebXML -->|Applies| CSRFFilter
    BizLogic -->|Uses Hash| BCrypt
    BizLogic -->|Uses Encryption| AES
    BizLogic -->|Uses Hash Utilities| Hasher

    MySQLDB -->|Result Set| DBLayer
    DBLayer -->|Data| BizLogic
    BizLogic -->|Response Data| JSPViews
    JSPViews -->|HTTP Response| BrowserUI

    %% Click Events
    click BrowserUI "https://github.com/thynkzone/pnc-social/tree/main/webapp/"
    click JSPViews "https://github.com/thynkzone/pnc-social/tree/main/webapp/"
    click WebXML "https://github.com/thynkzone/pnc-social/blob/main/webapp/WEB-INF/web.xml"
    click Manifest "https://github.com/thynkzone/pnc-social/blob/main/webapp/META-INF/MANIFEST.MF"
    click BizLogic "https://github.com/thynkzone/pnc-social/tree/main/java/com/thynkzone/jsp/"
    click DBLayer "https://github.com/thynkzone/pnc-social/blob/main/java/com/thynkzone/jsp/db.java"
    click SMTP "https://github.com/thynkzone/pnc-social/blob/main/java/com/thynkzone/jsp/Mailer.java"
    click ReCAPTCHAV2 "https://github.com/thynkzone/pnc-social/blob/main/java/com/thynkzone/jsp/reCaptchaV2.java"
    click ReCAPTCHAV3 "https://github.com/thynkzone/pnc-social/blob/main/java/com/thynkzone/jsp/reCaptchaV3.java"
    click BCrypt "https://github.com/thynkzone/pnc-social/blob/main/java/com/thynkzone/jsp/bcrypt.java"
    click AES "https://github.com/thynkzone/pnc-social/blob/main/java/com/thynkzone/jsp/encdecry.java"
    click CSRFFilter "https://github.com/thynkzone/pnc-social/blob/main/java/com/thynkzone/jsp/cf.java"
    click Hasher "https://github.com/thynkzone/pnc-social/blob/main/java/com/thynkzone/jsp/hasher.java"

    %% Styles
    classDef frontend fill:#D0E7FF,stroke:#333,stroke-width:1px
    classDef server fill:#D0FFD0,stroke:#333,stroke-width:1px
    classDef data fill:#FFE7B3,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef security fill:#FFD0D0,stroke:#333,stroke-width:1px
```
