# anurag17604/billzen architecture

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

- Interactive diagram: https://gitdiagram.com/anurag17604/billzen
- Repository: https://github.com/anurag17604/billzen

## Overview

##### Project Type and Purpose
- This is a full-stack ERP/CRM/accounting web application (“BillZen”) with a React.js + Redux front end and a Node.js/Express back end.
- Its purpose is to let users manage customers, quotes, invoices, payments, settings, dashboards, localization, and file-based reports (PDFs), all secured by JWT.

##### File Structure Analysis
- Top-level “frontend” and “backend” folders clearly separate UI from server logic.
- Backend follows an MVC-style organization:
- src/routes → defines REST endpoints (coreRoutes vs. appRoutes)
- src/controllers → business logic split into “coreControllers” (admin, settings, auth) and “appControllers” (clients, invoices, quotes, payments, taxes)
- src/models → ORM/ODM schemas for core and app entities
- src/middlewares → request pipelines for auth, CRUD scaffolding, file uploads, settings injection
- src/handlers, src/emailTemplate, src/pdf → utilities for error handling, PDF generation (Pug templates), and email composition
- Frontend is a modular React + Redux app:
- src/apps, src/modules, src/pages → feature modules for ERP panel, Dashboard, Quotes, Invoices, Payments, Settings, Profile, Auth flows
- src/components, src/layout → generic UI components and layout containers using Ant Design
- src/context & src/redux → two parallel state management approaches (Context API for some flows, Redux Toolkit for global state)
- src/request, src/router → API wrapper/services and client-side routing
- src/utils, src/hooks, src/locale → shared utilities, custom hooks, localization support

##### README Insights
- Frontend: React.js, Ant Design, Redux Toolkit
- Backend: Node.js, Express.js, JWT Auth, REST API, file upload
- Database: MongoDB or MySQL (configurable)
- Features: PDF invoice generation, email notifications, role-based access, localization, dashboard analytics

a. Main Components
- Client Browser (Web UI)
- Frontend App (React + Redux)
- API Gateway (Express.js server entry point)
- Authentication Service (JWT issuance & validation middleware)
- Business Logic Layer (Express controllers/processors)
- Data Access Layer (ORM/ODM models)
- Database(s) (MongoDB or MySQL)
- File Storage (local “public/uploads” or S3-style)
- PDF Generator (Pug templates → PDF)
- Email Service (SMTP or 3rd-party like SendGrid)
b. Relationships & Interactions
- Browser → Frontend: HTTP/WS for data fetch, UI events
- Frontend → API: REST calls with JWT in headers
- API Gateway → Auth Middleware → Protected Routes
- Controllers invoke Models → Database CRUD
- Controllers invoke PDF Generator or Email Service as needed
- Upload middleware saves files to storage, updates DB
- Settings middleware loads configuration for requests
c. Architectural Patterns
- Layered MVC on backend
- Feature-based modular structure on frontend
- Middleware pipeline for cross-cutting concerns (auth, logging, settings)
- Redux for global state; Context API for isolated flows
- Separation of concerns: controllers vs. handlers vs. models vs. services
d. Key Technologies
- Node.js + Express.js
- JWT (jsonwebtoken)
- Mongoose or Sequelize (MongoDB/MySQL)
- Pug for PDF views
- React.js + Ant Design
- Redux Toolkit & React Context
- Vite/Rollup
- REST API with Axios/fetch wrappers

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Zone
    Browser["Client Browser"]:::frontend

    %% Frontend Zone
    subgraph "Frontend"
        RootApp["RootApp.jsx"]:::frontend
        Components["UI Components"]:::frontend
        Layout["Layout Containers"]:::frontend
        Modules["Feature Modules"]:::frontend
        Pages["Pages / Router"]:::frontend
        Redux["Redux Toolkit"]:::frontend
        Context["React Context"]:::frontend
        APIClient["API Client / Services"]:::frontend
        Locale["Localization Support"]:::frontend
        Style["Styling"]:::frontend
    end

    %% Backend Zone
    subgraph "Backend"
        Server["server.js"]:::backend
        AppConfig["app.js"]:::backend

        subgraph "Middleware Pipeline"
            AuthMW["Auth Middleware"]:::backend
            UploadMW["File Upload Middleware"]:::backend
            SettingsMW["Settings Loader MW"]:::backend
            InventoryMW["Inventory Number Generator MW"]:::backend
        end

        subgraph "Controllers"
            CoreCtrl["Core Controllers"]:::backend
            AppCtrl["App Controllers"]:::backend
            PDFCtrl["PDF Controller"]:::backend
        end

        subgraph "Models"
            CoreModels["Core Models"]:::data
            AppModels["App Models"]:::data
        end

        PDFGen["PDF Generator"]:::backend
        EmailTemp["Email Templates"]:::backend
        EmailSvc["Email Service"]:::external
        Storage["File Storage"]:::external
        DB["Database"]:::data
        Handlers["Error & Download Handlers"]:::backend
        SettingsLoader["App Settings Loader"]:::backend
        Env["Env & Config Files"]:::backend
    end

    %% Connections
    Browser -->|"loads"| RootApp
    RootApp -->|"renders"| Components
    RootApp -->|"uses layouts"| Layout
    RootApp -->|"organizes modules"| Modules
    RootApp -->|"routes via"| Pages
    Modules -->|"dispatches actions to"| Redux
    Modules -->|"provides context via"| Context
    Pages -->|"calls API"| APIClient
    APIClient -->|"HTTP/HTTPS with JWT"| Server
    Server -->|"initializes"| AppConfig
    AppConfig -->|"executes"| AuthMW
    AuthMW -->|"validates JWT"| UploadMW
    UploadMW -->|"handles file uploads"| SettingsMW
    SettingsMW -->|"injects settings"| InventoryMW
    InventoryMW -->|"generates IDs"| CoreCtrl
    InventoryMW -->|"generates IDs"| AppCtrl
    CoreCtrl -->|"CRUD operations via"| CoreModels
    AppCtrl -->|"CRUD operations via"| AppModels
    AppCtrl -->|"invokes"| PDFCtrl
    PDFCtrl -->|"renders templates"| PDFGen
    PDFGen -->|"stores PDFs to"| Storage
    PDFCtrl -->|"fetches email templates"| EmailTemp
    EmailTemp -->|"sends emails via"| EmailSvc
    CoreModels -->|"reads/writes"| DB
    AppModels -->|"reads/writes"| DB
    AppCtrl -->|"handles errors/downloads via"| Handlers
    AppConfig -->|"loads configs from"| Env
    AppConfig -->|"loads defaults via"| SettingsLoader

    %% Click Events
    click Browser "https://github.com/anurag17604/billzen/blob/main/frontend/index.html"
    click RootApp "https://github.com/anurag17604/billzen/blob/main/frontend/src/RootApp.jsx"
    click Components "https://github.com/anurag17604/billzen/tree/main/frontend/src/components"
    click Layout "https://github.com/anurag17604/billzen/tree/main/frontend/src/layout"
    click Modules "https://github.com/anurag17604/billzen/tree/main/frontend/src/modules"
    click Pages "https://github.com/anurag17604/billzen/blob/main/frontend/src/router/AppRouter.jsx"
    click Redux "https://github.com/anurag17604/billzen/tree/main/frontend/src/redux"
    click Context "https://github.com/anurag17604/billzen/tree/main/frontend/src/context"
    click APIClient "https://github.com/anurag17604/billzen/blob/main/frontend/src/request/index.js"
    click Locale "https://github.com/anurag17604/billzen/tree/main/frontend/src/locale"
    click Style "https://github.com/anurag17604/billzen/tree/main/frontend/src/style"
    click Server "https://github.com/anurag17604/billzen/blob/main/backend/src/server.js"
    click AppConfig "https://github.com/anurag17604/billzen/blob/main/backend/src/app.js"
    click AuthMW "https://github.com/anurag17604/billzen/blob/main/backend/src/controllers/middlewaresControllers/createAuthMiddleware/isValidAuthToken.js"
    click CoreCtrl "https://github.com/anurag17604/billzen/tree/main/backend/src/controllers/coreControllers"
    click AppCtrl "https://github.com/anurag17604/billzen/tree/main/backend/src/controllers/appControllers"
    click CoreModels "https://github.com/anurag17604/billzen/tree/main/backend/src/models/coreModels"
    click AppModels "https://github.com/anurag17604/billzen/tree/main/backend/src/models/appModels"
    click UploadMW "https://github.com/anurag17604/billzen/tree/main/backend/src/middlewares/uploadMiddleware"
    click SettingsMW "https://github.com/anurag17604/billzen/tree/main/backend/src/middlewares/settings"
    click InventoryMW "https://github.com/anurag17604/billzen/tree/main/backend/src/middlewares/inventory"
    click PDFGen "https://github.com/anurag17604/billzen/tree/main/backend/src/pdf"
    click PDFCtrl "https://github.com/anurag17604/billzen/blob/main/backend/src/controllers/pdfController/index.js"
    click EmailTemp "https://github.com/anurag17604/billzen/tree/main/backend/src/emailTemplate"
    click Storage "https://github.com/anurag17604/billzen/tree/main/backend/src/public/uploads"
    click Handlers "https://github.com/anurag17604/billzen/blob/main/backend/src/handlers/errorHandlers.js"
    click SettingsLoader "https://github.com/anurag17604/billzen/tree/main/backend/src/setup"
    click Env "https://github.com/anurag17604/billzen/blob/main/backend/.env"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#00ACC1,color:#000
    classDef backend fill:#E8F5E9,stroke:#43A047,color:#000
    classDef data fill:#FFF3E0,stroke:#FB8C00,color:#000
    classDef external fill:#F3E5F5,stroke:#8E24AA,color:#000
```
