How g8row/authserver works
Project Type and Purpose
• This is a stand‐alone networked Authentication Server (no web GUI), built with Java NIO for nonblocking I/O.
• It provides session management, user/ban management, command parsing, and file‐based persistence for users and audit logs.
File Structure
• Top-level:
• MainClient.java (CLI client)
• MainServer.java (NIO-based server entry point)
• data/ (file-based database and logs)
• src/bg/sofia/uni/fmi/mjt/authserver/… (packages by feature: server, client, database, session, user, ban, log, response, exception)
• test/… (unit tests per feature)
• Configuration: none external; database is a text file (data/db.txt). Logs live under data/log and data/clientLogs.
• Build: standard Java project (no Maven/Gradle visible).
Extract Architectural Insights from README
• Java NIO library is used for networking.
• Key responsibilities: accept connections, parse commands, manage domain state (sessions, users, bans), persist data, produce logs, and send responses.
Main Components & Their Relationships
a. Client (MainClient)
• Initiates TCP connection to the server, sends text commands, receives text responses, writes its own client log.
b. Server (MainServer + Server class)
• Network layer: Java NIO Selector handles multiple channels.
• Command layer: Command parser reads input, maps to Command enum.
• Dispatcher: routes commands to appropriate Manager.
c. Business‐Logic Modules (each implements an “Api” interface)
• UserManager / UserManagerApi (create, find users)
• SessionManager / SessionManagerApi (create, validate sessions)
• BanManager / BanManagerApi (track banned clients)
• DatabaseManager / DatabaseManagerApi (load/save users to data/db.txt)
• AuditLog / AuditLogApi (append events to data/log/*.txt)
d. Persistence
• data/db.txt (users and credentials)
• data/log/… (audit log entries)
• data/clientLogs/… (client‐side logs)
e. Response (Response class)
• Encapsulates standard server replies.
Interactions:
• Client → Server (TCP Channel)
• Server’s Selector → accepts new connections → reads bytes → decodes to text → Command parser → returns a Command object
• Dispatcher → invokes the matching ManagerApi → may call DatabaseManager, SessionManager, BanManager or UserManager → returns data or throws exception
• AuditLog records each successful/failed operation → writes to file
• Server → wraps result in Response → writes back to client channel
Architectural Patterns & Design Principles
• Layered architecture:
1. Network layer (Java NIO Selector, Channel)
2. Command parsing layer
3. Business‐logic layer (managers)
4. Persistence layer (file I/O)
• Dependency inversion: business modules depend on interfaces (e.g., DatabaseManagerApi)
• Single Responsibility per package (user, session, ban, log)