- Express (layered architecture)
- Domain-driven design (light, bounded contexts)
- Awilix DI container per request scope
- OpenAPI-driven contract validation
- MongoDB persistence layer
- Jest + Cucumber testing pyramid (unit / feature / contract)
- Node.js version = 24.x (>= 24.22.1)
- npm version >= 10.1.0
A .tool-versions file is provided to easily work with asdf
- Clone the repository:
git clone https://github.com/vinjatovix/agro-back.git
cd agro-back- Install dependencies:
npm installPlease rename .env_example to .env And fill in the variables.
Run the development server:
npm run devYou can build and run it locally with:
npm run start:localOr just with:
npm run docker:local- Starts the mongo db
npm run docker:mongo- Provisioning the db
Provisioning the local mongo with cloud
$ENVdata
npm run restoreDB <env> <database> <user> <password>- Or restore previous dumped data.
npm run restoreDump $ENVNote this will only work if previous data for such
$ENVwas dumped and restored before
-
Unit tests → domain logic (pure)
-
Feature tests → HTTP API (controllers + flow)
-
Contract tests → OpenAPI schema validation
-
Acceptance tests
npm run test:features- Unit tests
npm run test:unit # both groups in parallel, with coverage
npm run test:unit:nodb # tests that need no database (Mongo can be stopped)
npm run test:unit:db # *.db.test.ts files, against the Docker MongoDB
npm run test:unit:leaks # slow diagnostic: shows where a leaked timer/socket was openedA test file opens a real Mongo connection if and only if it is named
*.db.test.ts. A file that leaves timers, sockets or servers open fails with a pointer tonpm run test:unit:leaks. Application logs are silent in tests and log files are never written; run any test command withTEST_LOGS=1to print them.
Repository tests run against the Docker MongoDB. Jest workers run in parallel and each one gets its own database (
test-1,test-2…, seetests/shared/infrastructure/persistence/mongo/testDBConfig.ts);docker/mongo/mongo-init.jslets the test user write totest-1…test-16. A container created before this rule needs the grant once:docker exec agro-api-mongo mongosh -u root -p rootPassword --quiet --eval 'db.getSiblingDB("test").grantRolesToUser("localUser", Array.from({length:16},(_,i)=>({role:"readWrite",db:"test-"+(i+1)})))'
- Full tests routines
npm run testFeel free to contribute to this project but keep in mind the guidelines in CONTRIBUTING.md
Open an issue or create a pull request.
Please report bugs, issues or Report a vulnerability at GitHub Issues.
This project is licensed under the MIT License.
See LICENSE for details.