|
| 1 | +# π‘οΈ Nafath-Mock: AI-Enhanced SSO Middleware |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <b>A high-fidelity simulation of the Saudi National Single Sign-On (Nafath) ecosystem.</b><br> |
| 5 | + <i>Integrating real-time AI behavioral risk assessment with Spring Boot & Next.js.</i> |
| 6 | +</p> |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## ποΈ System Architecture |
| 11 | + |
| 12 | +The repository is structured as a **Monorepo** to maintain tight coupling between the security contract and implementation layers. |
| 13 | + |
| 14 | +### π» Tech Stack |
| 15 | +* **Frontend:** Next.js 15 (App Router), TypeScript, Tailwind CSS. |
| 16 | +* **Backend:** Spring Boot 3.4 (Java 21), Spring Data JPA, Hibernate. |
| 17 | +* **Database:** Microsoft SQL Server 2022. |
| 18 | +* **Intelligence:** Simulated LLM Middleware for Behavioral Risk Assessment. |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## π οΈ Installation & Setup |
| 23 | + |
| 24 | +### 1. Database Configuration |
| 25 | +The application expects a Microsoft SQL Server instance with a database named `nafath_db`. |
| 26 | + |
| 27 | +```Bash |
| 28 | +docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Password123" \ |
| 29 | + -p 1433:1433 --name nafath-sql -d \ |
| 30 | + [mcr.microsoft.com/mssql/server:2022-latest](https://mcr.microsoft.com/mssql/server:2022-latest) |
| 31 | +``` |
| 32 | +### 2. Backend Initialization |
| 33 | +```Bash |
| 34 | +cd backend |
| 35 | +mvn clean package:spring-boot:repackage -U -X |
| 36 | +mvn spring-boot:run |
| 37 | +``` |
| 38 | + |
| 39 | +### 3. Frontend Initialization |
| 40 | +```Bash |
| 41 | +cd frontend |
| 42 | +npm install |
| 43 | +npm run dev |
| 44 | +``` |
| 45 | +## π§ Technical Highlights (Senior Level) |
| 46 | + |
| 47 | +### π AI Risk Assessment Middleware |
| 48 | +Unlike standard auth flows, this system intercepts the /initiate request to perform: |
| 49 | + |
| 50 | + - Contextual Analysis: Evaluates National ID patterns and metadata. |
| 51 | + - Risk Scoring: Assigns a value (0.0 to 1.0). Scores > 0.8 trigger an immediate REJECTED_BY_AI state, bypassing the Nafath challenge entirely to prevent credential stuffing. |
| 52 | + |
| 53 | +### π Asynchronous State Machine |
| 54 | +The system utilizes a decoupled state machine to ensure data integrity: |
| 55 | + |
| 56 | + - Backend: Manages persistent state in SQL Server via JPA. |
| 57 | + - Frontend: Implemented with a resilient polling hook. |
| 58 | + - Simulator: External trigger for PATCH state transitions, mimicking mobile app interaction. |
| 59 | + |
| 60 | +## π§ͺ Simulation Flow |
| 61 | +1. Initiate: Enter a valid dummy ID: 1010101010 (Citizen) or 2020202020 (Resident). |
| 62 | +2. Challenge: The system generates a Random Code (Handshake). |
| 63 | +3. Approve: Use the Simulator Panel to trigger a biometric success simulation. |
| 64 | +4. Verify: The Next.js frontend detects the COMPLETED state and grants access. |
| 65 | + |
| 66 | +## π Project Structure |
| 67 | +```Bash |
| 68 | +nafath-project/ |
| 69 | +βββ backend/ # Spring Boot Service (Java 21) |
| 70 | +β βββ src/main/java/ # Domain Logic & AI Middleware |
| 71 | +β βββ src/main/resources/ # application.properties & SQL scripts |
| 72 | +βββ frontend/ # Next.js 15 Application |
| 73 | +β βββ app/ # App Router & UI Components |
| 74 | +β βββ public/ # Static Branding Assets |
| 75 | +βββ README.md # System Documentation |
| 76 | +``` |
| 77 | +<p align="center"> |
| 78 | +Developed for secure, scalable authentication demonstrations. |
| 79 | +</p> |
0 commit comments