How hospitalrun/hospitalrun-server works
Project Type and Purpose
• This is a Node.js‐based backend service implementing a GraphQL API for the HospitalRun full-stack hospital management application.
• It serves as the data layer and business logic layer, exposing health checks and domain resolvers, persisting data in CouchDB/PouchDB.
File Structure
• Top‐level folders:
• src/ – Application source:
– app.ts defines the Express/HTTP server and GraphQL middleware
– index.ts entry point bootstrapping the app
– graphql/ holds schema.ts (type definitions) and resolvers.ts (resolver functions)
– services/ contains discrete service modules (health.ts, root.ts) encapsulating business logic
• bin/ddoc.js – CLI tool to generate CouchDB design documents
• db/ – local development database config (config.json) for pouchdb‐server
• docker-compose.yml – spins up the Node server and a dev PouchDB instance
• test/ – tests using node-tap against service modules
• Configuration files:
• .env.example + dotenv for environment variables
• TypeScript configs in tsconfig.json
• Linting/prettier/CI configs under .github/ and root
README Insights
• Confirms GraphQL over HTTP, PouchDB‐server in development and CouchDB in production.
• Encourages Docker Compose for local dev.
Core Components
a. API Layer
• HTTP/Express server (app.ts)
• GraphQL endpoint
b. Business Logic Layer
• GraphQL Resolvers (resolvers.ts)
• Service modules (health.ts, root.ts, plus future domain services)
c. Data Layer
• PouchDB‐server (development) or CouchDB (production)
• db/config.json for DB endpoints & credentials
d. Dev Tooling & Infrastructure
• docker-compose orchestration: Node.js container ↔ PouchDB container
• CLI script (bin/ddoc.js) for design docs generation
• Test runner (node-tap) exercising services
Relationships and Data Flows
• Client (e.g., HospitalRun Frontend) → HTTP POST to /graphql → Express
• Express → GraphQL engine → Resolver
• Resolver → Service layer → DB driver → PouchDB/CouchDB
• Health check service → /health HTTP endpoint
• Docker Compose network between containers (Node ↔ PouchDB)
Architectural Patterns
• Layered Architecture:
Presentation (HTTP/GraphQL) → Business (services) → Data (CouchDB)
• Modularity: Distinct service modules for separation of concerns
• 12-factor app: uses environment variables, externalized config, single codebase