A high-fidelity simulation of the Saudi National Single Sign-On (Nafath) ecosystem.
Integrating real-time AI behavioral risk assessment with Spring Boot & Next.js.
The repository is structured as a Monorepo to maintain tight coupling between the security contract and implementation layers.
- Frontend: Next.js 15 (App Router), TypeScript, Tailwind CSS.
- Backend: Spring Boot 3.4 (Java 21), Spring Data JPA, Hibernate.
- Database: Microsoft SQL Server 2022.
- Intelligence: Simulated LLM Middleware for Behavioral Risk Assessment.
The application expects a Microsoft SQL Server instance with a database named nafath_db.
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Password123" \
-p 1433:1433 --name nafath-sql -d \
[mcr.microsoft.com/mssql/server:2022-latest](https://mcr.microsoft.com/mssql/server:2022-latest)cd backend
mvn clean package:spring-boot:repackage -U -X
mvn spring-boot:runcd frontend
npm install
npm run devUnlike standard auth flows, this system intercepts the /initiate request to perform:
- Contextual Analysis: Evaluates National ID patterns and metadata.
- 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.
The system utilizes a decoupled state machine to ensure data integrity:
- Backend: Manages persistent state in SQL Server via JPA.
- Frontend: Implemented with a resilient polling hook.
- Simulator: External trigger for PATCH state transitions, mimicking mobile app interaction.
- Initiate: Enter a valid dummy ID: 1010101010 (Citizen) or 2020202020 (Resident).
- Challenge: The system generates a Random Code (Handshake).
- Approve: Use the Simulator Panel to trigger a biometric success simulation.
- Verify: The Next.js frontend detects the COMPLETED state and grants access.
nafath-project/
├── backend/ # Spring Boot Service (Java 21)
│ ├── src/main/java/ # Domain Logic & AI Middleware
│ └── src/main/resources/ # application.properties & SQL scripts
├── frontend/ # Next.js 15 Application
│ ├── app/ # App Router & UI Components
│ └── public/ # Static Branding Assets
└── README.md # System Documentation- Mock existing approver application
Developed for secure, scalable authentication demonstrations.