How harrishphotos/go_user_auth works
Project Type & Purpose
• Full-stack web service providing user authentication, email verification, and CRUD operations for books and stores.
• Backend: Go (Fiber framework)
• Frontend: React + Vite + TypeScript
• Persistence: PostgreSQL (GORM ORM)
• Messaging: Kafka for asynchronous email/event processing
• Containerization: Docker & Docker Compose
Main System Components
A. Client Layer (Frontend)
• React/Vite application served on port (e.g., 3000)
• Pages: Login, Register, Home, Forgot Password, Verify Email
• AuthContext for state, Axios wrapper for API calls
B. API Layer (Go Fiber Backend)
• Entry point: main.go
• Configuration: config/config.go (loads .env)
• Router: routes/routes.go ─ registers auth, book, store sub-routes
• Controllers: controllers/*_controller.go ─ handle HTTP requests, invoke services
• Middleware: middleware/auth_middleware.go & middleware.go ─ PASETO token validation, logging, CORS
• Services:
• email.go ─ constructs and sends emails (via SMTP)
• kafka/producer.go ─ publishes verification/reset messages to Kafka
• kafka/consumer.go ─ subscribed to the same topics when running in consumer mode
• Utilities: password hashing (Argon2id), token generation (PASETO), verification token handling
• Database: database/database.go ─ initializes GORM with PostgreSQL
C. Data Layer
• PostgreSQL container (“postgres”)
• GORM models: models/user.go, book.go, store.go
• Tables for users, tokens, books, stores
D. Messaging Layer
• Kafka broker container (“kafka”)
• Topics: “user-verification”, “password-reset” (or similar)
• Producer in backend publishes events, consumer processes them
E. External Services
• SMTP/Email provider for sending verification and reset emails
F. Deployment Infrastructure
• Docker Compose orchestrates:
• app (Go/Fiber service)
• postgres
• kafka (and implicitly Zookeeper)
Relationships & Data Flows
1. User → Browser/React client
• User interacts via UI, triggers API calls
2. React client → HTTP(S) → Go API
• Auth calls: /api/auth/*
• Book calls: /api/book/*
• Store calls: /api/store/*
3. API → PostgreSQL
• GORM ORM reads/writes user, book, store records
4. API → Kafka
• On registration/forgot-password: controllers call kafka.Producer to enqueue messages
5. Kafka → Consumer (could be same app in a consumer role or separate microservice)
• Consumer receives messages, invokes services/email.go to send emails
6. Consumer → SMTP
• SMTP connection to external mail server
Architectural Patterns & Design Principles
• Layered (presentation → API router → controllers → services → data)
• MVC-style separation (controllers/models)
• Asynchronous messaging for scalability & reliability (Kafka)
• Token-based stateless authentication (PASETO)
• Containerized, microservice-friendly deployment
• Client Section: Browser → React SPA
• API Section:
• config → routes → middleware → controllers → services → utils/database
• Data & Messaging:
• PostgreSQL ←→ GORM
• Kafka Producer → Kafka Broker → Kafka Consumer → Email Service
• External: SMTP server