How normancao2702/cmpt213-asgn4-restapi works
Main Components
a. Front-End (Static Resources)
– index.html, game.js, game.css, audio assets in src/main/resources/public
– Served by Spring’s static resource handler at “/” on port 8080
b. Web Layer (Spring Boot Application)
– DispatcherServlet (Spring MVC)
– GameController (handles all /api/** endpoints)
– GlobalExceptionHandler (handles 404, 400, etc.)
c. DTO Layer
– ApiGameDTO, ApiBoardDTO, ApiLocationDTO convert model to JSON
d. Model Layer (Game Logic)
– MazeGame (holds player, cats, cheese)
– Maze, PathFinder, CellLocation, CellState, MoveDirection
– Cat (enemy logic)
e. In-Memory Store
– A simple List<MazeGame> inside GameController to track active games
f. Client Interaction
– Browser loads index.html
– game.js issues AJAX calls (GET /api/games, POST /api/games/{id}/moves, etc.)
Relationships & Data Flows
– Browser → HTTP GET “/” → Static index.html, CSS, JS
– game.js → HTTP GET/POST → GameController endpoints
– Controller receives JSON requests → invokes Model methods on MazeGame instances → returns DTO JSON responses → game.js updates UI
– Exception handler intercepts invalid calls → returns error codes to front-end
Architectural Patterns & Tech Stack
– Spring MVC (Controller → Model → DTO → View)
– RESTful API design (resource-oriented URIs, proper HTTP status codes)
– In-memory state management (no external database)
– Static resource serving from Spring Boot
Step-by-Step Construction
– Static Resource Handler
– DispatcherServlet
– GameController (with endpoints grouped)
– GlobalExceptionHandler beside the Controller
e. In the Model layer, show MazeGame, Maze, PathFinder, CellLocation, Cat, etc.
f. In-memory List<MazeGame> as a storage component connected to MazeGame.
Detail Without Over-Complicating
– Show how DTOs map to Models via factory methods.
– Indicate exception flows (e.g., GameNotFoundException → 404).