# nhnnhnnnhn/baoliemkhiet architecture

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

- Interactive diagram: https://gitdiagram.com/nhnnhnnnhn/baoliemkhiet
- Repository: https://github.com/nhnnhnnnhn/baoliemkhiet

## Overview

##### Main Components
- Frontend:
- The React application (built with Vite) that manages UI rendering.
- UI components including common components (header, footer, buttons), layouts, pages, and modules for different sections like news, auth, admin, etc.
- React Router for navigation and Context API for state management.
- API modules that abstract calls to the backend (authAPI, newsAPI, searchAPI, userAPI).

- Backend:
- The Node.js server (possibly using Express or a similar framework) defined in the server.js file.
- Routes: Dedicated route files for authentication and OTP (auth.route.js and otp.route.js).
- Controllers: Controller files handling logic for auth and OTP (auth.controller.js, otp.controller.js).
- Services: Business logic encapsulated in auth.service.js and otp.service.js.
- Middlewares: Such as the authentication middleware (auth.middleware.js).
- Database Access: Prisma integration (schema.prisma and seed.js) to interact with the database.

- External Components and Tools:
- The database itself, as defined via the Prisma schema.
- Static assets (images, audio, videos) served from the frontend’s public and assets directories.
- External design documentation (the Figma design link as stated in the README).

##### Relationships and Data Flow
- Frontend sends API calls (HTTP requests) to the backend endpoints for authentication, news retrieval, search, etc.
- Backend routes map these requests to controllers, which then call the related service functions.
- Middleware handles authentication or pre-request validations.
- The services interact with the database through Prisma.
- Data flows back from the database to the service layer, up to the controller, and finally as responses to the frontend.

##### Architectural Patterns & Design Principles
- Separation of concerns: The backend logically separates routes, controllers, services, and middleware.
- Modular frontend design: The components, layouts, pages, and modules indicate a component-based architecture powered by React.
- Environment-specific configuration: Use of .env files and configuration for Vite in the frontend, and package.json-based configuration for dependencies and scripts.
- Migration note: The README indicates that the project transitioned from Create React App to Vite — be sure to note that the frontend build and development process may have unique configuration aspects that are significant for deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Section
    subgraph "Frontend (React/Vite)"
        F1["Index & vite.config.js"]:::frontend
        F2["Main Entry (App.jsx)"]:::frontend
        F3["Router (index.js)"]:::frontend
        F4["UI Components"]:::frontend
        F5["API Modules"]:::frontend
    end

    %% Backend Section
    subgraph "Backend (Node.js & Prisma)"
        B1["Node.js Server (server.js)"]:::backend
        B2["Routes"]:::backend
        B4["Auth Middleware"]:::backend
        B3["Controllers"]:::backend
        B5["Services"]:::backend
        B6["Database (via Prisma)"]:::external
    end

    %% Frontend Flow
    F1 -->|"load"| F2
    F2 -->|"initialize"| F3
    F3 -->|"render"| F4
    F4 -->|"triggers API call"| F5

    %% Communication from Frontend to Backend
    F5 -->|"HTTPrequest"| B1
    B1 -->|"dispatch to"| B2

    %% Backend Processing Flow
    B2 -->|"verify"| B4
    B2 -->|"forward to"| B3
    B3 -->|"invoke business logic"| B5
    B5 -->|"database query"| B6
    B6 -->|"response data"| B5
    B5 -->|"result returned"| B3
    B3 -->|"controller response"| B2
    B2 -->|"send response"| B1
    B1 -->|"HTTPresponse"| F5

    %% Click Events for Frontend
    click F1 "https://github.com/nhnnhnnnhn/baoliemkhiet/tree/master/frontend/"
    click F2 "https://github.com/nhnnhnnnhn/baoliemkhiet/blob/master/frontend/src/App.jsx"
    click F3 "https://github.com/nhnnhnnnhn/baoliemkhiet/blob/master/frontend/src/router/index.js"
    click F4 "https://github.com/nhnnhnnnhn/baoliemkhiet/tree/master/frontend/src/components/"
    click F5 "https://github.com/nhnnhnnnhn/baoliemkhiet/tree/master/frontend/src/apis/"

    %% Click Events for Backend
    click B1 "https://github.com/nhnnhnnnhn/baoliemkhiet/blob/master/backend/src/server.js"
    click B2 "https://github.com/nhnnhnnnhn/baoliemkhiet/tree/master/backend/src/routes/"
    click B3 "https://github.com/nhnnhnnnhn/baoliemkhiet/tree/master/backend/src/controllers/"
    click B4 "https://github.com/nhnnhnnnhn/baoliemkhiet/blob/master/backend/src/middlewares/auth.middleware.js"
    click B5 "https://github.com/nhnnhnnnhn/baoliemkhiet/tree/master/backend/src/services/"
    click B6 "https://github.com/nhnnhnnnhn/baoliemkhiet/tree/master/backend/prisma/"

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