How bolboceanuigor/espace works
1. Repository shape
- This is a monorepo for a condominium/association management platform called Espace.
- The repo is split into a NestJS backend, a Next.js frontend, a small iOS companion app, and deployment/ops assets.
- The product is explicitly organized around three operating roles: Superadmin, Administrator, and Resident.
2. Backend is a modular monolith
- backend/src is a large NestJS application, organized by domain modules rather than microservices.
- The backend exposes the main API under /api, plus a WebSocket gateway for live events.
- Each feature area has its own controller/service/module pair, with Prisma repositories used where the module needs direct data access.
3. Persistence and schema management
- The backend uses Prisma with a PostgreSQL database.
- backend/prisma/schema.prisma and the migration history are the source of truth for the data model.
- There are seed scripts for demo, production base data, and production admin/superadmin accounts, which indicates the app depends heavily on seeded role and org setup.
4. Security, auth, and access boundaries
- Auth is JWT-based, with local and Google strategies, password reset and email verification flows, and rate-limited auth endpoints.
- Authorization is layered through roles, permissions, and multiple guards for:
- superadmin access
- organization scoping
- resident-portal restrictions
- demo-mode restrictions
- A tenant/association context layer ensures requests are evaluated in the correct organization scope.
5. Multi-tenant data model
- The app is effectively organization-scoped: most operational data belongs to one A.P.C./association.
- Superadmin modules can see across organizations, while admin and resident modules are constrained by tenant context.
- The backend contains explicit support for association context, support-session context, and organization limits, which are important boundaries for the diagram.
6. Frontend is a role-based Next.js application
- The frontend uses Next.js App Router with a very large route tree.
- It is split into:
- public/marketing pages
- auth flows
- admin workspace
- resident workspace
- superadmin workspace
- locale-prefixed equivalents under /[locale]/...
- UI composition is done through reusable shells, sidebars, nav bars, and feature-specific page components.
7. Internationalization is a first-class routing concern
- Locale is encoded in the URL (ro, ru, en) and persisted via middleware/cookies.
- The frontend has both localized and non-localized route families, with localized routes taking priority for the product experience.
- This matters architecturally because route handling, redirects, and navigation are locale-aware rather than purely presentation-layer concerns.
8. Main domain subsystems
- The backend and frontend are organized around the platform’s core workflows:
- apartment/building/resident management
- meters and meter readings
- billing, invoices, and payments
- requests, issues, maintenance, announcements
- documents, exports, imports
- team/invitations/permissions
- notifications and communication
- There are also substantial superadmin CRM / customer-success / SaaS management modules for the platform operator.
9. Billing and payment flow
- Billing is split into read/write concerns, draft generation, invoice publishing, payment intents, proofs, and reconciliation.
- The backend includes several payment providers and a provider factory, so payment handling is abstracted behind provider interfaces.
- The frontend mirrors this with dedicated resident and admin payment pages, invoice PDFs/prints, and superadmin billing views.
- The repository also contains SaaS billing concepts for platform subscriptions, usage, upgrade requests, and SaaS invoices.
10. Data operations and quality controls
- Imports, exports, bulk operations, saved views, and data-quality modules are core platform features.
- The system includes duplicate detection, merge/fix flows, data retention, archive/export capabilities, and admin-facing bulk operations.
- This indicates the backend is not just transactional CRUD; it also acts as an operational data-management platform with auditability and correction workflows.
11. Notifications, email, and real-time updates
- The backend has a dedicated email subsystem, notification delivery management, transactional notifications, and websocket events.
- Email is environment-driven: console in dev, Resend in production.
- Realtime events appear to support UI refreshes and status updates rather than being the primary application backbone.
12. Operational and platform services
- The backend contains modules for backup/recovery, launch control, system monitoring, legal/help center content, feature flags, and audit logs.
- These are not product “business” features so much as platform-operating subsystems for running the SaaS and managing customer support/onboarding.
- The superadmin area in particular is a control plane for organization lifecycle, health, onboarding, billing, and support work.
13. Legacy/hidden modules are present but not the primary architecture
- The repo still contains older modules for rentals, reservations, cleaning, and other legacy flows.
- The README says these are legacy-only, hidden from production navigation, and redirected away where possible.
- For an architecture diagram, these should be shown as non-primary or deprecated paths, not central business flows.
14. Mobile companion app
- The ios folder contains a native Swift app that talks to the backend through its own API client and token/session storage.
- It is focused on resident-facing experiences, so it should be treated as a secondary client of the same backend rather than a separate system.
15. Deployment and runtime topology
- The repo supports Docker-based local and production setups, with Caddy used as a reverse proxy in the full-stack deployment path.
- There are backup/restore scripts, deploy scripts, and production environment templates.
- The documented baseline deployment is a Docker-hosted backend + database + frontend setup, with an alternate option of hosting the frontend separately.
Main entry points: main.ts API entry · app Web app · schema.prisma Prisma DB · docker-compose.prod.yml Runtime deploy
Components 22
NestJS backend
Modular monolith API and domain logic
- API entry · Main HTTP application wiring and cross-cutting setup
backend/src/main.ts - Auth & RBAC · JWT, local/google auth, roles, permissions, and guards
backend/src/auth - Tenant context · Organization scope, support-session context, and tenant guards
backend/src/tenant - Organization core · Associations, onboarding, limits, contracts, and admin scoping
backend/src/organizations - Resident domain · Apartments, residents, access, invitations, requests, chat, and votes
backend/src/residents - Billing stack · Billing drafts, invoices, payments, reconciliation, and providers
backend/src/billing-read - Payment providers · Payment intent orchestration and provider factory abstractions
backend/src/payments/providers - Ops controls · Monitoring, backups, launch control, feature flags, audit, help, legal
backend/src/system-monitoring - Data ops · Imports, exports, bulk operations, saved views, retention, and duplicates
backend/src/data-quality - Notifications · Email, transactional notifications, notification management, and websocket events
backend/src/notifications - SaaS control plane · Subscriptions, upgrade requests, SaaS invoices, usage, and client success
backend/src/saas-billing - Legacy flows · Hidden or legacy-only paths retained for compatibility
backend/src/reservations
Next.js frontend
Role-based web application with locale-aware routing
- Web app · Public site plus localized role workspaces
frontend/app - App shells · Shared layouts, sidebars, nav, and role-aware wrappers
frontend/components/layout - Locale routing · Locale-prefixed routes, cookies, redirects, and translations
frontend/middleware.ts - Admin workspace · Association operations, billing, data quality, and settings
frontend/app/(app)/admin - Resident workspace · Resident dashboard, invoices, requests, payments, and profile
frontend/app/(app)/resident - Superadmin workspace · CRM, SaaS management, monitoring, launch, and support control plane
frontend/app/(app)/superadmin
iOS app
Resident companion client
- iOS app · Resident-facing mobile client using its own API client and session store
ios/Espace
Deployment & data
Prisma, migrations, seeds, and runtime ops
- Prisma DB · Source-of-truth schema, migrations, and direct repository access
backend/prisma/schema.prisma - Seed data · Demo, production base, and privileged account seed routines
backend/prisma/seed.ts - Runtime deploy · Containerized deployment, reverse proxy, backups, and restore scripts
docker-compose.prod.yml
Connections 29
- Web app → App shells: composes · Routes are rendered through shared shells and layouts
- Web app → Locale routing: localized by · App routes are locale-aware and middleware-driven
- Web app → Admin workspace: includes · Admin routes are a major product workspace
- Web app → Resident workspace: includes · Resident routes are a major product workspace
- Web app → Superadmin workspace: includes · Superadmin routes form the operator workspace
- Admin workspace → API entry: calls · Admin pages consume backend APIs
- Resident workspace → API entry: calls · Resident pages consume backend APIs
- Superadmin workspace → API entry: calls · Operator pages consume backend APIs
- API entry → Auth & RBAC: uses · HTTP endpoints are protected by auth and RBAC
- API entry → Tenant context: scopes by · Requests are resolved into an organization context
- API entry → Organization core: routes to · Organization lifecycle and tenancy operations
- API entry → Resident domain: routes to · Core association workflows and resident-facing data
- API entry → Billing stack: routes to · Billing, invoices, and payment operations
- Billing stack → Payment providers: delegates to · Online payment handling is abstracted behind providers
- API entry → Ops controls: routes to · Platform control, audit, and support modules
- API entry → Data ops: routes to · Bulk ops, imports/exports, and data correction workflows
- API entry → Notifications: routes to · Email, notifications, and realtime events
- API entry → SaaS control plane: routes to · Subscription and SaaS operator workflows
- API entry → Legacy flows: contains · Legacy modules remain present but are not primary flows
- Organization core → Prisma DB: persists in · Organization-scoped state is stored via Prisma
- Resident domain → Prisma DB: persists in · Association data is stored via Prisma repositories
- Billing stack → Prisma DB: persists in · Billing state and invoice records live in PostgreSQL
- Ops controls → Prisma DB: persists in · Operational modules share the same database
- Data ops → Prisma DB: persists in · Data ops workflows rely on the shared schema
- Seed data → Prisma DB: initializes · Seed scripts populate demo and production baselines
- Runtime deploy → API entry: runs · Backend is deployed in containerized runtime
- Runtime deploy → Web app: serves · Frontend is deployed in the same stack or adjacent runtime
- Runtime deploy → Prisma DB: depends on · Production setup includes a database service
- iOS app → API entry: calls · Mobile client talks to the same backend API