https://github.com/anthonykewl20/efncore
Enterprise SaaS framework (FastAPI + Next.js) β Hybrid DDD Core + governed modules
https://github.com/anthonykewl20/efncore
ddd-architecture fastapi modular-architecture monorepo multi-tenancy nextjs opentelemetry plugin-architecture postgresql python3 rabbitmq redis typescript
Last synced: 4 months ago
JSON representation
Enterprise SaaS framework (FastAPI + Next.js) β Hybrid DDD Core + governed modules
- Host: GitHub
- URL: https://github.com/anthonykewl20/efncore
- Owner: anthonykewl20
- License: other
- Created: 2025-12-17T09:08:52.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-12-27T18:35:56.000Z (5 months ago)
- Last Synced: 2025-12-30T01:04:15.316Z (4 months ago)
- Topics: ddd-architecture, fastapi, modular-architecture, monorepo, multi-tenancy, nextjs, opentelemetry, plugin-architecture, postgresql, python3, rabbitmq, redis, typescript
- Language: Python
- Homepage: https://ranex.dev
- Size: 2.66 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# efncore
**The Enterprise SaaS Framework Kernel** β Production-grade multi-tenancy, events, jobs, and observability for building SaaS products.
[](https://github.com/anthonykewl20/efncore/actions/workflows/ci-pipeline.yml)
[](https://github.com/anthonykewl20/efncore/actions/workflows/security-scan.yml)
[](LICENSE)
---
## π― What is efncore?
efncore is a **production-grade framework for building multi-tenant SaaS products**. Like WordPress for enterprise SaaS, it provides:
- ποΈ **Domain-Driven Design architecture** that scales with your team
- π’ **Built-in multi-tenancy** with tenant isolation at all layers
- β‘ **Event-driven architecture** with transactional outbox
- π **Background jobs** with retry logic and scheduling
- π **OpenTelemetry observability** from day one
- π **Module system** for extensible features
- π¨ **Frontend shell included** (Next.js 16)
**For SaaS Founders**: Ship months faster with production-grade patterns.
**For Developers**: FastAPI + Next.js with TypeScript everywhere.
**For AI Agents**: CLAUDE.md with explicit architecture documentation.
---
## β‘ Quick Start (5 minutes)
Get efncore running locally with Docker Compose.
### Prerequisites
- Docker & Docker Compose
- Git
### One-Command Setup
```bash
git clone https://github.com/anthonykewl20/efncore.git
cd efncore
docker compose up -d
```
### Access Your SaaS
| Service | URL | Credentials |
|---------|-----|-------------|
| Frontend | http://localhost:3001 | - |
| Backend API | http://localhost:8001 | - |
| API Docs | http://localhost:8001/docs | - |
| Debug Context | http://localhost:8001/debug/context | - |
| Keycloak | http://localhost:8080 | admin/admin |
### Verify It's Working
```bash
# Check health status
curl http://localhost:8001/health
# Check request context (tenant isolation)
curl -H "X-Tenant-Id: 123e4567-e89b-12d3-a456-426614174000" \
http://localhost:8001/debug/context
```
**[β Full Setup Guide](docs/dev-docs/QUICK_START.md)**
---
## β¨ Why efncore?
### For SaaS Founders
| Challenge | efncore Solution |
|-----------|-----------------|
| **Building multi-tenancy from scratch** | Tenant isolation built-in (DB, cache, events) |
| **Handling background jobs reliably** | Transactional outbox + RabbitMQ workers |
| **Scaling read load** | Automatic replica routing (ADR-014) |
| **Observability after the fact** | OpenTelemetry tracing from day one |
| **Hiring developers** | Standard DDD patterns, clear documentation |
### For Developers
```python
# Tenant-scoped requests (automatic)
from efncore.kernel.request_context import RequestContextDep
@router.get("/users")
async def list_users(ctx: RequestContextDep):
# ctx.tenant_id automatically filters queries
users = await user_service.list(ctx.tenant_id)
return users
```
```bash
# Read from replicas automatically
# Write to primary explicitly
async with get_db_session(prefer_replica=True) as session:
user = await session.get(User, id) # Routes to replica
async with get_write_db_session() as session:
session.add(new_user) # Always goes to primary
await session.commit()
```
### For AI Agents
efncore includes **CLAUDE.md** β explicit architecture documentation for AI assistants:
- File placement rules (non-negotiable)
- API patterns and conventions
- Testing workflows and patterns
- Configuration system reference
---
## β¨ Core Features
### π’ Multi-Tenancy
- **Tenant isolation** at database, cache, and event layers
- **Request context middleware** automatically scopes all operations
- **Tenant-scoped Redis keys** prevent data leakage
- **Row-level security** with tenant governance
- **Tenant onboarding** flows built-in
### β‘ Event-Driven Architecture
- **Transactional outbox pattern** prevents event loss
- **RabbitMQ integration** with at-least-once delivery
- **Event handlers** with idempotency and replay
- **Dead-letter queues** for failed events
- **Module-to-core** communication via events
### π Background Jobs
- **Arq-based job queue** with Redis backend
- **Retry logic** with exponential backoff
- **Scheduled jobs** and cron-like workflows
- **Tenant-isolated** job execution
- **Job observability** with tracing
### π Observability
- **OpenTelemetry tracing** (OTLP) with W3C trace context
- **Structured logging** with tenant/user context
- **Performance guardrails** (query timeouts, backpressure)
- **Slow query logging** with automatic detection
- **Health checks** for all dependencies
### π Module System
- **Dynamic module loading** from directory
- **Strict contracts** (HTTP APIs + domain events)
- **Module governance** (allowlist, version checks)
- **UI extension points** for frontend modules
- **Kill switch** for emergency disabling
### π‘οΈ Security
- **OIDC authentication** (Keycloak integration)
- **Role-based access control** (RBAC)
- **Audit logging** for compliance (SOC 2, HIPAA)
- **PII redaction** in logs and events
- **Rate limiting** and load shedding
---
## ποΈ Architecture Overview
efncore follows **Domain-Driven Design (DDD)** with bounded contexts:
```mermaid
graph TB
subgraph "Frontend (Next.js)"
A[app/] --> B[core/templates/]
A --> C[modules/]
A --> D[platform/]
end
subgraph "Backend (FastAPI)"
E[app/main.py] --> F[core/contexts/]
E --> G[modules/]
E --> H[efncore/kernel/]
end
subgraph "Kernel Services"
H --> I[request_context/]
H --> J[data/]
H --> K[eventing/]
H --> L[jobs/]
H --> M[cache/]
end
A -->|HTTP/REST| E
K -->|RabbitMQ| N[Workers]
J -->|PostgreSQL| O[(Primary)]
J -->|Read Replicas| O
M -->|Redis| P[(Cache)]
```
### Repository Structure
```
efncore/
βββ backend/ # FastAPI application
β βββ src/
β β βββ app/ # Composition root
β β βββ core/ # Non-removable bounded contexts
β β β βββ tenancy/ # Tenant lifecycle
β β β βββ iam/ # Users, auth, RBAC
β β β βββ audit/ # Audit logging
β β β βββ billing/ # Subscriptions, entitlements
β β βββ modules/ # Installable features
β β βββ efncore/ # Platform kernel
β β βββ kernel/
β β β βββ request_context/ # Tenant/user metadata
β β β βββ data/ # Read/write splitting
β β β βββ eventing/ # Outbox, events
β β β βββ jobs/ # Background jobs
β β β βββ cache/ # Redis caching
β β βββ http/ # Middleware, errors
β β βββ config/ # Centralized settings
β βββ tests/ # Unit, integration, E2E
β βββ worker/ # Background job worker
β
βββ frontend/ # Next.js application
β βββ src/
β β βββ app/ # App Router
β β βββ core/ # Shell/core UI
β β βββ modules/ # Module UI
β β βββ platform/ # Theme, UI kit
β βββ e2e/ # Playwright E2E tests
β
βββ docs/ # Architecture & dev docs
β βββ architecture/ # ADRs, system context
β βββ development/ # Roadmap, workstreams
β βββ dev-docs/ # Developer guides
β
βββ CLAUDE.md # AI agent documentation
```
**Key Principles:**
- π **No `utils/`, `common/`, or `shared/`** directories
- π« **No business logic in HTTP routers**
- π **All requests tenant-scoped**
- π‘ **Modules communicate via HTTP APIs or events**
---
## π Documentation
### Getting Started
| Guide | Description |
|-------|-------------|
| [**Quick Start**](docs/dev-docs/QUICK_START.md) | Get running in 5 minutes |
| [**Configuration Guide**](docs/dev-docs/configuration/README.md) | All 100+ environment variables |
| [**Debugging Guide**](docs/dev-docs/debugging/README.md) | Troubleshooting common issues |
| [**Request Context**](docs/dev-docs/request-context/README.md) | Tenant/user propagation |
### Architecture
| Document | Description |
|----------|-------------|
| [**System Context**](docs/architecture/system-context.md) | C4 system-level architecture |
| [**ADR Index**](docs/architecture/adr/adrs.md) | Architecture decision records |
| [**Deployment**](docs/architecture/deployment-reliability.md) | Production deployment guide |
| [**Performance**](docs/architecture/scalability-performance.md) | Scaling and optimization |
### Development
| Document | Description |
|----------|-------------|
| [**File Governance**](docs/development/000-file-folder-governance.md) | Where code belongs (NON-NEGOTIABLE) |
| [**Module Development**](docs/dev-docs/module-development-guide.md) | Building modules |
| [**Eventing Guide**](docs/dev-docs/eventing/README.md) | Event handlers and outbox |
| [**Jobs Guide**](docs/dev-docs/jobs/README.md) | Background job patterns |
---
## π§ͺ Testing
efncore uses **Shin et al methodologies** (mutation testing, sad path first):
```bash
# Backend tests
cd backend
pytest # All tests
pytest -m unit # Unit tests only
pytest -m integration # Integration tests (requires DB)
pytest -m smoke # Health checks against running services
# Frontend tests
cd frontend
npm test # Unit tests (Vitest)
npm run test:e2e # E2E tests (Playwright)
npm run test:coverage # With coverage
```
**Test Philosophy:**
- β
Sad path before happy path
- β
Tenant isolation tests
- β
Mutation testing for critical modules
- β
Cross-module integration tests
---
## π Deployment
### Development (Docker Compose)
```bash
docker compose up -d
```
### Production
See [Deployment Guide](docs/architecture/deployment-reliability.md) for:
- Kubernetes manifests
- Environment variable reference
- Database migrations
- PgBouncer for read replicas
- OpenTelemetry collector setup
**Current Deployment:** Single VPS with Dokploy (Phase 0)
**Migration Path:** VPS β Split DB β Multi-region (same codebase)
---
## π€ Contributing
We welcome contributions! Please see [CONTRIBUTING.md](docs/development/CONTRIBUTING.md) for guidelines.
**Areas for Contribution:**
- π Bug fixes
- π New modules
- π Documentation improvements
- β
Test coverage
- β‘ Performance optimizations
**Good First Issues:** [GitHub Issues](https://github.com/anthonykewl20/efncore/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)
---
## π¬ Community
- **GitHub Discussions:** [Ask questions](https://github.com/anthonykewl20/efncore/discussions)
- **Issues:** [Bug reports & feature requests](https://github.com/anthonykewl20/efncore/issues)
- **Documentation:** [CLAUDE.md](CLAUDE.md) for AI agent contributors
---
## πΊοΈ Roadmap
| Phase | Status | Description |
|-------|--------|-------------|
| **Phase 0** | β
Complete | Single VPS deployment (cost optimization) |
| **Phase 1** | β
Complete | Core multi-tenancy + read replicas |
| **Phase 2** | π§ In Progress | Module marketplace + governance UI |
| **Phase 3** | π Planned | AI agent SDK for module development |
| **Phase 4** | π Planned | Multi-region high availability |
**[Full Roadmap](docs/architecture/scalability-performance.md)**
---
## π Performance
efncore is built for scale:
- **Throughput:** 10,000+ req/sec per instance
- **Database:** Read replicas with automatic routing
- **Caching:** Tenant-scoped Redis with TTL governance
- **Backpressure:** Load shedding when overloaded
- **Query Timeouts:** 50% of request timeout threshold
- **Slow Queries:** Auto-logged when exceeding 1 second
**[Performance Guide](docs/architecture/performance-optimization-playbook.md)**
---
## π οΈ Tech Stack
**Backend:**
- [FastAPI](https://fastapi.tiangolo.com) 0.124.4 β Web framework
- [Python](https://www.python.org) 3.12 β Runtime
- [PostgreSQL](https://www.postgresql.org) 18.1 β Primary database
- [Redis](https://redis.io) 7 β Caching & sessions
- [RabbitMQ](https://www.rabbitmq.com) 4.1 β Message broker
- [Alembic](https://alembic.sqlalchemy.org) 1.17.2 β Migrations
**Frontend:**
- [Next.js](https://nextjs.org) 16.0.10 β React framework
- [TypeScript](https://www.typescriptlang.org) β Type safety
- [Tailwind CSS](https://tailwindcss.com) 4.1.18 β Styling
- [Radix UI](https://www.radix-ui.com) β Component primitives
- [Playwright](https://playwright.dev) β E2E testing
**Observability:**
- [OpenTelemetry](https://opentelemetry.io) β Tracing & metrics
- [SigNoz](https://signoz.io) β APM backend
---
## π License
**RANEX FRAMEWORKS SOURCE-AVAILABLE EVALUATION LICENSE (RSEL) v1.0**
See [LICENSE](LICENSE) for details.
---
## π Acknowledgments
efncore stands on the shoulders of giants:
- **WordPress** β Plugin architecture inspiration
- **Stripe** β API design patterns
- **Shopify** β Multi-tenancy patterns
- **FastAPI** β Backend framework
- **Next.js** β Frontend framework
---
## π Citation
If you use efncore in your research or production, please cite:
```bibtex
@software{efncore,
title = {efncore: Enterprise SaaS Framework Kernel},
author = {Anthony Kewl},
year = {2024},
url = {https://github.com/anthonykewl20/efncore}
}
```
---
**β Star us on GitHub** β it helps more people discover efncore!
**[β Back to Docs](docs/) | [Quick Start β](docs/dev-docs/QUICK_START.md)**