# rahul-mygit/mid-test architecture

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

- Interactive diagram: https://gitdiagram.com/rahul-mygit/mid-test
- Repository: https://github.com/rahul-mygit/mid-test

## Overview

#### Purpose and Entry Points
This repository is a black-box conformance test suite for a Live Attendance System server; it does not contain the server implementation. The primary execution entry point is `npm test`, which runs the integration suite in `index.test.js`. Watch execution is exposed through `npm run test:watch`.

Paths: `index.test.js`, `package.json`, `vitest.config.js`

#### System Boundary Under Test
Tests target an independently running Node-compatible HTTP/WebSocket server. Default endpoints are `http://localhost:3000` and `ws://localhost:3000/ws`; `SERVER_URL` and `WS_URL` override them. MongoDB is an external persistence dependency expected to be connected to that server.

The harness validates API contracts rather than directly accessing application internals or the database.

Paths: `README.md`, `index.test.js`

#### Authentication Contract
The first control-flow stage establishes user identity and authorization through `POST /auth/signup`, `POST /auth/login`, and `GET /auth/me`. Tests cover validation, duplicate-email handling, invalid credentials, authenticated identity lookup, and unauthorized access.

Authentication output is also a prerequisite for protected HTTP routes and authenticated WebSocket connections.

Paths: `index.test.js`

#### Class and Enrollment Boundary
Class management models the teacher-owned domain boundary. The tested server must support class creation, teacher-controlled student enrollment, and class retrieval with ownership/access checks. Student listing is restricted to teachers.

This stage supplies the class membership and ownership state required before attendance can begin.

Paths: `index.test.js`

#### Attendance Session Lifecycle
Attendance begins over HTTP via `POST /attendance/start`, which must validate class ownership and input. A student can retrieve personal class attendance through `GET /class/:id/my-attendance`, subject to enrollment checks.

The suite assumes a global constraint of only one active attendance session at a time. Completion must persist attendance, mark remaining students absent, and clear the active session.

Paths: `index.test.js`, `README.md`

#### Real-Time WebSocket Protocol
The WebSocket endpoint handles authenticated, event-based attendance operations. Teacher-only events include `ATTENDANCE_MARKED` and `TODAY_SUMMARY`, which broadcast relevant updates. Student-only `MY_ATTENDANCE` is expected to unicast the student’s status. `DONE` closes and persists the session.

Messages use `{ "event": "...", "data": ... }`; invalid tokens, malformed messages, unknown events, role violations, and missing sessions are tested error boundaries.

Paths: `index.test.js`, `README.md`

#### Response and Verification Infrastructure
HTTP responses must consistently use `{ success: true, data }` or `{ success: false, error }`. Vitest provides the test runtime and timeout configuration; package scripts and lockfile define the Node dependency environment. The suite includes an end-to-end workflow covering signup through persisted attendance.

Paths: `vitest.config.js`, `package.json`, `package-lock.json`

Main entry points: [`README.md`](https://github.com/rahul-mygit/mid-test/blob/main/README.md) (HTTP API), [`index.test.js`](https://github.com/rahul-mygit/mid-test/blob/main/index.test.js) (Attendance session), [`vitest.config.js`](https://github.com/rahul-mygit/mid-test/blob/main/vitest.config.js) (Vitest runtime), [`package.json`](https://github.com/rahul-mygit/mid-test/blob/main/package.json) (npm test / watch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_suite["Conformance Suite"]
  node_npm["npm test / watch<br/>test command<br/>[package.json]"]
  node_vitest{{"Vitest runtime<br/>test runner<br/>[vitest.config.js]"}}
  node_integration["Integration suite<br/>conformance tests<br/>[index.test.js]"]
  node_workflow["End-to-end workflow<br/>test scenario<br/>[index.test.js]"]
end

subgraph group_sut["Server Under Test"]
  node_http["HTTP API<br/>server interface<br/>[README.md]"]
  node_auth["Authentication<br/>API contract<br/>[index.test.js]"]
  node_classes["Classes &amp; enrollment<br/>domain API<br/>[index.test.js]"]
  node_session["Attendance session<br/>lifecycle API<br/>[index.test.js]"]
  node_personal["Personal attendance<br/>student API<br/>[index.test.js]"]
  node_websocket["WebSocket protocol<br/>server interface<br/>[README.md]"]
  node_teacher_events["Teacher events<br/>WebSocket events<br/>[index.test.js]"]
  node_student_events["Student events<br/>WebSocket events<br/>[index.test.js]"]
  node_completion["DONE event<br/>WebSocket event<br/>[index.test.js]"]
  node_response_contract["Response &amp; error contract<br/>API boundary<br/>[index.test.js]"]
end

node_mongodb[("MongoDB<br/>external persistence<br/>[README.md]")]

node_npm -->|"runs"| node_vitest
node_vitest -->|"executes"| node_integration
node_integration -->|"includes"| node_workflow
node_integration -->|"tests"| node_http
node_integration -->|"tests"| node_websocket
node_http -->|"serves"| node_auth
node_http -->|"serves"| node_classes
node_http -->|"starts"| node_session
node_http -->|"retrieves"| node_personal
node_auth -->|"authorizes"| node_classes
node_classes -->|"supplies ownership and enrollment"| node_session
node_classes -->|"gates access"| node_personal
node_auth -->|"authenticates connections"| node_websocket
node_websocket -->|"handles"| node_teacher_events
node_websocket -->|"handles"| node_student_events
node_websocket -->|"handles"| node_completion
node_teacher_events -->|"updates active attendance"| node_session
node_student_events -->|"reads status"| node_session
node_completion -->|"completes"| node_session
node_session -->|"persists attendance"| node_mongodb
node_http -->|"returns"| node_response_contract
node_websocket -->|"enforces errors"| node_response_contract

click node_npm "https://github.com/rahul-mygit/mid-test/blob/main/package.json"
click node_vitest "https://github.com/rahul-mygit/mid-test/blob/main/vitest.config.js"
click node_integration "https://github.com/rahul-mygit/mid-test/blob/main/index.test.js"
click node_workflow "https://github.com/rahul-mygit/mid-test/blob/main/index.test.js"
click node_http "https://github.com/rahul-mygit/mid-test/blob/main/README.md"
click node_auth "https://github.com/rahul-mygit/mid-test/blob/main/index.test.js"
click node_classes "https://github.com/rahul-mygit/mid-test/blob/main/index.test.js"
click node_session "https://github.com/rahul-mygit/mid-test/blob/main/index.test.js"
click node_personal "https://github.com/rahul-mygit/mid-test/blob/main/index.test.js"
click node_websocket "https://github.com/rahul-mygit/mid-test/blob/main/README.md"
click node_teacher_events "https://github.com/rahul-mygit/mid-test/blob/main/index.test.js"
click node_student_events "https://github.com/rahul-mygit/mid-test/blob/main/index.test.js"
click node_completion "https://github.com/rahul-mygit/mid-test/blob/main/index.test.js"
click node_response_contract "https://github.com/rahul-mygit/mid-test/blob/main/index.test.js"
click node_mongodb "https://github.com/rahul-mygit/mid-test/blob/main/README.md"

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_npm,node_vitest,node_integration,node_workflow toneBlue
class node_http,node_auth,node_classes,node_session,node_personal,node_websocket,node_teacher_events,node_student_events,node_completion,node_response_contract toneAmber
class node_mongodb toneNeutral
```

## Components

### Conformance Suite

Black-box integration tests and Node test tooling.

- [npm test / watch](https://github.com/rahul-mygit/mid-test/blob/main/package.json): test command · `package.json`
- [Vitest runtime](https://github.com/rahul-mygit/mid-test/blob/main/vitest.config.js): test runner · Provides integration execution and timeout settings. · `vitest.config.js`
- [Integration suite](https://github.com/rahul-mygit/mid-test/blob/main/index.test.js): conformance tests · Validates public HTTP and WebSocket contracts end to end. · `index.test.js`
- [End-to-end workflow](https://github.com/rahul-mygit/mid-test/blob/main/index.test.js): test scenario · Covers signup through persisted attendance. · `index.test.js`

### Server Under Test

Independently running Live Attendance System.

- [HTTP API](https://github.com/rahul-mygit/mid-test/blob/main/README.md): server interface · Default target is localhost:3000; SERVER_URL can override it. · `README.md`
- [Authentication](https://github.com/rahul-mygit/mid-test/blob/main/index.test.js): API contract · Signup, login, and identity lookup establish authorized users. · `index.test.js`
- [Classes & enrollment](https://github.com/rahul-mygit/mid-test/blob/main/index.test.js): domain API · Teacher ownership and membership gate attendance access. · `index.test.js`
- [Attendance session](https://github.com/rahul-mygit/mid-test/blob/main/index.test.js): lifecycle API · One global active session; completion persists results and marks absences. · `index.test.js`
- [Personal attendance](https://github.com/rahul-mygit/mid-test/blob/main/index.test.js): student API · Enrolled students retrieve their own class attendance. · `index.test.js`
- [WebSocket protocol](https://github.com/rahul-mygit/mid-test/blob/main/README.md): server interface · Authenticated event channel at /ws; WS_URL can override it. · `README.md`
- [Teacher events](https://github.com/rahul-mygit/mid-test/blob/main/index.test.js): WebSocket events · ATTENDANCE_MARKED and TODAY_SUMMARY broadcast updates. · `index.test.js`
- [Student events](https://github.com/rahul-mygit/mid-test/blob/main/index.test.js): WebSocket events · MY_ATTENDANCE unicasts a student's status. · `index.test.js`
- [DONE event](https://github.com/rahul-mygit/mid-test/blob/main/index.test.js): WebSocket event · Closes the active session and persists attendance. · `index.test.js`
- [Response & error contract](https://github.com/rahul-mygit/mid-test/blob/main/index.test.js): API boundary · HTTP envelopes and protocol errors cover invalid input, tokens, roles, and sessions. · `index.test.js`

### Other components

- [MongoDB](https://github.com/rahul-mygit/mid-test/blob/main/README.md): external persistence · Persistence dependency connected to the server under test. · `README.md`

## Connections

- npm test / watch → Vitest runtime: runs
- Vitest runtime → Integration suite: executes
- Integration suite → End-to-end workflow: includes
- Integration suite → HTTP API: tests
- Integration suite → WebSocket protocol: tests
- HTTP API → Authentication: serves
- HTTP API → Classes & enrollment: serves
- HTTP API → Attendance session: starts
- HTTP API → Personal attendance: retrieves
- Authentication → Classes & enrollment: authorizes
- Classes & enrollment → Attendance session: supplies ownership and enrollment
- Classes & enrollment → Personal attendance: gates access
- Authentication → WebSocket protocol: authenticates connections
- WebSocket protocol → Teacher events: handles
- WebSocket protocol → Student events: handles
- WebSocket protocol → DONE event: handles
- Teacher events → Attendance session: updates active attendance
- Student events → Attendance session: reads status
- DONE event → Attendance session: completes
- Attendance session → MongoDB: persists attendance
- HTTP API → Response & error contract: returns
- WebSocket protocol → Response & error contract: enforces errors
