How nachoov/spl-access works
Project Type and Purpose
• This is a backend API service written in Go, exposing REST endpoints and a WebSocket endpoint for real-time access-control events.
• It uses the Fiber web framework, Ent for ORM, and PostgreSQL as the data store.
• The project follows a layered, monolithic architecture.
File Structure and Key Directories
• Top‐level orchestration:
• Dockerfile / docker-compose.yaml – container definitions for the Go app and Postgres.
• Makefile / .air.toml – build and hot-reload scripts.
• main.go – application entry point.
• Application code under src/:
• server/fiber.go – HTTP server bootstrap, route registration, WebSocket upgrade.
• middleware/auth.go – request authentication.
• controller/… – HTTP handlers (access.go, main.go).
• service/… – business logic (access.go).
• repository/… – data access interfaces and Postgres implementations using Ent (access_postgres.go, access_query.sql).
• db/postgres.go – raw DB initialization for Ent.
• dto/… – request/response payload definitions.
• model/… – domain models (if any custom beyond Ent).
• websocket/websocket.go – real-time event hub for connected clients.
• helpers/… – utility and error handling.
README for Additional Insights
• Confirms Go 1.19, PostgreSQL requirement, environment variables.
• Development flow uses Air for hot reload.
Main Components
a. Client Tier
• API Consumers (e.g., web/mobile clients)
• WebSocket Clients
b. Entry Point
• Load Balancer / Reverse Proxy (optional)
• Fiber HTTP Server
c. Cross-Cutting Concerns
• Middleware (Auth, Logging)
• DTOs for request/response shaping
d. Business Logic
• Controller Layer (HTTP handlers)
• Service Layer (use-case orchestration)
e. Data Access
• Repository Interface
• Ent ORM client
• Raw SQL module (for complex queries)
f. Persistence
• PostgreSQL Database
g. Dev/Infra
• Docker Compose (App container, Postgres container)
• Air (hot-reload in dev)
h. (Future) Batch Processor
• Cron Job → BigQuery
Relationships and Data Flows
• WebSocket Flow: Client ↔ Fiber WebSocket Route ↔ Websocket Hub ↔ Service → Repository → DB (and back)
Architectural Patterns and Principles
• Layered Architecture: clear separation of concerns (Presentation, Business, Data).
• Repository Pattern: abstracts DB operations behind interfaces.
• DTOs: isolate API contract from domain entities.
• ORM (Ent): code-first schema, type safety.
• Middleware chaining in Fiber.
• Dependency injection via constructor functions in main.go.
• Containerization with Docker, orchestration via docker-compose.
Technologies and Frameworks to Label
• Go 1.19+
• Fiber (github.com/gofiber/fiber)
• Ent ORM (entgo.io)
• PostgreSQL
• Docker / Docker Compose
• Air (dev hot reload)
• SQL (raw .sql files for intricate queries)
• WebSockets (real-time channel)