How dataesr/paysage-api works
1. This repository is a Node.js backend API for “Paysage”, centered on managing a large catalog of public-organization data: structures, persons, projects, terms, categories, relations, documents, and related metadata. The README and folder layout suggest an Express-style HTTP service exposed as a REST API with OpenAPI documentation.
2. The application entry points are split between index.js, src/api/app.js, and src/api/index.js. src/config.js and the src/setup/* modules indicate bootstrapping for external infrastructure before the API starts, especially MongoDB, Elasticsearch, and storage.
3. The HTTP layer is organized by domain under src/api/*. Each major business object has its own route bundle, for example structures, persons, projects, terms, categories, relations, groups, documents, domains, officialtexts, prizes, legalcategories, email-types, followups, journal, search, auth, users, apikeys, and me. This is the primary boundary for the architecture diagram.
4. Most domains have nested subresources that reflect the data model rather than generic CRUD only. Examples include identifiers, web links, social media, localisations, emails, names, logos, key numbers, geographical categories, and group members. That implies a hierarchical resource model with many child collections attached to a root entity.
5. Cross-cutting behavior is centralized in src/api/commons/middlewares. These middlewares cover authentication, RBAC, validation, file handling, event handling, CRUD orchestration, alternative IDs, context propagation, and error handling. In the architecture, these sit between route definitions and the service/repository layer.
6. Persistence is MongoDB-first. src/services/mongo.service.js, src/setup/mongo.js, and the repository helpers under src/api/commons/libs show a repository abstraction over Mongo collections, including base and nested repositories. This suggests most API operations read/write Mongo documents directly through a shared data-access layer.
7. Elasticsearch is a second major data store, but mainly for search and indexing rather than as the source of truth. The search routes, the various *.elastic.js query files, and src/services/elastic.service.js indicate a dedicated search/indexing path for autocomplete and aggregated lookup queries across entities such as structures, persons, projects, legal categories, and terms.
8. File and media handling are handled separately from core entity data. src/services/storage.service.js, src/api/assets, src/api/files, and the OpenAPI file schemas indicate that documents or binaries are stored outside MongoDB, while the API manages metadata and access to those files.
9. Authentication and authorization are explicit subsystems. src/api/auth, src/api/apikeys, src/api/users, and src/api/me point to sign-in/sign-out/token flows, API key management, and user profile access. These are backed by queries for user/admin/token views and enforced through auth/RBAC middlewares.
10. Background processing is substantial and part of the architecture, not a side detail. src/jobs contains indexing, email validation, Sirene synchronization, open-data imports, dump generation, key-number datasets, treatments, and notifications. These jobs likely act on MongoDB data, update Elasticsearch indexes, and call external services such as mail or Mattermost.
11. The scripts/ directory contains operational import/reset utilities, especially for geographical categories and localisation status. Together with mongo-init.js, this indicates bootstrap and data-seeding workflows for local or fresh environments.
12. The repo is designed with strong API contract discipline. src/openapi contains the full API specification, path definitions, schemas, parameters, and error responses, while docs/ provides human documentation. This makes the OpenAPI model a key architectural artifact alongside the code.
13. Tests are organized by domain and also cover shared infrastructure. There are unit/integration tests for categories, persons, projects, structures, legal categories, document types, official texts, search, and base repository behavior, plus dedicated test setup under tests/. GitHub Actions and Docker Compose files show the project is built and tested in containerized CI environments.
14. In diagram terms, the main flow is: client request -> route module -> shared middlewares -> domain logic/repository -> MongoDB and/or Elasticsearch -> optional storage/mail/external integrations -> response. Jobs and scripts operate alongside this path as asynchronous or operational pipelines over the same underlying data stores.
Main entry points: authenticate.middlewares.js Middlewares · index.js Entry · api/index.js API index · jobs/index.js Jobs
Components 23
HTTP API
Request handling and domain routes
- App · HTTP application bootstrap
src/api/app.js - API index · Main API router composition
src/api/index.js - Domains · Resource routes for structures, persons, projects, terms, and related entities
src/api/structures/structures.routes.js - Relations · Relations, relation groups, and relation types
src/api/relations/relations.routes.js - Support APIs · Auth, users, api keys, search, documents, files, jobs, and utilities
src/api/auth/auth.routes.js - Subresources · Identifiers, web links, social media, emails, names, localisations, logos, key numbers, and members
src/api/structures/identifiers/identifiers.routes.js
Shared core
Bootstrap, middlewares, repositories, and queries
- Entry · Process startup and top-level wiring
index.js - Middlewares · Auth, RBAC, validation, files, events, CRUD, context, and errors
src/api/commons/middlewares/authenticate.middlewares.js - Repositories · Mongo repository abstractions and shared catalog/tokens
src/api/commons/libs/base.mongo.repository.js - Queries · Mongo and Elasticsearch query builders for domain views
src/api/commons/queries/structures.query.js - Config · Runtime configuration and startup settings
src/config.js
Data & integrations
Persistent stores and external services
- Mongo setup · MongoDB connection and initialization
src/setup/mongo.js - Search setup · Elasticsearch connection and indexing setup
src/setup/elastic.js - Storage setup · File storage initialization
src/setup/storage.js - MongoDB · System of record for domain data
src/services/mongo.service.js - Elasticsearch · Search and autocomplete index
src/services/elastic.service.js - Storage · Files and media persistence
src/services/storage.service.js - Mailer · Email delivery integration
src/services/mailer.service.js
Async ops
Jobs and operational pipelines
Connections 30
- Entry → Config: loads · Reads runtime configuration before bootstrapping
- Entry → Mongo setup: starts · Initializes MongoDB on startup
- Entry → Search setup: starts · Initializes search infrastructure
- Entry → Storage setup: starts · Initializes file storage
- Entry → App: mounts · Creates the HTTP application
- App → API index: routes · Attaches the main API router
- API index → Domains: mounts · Registers core business resource routes
- API index → Relations: mounts · Registers relation-related routes
- API index → Support APIs: mounts · Registers auth, search, documents, jobs, and admin routes
- Domains → Subresources: nests · Exposes child collections under each root entity
- Domains → Middlewares: uses · Applies shared request orchestration and validation
- Relations → Middlewares: uses · Applies shared request orchestration and validation
- Support APIs → Middlewares: uses · Applies shared request orchestration and validation
- Middlewares → Repositories: calls · Delegates CRUD operations to repository layer
- Middlewares → Queries: calls · Uses read models and projections
- Repositories → MongoDB: reads/writes · Persists domain documents in MongoDB
- Queries → MongoDB: reads · Builds Mongo-backed views and lookups
- Queries → Elasticsearch: searches · Uses Elasticsearch for autocomplete and indexed search
- Middlewares → Storage: handles · Manages upload and file access flows
- Support APIs → Mailer: sends · Triggers mail flows for auth and notifications
- Jobs → MongoDB: processes · Runs async operations against source data
- Jobs → Elasticsearch: indexes · Updates search indexes and autocomplete data
- Jobs → Mailer: notifies · Sends email and operational notifications
- Jobs → Storage: exports · Produces dumps and file-based outputs
- Scripts → MongoDB: seeds · Operational import/reset actions on data
- OpenAPI → API index: describes · Documents the HTTP API surface
- Docs → OpenAPI: explains · Human documentation complements the contract
- Tests → Repositories: verifies · Covers shared repository behavior
- Tests → Domains: verifies · Covers major domain routes and nested resources
- Tests → Middlewares: verifies · Covers shared infrastructure behavior