This project was built to provide a simple, modular and testable RESTful API using NestJS. The goal is to process Raspberry Awards data from a CSV file, identify producers with the shortest and longest intervals between wins, and expose this information through clean endpoints.
The application follows best practices with:
- Modular structure via NestJS
- In-memory database via SQLite + TypeORM
- CSV parsing with fast-csv
- High test coverage using Jest (unit + e2e)
- NestJS — a progressive Node.js framework for scalable server-side applications
- SQLite3 — lightweight database, ideal for testing and in-memory persistence
- TypeORM — a powerful ORM supporting multiple databases
- fast-csv — efficient streaming parser for CSV files
- Jest — testing framework for unit and e2e tests
- CSV loading and parsing with
fast-csv - Automatic table creation using TypeORM's
synchronize: true - Clean modular architecture with NestJS
- Producer interval logic split into small and testable functions
- Test coverage with Jest
Quick and easy setup: the movies table is created automatically based on the Movie entity structure.
Setting
synchronize: trueshouldn't be used in production - otherwise you can lose production data. NestJS
TypeOrmModule.forRoot({
type: 'sqlite',
database: ':memory:',
entities: [Movie],
synchronize: true, // auto-creates the table
}),fs.createReadStream(csvPath)
.pipe(csv.parse({ headers: true, delimiter: ';' }))
...This project was created using the NestJS CLI:
$ nest new raspberry-awards-apiUsing the Nest CLI ensures a clean and organized architecture out of the box, following best practices for modularity, testing, and maintainability.
Then, the main module for handling movie data was generated using the CLI:
$ nest generate resource movieThis created the controller, service, module, DTOs, and entity structure following NestJS best practices for a RESTful resource.
- Clone the repository
❯ git clone git@github.com:lucasfdcampos/raspberry-awards-api.git- Enter the directory
❯ cd raspberry-awards-api/- Start the application
# install dependencies
❯ make install
# starts the project (also creates .env if missing)
❯ make start# unit tests
❯ make test
# e2e tests
❯ make test-e2e
# test coverage
❯ make test-cov-
GET /movie
Returns all movies loaded from the CSV. -
GET /awards/intervals
Returns a JSON with two arrays (minandmax) showing producers with the shortest and longest intervals between wins.
├── app.module.ts
├── main.ts
└── movie
├── awards.controller.spec.ts
├── awards.controller.ts
├── dto
│ ├── award-interval.dto.ts
│ └── producer-interval.dto.ts
├── entities
│ └── movie.entity.ts
├── movie.controller.spec.ts
├── movie.controller.ts
├── movielist.csv
├── movie.module.ts
├── movie.service.spec.ts
└── movie.service.ts
Link to extra documentation shows organization and formation of ideas for the project.
This project is licensed under the MIT License - see the LICENSE file for details