# durgaprasad118/blogging_app architecture

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

- Interactive diagram: https://gitdiagram.com/durgaprasad118/blogging_app
- Repository: https://github.com/durgaprasad118/blogging_app

## Overview

##### Main Components
- Frontend (Client):
- Contains a “client” folder with assets, pages, components, hooks, and store modules.
- Uses React with TypeScript and TailwindCSS.
- Key areas include layout and routing (client/src/Layout), page-level components for features like BlogList, BlogPage, Login, Signup, etc.
- Uses libraries such as react-simple-wysiwyg for the editor, recoil for state management, and other utilities.

- Backend (Server):
- Located in the “server” folder and structured into modules such as controllers, routes, middleware (for authentication), and utils.
- Uses Hono as a lightweight framework along with Prisma, which is used to handle database migrations and ORM for PostgreSQL.
- Controllers are divided by domain (blogs and users) and handle operations like creating, reading, updating, and deleting blog posts, as well as user authentication actions.
- Includes configuration and migration files under “server/prisma” for managing the PostgreSQL schema.

- Database:
- A PostgreSQL database managed via Prisma, with migrations stored in the prisma/migrations directories.

- External Services:
- The README mentions Cloudinary for handling image uploads.

##### Relationships and Interactions
- The Frontend communicates with the Backend via RESTful API calls over HTTP.
- Routing in the client directs users to various pages (blogs, authentication screens, editor) which then invoke API endpoints on the server.
- The Backend uses controllers (for blog and user operations) that process incoming requests, perform authentication (using the authMiddleware), and then interact with the PostgreSQL database using Prisma.
- Data flow parts:
- User actions in the client (e.g., creating a blog post, signing in) trigger API calls to the backend routes.
- The backend validates/authenticates the request, processes the operation via its controllers, and then returns responses.
- Image uploads are managed by sending files which may be forwarded to Cloudinary.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The division between client and server ensures a clear separation between presentation logic and business logic.
- MVC-like Pattern on the Backend: Controllers, routes, and middleware suggest a layered architecture where the controller layer handles business logic, the middleware handles cross-cutting concerns (like authentication), and the routes define the API structure.
- Component-based Architecture on the Frontend: The client is organized in React components (e.g., BlogCard, Navbar, Editor) and pages that isolate UI concerns.
- Use of State Management: The client’s “store” (using Recoil) and hooks indicates a design that centralizes state and side effects.

- Pages (e.g., Home, Login, Signup, BlogPage)
- Components (e.g., Navbar, BlogCard, Editor)
- Layout & Routing
- Hooks & State Management
- API Routes (blog.routes, user.routes)
- Controllers (blog controllers, user controllers)
- Middleware (authMiddleware)
- Utilities (e.g., password hashing)
- Prisma ORM Integration

c. External Services:
- Optionally, include other external libraries or services that affect the system.

d. Interactions between components:
- From “Frontend” to “Backend” labeled “API Calls (HTTP/REST)”.
- From “Backend” to “Database” labeled “Prisma ORM Queries/Mutations”.
- From “Backend” to “Cloudinary” (if applicable) for image uploads.
- Middleware intercepting API calls for authentication.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (Client)"
        FE_Main["Main Entry & Assets"]:::frontend
        FE_Pages["Pages"]:::frontend
        FE_Components["Components"]:::frontend
        FE_Layout["Layout & Routing"]:::frontend
        FE_Hooks["Hooks"]:::frontend
        FE_State["State Management"]:::frontend
    end

    subgraph "Backend (Server)"
        BE_Main["Main Entry & Setup"]:::backend
        BE_Routes["API Routes (blog.routes & user.routes)"]:::backend
        BE_BlogControllers["Blog Controllers"]:::backend
        BE_UserControllers["User Controllers"]:::backend
        BE_Middleware["Authentication Middleware"]:::backend
        BE_Utilities["Utilities (e.g., Password Hashing)"]:::backend
        BE_Prism["Prisma ORM Integration"]:::backend
    end

    DB["PostgreSQL Database"]:::database
    EXT["Cloudinary (Image Storage)"]:::external

    %% Frontend internal connections
    FE_Main --> FE_Pages
    FE_Main --> FE_Components
    FE_Main --> FE_Layout
    FE_Main --> FE_Hooks
    FE_Main --> FE_State

    %% Frontend to Backend interactions
    FE_Pages -->|"API_Calls"| BE_Routes
    FE_Components -->|"API_Calls"| BE_Routes
    FE_Layout -->|"Navigation_triggers_API"| BE_Routes

    %% Backend internal connections
    BE_Main --> BE_Routes
    BE_Main --> BE_BlogControllers
    BE_Main --> BE_UserControllers
    BE_Main --> BE_Middleware
    BE_Main --> BE_Utilities

    BE_Routes -->|"Routes_to"| BE_BlogControllers
    BE_Routes -->|"Routes_to"| BE_UserControllers
    BE_Routes -->|"Secured_by"| BE_Middleware

    BE_BlogControllers -->|"DB_Operations"| BE_Prism
    BE_UserControllers -->|"DB_Operations"| BE_Prism

    BE_Utilities --> BE_BlogControllers
    BE_Utilities --> BE_UserControllers

    BE_Prism -->|"DB_Queries"| DB

    BE_BlogControllers -->|"UploadsImages"| EXT
    BE_UserControllers -->|"UploadsImages"| EXT

    %% Click Events for Frontend
    click FE_Main "https://github.com/durgaprasad118/blogging_app/tree/main/client"
    click FE_Pages "https://github.com/durgaprasad118/blogging_app/tree/main/client/src/pages"
    click FE_Components "https://github.com/durgaprasad118/blogging_app/tree/main/client/src/components"
    click FE_Layout "https://github.com/durgaprasad118/blogging_app/tree/main/client/src/Layout"
    click FE_Hooks "https://github.com/durgaprasad118/blogging_app/tree/main/client/src/hooks"
    click FE_State "https://github.com/durgaprasad118/blogging_app/tree/main/client/src/store"

    %% Click Events for Backend
    click BE_Main "https://github.com/durgaprasad118/blogging_app/blob/main/server/src/index.ts"
    click BE_Routes "https://github.com/durgaprasad118/blogging_app/tree/main/server/src/routes"
    click BE_BlogControllers "https://github.com/durgaprasad118/blogging_app/tree/main/server/src/contorllers/blog"
    click BE_UserControllers "https://github.com/durgaprasad118/blogging_app/tree/main/server/src/contorllers/user"
    click BE_Middleware "https://github.com/durgaprasad118/blogging_app/blob/main/server/src/middleware/authMiddleware.ts"
    click BE_Utilities "https://github.com/durgaprasad118/blogging_app/tree/main/server/src/utils"
    click BE_Prism "https://github.com/durgaprasad118/blogging_app/tree/main/server/prisma"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
