# aniketmishra31/digi-diary architecture

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

- Interactive diagram: https://gitdiagram.com/aniketmishra31/digi-diary
- Repository: https://github.com/aniketmishra31/digi-diary

## Overview

##### Project type and purpose
- Digi Diary is a full-stack web application (MERN stack) that lets authenticated users write, edit, delete, and browse private diary entries online.
- The front end is built in React (components under src/components), and the back end is an Express/Node.js API connecting to MongoDB.

##### File structure
- Top-level files:
– package.json / package-lock.json: front-end dependencies and build scripts
– README.md: project description
- public/: React’s static assets and index.html (SPA entry point)
- src/: React application source
– src/.env: environment variables (e.g., REACT_APP_API_URL, JWT secret)
– src/index.js + src/App.js: application bootstrap and routing (React Router)
– src/components/: UI components covering authentication (Login, Signup, AuthNavbar), navigation (Navbar, Footer), diary CRUD pages (Create, Update, PostsList, Post), static pages (About, Help, Contact, Cover), and user profile.

(Note: Although the back-end code is not present here, the README confirms an Express/Node API and a MongoDB database.)

##### README for additional insights
- Confirms use of JWT for auth and MongoDB for data persistence
- Mentions Express.js for RESTful API development
- Highlights client-server communication via JSON over HTTP

a. Main components:
1. React Front End (SPA)
2. Node.js/Express Back End (REST API)
3. MongoDB Database
4. Authentication Service (JWT issuance & validation)
5. (Optional) Hosting/CDN for front end and cloud provider for database
b. Relationships and interactions:
- The React SPA issues HTTPS requests (GET/POST/PUT/DELETE) to Express endpoints (e.g., /api/auth, /api/diaries).
- On login/signup, the back end verifies credentials against MongoDB, issues a JWT, and returns it to the client.
- For protected routes, the SPA includes the JWT in the Authorization header. The Express middleware validates the token before granting access.
- CRUD operations go through the Express controllers, which read/write diary documents in MongoDB.
c. Architectural patterns and design principles:
- SPA architecture (separation of concerns between UI and data layer)
- RESTful API design on the server
- Token-based stateless authentication (JWT)
- Component-based UI in React
d. Relevant technologies:
- React & React Router for front end
- Express.js & Node.js for back end
- Mongoose or MongoDB driver for data modeling/persistence
- JSON Web Tokens (jsonwebtoken) for auth
- Fetch or Axios for HTTP requests

##### Essential detail checklist
- Front-end: index.html → App.js (Router) → key page components
- Back-end: route layers → auth middleware → controller logic → database operations
- Auth flow: sign-up, login, token storage, token validation on subsequent requests
- Data flow for CRUD operations: create, read (list & single), update, delete
- Environment boundaries: client vs. server vs. database vs. external (e.g., cloud database)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side (Browser & React SPA)"
        direction TB
        Browser["Browser"]
        indexHTML["public/index.html"]:::frontend
        indexJS["src/index.js"]:::frontend
        appJS["src/App.js"]:::frontend
        Router["React Router"]
        FetchAPI["Fetch/Axios"]:::frontend

        subgraph "UI Components"
            direction TB
            AuthNavbar["AuthNavbar"]:::frontend
            Login["Login"]:::frontend
            Signup["Signup"]:::frontend
            Navbar["Navbar"]:::frontend
            Footer["Footer"]:::frontend
            Create["Create Entry"]:::frontend
            Update["Update Entry"]:::frontend
            PostsList["Posts List"]:::frontend
            Post["Single Post"]:::frontend
            Profile["Profile"]:::frontend
            Home["Home"]:::frontend
            Cover["Cover"]:::frontend
            About["About"]:::frontend
            Help["Help"]:::frontend
            Contact["Contact"]:::frontend
        end
    end

    %% Server Side
    subgraph "Server Side (Express API)"
        direction TB
        ExpressRouter["Express Router"]:::backend
        AuthMiddleware["Auth Middleware (JWT)"]:::auth
        Controllers["Controllers (Auth & Diary)"]:::backend
    end

    %% Database
    subgraph "Database"
        direction TB
        MongoDB["MongoDB"]:::db
    end

    %% Flows
    Browser -->|loads SPA| indexHTML
    indexHTML --> indexJS
    indexJS --> appJS
    appJS --> Router
    Router --> AuthNavbar
    Router --> Navbar
    Router --> Footer
    Router --> Create
    Router --> Update
    Router --> PostsList
    Router --> Post
    Router --> Profile
    Router --> Home
    Router --> Cover
    Router --> About
    Router --> Help
    Router --> Contact
    appJS --> FetchAPI
    FetchAPI -->|POST /api/login| ExpressRouter
    FetchAPI -->|POST /api/signup| ExpressRouter
    FetchAPI -->|GET /api/diaries| ExpressRouter
    FetchAPI -->|GET /api/diaries/:id| ExpressRouter
    FetchAPI -->|POST /api/diaries| ExpressRouter
    FetchAPI -->|PUT /api/diaries/:id| ExpressRouter
    FetchAPI -->|DELETE /api/diaries/:id| ExpressRouter

    ExpressRouter --> AuthMiddleware
    AuthMiddleware --> Controllers
    Controllers --> MongoDB

    %% Click Events
    click indexHTML "https://github.com/aniketmishra31/digi-diary/blob/master/public/index.html"
    click indexJS "https://github.com/aniketmishra31/digi-diary/blob/master/src/index.js"
    click appJS "https://github.com/aniketmishra31/digi-diary/blob/master/src/App.js"
    click AuthNavbar "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/AuthNavbar.jsx"
    click Login "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Login.jsx"
    click Signup "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Signup.jsx"
    click Navbar "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Navbar.jsx"
    click Footer "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Footer.jsx"
    click Create "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Create.jsx"
    click Update "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Update.jsx"
    click PostsList "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/PostsList.jsx"
    click Post "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Post.jsx"
    click Profile "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Profile.jsx"
    click Home "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Home.jsx"
    click Cover "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Cover.jsx"
    click About "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/About.jsx"
    click Help "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Help.jsx"
    click Contact "https://github.com/aniketmishra31/digi-diary/blob/master/src/components/Contact.jsx"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#00796b,color:#004d40
    classDef backend fill:#e8f5e9,stroke:#388e3c,color:#1b5e20
    classDef db fill:#fff3e0,stroke:#f57c00,color:#e65100
    classDef auth fill:#ffebee,stroke:#c62828,color:#b71c1c
```
