Skip to main content

Overview

Zou is built on Flask, a lightweight Python web framework, and follows a modular architecture that separates concerns into blueprints (routing), services (business logic), and models (data layer).

Core Components

Flask Application

The main application is initialized in zou/app/__init__.py and configured with:
  • Flask-SQLAlchemy - Database ORM for PostgreSQL
  • Flask-JWT-Extended - JWT token authentication
  • Flask-Principal - Role-based permissions
  • Flask-Migrate - Database schema migrations
  • Flask-Mail - Email notifications
  • Flasgger - OpenAPI/Swagger documentation
zou/app/__init__.py

Configuration

The application configuration is environment-driven through zou/app/config.py, supporting:
  • Authentication strategies (local, LDAP, SAML)
  • Database connection pooling
  • JWT token expiration
  • File storage backends (local, S3, Swift)
  • Email settings
  • Search indexer (Meilisearch)
  • Two-factor authentication enforcement

Blueprint Architecture

Zou uses Flask blueprints to organize routes into logical modules. Each blueprint handles a specific domain:

Blueprint Structure

Blueprint Registration

All blueprints are registered in zou/app/api.py:
zou/app/api.py

Example Blueprint

Each blueprint defines routes and maps them to resource classes:
zou/app/blueprints/auth/__init__.py

Service Layer

The service layer contains all business logic and sits between blueprints (controllers) and models (data layer).

Service Organization

Service Pattern

Services provide reusable business logic functions:
Services are stateless and focus on business logic. They handle:
  • Data validation and transformation
  • Permission checks
  • Event emission
  • Cache management
  • External API calls

Data Flow

Request Lifecycle

  1. HTTP Request arrives at a blueprint route
  2. Route dispatches to a Resource class method (GET, POST, PUT, DELETE)
  3. Resource validates input and calls service functions
  4. Service performs business logic and database operations
  5. Model interacts with PostgreSQL via SQLAlchemy
  6. Response is serialized and returned as JSON

Database Layer

Base Model

All models inherit from BaseMixin which provides:
  • UUID primary keys
  • Audit timestamps (created_at, updated_at)
  • Common query methods (get, get_by, get_all)
  • CRUD operations (create, update, delete)
  • Serialization support
zou/app/models/base.py

Connection Pooling

Zou uses SQLAlchemy’s connection pooling for performance:

Caching Strategy

Zou uses Redis for caching frequently accessed data:
  • Memoization - Function result caching with TTL
  • Auth tokens - JWT token blacklist for logout
  • User data - Current user profile caching
  • Project data - Active project information

Event System

Zou emits events for major operations, allowing plugins and external systems to react:
Events are processed asynchronously and can trigger:
  • Email notifications
  • Slack/Discord messages
  • Webhook calls to external systems
  • Status automations
  • Search index updates

Extensions & Integrations

Search Indexing

Zou integrates with Meilisearch for full-text search:

File Storage

Supports multiple storage backends:
  • Local filesystem - Default for development
  • Amazon S3 - Scalable cloud storage
  • OpenStack Swift - Object storage

Authentication Providers

  • Local - Built-in password authentication
  • LDAP/Active Directory - Enterprise directory integration
  • SAML SSO - Single sign-on support
  • Two-Factor Auth - TOTP, Email OTP, FIDO2/WebAuthn

Scalability Considerations

Zou can be scaled horizontally by:
  1. Load balancing multiple Flask instances
  2. Shared Redis for cache and sessions
  3. PostgreSQL read replicas for read-heavy workloads
  4. CDN for static file delivery
  5. Background workers for async tasks (email, exports)
  • Database query optimization with indexes
  • N+1 query prevention with eager loading
  • Response caching with Redis
  • Connection pooling for database
  • Pagination for large result sets
  • Thumbnail generation for preview files

Next Steps

Data Model

Explore the core entities and their relationships

Authentication

Learn about JWT tokens and auth strategies

Permissions

Understand role-based access control

API Reference

Browse the complete API documentation