How adilamejoud/medisync works
1. Overall shape
MediSync is a role-based clinic management system split into three major parts: an Angular 17 frontend, a Node.js/Express backend layer, and a PostgreSQL database accessed through Prisma. The repo also includes Docker orchestration, a gateway, and a few service-oriented workers/services for specific domains.
2. Frontend boundary
The Angular app is organized around roles and workflows, not generic technical modules. Under features/ there are separate experiences for admin, doctor/medecin, patient, secretary/secretaire, plus auth, landing, and unauthorized screens. Shared UI lives in shared/, while core/ contains guards, interceptors, API-facing services, models, and cross-cutting app state.
3. Client-side request flow
Frontend services such as auth.service, appointment.service, doctor.service, patient.service, billing.service, notification.service, and socket.service are the main API consumers. Guards and interceptors enforce access control and attach JWTs before requests reach the backend. This means the frontend is not just presentation; it is the first enforcement layer for role-based navigation and session handling.
4. Primary backend
The main backend in backend/server.js and backend/src/ is an Express application structured by domain: controllers, routes, middlewares, config, and utilities. It appears to be the core API for clinic operations such as users, admins, doctors, secretaries, appointments, patients, prescriptions, invoices, documents, reports, services, and statistics.
5. Authentication and authorization
Auth is split across the main backend and a dedicated auth-service under backend/src/services/auth-service. The system uses JWT plus role-based middleware (authAdmin, authDoctor, authUser) and supports TOTP 2FA, especially for admin accounts. Password rules are enforced through a dedicated validator utility, and the README indicates bcrypt hashing and rate limiting as part of the security boundary.
6. Operational domains
The business logic is centered on clinic workflows:
• Appointments and scheduling
• Doctor availability and patient files
• Prescriptions and medical dossiers
• Invoices/billing
• Patient registration
• Care sheets, reports, and documents
• Stats/analytics for admin and doctor views
These are separated into their own routes/controllers, which is a strong clue for drawing the main application boundary in a diagram.
7. Real-time and asynchronous behavior
The repo includes socket.js and a frontend socket.service, which indicates Socket.IO is used for live updates such as notifications, scheduling changes, or status changes. There is also a notification-service worker and a publisher utility in the auth service, suggesting asynchronous event flow rather than only synchronous HTTP calls.
8. External integrations
Two integrations materially affect architecture: Cloudinary for document/image storage and an email system (emailService.js, plus cron-based reminder behavior described in the README). File uploads are handled with Multer middleware before assets are stored externally, so medical documents do not live only in PostgreSQL.
9. Persistence layer
All persistent domain data flows through Prisma, with database/schema.prisma as the schema source and database/migrations/ capturing schema evolution. The backend also has a seed.js script for bootstrapping test accounts and initial data. This is the primary data boundary: application services manipulate Prisma models, then persist to PostgreSQL.
10. Service decomposition
The repo contains multiple service directories: gateway, auth-service, booking-service, doctor-service, and notification-service. The README shows a gateway-centered architecture where the Angular app talks to an API Gateway, which forwards traffic to the auth service and the main backend. In practice, the codebase looks like a hybrid: a main monolith plus specialized services and workers for selected concerns.
11. Deployment and runtime
Docker is a first-class part of the architecture. Each major component has its own Dockerfile, and the root docker-compose.yml orchestrates frontend, gateway, backend, PostgreSQL, and supporting infrastructure. The frontend is built for Angular + Nginx production serving, while the backend runs as Node 20 services.
12. Cross-cutting concerns and observability
Security and auditability are prominent architectural concerns. There is an auditLogger, an audit route, security-focused tests, and support for user/IP-tracked sensitive actions. That means the system is designed not just for CRUD workflows but for traceable clinical operations, which is important when diagramming the control plane around auth, auditing, and logging.
13. Test architecture
The test suite is broad and should be treated as part of the repo architecture: unit tests for controllers/middlewares, integration tests for API behavior, security tests for auth/OWASP/rate limiting/uploads, end-to-end Playwright journeys, and UX completeness/flow tests. This implies the team validates both functional boundaries and role-specific user journeys across frontend and backend.
14. How to diagram it
A good architecture diagram for this repo should show:
• Angular role-based client at the edge
• API Gateway as the first backend hop
• Main Express backend as the core domain API
• Auth service and async notification/service workers as specialized side services
• Prisma as the ORM boundary to PostgreSQL
• External services for email and document storage
• Socket.IO as the real-time channel between backend and clients
The main conceptual split is between presentation, request routing, domain services, persistent data, and external integrations.
Main entry points: server.js Clinic API · tests Test suite · app Angular app · core Core services
Components 19
Frontend
Angular client with role-based workflows and shared UI.
- Angular app · Angular 17 application shell and route entrypoints.
frontend/src/app - Core services · Guards, interceptors, models, and API-facing services.
frontend/src/app/core - Shared UI · Reusable components, directives, and pipes.
frontend/src/app/shared - Role screens · Admin, doctor, patient, secretary, auth, landing, and unauthorized experiences.
frontend/src/app/features
Backend
Express API, gateway, and specialized services.
- API gateway · First backend hop that fronts the service stack.
backend/src/services/gateway/server.js - Clinic API · Main domain API for clinic operations.
backend/server.js - Domain routes · Routes for auth, users, appointments, patients, prescriptions, billing, reports, stats, and audit.
backend/src/routes - Controllers · Admin, doctor, secretary, user, auth, appointment, config, and stats controllers.
backend/src/controllers - Auth middleware · Role-based access control and upload/session middleware.
backend/src/middlewares - Auth service · Dedicated auth service with JWT and 2FA support.
backend/src/services/auth-service/server.js - Booking service · Separate runtime for appointment-related workflows.
backend/src/services/booking-service/server.js - Doctor service · Separate runtime for doctor-focused operations.
backend/src/services/doctor-service/server.js - Notification worker · Background notification processing and event handling.
backend/src/services/notification-service/worker.js
Data
ORM boundary and PostgreSQL persistence.
- Prisma schema · Schema and migrations for persistence models.
database/schema.prisma - PostgreSQL · Primary relational data store for clinic records.
External
Real-time, storage, and messaging integrations.
- Cloudinary · External storage for uploaded documents and images.
backend/src/config/cloudinary.js - Email service · Outbound email delivery for reminders and account flows.
backend/src/services/emailService.js - Socket.IO · Live updates between backend and clients.
backend/socket.js
Tests
Cross-layer validation for API, security, UX, and journeys.
- Test suite · Integration, security, E2E, UX, and unit coverage across the repo.
tests
Connections 22
- Angular app → Core services: uses · Client UI relies on guards, interceptors, and API services.
- Angular app → Shared UI: renders · Role screens compose reusable UI building blocks.
- Angular app → Role screens: navigates · Route structure is organized around role-specific workflows.
- Core services → API gateway: API calls · Angular services send authenticated requests to the backend entrypoint.
- Core services → Socket.IO: subscribes · Client listens for live notifications and updates.
- API gateway → Auth service: routes auth · Gateway forwards authentication traffic to the auth service.
- API gateway → Clinic API: routes domain · Gateway forwards clinic domain traffic to the main API.
- Clinic API → Domain routes: exposes · Express app mounts domain routes.
- Domain routes → Controllers: dispatches · Routes delegate to domain controllers.
- Controllers → Auth middleware: protected by · Controllers depend on role checks, uploads, and request policy.
- Clinic API → Prisma schema: persists via · Core API reads and writes through Prisma.
- Prisma schema → PostgreSQL: stores · Prisma migrations and schema map to PostgreSQL.
- Clinic API → Cloudinary: uploads · Medical documents and images are stored externally.
- Clinic API → Email service: sends mail · Reminders and notifications flow through email delivery.
- Clinic API → Socket.IO: publishes · Backend emits live events to connected clients.
- Auth service → Notification worker: publishes events · Auth flows feed asynchronous notification handling.
- Booking service → Clinic API: supports · Specialized booking runtime complements the main API.
- Doctor service → Clinic API: supports · Specialized doctor runtime complements the main API.
- Test suite → Angular app: covers · E2E and UX tests validate user journeys.
- Test suite → Clinic API: covers · Unit, integration, and security tests validate backend behavior.
- Test suite → Auth service: covers · Security and auth tests exercise the dedicated auth path.
- Test suite → Prisma schema: covers · Test helpers seed and verify data persistence behavior.