How afloresc/time-control works
Purpose and Deployable Entry Points
Time Control is a labor time-tracking system: a Go HTTP API records work sessions under Spanish labor-control requirements, and a separate React/Vite client provides clock and session views. The API starts at cmd/api/main.go; the browser client boots from time-control-frontend/src/main.jsx into time-control-frontend/src/App.jsx.
API Composition and Routing
The backend is modular by domain and exposes protected user (/me) and administrator (/admin) APIs. Router assembly, middleware placement, and endpoint binding are centralized in internal/router/router.go. Session operations flow handler → service → repository, separating HTTP concerns, business rules, and persistence:
• internal/sessions/handler.go
• internal/sessions/service.go
• internal/sessions/repository.go
Authentication and Authorization Boundary
Firebase is the identity authority. Request middleware validates Bearer JWTs, derives identity/claims, provisions a local user when needed, and places user ID, email, and role in request context. Admin routes add a role gate after authentication. This is the principal external trust boundary:
• internal/auth/firebase.go
• internal/auth/firebase_middleware.go
• internal/admin/handler.go
Work-Session Lifecycle
Authenticated users start and end an active work session or create manual dated intervals; they can retrieve their own session history. The session model represents persisted work-time records, while the service governs lifecycle transitions and repository writes/queries:
• internal/sessions/model.go
• internal/sessions/service.go
• internal/sessions/repository.go
An admin can inspect all sessions and filter them by Firebase/local user ID through the admin-facing routing/handler layer.
Interval and Time Presentation Domain
A distinct intervals module appears to support interval-oriented API behavior alongside the core sessions domain. It has its own HTTP, service, persistence, and model boundaries:
• internal/intervals/handler.go
• internal/intervals/service.go
• internal/intervals/repository.go
On the frontend, clock state and elapsed-time behavior are encapsulated separately from visual active/inactive states:
• time-control-frontend/src/hooks/useClock.js
• time-control-frontend/src/components/clock/ClockActiveSession.jsx
• time-control-frontend/src/components/clock/ClockInactiveSession.jsx
Persistence and Local User Projection
SQLite is the system of record, accessed through GORM, with the checked-in runtime database located at data/timecontrol.db. Firebase identities are projected into a local users table so application roles and session ownership can be queried locally. User persistence is isolated from auth and sessions:
• internal/database/sqlite.go
• internal/users/model.go
• internal/users/repository.go
Frontend Application Boundary
The React client uses Firebase client authentication, maintains auth state in context, protects routes, and calls the backend session API. Its main application flow is auth bootstrap → protected route → clock/sessions page → API request carrying Firebase credentials:
• time-control-frontend/src/Firebase.js
• time-control-frontend/src/context/AuthContext.jsx
• time-control-frontend/src/api/sessionsApi.js
Routing and application shell are separated from feature pages:
• time-control-frontend/src/app/router.jsx
• time-control-frontend/src/components/RequireAuth.jsx
• time-control-frontend/src/pages/Clock.jsx
Main entry points: router.go HTTP router · sqlite.go SQLite via GORM · Clock.jsx Clock and sessions page · firebase_middleware.go JWT authentication
Components 21
React Client
- Client bootstrap
time-control-frontend/src/main.jsx - Application shell
time-control-frontend/src/App.jsx - Client routes
time-control-frontend/src/app/router.jsx - Auth state · Maintains Firebase client authentication state.
time-control-frontend/src/context/AuthContext.jsx - Protected routes
time-control-frontend/src/components/RequireAuth.jsx - Clock and sessions page
time-control-frontend/src/pages/Clock.jsx - Elapsed clock state
time-control-frontend/src/hooks/useClock.js - Active/inactive clock
time-control-frontend/src/components/clock/ClockActiveSession.jsx - Session API client · Sends Firebase credentials with session requests.
time-control-frontend/src/api/sessionsApi.js - Firebase client SDK
time-control-frontend/src/Firebase.js
Go API
- API server
cmd/api/main.go - HTTP router · Binds /me and /admin endpoints and middleware.
internal/router/router.go - JWT authentication · Validates Bearer tokens, projects users, and adds claims to context.
internal/auth/firebase_middleware.go - Firebase verifier
internal/auth/firebase.go - Session lifecycle · Handles active sessions, manual intervals, and personal history.
internal/sessions/service.go - Intervals domain · Provides interval-oriented API behavior.
internal/intervals/service.go - Admin session access · Role-gated inspection and user-filtered session queries.
internal/admin/handler.go
Persistence
- Local user projection · Stores Firebase identities and local application roles.
internal/users/repository.go - SQLite via GORM
internal/database/sqlite.go - Time-control database · System of record for users and work-time records.
data/timecontrol.db
Identity Provider
- Firebase Auth · Issues client credentials and validates identity claims.
Connections 25
- Client bootstrap → Application shell: mounts
- Application shell → Client routes: renders
- Client routes → Protected routes: protects routes
- Protected routes → Auth state: reads auth state
- Auth state → Firebase client SDK: uses
- Firebase client SDK → Firebase Auth: authenticates with
- Protected routes → Clock and sessions page: allows authenticated access
- Clock and sessions page → Elapsed clock state: uses
- Clock and sessions page → Active/inactive clock: renders
- Clock and sessions page → Session API client: loads and updates sessions
- Session API client → API server: authenticated HTTP requests
- API server → HTTP router: starts
- HTTP router → JWT authentication: applies to protected APIs
- JWT authentication → Firebase verifier: verifies JWT
- Firebase verifier → Firebase Auth: validates claims with
- JWT authentication → Local user projection: provisions local user
- HTTP router → Session lifecycle: /me session routes
- HTTP router → Intervals domain: interval routes
- HTTP router → Admin session access: /admin routes
- JWT authentication → Admin session access: authenticated role context
- Session lifecycle → SQLite via GORM: writes and queries sessions
- Intervals domain → SQLite via GORM: persists intervals
- Admin session access → SQLite via GORM: queries all sessions
- Local user projection → SQLite via GORM: persists users and roles
- SQLite via GORM → Time-control database: opens