How edithkaren/ticket-raising-system works
Purpose and Entry Points
This repository implements a Go/Gin REST API for authenticated, owner-scoped support-ticket management. The backend process starts in main.go; HTTP route handlers are in handlers/handlers.go. Dockerfile packages the service for port-8080 deployment.
A separate Vite/React frontend also exists, rooted at src/main.tsx and src/App.tsx, with server.ts potentially serving as a Node-side integration entry point.
HTTP API and Routing Layer
main.go initializes the Gin server, database, handlers, and route groups. handlers/handlers.go implements:
• public health and authentication endpoints;
• protected ticket creation, listing, retrieval, and status-update endpoints;
• request parsing, response formatting, and business-rule enforcement.
The API boundary is JSON over HTTP; protected routes depend on authenticated identity supplied by middleware.
Authentication and Authorization
middleware/auth.go validates JWT bearer tokens and places authenticated user context into Gin requests. handlers/handlers.go uses that context to associate created tickets with a user and restrict reads/updates to the ticket owner.
Registration and login reside in handlers/handlers.go; password credentials are bcrypt-hashed and JWTs are signed using JWT_SECRET. This is the primary security boundary between public authentication routes and /tickets operations.
Domain Model and Workflow Rules
models/models.go defines the core persisted/request domain types, notably users and tickets. Tickets have an ownership relationship to users and a constrained lifecycle: open → in_progress → closed; closed tickets cannot be reopened.
The status transition rule is enforced at the handler/domain boundary in handlers/handlers.go, before persistence updates. Ownership checks likewise occur before exposing or mutating ticket records.
Persistence Layer
db/db.go owns SQLite initialization and database access setup. It uses the pure-Go modernc.org/sqlite driver, avoiding CGO and any external database service.
Control flow is: application startup initializes SQLite schema/access through db/db.go; handlers in handlers/handlers.go query or mutate users and tickets; model structures in models/models.go carry data between HTTP and persistence concerns.
Runtime and Deployment
The primary runtime is Go 1.21+ with Gin, SQLite, JWT, and bcrypt dependencies defined by go.mod. Environment-controlled operational inputs are PORT (default 8080) and JWT_SECRET (default secret).
Dockerfile is the deployable backend packaging boundary. SQLite persistence is local to the runtime filesystem, so durable production storage requires an appropriate mounted volume or equivalent filesystem strategy.
Frontend Surface
The repository includes a TypeScript React/Vite client: src/main.tsx bootstraps the app, src/App.tsx contains the main UI, and src/types.ts defines client-side shared shapes. It is operationally distinct from the Go API and communicates across the same HTTP/JSON API boundary.
Main entry points: handlers.go Handlers · main.go API bootstrap · App.tsx Ticket UI · db.go SQLite access
Components 15
Go API
Authenticated ticket-management backend.
- Docker image · Packages the backend for port 8080.
Dockerfile - API bootstrap · Initializes Gin, database, handlers, and routes.
main.go - Gin routes · Public auth/health and protected ticket endpoints.
main.go - Handlers · Parses requests, enforces ownership and ticket rules.
handlers/handlers.go - JWT middleware · Validates bearer tokens and injects user context.
middleware/auth.go - Users and tickets · Defines persisted and request domain types.
models/models.go - Ticket lifecycle · Allows open → in_progress → closed; closed tickets stay closed.
handlers/handlers.go - SQLite access · Initializes schema and database access with modernc SQLite.
db/db.go - Local SQLite data · Durability depends on runtime filesystem storage.
- Go runtime config · Uses PORT and JWT_SECRET.
go.mod
React Client
Operationally distinct Vite frontend.
- Client bootstrap · Bootstraps the Vite React application.
src/main.tsx - Ticket UI · Main frontend user interface.
src/App.tsx - Client types · Shared client-side shapes.
src/types.ts - Node integration · Potential Node-side integration entry.
server.ts
Other components
- HTTP/JSON API · Public and authenticated REST interface.
Connections 16
- Docker image → API bootstrap: runs
- Go runtime config → API bootstrap: configures
- API bootstrap → SQLite access: initializes
- API bootstrap → Gin routes: registers
- Gin routes → Handlers: dispatches
- Gin routes → JWT middleware: protects ticket routes
- JWT middleware → Handlers: supplies identity
- Handlers → Ticket lifecycle: enforces
- Handlers → Users and tickets: uses
- Handlers → SQLite access: queries and mutates
- SQLite access → Local SQLite data: stores locally
- HTTP/JSON API → Gin routes: requests
- Client bootstrap → Ticket UI: renders
- Ticket UI → Client types: uses
- Ticket UI → HTTP/JSON API: HTTP/JSON
- Node integration → Ticket UI: integrates