Framework Architecture
Understanding EZ-Console's architecture is essential for building robust applications. This guide explains the framework's design, components, and how they interact.
High-Level Architectureβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend Layer β
β React + TypeScript + Ant Design + React Router β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β HTTP/HTTPS (JSON)
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββ
β API Gateway Layer β
β Gin Router + Middleware (Auth, CORS, Log) β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββ
β Controller Layer β
β HTTP Request Handling + Input Validation β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββ
β Service Layer β
β Business Logic + Transaction Management β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββ
β Data Access Layer β
β GORM ORM + Database Operations β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββΌβββββββ ββββββββββββββββββββββββββββββββ
β Database β
β SQLite / MySQL / PostgreSQL β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Backend Architectureβ
Layered architectureβ
The backend splits HTTP handling, business logic, persistence shapes, and cross-cutting behavior. Full patterns, request/response helpers, and copy-pastable examples are in Core concepts so this page stays focused on diagrams and flow.
| Layer | Role |
|---|---|
| Controller | Routes, binding/validation, calls services, writes HTTP responses |
| Service | Rules, transactions, DB and integrations; no gin.Context |
| Model | GORM schema and relationships; embed model.Base for public id and soft delete |
| Middleware | Auth, RBAC, CORS, logging, metricsβsee Middleware |
The stock server ships JWT auth, permission checks, structured logging, CORS, panic recovery, and metrics. For global Gin setup that runs after that default stack (extra Use, top-level routes), use consoleserver.WithEngineOptions on NewCommandServer; timing and examples: Middleware: global middleware and Command server options.
Request Flowβ
Here's how a typical request flows through the backend:
1. Client Request
β
2. Gin Router (route matching)
β
3. Middleware Chain
- Logging (start)
- CORS headers
- Authentication (JWT validation)
- Permission check
β
4. Controller
- Parse request parameters
- Validate input
- Call service
β
5. Service
- Execute business logic
- Database operations
- Call other services if needed
β
6. Model/Repository
- GORM query execution
- Data persistence
β
7. Controller (continued)
- Format response
- Return HTTP response
β
8. Middleware Chain (reversed)
- Logging (end)
- Metrics collection
β
9. Client Response
Frontend Architectureβ
Component Hierarchyβ
βββββββββββββββββββββββββββββββββββββββββββ
β Application Shell β
β (Layout, Navigation, Authentication) β
ββββββββββββββ¬βββββββββββββββββββββββββββββ
β
ββββββββββ΄βββββββββ
β β
βββββΌβββββ ββββββββΌβββββββ
β Public β β Private β
β Routes β β Routes β
β β β (Protected) β
ββββββββββ ββββββββ¬βββββββ
β
βββββββββββββΌββββββββββββ
β β β
ββββββΌββββ βββββΌββββ β βββββΌβββββ
β Page β β Page β β Page β
βComponentsβ βComponentsβ βComponentsβ
ββββββ¬ββββ βββββ¬βββββ βββββ¬βββββ
β β β
ββββββΌβββββββββββΌβββββββββββΌβββββ
β Shared Components β
β (Tables, Forms, Modals) β
ββββββ¬βββββββββββββββββββββββββββ
β
ββββββΌβββββββββββββββββββββββββ
β API Service Layer β
β (HTTP Client + Interceptors)β
ββββββ¬βββββββββββββββββββββββββ
β
ββββββΌβββββββββββββββββββββββββ
β State Management β
β (Context API + React Query) β
βββββββββββββββββββββββββββββββ
Frontend Layersβ
1. Application Shellβ
The EZApp component provides:
- Layout (header, sidebar, content)
- Navigation menu
- Authentication flow
- Route protection
- Global state providers
<EZApp
basePath='/'
extraPrivateRoutes={[
{
path: '/products',
element: withSuspense(ProductPage),
name: 'products',
}
]}
/>
2. Page Componentsβ
Pages are lazy-loaded route components:
const ProductPage = lazy(() => import('@/pages/ProductPage'));
3. Shared Componentsβ
Reusable UI components:
DataTable- Table with pagination, sorting, filteringFormModal- Modal with form handlingFileUpload- File upload with progressPermissionGuard- Component-level permission check
4. API Service Layerβ
Axios-based HTTP client with interceptors:
// Request interceptor - add auth token
axios.interceptors.request.use((config) => {
const token = getToken();
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
// Response interceptor - handle errors
axios.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) {
// Token expired, redirect to login
window.location.href = '/login';
}
return Promise.reject(error);
}
);
5. State Managementβ
Two types of state:
Server State (React Query):
const { data, loading } = useRequest(() => apiGet('/users'));
Client State (React Context):
const { user, updateUser } = useAuth();
const { siteConfig, currentOrgId } = useSite();
See React hooks & context for useAuth, useSite, usePermission, and useAI.
Core concepts (read next)β
This page focuses on shape and flow: layers, diagrams, and how frontend and backend connect. The conventions you apply in day-to-day codeβcontroller vs service, standard responses, resource_id, soft deletes, audit helpers, RBAC, and the middleware pipelineβare documented in one place so they do not drift across pages:
- Core concepts β patterns, IDs, auth flow, audit usage, middleware overview
Skim the diagrams here first; keep Core concepts open while you implement.
Built-in Modulesβ
EZ-Console provides several built-in modules:
1. User Management Moduleβ
- User CRUD operations
- Password management
- MFA configuration
- Status management
- Last login tracking
2. Authorization Moduleβ
- Role management
- Permission definitions
- Permission groups
- Service accounts
- Session management
- OAuth2/OIDC integration
- LDAP/AD integration
3. System Settings Moduleβ
- Password policies
- MFA settings
- Session timeout
- Email/SMTP configuration
- OAuth provider configuration
4. File Management Moduleβ
- File upload/download
- Storage abstraction
- Access control
- File metadata
5. Audit Log Moduleβ
- Action logging
- IP tracking and geolocation
- User agent tracking
- Searchable logs
6. Statistics Moduleβ
- User activity metrics
- Login statistics
- API usage tracking
- System health
Extensibilityβ
Controllers and routesβ
Register HTTP controllers from your application module (typically in init()):
func init() {
server.RegisterControllers(func(ctx context.Context, svc server.Service) server.Controller {
return NewProductController(svc)
})
}
Gin middlewareβ
The stock server owns the Gin *gin.Engine. For global middleware or extra top-level routes, use consoleserver.WithEngineOptions on NewCommandServer: callbacks run after the default stack (recovery, OpenTelemetry, Prometheus, request logging, CORS, delay) and before services and controller registration. Examples and ordering details: Middleware, Command server options.
User and role change hooksβ
The underlying authorization layer supports RegisterUserChangeHook and RegisterUserRoleChangeHook on server.Service. The default Run path constructs the service inside the framework, so registering these hooks from a plain main + NewCommandServer app may require following the patterns in the source or a custom bootstrap. See Hooks & Events.
Next Stepsβ
- If you have not run the stock app yet, use Quick Start
- Keep Core concepts nearby while you implement controllers and services
- Explore Backend development for deeper guides
Questions about the architecture? Ask on GitHub Discussions.