# omar290904/app-backend architecture

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

- Interactive diagram: https://gitdiagram.com/omar290904/app-backend
- Repository: https://github.com/omar290904/app-backend

## Overview

##### Project type and purpose
- This is a monolithic backend API service (“JALADO BACKEND”) written in Node.js and Express, persisting data in a MySQL database.
- Its core responsibilities are user authentication (JWT + bcrypt + HMAC), attendance management (marking punctual or late), scheduled cron tasks, and integration with WhatsApp for notifications.

##### File structure
- Top-level files
- .env, package.json/lock, nodemon.json, readme.md
- auth/ folder containing WhatsApp authentication keys and sessions
- src/
- index.js – application entry point, sets up Express server
- config.js – loads environment variables, common configuration
- db/ – MySQL connection (db.js) and SQL schema (jaladope.sql)
- routes/ – Express route definitions grouped by resource (auth, assistance, parents, students, teachers, admin, report, whatsapp)
- controllers/ – handlers for business logic and request processing, mirroring routes
- cron/ – scheduled job (markAbsent.js)
- Whatsapp/ – client.js for WhatsApp API integration

##### README for additional insights
- Describes routes (POST /login, POST /sign, POST /assistence, upcoming GET endpoints)
- Lists key technologies: Node.js, Express, MySQL, bcrypt, crypto/HMAC, jsonwebtoken, dotenv
- No front-end; strictly an HTTP JSON API plus background jobs and third-party messaging

a. Main components
1. Client Applications (e.g., Web/Mobile)
2. API Gateway / Express Server
3. Route Layer (routes/*.js)
4. Controller Layer (controllers/*.js)
5. Service/Utility modules
– Authentication (JWT issuance/verification, bcrypt, HMAC)
– WhatsApp Client (src/Whatsapp/client.js)
– Cron Scheduler (markAbsent.js)
6. Data Layer
– MySQL Database
– SQL schema (jaladope.sql)
7. External Services
– WhatsApp service (via WhatsApp API)
b. Relationships and data flows
- Clients → HTTP(S) → Express (index.js)
- Express → route dispatcher → controllers
- Controllers → service modules (auth logic, notification logic)
- Controllers → db.js (MySQL queries) → MySQL
- Cron Scheduler → runs markAbsent job at scheduled intervals → controllers/db
- WhatsApp Client ↔ External WhatsApp API
- Auth module issues/verifies JWT on login; controllers enforce token validation
c. Architectural patterns & principles
- Layered architecture (Presentation: routes → Business: controllers → Data: db)
- Single codebase (monolith) with clear separation of concerns
- Dependency injection of config via dotenv
- Scheduled background processing decoupled via cron module
d. Key technologies/frameworks
- Node.js runtime, Express framework
- MySQL via mysql2 or similar driver
- dotenv for config
- jsonwebtoken, bcrypt, crypto for security
- nodemon for development auto-reload
- cron or node-schedule for background tasks
- External WhatsApp API integration

## Diagram (Mermaid)

```mermaid
graph TB
    Client["Client Applications"]:::external

    subgraph "JALADO BACKEND"
        Env[".env"]:::service
        Config["Configuration Module"]:::service
        Server["API Gateway / Express Server"]:::service

        subgraph "Route Layer"
            AuthR["Auth Routes"]:::route
            AssistR["Assistance Routes"]:::route
            ParentsR["Parents Routes"]:::route
            StudentsR["Students Routes"]:::route
            TeachersR["Teachers Routes"]:::route
            AdminR["Admin Routes"]:::route
            ReportR["Report Routes"]:::route
            WhatsAppR["WhatsApp Routes"]:::route
            IndexR["Index Routes"]:::route
        end

        subgraph "Controller Layer"
            AuthC["Authentication Controller"]:::controller
            AssistC["Assistance Controller"]:::controller
            ParentsC["Parents Controller"]:::controller
            StudentsC["Students Controller"]:::controller
            TeachersC["Teachers Controller"]:::controller
            AdminC["Admin Controller"]:::controller
            ReportC["Reporting Controller"]:::controller
            WhatsAppC["WhatsApp Controller"]:::controller
            NotifC["Notification Controller"]:::controller
        end

        subgraph "Service Layer"
            AuthSvc["Auth Service (JWT, bcrypt, HMAC)"]:::service
            WhatsAppClient["WhatsApp Client"]:::service
            CronJob["Cron Scheduler (markAbsent)"]:::service
        end

        subgraph "Data Access Layer"
            DBConn["Database Connection"]:::db
            SQLSchema["SQL Schema"]:::db
        end
    end

    DB["MySQL Database"]:::db
    WhatsAppExt["External WhatsApp API"]:::external

    %% Data Flow
    Client -->|"HTTP Request"| Server
    Env --> Config
    Config --> Server

    Server -->|"Dispatch to Routes"| AuthR
    Server -->|"Dispatch to Routes"| AssistR
    Server --> ParentsR
    Server --> StudentsR
    Server --> TeachersR
    Server --> AdminR
    Server --> ReportR
    Server --> WhatsAppR
    Server --> IndexR

    AuthR -->|"calls"| AuthC
    AssistR --> AssistC
    ParentsR --> ParentsC
    StudentsR --> StudentsC
    TeachersR --> TeachersC
    AdminR --> AdminC
    ReportR --> ReportC
    WhatsAppR --> WhatsAppC
    IndexR --> NotifC

    AuthC -->|"uses"| AuthSvc
    AuthSvc -->|"queries"| DBConn
    AssistC --> DBConn
    ParentsC --> DBConn
    StudentsC --> DBConn
    TeachersC --> DBConn
    AdminC --> DBConn
    ReportC --> DBConn
    NotifC --> DBConn

    DBConn -->|"SQL Query"| DB
    SQLSchema --> DB

    CronJob -->|"scheduled trigger"| AssistC
    CronJob --> DBConn

    WhatsAppC -->|"invokes"| WhatsAppClient
    WhatsAppClient -->|"HTTP API Call"| WhatsAppExt

    %% Click Events
    click Server "https://github.com/omar290904/app-backend/blob/main/src/index.js"
    click Config "https://github.com/omar290904/app-backend/blob/main/src/config.js"
    click Env "https://github.com/omar290904/app-backend/blob/main/.env"
    click DBConn "https://github.com/omar290904/app-backend/blob/main/src/db/db.js"
    click SQLSchema "https://github.com/omar290904/app-backend/blob/main/src/db/jaladope.sql"
    click AuthR "https://github.com/omar290904/app-backend/blob/main/src/routes/auth.routes.js"
    click AssistR "https://github.com/omar290904/app-backend/blob/main/src/routes/assistence.routes.js"
    click ParentsR "https://github.com/omar290904/app-backend/blob/main/src/routes/parents.routes.js"
    click StudentsR "https://github.com/omar290904/app-backend/blob/main/src/routes/students.routes.js"
    click TeachersR "https://github.com/omar290904/app-backend/blob/main/src/routes/teachers.routes.js"
    click AdminR "https://github.com/omar290904/app-backend/blob/main/src/routes/admin.routes.js"
    click ReportR "https://github.com/omar290904/app-backend/blob/main/src/routes/report.routes.js"
    click WhatsAppR "https://github.com/omar290904/app-backend/blob/main/src/routes/whatsapp.routes.js"
    click IndexR "https://github.com/omar290904/app-backend/blob/main/src/routes/index.routes.js"
    click AuthC "https://github.com/omar290904/app-backend/blob/main/src/controllers/auth.controller.js"
    click AssistC "https://github.com/omar290904/app-backend/blob/main/src/controllers/assistence.controller.js"
    click ParentsC "https://github.com/omar290904/app-backend/blob/main/src/controllers/parents.controller.js"
    click StudentsC "https://github.com/omar290904/app-backend/blob/main/src/controllers/students.controller.js"
    click TeachersC "https://github.com/omar290904/app-backend/blob/main/src/controllers/teachers.controller.js"
    click AdminC "https://github.com/omar290904/app-backend/blob/main/src/controllers/admin.controller.js"
    click ReportC "https://github.com/omar290904/app-backend/blob/main/src/controllers/report.controller.js"
    click WhatsAppC "https://github.com/omar290904/app-backend/blob/main/src/controllers/whatsapp.controller.js"
    click NotifC "https://github.com/omar290904/app-backend/blob/main/src/controllers/notification.controller.js"
    click WhatsAppClient "https://github.com/omar290904/app-backend/blob/main/src/Whatsapp/client.js"
    click CronJob "https://github.com/omar290904/app-backend/blob/main/src/cron/markAbsent.js"

    %% Styles
    classDef route fill:#AED6F1,stroke:#2980B9,stroke-width:1px
    classDef controller fill:#D2B4DE,stroke:#8E44AD,stroke-width:1px
    classDef service fill:#FAD7A0,stroke:#B9770E,stroke-width:1px
    classDef db fill:#A9DFBF,stroke:#27AE60,stroke-width:1px
    classDef external fill:#F5B7B1,stroke:#C0392B,stroke-width:1px
```
