Skip to content

green_dot

Security and DX focused NodeJs backend framework

npx green_dot@latest generate

Back / Front Type-safe API

Simply generate a new api route with npx green_dot generate and configure it:

export const
const getUserByEmail: void
getUserByEmail
=
function svc(config: {
for: [string | {
role: string;
hasValidatedEmail: boolean;
}];
main(ctx: {
_id: string;
role: "appUser";
}, body: {
email: string;
}): any;
}): void
svc
({
for: [string | {
role: string;
hasValidatedEmail: boolean;
}]
for
: [
'customRole',
{
role: string
role
: 'user',
hasValidatedEmail: boolean
hasValidatedEmail
: true }
],
input: {
email: any;
}
input
: {
email: any
email
:
any
_
.
any
email
().
any
required
(),
},
output: any
output
:
any
_
.
any
model
('myDbName', 'user'),
rateLimiter: string
rateLimiter
: '10/min',
...
any
async
function main(ctx: {
_id: string;
role: "appUser";
}, body: {
email: string;
}): any
main
(
ctx: {
_id: string;
role: "appUser";
}
ctx
, { email }) {
email: string
return await
any
db
.
any
user
.
any
getOne
(
ctx: {
_id: string;
role: "appUser";
}
ctx
, {
email: string
email
}) // this db call will automatically apply mask and filter depending on user perm (see below)
},
})

Note: the above will auto generate a route on POST myDomain.com/get-user-by-email based on the const value. You can modify this by adding a route and method config



In frontend, you just have to import the SDK and use it like:

const
const user: User
user
= await
const $: {
getUserByEmail(): Promise<User>;
useQuery: {
getUserByEmail(): User;
};
}
$
.
function getUserByEmail(): Promise<User>
getUserByEmail
()
// OR if in the context of a react component (cache friendly, tanstack query)
const user =
const $: {
getUserByEmail(): Promise<User>;
useQuery: {
getUserByEmail(): User;
};
}
$
.
useQuery: {
getUserByEmail(): User;
}
useQuery
.
function getUserByEmail(): User
getUserByEmail
()
const user: User

API services Doc

Frontend Usage Doc



Shared Models, Unified Security

Generate a new model and DAO (data access object) npx green_dot generate and configure it:

company.model.ts
export const companyModel = _.mongoModel(
// Automatic timestamp fields
['creationDate', 'updateDate'],
{
name: _.string().required(),
admin: _.ref('user').required(), // ref to user model
companyIdenfier: _.string().required().unique(), // unique fields
})
export type CompanyModel = InferType<typeof companyModel>
// type may differ when writing (create / update) vs reading
export type CompanyModelWrite = InferTypeWrite<typeof companyModel>

Dao files are a way to configure the security of your model and expose automatically some method via API (getById, update…):


company.dao.ts
export const dao = {
type: 'mongo',
// EXPOSE: auto generate routes and SDK methods with configured access
expose: [{
for: 'appUser',
expose: ['getOne', 'create'],
}, {
for: 'admin',
expose: ['read', 'write'],
}],
// FILTER
filter: [{
for: 'appUser',
filter: (ctx, filter) => {
filter.admin === ctx._id // forces admin fields to be equal to user._id
}
}],
// MASK
mask: [{
for: 'appUser',
mask: ctx => ({
sensitiveData: true
}),
},],
populate: [],
} satisfies MongoDao<User>
export default dao


And much more…

A powerful plugin system

Actually 3 plugins can be installed when you run npx green_dot@latest generate for the first time:

GDmanagedLogin: Managed JWT login, email and password updates with custom emails (see doc)

GDapiKeyAuthentication: Managed 2FA, Pin Code or biometric authentication (see doc)

GDdoubleAuthentication: Api Key Authentication (see doc)

Loved by your IDE

Whenever you are lost, just hover the name of anything green_dot to see a full documentation without leaving your IDE

Cursor and VSCode plugins for specific syntax highlights and helpers

Use gd_ snippets anywhere to help with writing code faster

Performance friendly

  • All your requests are automatically cached with @tanstack/react-query to use in frontend components without the need to await your requests
  • refresh cache or disable it on demand via simple configuration (in API service or SDK directly)
  • prefetch heavy requests via $.prefetch.myHeavyRequest() so that when you need them they’ll load instantly
  • defer requests to make them async $.defer.myHeavyRequest()

Learn more about caching and performances

Plus

  • File Generation from template via npx green_dot generate
  • MongoDb integration (more database to come)
  • Auto generates a swagger documentation
  • Open Source