How drcount-root/securefabric works
1. This repository is a Turborepo monorepo with three runnable apps and several shared packages. The main product surface is the web app, the backend is api, and docs is a separate Next.js app for documentation or marketing content.
2. The frontend boundary is split cleanly by concern:
- apps/web is the authenticated product UI.
- apps/docs is a standalone public-facing Next.js site.
Both are App Router-based Next.js apps and share design primitives from packages/ui.
3. apps/web is organized around authentication and account management flows rather than a generic CRUD UI. Its routes include signup, login, password reset, MFA, mobile verification, profile completion, and a post-login dashboard with profile, security, and setup pages. web/middleware.ts suggests client-side route gating before pages render.
4. The backend lives in apps/api and is structured as an HTTP service with clear layers:
- route definitions in src/routes
- domain services in src/services
- middleware in src/middleware
- shared infrastructure in src/lib
- startup/container wiring in src/app.ts, src/index.ts, and src/container.ts
This is an Express-style architecture centered on auth/session workflows.
5. The API’s domain is identity-heavy. Separate route modules exist for auth, passwords, MFA, passkeys, sessions, and users. The service layer mirrors that split with dedicated services for sessions, users, passwords, OTP, passkeys, magic links, MFA, devices, notifications, and auditing.
6. The persistence layer is centralized in packages/database, which contains the Prisma schema and migrations. apps/api uses src/lib/prisma.ts plus the shared database package, so the API is the sole application boundary that should directly talk to the relational database.
7. Redis is a second infrastructure dependency in the API layer. It is likely used for session state, rate limiting, verification codes, and other ephemeral auth data. That fits the presence of rate-limit middleware, OTP, cleanup jobs, and session-oriented services.
8. Real-time session awareness is handled separately through apps/api/src/ws/sessions.gateway.ts. That indicates the backend can push session/device changes to clients, likely for security-related UI updates such as active session lists or logout events.
9. There is a background job subsystem in apps/api/src/jobs, including a cleanup task. Combined with audit/notification services, the backend is designed to manage lifecycle work outside request-response flow, such as expiring records, pruning state, or sending auth-related notifications.
10. Shared cross-cutting contracts live in packages/types. These type packages define auth, JWT, session, and user shapes that can be reused across the API and web app to keep client/server behavior aligned.
11. Shared UI and tooling are also first-class packages:
- packages/ui provides reusable React components like buttons, inputs, cards, alerts, and spinners.
- packages/eslint-config and packages/typescript-config standardize linting and TypeScript settings across all apps.
This reduces duplication and keeps app-level code focused on product logic.
12. Deployment is containerized. The repo includes Dockerfiles for api and web, top-level docker-compose files, and an nginx configuration directory, implying a production topology where Nginx fronts one or more app containers and the API runs alongside the database/Redis stack.
13. The primary data flow is: browser UI in web initiates auth or account actions, web/lib/api.ts and web/lib/socket.ts connect to the API over HTTP and WebSocket, api applies validation/auth/rate-limiting middleware, then services read/write Prisma-backed persistence and Redis-backed ephemeral state, and finally the UI reflects the resulting session/user state.
14. The repository is not just code; it includes operational scaffolding. CI is defined in GitHub Actions, there are tests for the API auth flows, and root docs like ROADMAP.md, ISSUES.md, and PROCESS_TO_RUN.md suggest this is an actively managed product repo with explicit development/process guidance.
Main entry points: web Web app · api API service · docker-compose.yml Compose stack · routes API routes
Components 20
Apps
Runnable product surfaces and backend service
- Web app · Authenticated product UI with account and security flows
apps/web - Docs app · Public-facing documentation or marketing site
apps/docs - API service · Identity and session backend with HTTP, WebSocket, and background jobs
apps/api - Web routes · Signup, login, reset, MFA, onboarding, and dashboard pages
apps/web/app - Web client · HTTP and socket clients plus auth/session glue
apps/web/lib - Route guard · Pre-render access control for authenticated and onboarding flows
apps/web/middleware.ts - Docs routes · Standalone public app pages and layout
apps/docs/app - API routes · Auth, password, MFA, passkey, session, and user endpoints
apps/api/src/routes - Domain services · Auth, sessions, users, MFA, passkeys, passwords, notifications, audit, and devices
apps/api/src/services - API middleware · Auth, onboarding, profile, validation, rate limiting, and request IDs
apps/api/src/middleware - API lib · Prisma, Redis, JWT, crypto, errors, and async handler utilities
apps/api/src/lib - Background jobs · Cleanup and other lifecycle tasks outside request-response flow
apps/api/src/jobs - Session gateway · Pushes session and device state changes to clients
apps/api/src/ws/sessions.gateway.ts
Packages
Shared libraries and platform contracts
- Database · Shared schema, migrations, and Prisma client for relational persistence
packages/database - Types · Auth, JWT, session, and user types shared across client and server
packages/types - UI kit · Shared buttons, inputs, cards, alerts, code, and spinners
packages/ui - Lint config · Common ESLint rules for app and package code
packages/eslint-config - TS config · Shared TypeScript baselines for node, next, and React packages
packages/typescript-config
Infra
Deployment and operational scaffolding
- Compose stack · Local and production container orchestration for app, database, and Redis
docker-compose.yml - Nginx · Fronts app containers in deployed topology
nginx/nginx.conf
Connections 27
- Web app → Web routes: renders · Next.js app serves the authenticated route tree
- Web app → Web client: uses · UI calls backend over HTTP and WebSocket
- Web app → Route guard: protected by · Middleware gates access before rendering
- Web routes → UI kit: shares UI · Product pages reuse shared design primitives
- Web client → API routes: calls · HTTP client talks to backend endpoints
- Web client → Session gateway: subscribes · Socket client receives live session updates
- Docs app → Docs routes: renders · Standalone public Next.js route tree
- Docs routes → UI kit: shares UI · Docs app reuses the same component library
- API routes → API middleware: passes through · Requests are validated and guarded before handlers
- API routes → Domain services: delegates to · Route handlers orchestrate domain services
- Domain services → API lib: uses · Services rely on crypto, JWT, Redis, Prisma, and helpers
- API lib → Database: persists via · Prisma client reads and writes relational state
- API lib → Types: shares contracts · Backend uses shared auth and session shapes
- Domain services → Types: shares contracts · Service layer aligns domain payloads with shared types
- API service → API routes: exposes · HTTP server mounts route modules
- API service → Background jobs: runs · Service process executes cleanup and lifecycle work
- API service → Session gateway: hosts · Backend serves WebSocket session gateway
- API service → Database: depends on · API is the application boundary for relational persistence
- Compose stack → API service: orchestrates · Container stack runs backend service
- Compose stack → Web app: orchestrates · Container stack runs the product UI
- Compose stack → Docs app: orchestrates · Container stack can run the docs site
- Compose stack → Nginx: fronted by · Proxy terminates and routes external traffic
- API service → Nginx: served through · Deployment topology places the API behind proxying infrastructure
- Web app → Types: shares contracts · Frontend aligns auth and session state with backend types
- Web app → UI kit: uses · Frontend consumes shared component primitives
- Docs app → UI kit: uses · Docs site consumes shared component primitives
- Web app → API service: auth flow · Browser product flow drives backend identity operations