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

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,ExamEventobjects 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 andLocalNamefor 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.

Implementation:
- Decorated methods list: src/wrapper.js692-715
- Decorator application: src/wrapper.js717-719
Sources: src/wrapper.js679-719
Module Dependency Graph
This diagram maps the actual import relationships between source modules.

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

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:
- HTTP 513: Portal temporarily unavailable (src/wrapper.js138-140)
- HTTP 401: Session expired (src/wrapper.js141-143)
- Non-success status: Throws custom exception (src/wrapper.js147-149)
- CORS errors: Detected and wrapped (src/wrapper.js152-155)
Sources: src/wrapper.js97-158
Session Management Architecture
Login Flow

Implementation Details:
- Pre-token Check: src/wrapper.js169-175 - Validates username and CAPTCHA
- Token Generation: src/wrapper.js177-183 - Exchanges password for JWT
- Session Creation: src/wrapper.js184-185 - Stores session in
this.session - 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

Session Validation:
- The
authenticated()decorator (src/wrapper.js679-686) checksthis.session == null - Throws
NotLoggedInexception if no session exists - Applied to all data retrieval methods (src/wrapper.js692-715)
Sources: src/wrapper.js75-82 src/wrapper.js679-719
Error Handling Architecture
Exception Hierarchy

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:
- Authentication:
/token/pretoken-check,/token/generate-token1(src/wrapper.js169-170) - Attendance:
/StudentClassAttendance/getstudentInforegistrationforattendence(src/wrapper.js244) - Registration:
/reqsubfaculty/getregistrationList(src/wrapper.js307) - Exams:
/studentcommonsontroller/getstudentexamevents(src/wrapper.js355)
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

Import/Export Pattern:
- Line src/index.js5: Import from
wrapper.js - Line src/index.js6: Import from
attendance.js - Line src/index.js7: Import from
registration.js - Line src/index.js8: Import from
exam.js - Line src/index.js9: Import from
exceptions.js - Line src/index.js10: Import from
encryption.js - Lines src/index.js13-31: Re-export all imports
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 bundlessrc/- Source code for sourcemap resolution
Sources: package.json1-61