How espejelkevin/movie-reservation-system works
Purpose and entry point
This is a Go backend for a movie reservation system: user/admin authentication, catalog and showtime administration, and seat reservations. src/main.go is the composition entry point, connecting HTTP routes, middleware, GORM persistence, and application use cases. Database initialization is centralized in src/infrastructure/database/connection.go.
Layered architecture
The repository follows a domain/application/infrastructure split:
• Domain models, DTOs, validation, and persistence contracts: src/domain/entities/, src/domain/dto/, src/domain/interfaces/.
• Application use cases own business operations and depend on repository interfaces: src/application/usecases/.
• Infrastructure implements HTTP delivery, auth middleware, database access, and repository adapters: src/infrastructure/routes/, src/infrastructure/repositories/.
This creates a boundary where core use cases should not depend directly on GORM or HTTP.
HTTP API and authorization boundary
Route modules expose resource-specific endpoints and bind them to use cases: src/infrastructure/routes/user_routes.go, src/infrastructure/routes/movie_routes.go, and src/infrastructure/routes/reservation_routes.go. Administrative API surfaces are separated in src/infrastructure/routes/admin_routes.go and management route files such as src/infrastructure/routes/showtime_routes.go.
Authentication/authorization is enforced at the infrastructure edge by src/infrastructure/middlewares/middlewares.go. JWT creation/handling is implemented under src/application/usecases/auth/token/jwt.go; login paths are split between user and administrator flows in src/application/usecases/auth/login_user.go and src/application/usecases/admin/login_admin.go.
Identity, roles, and access control
Users and roles are domain entities with DTO boundaries: src/domain/entities/user.go, src/domain/entities/role.go, and src/domain/dto/userDTO.go. Registration/login use cases coordinate user lookup, credential handling, and token issuance through repository contracts. Role CRUD is available as an administrative capability through src/application/usecases/role/ and src/infrastructure/routes/role_routes.go.
Catalog and scheduling
Movie and genre management are distinct resource pipelines. Movie operations—including image update—live in src/application/usecases/movie/, while GORM persistence is in src/infrastructure/repositories/movie_repository_gorm.go; genres follow the parallel paths src/application/usecases/genre/ and src/infrastructure/repositories/genre_repository_gorm.go.
Showtimes bridge the catalog to reservable events. Their entity/interface and CRUD lifecycle reside in src/domain/entities/showtime.go, src/domain/interfaces/showtime_repository.go, and src/application/usecases/showtime/.
Reservation flow
Reservation operations are isolated as the principal transactional business area: creation, lookup, user-scoped history, cancellation, and deletion are in src/application/usecases/reservation/. The flow accepts reservation DTOs (src/domain/dto/reservationDTO.go), uses reservation/showtime domain data, and persists through src/domain/interfaces/reservation_repository.go and src/infrastructure/repositories/reservation_repository_gorm.go.
The intended control path is HTTP request → middleware identity/role validation → use case → repository interface → GORM/database → DTO/HTTP response. Seat availability, overbooking prevention, upcoming-only cancellation, capacity, and revenue reporting are expected to be enforced primarily in this reservation/use-case and persistence boundary.
Runtime and external dependencies
The service runs on Go, with dependencies declared in go.mod. Persistence is relational-database-oriented via GORM repository adapters, configured through src/infrastructure/database/connection.go. JWT is the externalized authentication mechanism; no payment, messaging, email, or separate frontend service is represented in the tree.
Main entry points: connection.go Database connection · main.go Service composition · middlewares.go Auth middleware · jwt.go JWT tokens
Components 15
Domain
Core models, DTOs, and repository contracts.
- Core entities · Users, roles, movies, genres, showtimes, and reservations.
- DTOs and validation · Request and response boundaries for identity and reservations.
- Repository contracts · Abstractions used by application use cases.
Application
Business use cases depend on domain contracts.
- Authentication · User and administrator login plus token issuance.
- JWT tokens · Creates and handles authentication tokens.
src/application/usecases/auth/token/jwt.go - Users and roles · Registration and administrative role management.
- Movies and genres · Catalog management, including movie image updates.
- Showtimes · Creates and manages reservable movie events.
- Reservations · Creation, history, cancellation, deletion, capacity, and revenue operations.
Infrastructure
HTTP, middleware, persistence, and runtime composition.
- Service composition · Wires routes, middleware, use cases, and persistence.
src/main.go - HTTP routes · Resource and administrative API endpoints.
- Auth middleware · Validates request identity and authorization at the HTTP edge.
src/infrastructure/middlewares/middlewares.go - Database connection · Central relational database initialization.
src/infrastructure/database/connection.go - GORM repositories · Implements domain persistence contracts with GORM.
- Relational database
Connections 21
- Service composition → HTTP routes: registers
- Service composition → Database connection: initializes
- HTTP routes → Auth middleware: protects requests with
- HTTP routes → Authentication: login endpoints
- HTTP routes → Users and roles: user and role endpoints
- HTTP routes → Movies and genres: catalog endpoints
- HTTP routes → Showtimes: management endpoints
- HTTP routes → Reservations: reservation endpoints
- Auth middleware → JWT tokens: validates
- Authentication → JWT tokens: issues
- Authentication → Repository contracts: uses
- Users and roles → Repository contracts: uses
- Movies and genres → Repository contracts: uses
- Showtimes → Repository contracts: uses
- Reservations → Repository contracts: uses
- Reservations → DTOs and validation: accepts and returns
- Reservations → Core entities: applies rules to
- Repository contracts → Core entities: persists
- GORM repositories → Repository contracts: implements
- GORM repositories → Database connection: uses
- Database connection → Relational database: connects to