Home Projects Jsjiit Architecture And Design System Architecture Overview

System Architecture Overview

Purpose and Scope

This document describes the high-level architecture of the jsjiit library, focusing on the organization of modules, their interactions, and the overall design patterns. It covers the layered structure, core components, data flow patterns, and session management mechanisms.

For details on specific API methods and their usage, see API Reference. For information about the encryption mechanisms, see Encryption and Security. For module export strategies, see Module Organization.


Layered Architecture

The jsjiit library follows a three-tier layered architecture that separates concerns between API communication, domain logic, and public interface exposure.

Architecture Layers Diagram

Architecture Diagram

Sources: src/index.js1-32 src/wrapper.js1-720 src/encryption.js src/attendance.js src/registration.js src/exam.js src/exceptions.js

Layer Responsibilities

Layer Modules Responsibility
Public API Surface src/index.js Re-exports all public classes and functions; serves as the single entry point for library consumers
Core Application Logic src/wrapper.js, src/encryption.js Implements HTTP communication, session management, encryption/decryption, and orchestrates API calls
Domain Models src/attendance.js, src/registration.js, src/exam.js Defines data structures for portal entities; parses API responses into typed objects
Cross-Cutting Concerns src/exceptions.js, src/utils.js, src/feedback.js Provides error handling, utility functions, and enumeration constants used across layers

Sources: src/index.js1-32 src/wrapper.js1-720


Core Components

WebPortal Class

The WebPortal class (src/wrapper.js75-671) is the primary orchestrator for all portal interactions. It maintains a reference to the current WebPortalSession and provides methods for each portal API endpoint.

Key Responsibilities:

  • Authentication: student_login() method (src/wrapper.js168-186)
  • HTTP Communication: __hit() internal method (src/wrapper.js97-158) handles all HTTP requests
  • Domain Object Creation: Instantiates AttendanceMeta, Registrations, ExamEvent objects from API responses
  • Session Lifecycle: Stores and validates session state

WebPortalSession Class

The WebPortalSession class (src/wrapper.js25-70) encapsulates authenticated session state.

Key Properties:

Property Description Source
token JWT authentication token src/wrapper.js49
expiry Parsed token expiration timestamp src/wrapper.js50-51
memberid Student identifier src/wrapper.js46
instituteid Institute identifier src/wrapper.js45
enrollmentno Student enrollment number src/wrapper.js56

Methods:

  • get_headers() (src/wrapper.js63-69): Generates authentication headers including JWT token and LocalName for each request

Sources: src/wrapper.js25-70

Authentication Decorator Pattern

The library uses a decorator pattern to enforce authentication requirements on methods. The authenticated() function (src/wrapper.js679-686) wraps methods that require an active session.

Architecture Diagram

Implementation:

Sources: src/wrapper.js679-719


Module Dependency Graph

This diagram maps the actual import relationships between source modules.

Architecture Diagram

Import Details:

File Imports Line Reference
src/index.js All public modules src/index.js5-10
src/wrapper.js exceptions, registration, attendance, exam, encryption src/wrapper.js1-5
src/encryption.js utils (assumed from diagram)

Sources: src/index.js1-32 src/wrapper.js1-5


Request/Response Flow Architecture

API Communication Flow

Architecture Diagram

Sources: src/wrapper.js97-158 src/wrapper.js242-254 src/wrapper.js63-69

HTTP Request Method: __hit()

The __hit() method (src/wrapper.js97-158) is the centralized HTTP communication handler.

Parameters:

Parameter Type Purpose
method string HTTP method (GET, POST)
url string Full API endpoint URL
options.headers Object Additional headers
options.json Object JSON payload (auto-stringified)
options.body string Raw body payload
options.authenticated boolean Whether to include session headers
options.exception Error Custom exception class to throw

Error Handling:

Sources: src/wrapper.js97-158


Session Management Architecture

Login Flow

Architecture Diagram

Implementation Details:

  1. Pre-token Check: src/wrapper.js169-175 - Validates username and CAPTCHA
  2. Token Generation: src/wrapper.js177-183 - Exchanges password for JWT
  3. Session Creation: src/wrapper.js184-185 - Stores session in this.session
  4. Token Parsing: src/wrapper.js50-51 - Extracts expiry from JWT payload

CAPTCHA Bypass: The library uses a default CAPTCHA value (src/wrapper.js20) that bypasses CAPTCHA validation:

export const DEFCAPTCHA = { captcha: "phw5n", hidden: "gmBctEffdSg=" };

Sources: src/wrapper.js168-186 src/wrapper.js20 src/wrapper.js39-57

Session State Management

Architecture Diagram

Session Validation:

Sources: src/wrapper.js75-82 src/wrapper.js679-719


Error Handling Architecture

Exception Hierarchy

Architecture Diagram

Exception Types: All defined in src/exceptions.js

Exception When Thrown Throwing Location
LoginError Authentication fails src/wrapper.js175 src/wrapper.js183
SessionExpired HTTP 401 received src/wrapper.js142
NotLoggedIn Method called without session src/wrapper.js682
AccountAPIError Account operations fail src/wrapper.js234
APIError Generic API failures src/wrapper.js98 src/wrapper.js156

Sources: src/exceptions.js src/wrapper.js1 src/wrapper.js97-158

Error Propagation Pattern

The __hit() method accepts an exception parameter to customize error types:

// Example from change_password method
const resp = await this.__hit("POST", API + ENDPOINT, {
  json: payload,
  authenticated: true,
  exception: AccountAPIError,  // Custom exception type
});

Reference: src/wrapper.js231-236

Sources: src/wrapper.js97-102 src/wrapper.js231-236


API Endpoint Constants

Base Configuration

The library defines two critical constants in src/wrapper.js:

Constant Value Purpose
API "https://webportal.jiit.ac.in:6011/StudentPortalAPI" Base URL for all API endpoints (src/wrapper.js14)
DEFCAPTCHA {captcha: "phw5n", hidden: "gmBctEffdSg="} Default CAPTCHA bypass values (src/wrapper.js20)

Endpoint Organization

Endpoints are defined inline within each method as relative paths appended to the API constant:

const ENDPOINT = "/StudentClassAttendance/getstudentInforegistrationforattendence";
const resp = await this.__hit("POST", API + ENDPOINT, {...});

Example Endpoints:

Sources: src/wrapper.js14 src/wrapper.js20 src/wrapper.js169-670


Public API Export Strategy

The src/index.js module (src/index.js1-32) serves as a facade that re-exports all public APIs from internal modules.

Export Mapping

Architecture Diagram

Import/Export Pattern:

Sources: src/index.js1-32


Build Configuration Integration

The architecture is reflected in the build configuration (package.json).

Module Entry Points

Field Value Purpose
main "src/index.js" CommonJS entry point (package.json5)
module "dist/jsjiit.esm.js" ES Module entry point (package.json6)
browser "dist/jsjiit.esm.js" Browser-specific entry (package.json7)
exports.import "./dist/jsjiit.esm.js" ESM import resolution (package.json23)

Bundled Files

The files array (package.json26-29) specifies which directories are included in the npm package:

  • dist/ - Built bundles
  • src/ - Source code for sourcemap resolution

Sources: package.json1-61