How alejandro-albiol/athenai works
Project Type and Purpose
• AthenAI is a monolithic, Go‐based full-stack application that serves a static frontend and provides RESTful API endpoints for gym management (users, gyms, admin functions) with subdomain-based multi-tenancy and JWT authentication.
• Key indicators:
• cmd/ contains server entrypoint and DB setup utilities
• frontend/ holds static HTML/CSS/JS
• internal/ modules (auth, user, gym, admin) implement layered business logic
• README describes monolith, modules, OpenAPI, multi-tenant auth
File Structure Analysis
• Top-level directories:
• cmd – entrypoints (main.go, setup scripts)
• api – API router and Swagger setup
• frontend – static assets served by Go’s FileServer
• internal – private modules (auth, user, gym, admin, database)
• pkg – shared reusable code (middleware, error handling, response helpers, utils)
• config, docs, scripts – configuration, documentation, automation scripts
• Layering pattern:
• HTTP layer (routers/handlers) → Service layer (business rules) → Repository layer (DB access)
• Interfaces for each layer support loose coupling and testability
• Deployment / build artifacts:
• Air config (.air.toml) for live reload
• go.mod, go.sum, Dockerfile (if any) / scripts for DB and tenant cleanup
README Insights
• Monolithic frontend + backend, served from same Go binary
• JWT-based auth with middleware extracting subdomain and routing to correct schema
• Modules: auth, user, gym, admin each with DTOs, interfaces, handlers, services, repositories
• OpenAPI 3 specification split into components and paths under docs/openapi/
a. Main Components
• Clients: Web Browser (static UI)
• HTTP Server (Go binary)
• API Router (api/api.go + versioned routes /api/v1/...)
• Static File Server (serving frontend/)
• Modules:
– Auth Module (middleware, handlers, services, repo)
– User Module
– Gym Module
– Admin Module
• Shared Packages: Middleware (pkg/middleware), Error Handling (pkg/apierror), Response (pkg/response), Utils
• Database: PostgreSQL with public schema (platform admin) + tenant schemas per gym
• External Docs: Swagger UI (/swagger-ui/) serving OpenAPI spec
b. Relationships & Interactions
• Browser → HTTP Server
– / → Static files
– /api/v1/... → API Router
• API Router → Module Routers (auth, user, gym, admin)
• Module Router → Handler → Service → Repository
• Repository → Database
• Middleware runs before handlers to:
– authenticate JWT
– extract subdomain (tenant) and select DB schema
• Swagger UI fetches /docs/openapi/openapi.yaml
c. Architectural Patterns
• Layered (Controller → Service → Repository)
• Modular Monolith (domain modules under internal/)
• Dependency Injection via Interfaces
• Subdomain-based Multi-Tenancy
• Static File Serving in same process
d. Technologies & Frameworks
• Go 1.19+ standard library (net/http)
• Air for live reload (.air.toml)
• PostgreSQL (multi-schema tenancy)
• OpenAPI 3.0 + Swagger (api/swagger.go, docs/openapi/)
• PowerShell scripts for Windows automation (in scripts/)