Overview
The Attendance App is a web application designed to manage classroom attendance with role-based access for teachers and students. Currently in early development, it demonstrates the foundational structure of a production Go application.This project is actively being built. The documentation reflects the current state, including incomplete features and placeholder code.
Project Vision
When complete, the Attendance App will:- Allow teachers to mark student attendance
- Provide students with a dashboard to view their attendance records
- Implement JWT-based authentication
- Use role-based access control (RBAC) to separate teacher and student views
- Store data persistently in a database
Current Structure
The project follows Go’s standard layout:Note the spelling: the directory is named
attendence (not “attendance”). Real projects often carry quirks like this!Code Walkthrough
Entry Point (cmd/attendence/main.go)
The main function is currently a skeleton:
- Server startup logic
- Configuration loading
- Database connection
- Graceful shutdown (see Graceful Shutdown)
Server Setup (internal/app/app.go)
Defines the HTTP server configuration:
routeris undefined (needs to be imported fromhttppackage)- Missing
:prefix in Addr (should be:8080) - No timeouts configured
Routing (http/routes.go)
Defines the application’s URL structure:
- Uses Go’s standard
http.NewServeMux()instead of external routers (like Gorilla Mux from REST API) - Missing
return muxstatement - Handlers are declared but not implemented
Route Design
The routing structure reveals the intended architecture:| Route | Purpose | Status |
|---|---|---|
/signup | User registration page | Planned |
/login | Login page | Planned |
/teacher | Teacher dashboard | Planned |
/student | Student dashboard | Planned |
/api/signup | Registration API endpoint | Planned |
/api/login | Authentication API endpoint | Planned |
/login) from API routes (/api/login). This allows:
- Serving HTML templates for browser requests
- Returning JSON for API requests
- Future migration to a separate frontend (React, Vue, etc.)
Handlers (http/handlers.go)
Currently empty, awaiting implementation:
Middleware (http/middleware.go)
Also empty, but will eventually handle:
Next Steps
To bring this project to a working state, the following are needed:Implement Database Layer
Create
internal/db package for MongoDB or PostgreSQL connection.Reference: AuthenticationBuild Authentication Service
Implement JWT token generation and validation.Reference: Authentication
Lessons from This Project
1. Start with Structure
Even though most files are empty, the directory layout already communicates intent:cmd/= “This is an executable”internal/= “This logic is private to this app”http/= “This handles web concerns”
2. Routing is Design
The routes inroutes.go serve as a specification. Before writing any handler logic, we’ve already decided:
- What URLs exist
- What roles are supported
- How frontend and API are separated
3. Work in Progress is Normal
Real projects evolve. This skeleton shows:- Missing return statements
- Undefined variables
- Empty implementations
Comparison to MiniAuth
This project mirrors the structure of MiniAuth from Chapter 10:| Feature | MiniAuth | Attendance App |
|---|---|---|
| Architecture | Service/Repository | Planned (not implemented) |
| Database | MongoDB | To be decided |
| Routing | Custom patterns | Standard http.ServeMux |
| Auth | JWT implemented | JWT planned |
| Structure | internal/auth, internal/repository | internal/app, http/ |
The Attendance App uses a flatter structure (
http/ instead of internal/http). Both approaches are valid—Go doesn’t enforce this.Running the Project
Once complete, it should run with:Cross-References
This project applies concepts from:- Project Structure
- Interfaces for Dependency Injection
- REST API Design
- JWT Authentication
- Clean Architecture
This project is a living document. As the code evolves, so will this documentation.