Fastify setup with TypeScript, EJS, Alpine, HTMX, Tailwind, MongoDB, Webpack, Eslint and much more.
- Node.js: (>= 14.x)
- npm: (>= 6.x)
- TypeScript: (>= 4.x)
- Fastify: (>= 3.x)
- EJS: (>= 3.x)
- Tailwind CSS: (>= 2.x)
- Webpack: (>= 5.x)
-
Clone the repository:
git clone https://github.com/maelacudini/FastifySetup.git
cd FastifySetup -
Install dependencies:
npm install
-
Build the project:
npm run build
-
Run the project:
npm run dev
- The main source code directory.
- Purpose: The main entry point for the Fastify application.
- Responsibility: Initializes and starts the Fastify server.
- Purpose: Handles incoming HTTP requests, extracts parameters, validates input, and delegates business logic to services. Formats and sends responses.
- Naming Convention:
[resource].controllers.ts
(e.g.,user.controllers.ts
,product.controllers.ts
). - Responsibility: Thin layer focused on HTTP request/response handling.
- Purpose: Encapsulates the core business logic of the application. Handles data processing, database interactions, and other domain-specific tasks.
- Naming Convention:
[resource].services.ts
(e.g.,user.services.ts
,product.services.ts
). - Responsibility: Implementing application functionality, promoting code reusability and testability.
- Purpose: Defines Fastify routes and connects them to controllers.
- Naming Convention:
[resource].routes.ts
(e.g.,user.routes.ts
,product.routes.ts
). - Responsibility: Routing requests to the appropriate controllers.
- Purpose: Contains larger, domain-specific, or core reusable modules.
- Responsibility: Encapsulating complex logic or integrations.
- Subfolders:
i18next/
: i18next logic with locales.mongoDB/
: Contains database-related code with models.
- Purpose: Contains custom plugins.
- Naming Convention:
[name].plugin.ts
(e.g.,jwt.plugin.ts
). - Responsibility: Dealing with plugin logic.
- Purpose: Stores small, general-purpose helper functions and utilities, only related to server (node).
- Subfolders:
constants/
: Keeps all constants in one place. Constants must be written in all caps, use snake case.functions/
: General-purpose helper functions.schemas/
: Routes schemas.types/
: Server side types, keep them separated from Client.
- Client side code.
- Purpose: Contains EJS fragments and layouts.
- Subfolders:
atoms/
: Simplest partials.molecules/
: Union of two or more atoms.organisms/
: Union of two or more molecules.layouts/
: General layouts common to multiple pages.
- Purpose: Contains general style, implemented with Tailwind.
- Responsibility: I mean it seems pretty obvious.
- Purpose: Contains EJS files, used with HTMX, that the server will return.
- Responsibility: Acts as the view layer for HTMX requests.
- Purpose: Stores static assets like CSS, JavaScript, and images.
- Responsibility: Serving static files.
- Purpose: Stores small, general-purpose helper functions and utilities, only related to client (browser).
- Responsibility: Providing reusable utility functions.
- Controllers:
[resource].controller.ts
- Services:
[resource].service.ts
- Routes:
[resource].routes.ts
- Models:
[resource].model.ts
- Schemas:
[resource].schemas.ts
- Utilities: descriptive names for function files.
- Libraries: descriptive names for library files.