# abhilash1401/attendance-ai architecture

> Architecture diagram of the GitHub repository abhilash1401/attendance-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhilash1401/attendance-ai
- Repository: https://github.com/abhilash1401/attendance-ai

## Overview

#### Purpose and Runtime
Attendance AI is a Python 3.10+ terminal application for NRCM students. It authenticates against the NRCM student portal, retrieves and analyzes semester attendance, and offers attendance-planning actions around a 75% target. The executable entry point is `main.py`; dependencies are declared in `requirements.txt`.

#### Application Orchestration
`main.py` owns the interactive lifecycle: credential prompts, login, initial data retrieval, menu dispatch, refresh, history access, database clearing, and exit. It coordinates portal access, parsing, calculation, and persistence rather than exposing an HTTP or GUI interface.
- `main.py`
- `config.py`

#### NRCM Portal Boundary
Portal-specific network/session behavior is isolated in `nrcm_portal.py`. This is the external-service boundary: runtime roll number/password are used to authenticate and request student and attendance pages. Portal URLs and attendance-related constants belong in `config.py`, keeping the rest of the application tied to normalized data rather than request details.
- `nrcm_portal.py`
- `config.py`

#### Data Extraction Pipeline
Raw portal responses flow through separate parsers: student identity/details are extracted by `student_parser.py`, while semester attendance records are extracted by `attendance_parser.py`. These modules form the adaptation layer most likely to require changes if NRCM changes its HTML/page structure.
- `student_parser.py`
- `attendance_parser.py`
- `nrcm_portal.py`

#### Attendance Analysis and Planning
`calculator.py` converts parsed attendance totals into user-facing decisions: current percentage, safe classes that can be bunked while retaining 75%, classes required to reach 75%, and a next-day attendance plan. `main.py` invokes these calculations for the corresponding menu actions.
- `calculator.py`
- `main.py`
- `config.py`

#### Refresh and State Flow
At startup and on “Refresh Attendance,” `main.py` reuses the portal integration and parsing pipeline to obtain current portal data, then feeds the refreshed records into calculation and history flows. Passwords are runtime-only by design; the application’s durable state is attendance history rather than portal credentials.
- `main.py`
- `nrcm_portal.py`
- `attendance_parser.py`

#### Local Persistence
`history.py` manages local SQLite attendance-history storage. The application automatically creates and uses `attendance_history.db`, enabling historical views and a menu operation to clear stored records. This database is the primary local infrastructure boundary and should be treated as sensitive student data.
- `history.py`
- `main.py`

Main entry points: [`nrcm_portal.py`](https://github.com/abhilash1401/attendance-ai/blob/main/nrcm_portal.py) (Portal session client), [`main.py`](https://github.com/abhilash1401/attendance-ai/blob/main/main.py) (Interactive lifecycle), [`calculator.py`](https://github.com/abhilash1401/attendance-ai/blob/main/calculator.py) (75% planning calculator), [`history.py`](https://github.com/abhilash1401/attendance-ai/blob/main/history.py) (History repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Terminal Application"]
  node_main["Interactive lifecycle<br/>Python entry point<br/>[main.py]"]
  node_config["Portal settings<br/>configuration module<br/>[config.py]"]
  node_credentials["Runtime credentials<br/>ephemeral input"]
end

subgraph group_portal["Portal Integration"]
  node_portal_service{{"NRCM student portal<br/>external service"}}
  node_portal_client["Portal session client<br/>network adapter<br/>[nrcm_portal.py]"]
  node_student_parser["Student details parser<br/>HTML parser<br/>[student_parser.py]"]
  node_attendance_parser["Attendance parser<br/>HTML parser"]
  node_student_profile["Student profile<br/>normalized data"]
end

subgraph group_analysis["Attendance Analysis"]
  node_attendance_records["Current attendance<br/>normalized records"]
  node_calculator["75% planning calculator<br/>calculation module<br/>[calculator.py]"]
end

subgraph group_storage["Local History"]
  node_history["History repository<br/>SQLite access module<br/>[history.py]"]
  node_history_db[("Attendance history<br/>SQLite database")]
end

node_credentials -->|"prompted input"| node_main
node_main -->|"login and refresh"| node_portal_client
node_config -->|"URLs and constants"| node_portal_client
node_portal_client -->|"authenticate and fetch pages"| node_portal_service
node_portal_client -->|"student page"| node_student_parser
node_portal_client -->|"attendance page"| node_attendance_parser
node_student_parser -->|"extract"| node_student_profile
node_attendance_parser -->|"extract"| node_attendance_records
node_attendance_records -->|"attendance totals"| node_calculator
node_config -->|"75% target"| node_calculator
node_calculator -->|"menu results and plan"| node_main
node_attendance_records -->|"record refresh"| node_history
node_main -->|"view or clear history"| node_history
node_history -->|"read, write, clear"| node_history_db

click node_main "https://github.com/abhilash1401/attendance-ai/blob/main/main.py"
click node_config "https://github.com/abhilash1401/attendance-ai/blob/main/config.py"
click node_portal_client "https://github.com/abhilash1401/attendance-ai/blob/main/nrcm_portal.py"
click node_student_parser "https://github.com/abhilash1401/attendance-ai/blob/main/student_parser.py"
click node_attendance_parser "https://github.com/abhilash1401/attendance-ai/blob/main/attendance_parser.py"
click node_calculator "https://github.com/abhilash1401/attendance-ai/blob/main/calculator.py"
click node_history "https://github.com/abhilash1401/attendance-ai/blob/main/history.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_config,node_credentials toneBlue
class node_portal_service,node_portal_client,node_student_parser,node_attendance_parser,node_student_profile toneAmber
class node_attendance_records,node_calculator toneMint
class node_history,node_history_db toneRose
```

## Components

### Terminal Application

- [Interactive lifecycle](https://github.com/abhilash1401/attendance-ai/blob/main/main.py): Python entry point · Prompts, dispatches menu actions, refreshes data, and exits. · `main.py`
- [Portal settings](https://github.com/abhilash1401/attendance-ai/blob/main/config.py): configuration module · Centralizes portal URLs and attendance constants. · `config.py`
- **Runtime credentials**: ephemeral input · Roll number and password are not persisted.

### Portal Integration

- **NRCM student portal**: external service
- [Portal session client](https://github.com/abhilash1401/attendance-ai/blob/main/nrcm_portal.py): network adapter · Authenticates and retrieves student and attendance pages. · `nrcm_portal.py`
- [Student details parser](https://github.com/abhilash1401/attendance-ai/blob/main/student_parser.py): HTML parser · `student_parser.py`
- [Attendance parser](https://github.com/abhilash1401/attendance-ai/blob/main/attendance_parser.py): HTML parser · Converts portal attendance pages into semester records. · `attendance_parser.py`
- **Student profile**: normalized data

### Attendance Analysis

- **Current attendance**: normalized records · Refreshed semester attendance totals.
- [75% planning calculator](https://github.com/abhilash1401/attendance-ai/blob/main/calculator.py): calculation module · Computes percentage, bunk allowance, required classes, and next-day plan. · `calculator.py`

### Local History

Sensitive student attendance data.

- [History repository](https://github.com/abhilash1401/attendance-ai/blob/main/history.py): SQLite access module · Stores, reads, and clears attendance snapshots. · `history.py`
- **Attendance history**: SQLite database

## Connections

- Runtime credentials → Interactive lifecycle: prompted input
- Interactive lifecycle → Portal session client: login and refresh
- Portal settings → Portal session client: URLs and constants
- Portal session client → NRCM student portal: authenticate and fetch pages
- Portal session client → Student details parser: student page
- Portal session client → Attendance parser: attendance page
- Student details parser → Student profile: extract
- Attendance parser → Current attendance: extract
- Current attendance → 75% planning calculator: attendance totals
- Portal settings → 75% planning calculator: 75% target
- 75% planning calculator → Interactive lifecycle: menu results and plan
- Current attendance → History repository: record refresh
- Interactive lifecycle → History repository: view or clear history
- History repository → Attendance history: read, write, clear
