Dr Maroc is a healthcare SaaS platform live at drmaroc.com. It gives Moroccan doctors, clinic staff and patients dedicated digital tools for scheduling, consultations, e-prescriptions, certificates and patient records, in place of paper registers and phone calls.
I designed it, built it, and run it.
The problem#
Many practices in Morocco still run on a paper appointment book, a phone that rings all day, and handwritten prescriptions. The doctor's time goes to administration, the assistant spends the day on the phone, and the patient's history lives in a folder in one clinic's cabinet.
Dr Maroc gives each role its own tool instead of one screen for everyone. The practitioner focuses on consultations, the clinic manager on the agenda and the team, the patient on booking and following their own care, and the platform admin on the clinics and their subscriptions.
What it does#
- Role-based portals: dedicated applications for platform admins, clinic managers, practitioners and patients, sharing one auth, UI and data-access layer
- Appointment scheduling: a conflict-aware booking engine with availability windows, blocked dates, cancellations and rescheduling
- Consultations and e-prescriptions: medications, analyses and radiography requests recorded as structured data, not free text
- Certificates from templates: medical certificates generated from templates each clinic can configure
- Patient records: a digital medical history with role-based access for practitioners, staff and the patient
- Subscription plans: features tied to plans and enforced by the backend
- Three languages: French, Arabic and English
- Self-hosted identity: Keycloak with custom extensions, two-factor login and branded themes
The architecture#
Dr Maroc is easiest to understand from three angles: how a request runs, how code is shared, and how a change reaches production. Select any part of the diagram to see what it does.
How a request flows through Dr Maroc, from the portals and the website to the data.
Hover or select a part to see what it does.
How the platform grew#
Dr Maroc did not start as a platform. The first version was a single Spring Boot API with a single frontend. That was the right call for proving the product, and the wrong shape once four very different audiences were using it.
It grew into a set of independently versioned repositories without a rewrite: the website, the portals workspace, the backend, the identity service, the shared libraries and contracts, and one infrastructure repository that the others build on. Every split was made in response to a concrete pain, which put each boundary where the system needed one.
Key decisions#
Four portals, one library layer#
The admin, management, practitioner and patient experiences share almost nothing at the screen level. Putting them in one app meant every role downloaded and routed around everyone else's features. Splitting them solved that, and immediately raised the risk of four copies of the login flow, the HTTP layer and the design system.
An Nx monorepo resolved the tension. The portals are separate applications with separate builds and deploys, but authentication, UI components and data access live in shared libraries. CI builds and tests only the projects a change affects, so the monorepo stays fast as it grows. A fix to session handling lands once and ships everywhere.
Identity as its own service#
Authentication started inside the Spring Boot application. As the platform grew, it became clear that login, password reset, two-factor authentication and sessions were not part of the medical domain and shouldn't change at its pace.
Identity moved into a dedicated, self-hosted Keycloak service with custom extensions and a token-driven theme system: one base theme, and a child theme per brand that only overrides tokens. The API validates tokens and reads claims; it no longer knows how a user logged in. The theming approach is written up in Building a Reusable Keycloak Theme Architecture.
Permissions as a contract#
The backend is Java and the portals are TypeScript, and both need the same list of permissions. Copying constants by hand guarantees drift.
So permissions live in one YAML file. A generator validates it, checks it against the last release so nothing is removed or renamed silently, and publishes it as both a Java and a TypeScript package at the same version. The backend decides who holds which permission and enforces it; the portals use the same names to show or hide features. A feature missing from the menu but reachable through the API is not gated, so the check that counts is always the server's.
Shared building blocks for every service#
Cross-cutting concerns live in shared Spring Boot starters, released together at one version:
- Caching with Redis and an in-memory standby, so a cache outage never fails a request
- Idempotent writes, so a retried request replays its first response instead of running twice
- Layered settings: a platform default, overridden per clinic or per practitioner, lockable and audited
Brand assets and design tokens live in their own configuration repository, read by the web apps, the login themes and the pipelines.
Clinical documents as templates, not code#
Prescriptions, certificates and clinic forms vary by specialty and by clinic. Hardcoding each flow would mean a deployment every time a clinic wanted a slightly different certificate.
They are modeled as configurable templates instead. A prescription is structured data rendered through a template, and certificates are generated from templates each clinic can configure. The data stays queryable and the presentation stays flexible.
GitHub as the source of truth#
Everything that defines the platform lives in Git: application code, the CI/CD workflows, the runtime stacks, the reverse-proxy configuration, the monitoring stack, and the secrets, encrypted.
One infrastructure repository provides reusable workflows that every other repository calls, pinned by tag and upgraded deliberately:
- A pull request with Conventional Commits runs CI: lint, tests and a security scan, only for what changed. One "CI passed" verdict gates the merge.
- A release pull request bumps the version and writes the notes from the commits. Merging it tags and publishes the release.
- The image is built once and promoted as-is to each environment. Deploys are health-checked and roll back automatically.
- Metrics and logs flow into Prometheus and Loki, with dashboards in Grafana.
Repeating this in each repository would have meant a dozen slightly different pipelines. Centralizing it means a fix to the release process lands once.
An AI platform for the team's tools#
The repositories are developed with AI coding assistants, and each tool wants its instructions in a different place. An internal AI platform keeps agents, skills and instructions in one vendor-neutral format and generates them into each repository for the tools it uses. Repositories pin a version and upgrade on their own schedule, the same way they use the shared workflows.
Stack#
| Layer | Technologies |
|---|---|
| Portals | Angular, Nx, PrimeNG, Tailwind CSS |
| Website | Next.js, Tailwind CSS |
| Backend | Java, Spring Boot, Spring Security, Spring Data JPA |
| Identity | Keycloak with custom extensions and themes |
| Data | PostgreSQL, Redis, Liquibase |
| Shared code | Spring Boot starters, generated Java and TypeScript contracts |
| Delivery | GitHub Actions, Docker, Conventional Commits |
| Monitoring | Prometheus, Loki, Grafana |
| Quality | JUnit, Testcontainers, Checkstyle, Trivy |
Results#
- Live at drmaroc.com, serving practitioners, clinic staff and patients in Morocco
- Grew from a single app into a multi-repository platform without a rewrite
- Permissions, building blocks and branding defined once and shared by Java and TypeScript code
- Every change ships through the same reviewed, versioned and monitored path
What I learned#
Starting as a monolith was right. Every split that came later, from the portals and identity to the shared contracts and the infrastructure repository, was made in response to a concrete pain. Had I started with a dozen repositories, at least a few boundaries would have been drawn in the wrong place.
The second lesson is that shared things need versions. Workflows, contracts, starters and AI instructions all work the same way: defined once, released with a version, and adopted by each repository when it is ready. That one rule is what keeps many repositories feeling like one system.