An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# efncore

**The Enterprise SaaS Framework Kernel** β€” Production-grade multi-tenancy, events, jobs, and observability for building SaaS products.

[![CI/CD](https://github.com/anthonykewl20/efncore/actions/workflows/ci-pipeline.yml/badge.svg)](https://github.com/anthonykewl20/efncore/actions/workflows/ci-pipeline.yml)
[![Security](https://github.com/anthonykewl20/efncore/actions/workflows/security-scan.yml/badge.svg)](https://github.com/anthonykewl20/efncore/actions/workflows/security-scan.yml)
[![License: RSEL v1.0](https://img.shields.io/badge/License-RSEL%20v1.0-blue.svg)](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)**