# Crystal for new projects

**URL:** <https://forum.crystal-lang.org/t/crystal-for-new-projects/5516>\
**Category:** Community\
**Created:** [March 27, 2023, 12:35am UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516 "2023-03-27T00:35:59Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![wontruefree](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/wontruefree/32/1467_2.png) [@wontruefree](https://forum.crystal-lang.org/u/wontruefree)\
**Post date:** [March 27, 2023, 12:35am UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/1 "2023-03-27T00:35:59Z")

</div>

I started a new position knowing there were some problems with the codebase. After a month the owner of the company and I have both come to the conclusion we need to rewrite the project. My first choice would be Crystal.

There are some libraries we need immediately that too be honest are just not well supported or do not exist in crystal. But I can get around the near term problems.

I wanted to hear from the community. What is the current state on production support and operations?

I need a suite of operations tools that integrate into a web framework. Mostly:  
Metrics  
APM  
Logging  
Incident response

Also it would be nice to know if there are any glaring holes in the ecosystem. It seems like AWS support is still lacking.

Anyways let me know your thoughts on the current state of Crystal in a production environment.

---

<div class="post-metadata">

**Author:** ![weirdbricks](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/weirdbricks/32/1741_2.png) [@weirdbricks](https://forum.crystal-lang.org/u/weirdbricks)\
**Post date:** [March 27, 2023, 3:41am UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/2 "2023-03-27T03:41:28Z")

</div>

Just curious: what AWS services specifically do you need to access from Crystal?

---

<div class="post-metadata">

**Author:** ![sdogruyol](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/sdogruyol/32/38_2.png) [@sdogruyol](https://forum.crystal-lang.org/u/sdogruyol)\
**Post date:** [March 27, 2023, 4:25am UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/3 "2023-03-27T04:25:50Z")

</div>

AWS, it’s been a long time since I worked with it,

I was maintaning AWS shard [GitHub - sdogruyol/aws: Unofficial AWS SDK for Crystal](https://github.com/sdogruyol/aws) (S3, SQS support) but nowadays I don’t use AWS or have time for it. Maybe someone can fork or revive it back?

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [March 27, 2023, 6:54am UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/4 "2023-03-27T06:54:10Z")

</div>

Based on the size of the program you want to deploy, [openfass](https://github.com/openfaas/faas) is also a option. there are a Crystal binding live maintain.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [March 27, 2023, 10:48am UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/5 "2023-03-27T10:48:16Z")

</div>

OpenTelemetry could be a good tool for most (all?) the monitoring features you’re looking for:

> **[GitHub - wyhaines/opentelemetry-api.cr: The core of open telemetry...](https://github.com/wyhaines/opentelemetry-api.cr)**
>
> The core of open telemetry instrumentation is the OpenTelemetry API/SDK. The initial aim of this shard is to implement the OpenTelemetry specification for metrics, traces, and logs. - GitHub - wyha...

---

<div class="post-metadata">

**Author:** ![bcardiff](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bcardiff/32/3_2.png) [@bcardiff](https://forum.crystal-lang.org/u/bcardiff)\
**Post date:** [March 27, 2023, 1:13pm UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/6 "2023-03-27T13:13:33Z")

</div>

Are you fixed/prefer a certain web framework and incident response services?

congrats on the new position!

---

<div class="post-metadata">

**Author:** ![miry](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/miry/32/1650_2.png) [@miry](https://forum.crystal-lang.org/u/miry)\
**Post date:** [March 27, 2023, 6:56pm UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/7 "2023-03-27T18:56:42Z")

</div>

There is a great work to use Opentelemtry with Crystal: [GitHub - wyhaines/opentelemetry-instrumentation.cr: Bundled integrations for opentelemetry-api.cr (https://github.com/wyhaines/opentelemetry-api.cr).](https://github.com/wyhaines/opentelemetry-instrumentation.cr)

The first doc how to use it in [https://newrelic.com/blog/how-to-relic/otel-crystal](https://newrelic.com/blog/how-to-relic/otel-crystal)  
but the library changed from time of written and presented in that article, so read the code.

Getting started from me on earliest version: [How to begin with Traces in Crystal | by Michael Nikitochkin | JTWay](https://medium.com/jetthoughts/how-to-begin-with-traces-in-crystal-2fd6a0255447)

---

<div class="post-metadata">

**Author:** ![wontruefree](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/wontruefree/32/1467_2.png) [@wontruefree](https://forum.crystal-lang.org/u/wontruefree)\
**Post date:** [April 8, 2023, 5:44pm UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/8 "2023-04-08T17:44:14Z")

</div>

right now dynamodb. There is a shard for it but it is lacking features.

---

<div class="post-metadata">

**Author:** ![wontruefree](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/wontruefree/32/1467_2.png) [@wontruefree](https://forum.crystal-lang.org/u/wontruefree)\
**Post date:** [April 8, 2023, 5:46pm UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/9 "2023-04-08T17:46:30Z")

</div>

Thanks!!! It has been a real journey.

I prefer Lucky Framework because I feel it leans into Crystals strengths but I am open to options.

I don’t have a preference for incident response services but I have used a few and there seems to be some that are better then others.

---

<div class="post-metadata">

**Author:** ![wontruefree](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/wontruefree/32/1467_2.png) [@wontruefree](https://forum.crystal-lang.org/u/wontruefree)\
**Post date:** [April 8, 2023, 5:47pm UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/10 "2023-04-08T17:47:14Z")

</div>

Thanks!

I tried the repo a while ago I should give it another shot.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [April 8, 2023, 7:13pm UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/11 "2023-04-08T19:13:33Z")

</div>

> [@wontruefree](#):
>
> I prefer Lucky Framework because I feel it leans into Crystals strengths but I am open to options.

Depending on what kind of application you’re making is, Athena could also be a good choice 🙂. I’d be happy to answer any questions etc if needed as well.

---

<div class="post-metadata">

**Author:** ![wontruefree](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/wontruefree/32/1467_2.png) [@wontruefree](https://forum.crystal-lang.org/u/wontruefree)\
**Post date:** [April 8, 2023, 8:26pm UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/12 "2023-04-08T20:26:23Z")

</div>

Does Athena have an ORM?

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [April 8, 2023, 9:06pm UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/13 "2023-04-08T21:06:04Z")

</div>

Not directly within its ecosystem. But would be able to use whichever (if any) you wanted. E.g. Jennifer, Granite, Clear, etc.

Alternatively, I found just using [DB::Serializable - db 0.11.0](https://crystal-lang.github.io/crystal-db/api/0.11.0/DB/Serializable.html) works quite well. Is easy enough to add some helper methods to leverage more of the repository pattern so you only have to really write the SQL once when/if you need a new repo method. You also have to handle inserts yourself, but similarly can exact that to some helper type(s).

I’m still planning on getting an updated version of a example demo application available to serve as reference, based on the blog application from the book. It’s a somewhat naive implementation to keep the book length down, but can serve as a good starting point. Tl;dr being:

- [Article](https://github.com/PacktPublishing/Crystal-Programming/blob/main/Projects/blog/src/entities/article.cr) - The primary entity (model) of the application. Includes some modules to make it be JSON (de)serializable, serializable from the DB, and validatable. Depending on the complexity of your application it may serve better to have a dedicated object to represent the request/response bodies versus coupling that with your DB entity. The entity also has some protected methods that act as simple DB hooks, these could be extracted into a base type/module for better reusability.
- [Article::Repository](https://github.com/PacktPublishing/Crystal-Programming/blob/main/Projects/blog/src/entities/article_repository.cr) - Contains all methods used to query for articles. Similar to the entity itself, common query methods like `#find`, `#find?`,`#find_all`, and `#find_by` could be implemented in an abstract repo type with generic as the `as` argument.
- [EntityManager](https://github.com/PacktPublishing/Crystal-Programming/blob/main/Projects/blog/src/services/entity_manager.cr) - Primary type used to interact with the DB from your business logic. Contains public methods to create/update a record, as well as to delete them. Also contains a method to get an `Article::Repository` instance cached in a class var. Could use a macro to auto-generate these for all entity types. Lastly this type contains the raw SQL used as part of the creation/updating process, which should return the PK of that entity to properly set its `#id` value. Could maybe do something again with macros to auto generate two methods, one for the column names, and another for column values (all based on ivar names or something).
- [ArticleController](https://github.com/PacktPublishing/Crystal-Programming/blob/main/Projects/blog/src/controllers/article_controller.cr) - Example of how the entity manager can be used along with the `EntityManager`. This is for an older version of Athena, the `ParamConverter` concept changed, so syntax is not 100% what it would be in the latest version. This controller also makes use of a custom converter that provides the record from the DB in addition to the one deserialized from the request payload. Mainly useful for `PUT` requests, (and maybe `PATCH`?).

---

<div class="post-metadata">

**Author:** ![wontruefree](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/wontruefree/32/1467_2.png) [@wontruefree](https://forum.crystal-lang.org/u/wontruefree)\
**Post date:** [April 18, 2023, 5:07pm UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/14 "2023-04-18T17:07:08Z")

</div>

I had not considered using `DB::Serializable` but that is a great idea. I think this is actually a really good idea. The hard part is getting from 0 to 1. Getting a fast initial iteration for CRUD and everything is hard. It would be an interesting project to have something scaffold up an initial web application.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [April 18, 2023, 5:14pm UTC](https://forum.crystal-lang.org/t/crystal-for-new-projects/5516/15 "2023-04-18T17:14:15Z")

</div>

It’s still a WIP, but can checkout [GitHub - athena-framework/demo at develop](https://github.com/athena-framework/demo/tree/develop). Still need to add an example of auth, update the `README.md` files, and add some more tests but it should give you the gist of my previous reply and/or serve as an alternate starting point versus the skeleton repository.
