Aeria is the new MongoDB-focused framework

Hi!

Since this section of the forum is dedicated to Node.js frameworks, I’d like to share a new MongoDB-focused framework I’m working on and ask for comments. Some features:

It autopopulates references using the Aggregation Framework. In thesis the network overhead should be dramatically reduced since everything gets populated with a single transaction. I don’t know yet how faster or slower this approach is compared to the hooks used by Mongoose and such. The payloads for nested lookups are now quite big, but there’s room for optimizations.

It ships a Prisma-like schema declaration language written in PureScript. Collections are declared inside a single “.aeria” file (just like in Prisma) and then compiled to .js and .d.ts files. Creating denormalized structures and referencing another collections is very easy as shown below. In this example, even “person.jobs[0].company” will get strongely typed with the properties of the “Company” collection!

collection Person {
  properties {
    name str
    jobs []{
      properties {
        company Company
        position enum @values([
          "programmer",
          "devops"
        ])
      }
    }
  }
}

Long story short, at the time the development started Mongoose TypeScript support wasn’t that good, and we wanted a more cohesive stack to work with data-centric applications. A lot of the effort was put in reducing the code surface needed to bring up some CRUDs. Aeria is a frontend for MongoDB plus a micro-HTTP framework with security builtins such as access control, ownership, document immutability, etc. More info can be found on our website.

We have been working on this project without funding for about 3 years now. Visibility matters a lot for us in this stage. Please give the repositories a star if you believe the project could thrive.

Example payload if anyone is interested:

[
  {
    "$lookup": {
      "from": "companys",
      "foreignField": "_id",
      "localField": "jobs.company",
      "as": "_jobs_company",
      "pipeline": [
        {
          "$project": {
            "name": 1
          }
        }
      ]
    }
  },
  {
    "$set": {
      "jobs": {
        "$filter": {
          "input": {
            "$map": {
              "input": "$jobs",
              "as": "jobs__elem",
              "in": {
                "$mergeObjects": [
                  "$$jobs__elem",
                  {
                    "company": {
                      "$cond": [
                        {
                          "$ne": [
                            {
                              "$indexOfArray": [
                                "$_jobs_company._id",
                                "$$jobs__elem.company"
                              ]
                            },
                            -1
                          ]
                        },
                        {
                          "$arrayElemAt": [
                            "$_jobs_company",
                            {
                              "$indexOfArray": [
                                "$_jobs_company._id",
                                "$$jobs__elem.company"
                              ]
                            }
                          ]
                        },
                        null
                      ]
                    }
                  }
                ]
              }
            }
          },
          "as": "elem",
          "cond": {
            "$ne": [
              "$$elem",
              null
            ]
          }
        }
      }
    }
  },
  {
    "$unset": [
      "_jobs_company"
    ]
  }
]

The project looks interesting, but out of curiosity do you feel that Mongoose type support has improved since you initially evaluated it? Are there still features missing from Mongoose that Aeria provides?

As you’re using Prisma as inspiration for the design I’m also curious if Prisma was considered for your usecase and then dismissed. If so, what features was Prisma missing?

1 Like

I haven’t tried Mongoose that much since then, but I know they added type inference from schemas in one major release. So yes, there was a big improvement in that sense. About features that Aeria has and Mongoose doesn’t, well, I could name automatic reference resolution using the Aggregation Framework as I mentioned above, I think that’s one of the strongest features we currently have. Also our abstraction layer around MongoDB is much thinner, the whole project sitting in around 8k lines of code right now.

About Prisma, Aeria makes it easier to declare denormalized structures. Prisma also makes it unecessarily difficult to build cross-collection relations. On top of that, we aimed at a more powerful DSL that could express more than static data structure.

I’ve written an article detailing some Aeria highlights (since writting it I learned Prisma actually supports denormalized data structures through a feature called “composite types”), so please check it out if you want to learn more about the project: We finally have a fullstack framework for MongoDB | by Joaosan | Sep, 2024 | Medium

1 Like