Case study
Gemsocial: rebuilding a multi-tenant SaaS
Six business modules, one platform, many companies. I help rebuild it on a new stack and add AI agents that are safe to run.
- modules
- 6
- tenants
- 131
- users
- 4,164
- paying users
- 850
Overview
What it is. Gemsocial is a multi-tenant B2B SaaS with six modules: CRM, HRM, Finance, Workplace, Knowledge and Connect.
My role. Full-Stack Developer since 07/2025. Before the contract, in 05-06/2025, I built an AI chat agent dashboard and an embeddable chat widget. In practice I lead a team of 2.
About the numbers. 131 tenants, 4,164 users and 850 paying users. None of these are concurrent users.
The rebuild
The legacy Node.js platform is being replaced by Gem One, built on a different stack.
Before
- Legacy Node.js platform
After: Gem One
- Next.js 16 + React (web client)
- Bun + Elysia API with TypeBox schemas
- Separate API and worker processes in one modular monolith
- MongoDB, one database per tenant
- Deployed with systemd + Nginx on Linux
- Layered architecture. The code follows clean-architecture principles, so business rules stay apart from HTTP and database details.
- Database per tenant. Each company's data lives in its own MongoDB database.
- Migration module by module. Legacy CRM data moves through an HMAC-signed export API with verify and rollback steps. I do not claim the legacy CRM data migration is complete in production.
Mobile
Gemsocial Mobile is a hybrid app built with React and Capacitor. It uses realtime WebSocket and push notifications.
AI in Gem One
- Aura agents. Background duty-loop routines with daily token budgets, run caps and a circuit breaker. They read and report by default.
- Safe tool-calling. Tools are generated from API routes and filtered by an allowlist. Each has a risk tier: read, write or danger.
- Human approval for writes. Write actions show an approval card with a TTL and idempotency.
- No prompt-injection escalation. Permission grants go through a separate admin route, never through the chat.
- Open interfaces. API keys and an MCP server endpoint.
- Models. Claude API and Gemini API.
- Omnichannel chat agents. Messenger, Telegram, Zalo OA and a web widget.
Other modules I built
- CDP. Identity resolution, merge and unmerge, segments and a CRM sync queue.
- HRM. Employment lifecycle, with commission added to the payslip automatically.
- Analytics engine. MongoDB aggregation with time and row caps, CSV export and layered permission checks.
- Auth. Invite and OTP sign-in with rate limiting and anti-enumeration.
- Email and images. AWS SES email and image processing.
What I learned
- Modular monolith over microservices. One deployable unit with clear module and process boundaries is easier to run and still lets API and workers scale apart.
- Guardrails before autonomy. Budgets, caps, risk tiers and human approval come first. Then agents get more freedom.
- Fail closed, with an audit trail. When a check cannot decide, deny the action and record why.
Frequently asked questions
What is Gemsocial?
Gemsocial is a multi-tenant B2B SaaS with six modules: CRM, HRM, Finance, Workplace, Knowledge and Connect.
How big is the platform?
It has 131 tenants, 4,164 users and 850 paying users. None of these are concurrent users.
What is Phat Huynh's role?
He has been a Full-Stack Developer there since 07/2025 and in practice leads a team of 2. Before the contract, in 05-06/2025, he built an AI chat agent dashboard and an embeddable chat widget.
Which AI agents does it use?
Aura agents run background duty-loop routines with daily token budgets, run caps and a circuit breaker. Omnichannel chat agents work on Messenger, Telegram, Zalo OA and a web widget. Models: Claude API and Gemini API.
How is tool-calling kept safe?
Tools are generated from API routes and filtered by an allowlist, each with a risk tier (read, write or danger). Write actions need human approval, and permission grants never go through the chat.
How is tenant data isolated?
Each company's data lives in its own MongoDB database. The new Gem One platform runs on Bun, Elysia and Next.js 16.