# aadesh49/codejournal architecture

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

- Interactive diagram: https://gitdiagram.com/aadesh49/codejournal
- Repository: https://github.com/aadesh49/codejournal

## Overview

##### Project type and purpose
- This is a full-stack blog application called “Code Journal.”
- Frontend: React SPA with rich-text editor, styled via Tailwind, routing via React Router, 3D visuals via Spline.
- Backend: Node/Express REST API with JWT-based auth, file uploads, MongoDB storage via Mongoose.

##### File structure
- Top level splits into “frontend/” and “backend/.”
- frontend/src/ contains React components (App, Layout, Header, Post, pages for Home, Create, Edit, etc.), a UserContext for auth state, and styling files.
- frontend/public/ holds static assets (index.html, images).
- frontend has config files: package.json, ESLint, Vite, Tailwind (implied).
- backend/ contains index.js as the server entry point, models/ for User and Post schemas, uploads/ for Multer-managed files, and package.json for dependencies.
- No explicit routes folder, so index.js likely mounts Express routers inline or imports them.

##### Extract README insights
- Frontend dependencies: React, React Router DOM, Quill.js, Tailwind, Spline 3D.
- Backend dependencies: Express, Mongoose, JWT, bcrypt, Multer, CORS, dotenv.
- Supported features: user signup/login, CRUD on posts, image uploads, JWT auth with protected routes, CORS for cross-origin.

##### Diagramming the architecture
a. Main components
- Browser / Client (React SPA)
- HTTP API Layer (Express server)
- Authentication service (JWT issuance & verification + bcrypt password hashing)
- Data persistence (MongoDB via Mongoose)
- File storage (local disk under backend/uploads)
- Optional: Static asset hosting (Vite dev server / production static hosting)
b. Interactions & data flow
- User interacts with React UI → React Router for page changes.
- On user action (login, post CRUD) → client issues HTTP request (JSON + JWT in header) to Express endpoints.
- Express middleware:
– CORS: allows requests from frontend origin
– Body parser + Multer: handles JSON and file multipart requests
– Auth middleware: verifies JWT for protected routes
- Controller logic → Mongoose models CRUD operations on MongoDB.
- File uploads saved to backend/uploads → served statically or via Express route.
- Responses with JSON payloads (posts, status, JWT token).
c. Architectural patterns & principles
– Separation of concerns: UI layer vs API layer vs persistence layer
– Stateless auth via JWT
– MVC-style structure in backend (routes/controllers/models)
– Component-based UI in frontend
– Single Page Application communicating via REST
d. Key technologies & libraries
- Frontend: React.js, React Router DOM, Quill.js, Tailwind CSS, Spline 3D, Vite
- Backend: Node.js, Express.js, Mongoose, MongoDB, JWT, bcrypt, Multer, CORS, dotenv

##### Elements
- Labels: “React SPA,” “Express API,” “MongoDB,” “File Storage,” “Browser,” “JWT Auth”
- From Browser → Express for all API calls
- From Express → MongoDB for data reads/writes
- From Express → File Storage for uploads
- From Browser → File Storage (if serving images directly)
- Green for backend services
- Network boundaries (CORS, HTTP/HTTPS).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser / Client Layer
    subgraph "Browser / Client"
        direction TB
        Browser["Browser"]:::external
        ReactSPA["React SPA"]:::frontend
        ReactRouter["React Router"]:::frontend
        UserCtx["User Authentication Context"]:::frontend
        Tailwind["Tailwind CSS Styling"]:::frontend
        Quill["Rich-Text Editor (Quill.js)"]:::frontend
        Spline["3D Visuals (Spline)"]:::frontend
        HomePage["Home Page"]:::frontend
        PostPage["Post Detail Page"]:::frontend
        LoginPage["Login Page"]:::frontend
        RegisterPage["Registration Page"]:::frontend
        CreatePost["Create Post Page"]:::frontend
        EditPost["Edit Post Page"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        Express["Express REST API Server"]:::backend
        CORS["CORS Middleware"]:::backend
        BodyParser["Body Parser Middleware"]:::backend
        Multer["Multer File Upload Middleware"]:::backend
        AuthMw["JWT Auth Middleware"]:::backend
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        MongoDB["MongoDB"]:::db
        UserModel["User Model"]:::backend
        PostModel["Post Model"]:::backend
        FileStorage["File Storage (uploads/)"]:::storage
    end

    %% Connections - Client to API
    Browser --> ReactSPA
    ReactSPA --> ReactRouter
    ReactSPA --> UserCtx
    ReactSPA --> Tailwind
    ReactRouter --> HomePage
    ReactRouter --> PostPage
    ReactRouter --> LoginPage
    ReactRouter --> RegisterPage
    ReactRouter --> CreatePost
    ReactRouter --> EditPost

    HomePage -->|GET /api/posts| Express
    PostPage -->|GET /api/posts/:id| Express
    LoginPage -->|POST /api/auth/login| Express
    RegisterPage -->|POST /api/auth/register| Express
    CreatePost -->|POST /api/posts| Express
    EditPost -->|PUT /api/posts/:id| Express

    %% API Layer internals
    Express --> CORS
    Express --> BodyParser
    Express --> AuthMw
    Express --> Multer

    %% API to Persistence
    Express -->|"uses"| UserModel
    Express -->|"uses"| PostModel
    UserModel --> MongoDB
    PostModel --> MongoDB
    Express -->|"stores files"| FileStorage

    %% File serving
    Browser -->|GET /uploads/:file| FileStorage

    %% Click Events
    click ReactSPA "https://github.com/aadesh49/codejournal/blob/main/frontend/src/App.jsx"
    click ReactRouter "https://github.com/aadesh49/codejournal/blob/main/frontend/src/App.jsx"
    click CreatePost "https://github.com/aadesh49/codejournal/blob/main/frontend/src/pages/CreatePost.jsx"
    click EditPost "https://github.com/aadesh49/codejournal/blob/main/frontend/src/pages/EditPost.jsx"
    click Spline "https://github.com/aadesh49/codejournal/blob/main/frontend/src/Layout.jsx"
    click Tailwind "https://github.com/aadesh49/codejournal/blob/main/frontend/vite.config.js"
    click Tailwind "https://github.com/aadesh49/codejournal/blob/main/frontend/src/index.css"
    click Tailwind "https://github.com/aadesh49/codejournal/blob/main/frontend/src/App.css"
    click Tailwind "https://github.com/aadesh49/codejournal/blob/main/frontend/index.html"
    click UserCtx "https://github.com/aadesh49/codejournal/blob/main/frontend/src/UserContext.jsx"
    click HomePage "https://github.com/aadesh49/codejournal/blob/main/frontend/src/pages/HomePage.jsx"
    click PostPage "https://github.com/aadesh49/codejournal/blob/main/frontend/src/pages/PostPage.jsx"
    click LoginPage "https://github.com/aadesh49/codejournal/blob/main/frontend/src/pages/LoginPage.jsx"
    click RegisterPage "https://github.com/aadesh49/codejournal/blob/main/frontend/src/pages/RegisterPage.jsx"
    click Express "https://github.com/aadesh49/codejournal/blob/main/backend/index.js"
    click UserModel "https://github.com/aadesh49/codejournal/blob/main/backend/models/User.model.js"
    click PostModel "https://github.com/aadesh49/codejournal/blob/main/backend/models/Post.model.js"
    click FileStorage "https://github.com/aadesh49/codejournal/tree/main/backend/uploads/"
    click Express "https://github.com/aadesh49/codejournal/blob/main/backend/index.js"
    click UserModel "https://github.com/aadesh49/codejournal/blob/main/backend/models/User.model.js"
    click PostModel "https://github.com/aadesh49/codejournal/blob/main/backend/models/Post.model.js"
    click FileStorage "https://github.com/aadesh49/codejournal/tree/main/backend/uploads/"
    click FTJSON "https://github.com/aadesh49/codejournal/blob/main/frontend/package.json"
    click BEJSON "https://github.com/aadesh49/codejournal/blob/main/backend/package.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#024173
    classDef backend fill:#DFF2D8,stroke:#2c662d,color:#1f4720
    classDef db fill:#FFE4B5,stroke:#c37d00,color:#6e4c00
    classDef storage fill:#EEEEEE,stroke:#888888,color:#444444
    classDef external fill:#F0F0F0,stroke:#999999,color:#333333
```
