🙌

様々なRailsアプリケーションのrake statsを集めてみた

2024/05/07に公開

rake stats見ていますか?
rake statsを見ることで、ModelやControllerのコード分量だったり、
テストがどのくらいの比率で書かれているかを「カバレッジ」以外の観点からテストの実装状況を知ることができるテストレシオもチェックできたりして、とても重宝しています。

自分たちの関わっているRails製のプロダクトが他のRailsアプリケーションと比べてどーなの?ということを知るために、OSSのものを中心に様々なRailsアプリケーションのRake statsを集めてみました。
この情報をベースにして自分たちのRailsアプリケーションがどのような特徴を持っていて、改善していけばよいかの指針となれば良いなと思っています。

OSS

RubyGems.org

Rubyコミュニティのgemのホスティングサービスである、RubyGems.orgもRails製です。
あまりコード量が多いプロダクトではない分、読みやすいプロダクトだと思います。

https://rubygems.org/

rake stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name                 |  Lines |    LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers          |   3834 |   3096 |      96 |     391 |   4 |     5 |
| Helpers              |    546 |    456 |       0 |      65 |   0 |     5 |
| Jobs                 |    899 |    703 |      36 |      59 |   1 |     9 |
| Models               |   4782 |   3786 |      55 |     524 |   9 |     5 |
| Mailers              |    286 |    239 |       5 |      30 |   6 |     5 |
| Views                |   5718 |   4887 |      35 |      72 |   2 |    65 |
| Stylesheets          |   3228 |   2804 |       0 |       0 |   0 |     0 |
| JavaScript           |    726 |    603 |       0 |      66 |   0 |     7 |
| Libraries            |   2207 |   1806 |      38 |     153 |   4 |     9 |
| Helper tests         |    310 |    265 |       0 |      46 |   0 |     3 |
| Job tests            |   1740 |   1412 |      28 |      63 |   2 |    20 |
| Model tests          |   9670 |   7669 |      49 |      42 |   0 |   180 |
| Mailer tests         |    280 |    224 |       4 |      37 |   9 |     4 |
| Integration tests    |   6625 |   5031 |      64 |     261 |   4 |    17 |
| System tests         |   3656 |   2893 |      23 |     147 |   6 |    17 |
| ViewComponents       |    272 |    225 |      13 |      10 |   0 |    20 |
+----------------------+--------+--------+---------+---------+-----+-------+
| Total                |  44779 |  36099 |     446 |    1966 |   4 |    16 |
+----------------------+--------+--------+---------+---------+-----+-------+
  Code LOC: 18605     Test LOC: 17494     Code to Test Ratio: 1:0.9

Discourse

コードベースとしては紹介する中でもコード量が多く、LibrariesにRailsのコードがかなり寄せられていそう。
https://www.discourse.org/

rake stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name                 |  Lines |    LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers          |  20459 |  16311 |     113 |    1051 |   9 |    13 |
| Helpers              |   1222 |    968 |       0 |     122 |   0 |     5 |
| Jobs                 |   8583 |   6810 |     208 |     430 |   2 |    13 |
| Models               |  41715 |  30240 |     280 |    2489 |   8 |    10 |
| Mailers              |   1141 |    954 |       9 |      51 |   5 |    16 |
| Views                |   3056 |   2744 |       0 |       0 |   0 |     0 |
| JavaScripts          | 254892 | 215351 |       0 |    5331 |   0 |    38 |
| Stylesheets          |  41009 |  35179 |       0 |       0 |   0 |     0 |
| Libraries            |  77950 |  60712 |     638 |    5113 |   8 |     9 |
| Generator specs      |    181 |    147 |       3 |       6 |   2 |    22 |
| Helper specs         |   1128 |    913 |       0 |       2 |   0 |   454 |
| Import_export specs  |    246 |    189 |       0 |       1 |   0 |   187 |
| Initializer specs    |    129 |     93 |       0 |       0 |   0 |     0 |
| Integration specs    |   3315 |   2792 |       0 |      12 |   0 |   230 |
| Integrity specs      |    371 |    295 |       0 |       9 |   0 |    30 |
| Job specs            |  10410 |   8240 |       5 |      42 |   8 |   194 |
| Lib specs            |  79024 |  64086 |      59 |     304 |   5 |   208 |
| Mailer specs         |   1978 |   1623 |       0 |       1 |   0 |  1621 |
| Migration specs      |     60 |     50 |       0 |       0 |   0 |     0 |
| Model specs          |  47112 |  37769 |       6 |     110 |  18 |   341 |
| Multisite specs      |    834 |    676 |       2 |      10 |   5 |    65 |
| Request specs        |  62783 |  50519 |       3 |      85 |  28 |   592 |
| Script specs         |   1137 |    967 |       1 |       6 |   6 |   159 |
| Serializer specs     |   5550 |   4424 |       1 |      11 |  11 |   400 |
| Service specs        |  17051 |  13729 |       0 |      42 |   0 |   324 |
| System specs         |  12694 |   9785 |      79 |     691 |   8 |    12 |
| Task specs           |    894 |    688 |       0 |       6 |   0 |   112 |
| View specs           |    120 |     94 |       0 |       0 |   0 |     0 |
+----------------------+--------+--------+---------+---------+-----+-------+
| Total                | 695044 | 566348 |    1407 |   15925 |  11 |    33 |
+----------------------+--------+--------+---------+---------+-----+-------+
  Code LOC: 369269     Test LOC: 197079     Code to Test Ratio: 1:0.5

GitLab

言わずとしれたGitHubを参考にして作成されたアプリケーション。
今回紹介する中では一番コード量もテストコードも多く、Servicesなど、Railsにはないディレクトリがいくつか追加されているのが特徴です。
https://about.gitlab.com/

rake stats
+----------------------+---------+---------+---------+---------+-----+-------+
| Name                 |   Lines |     LOC | Classes | Methods | M/C | LOC/M |
+----------------------+---------+---------+---------+---------+-----+-------+
| Controllers          |   33803 |   24938 |     364 |    3292 |   9 |     5 |
| Helpers              |   18304 |   14305 |       1 |    1761 | 1761 |     6 |
| Models               |   88086 |   62966 |     759 |    8057 |  10 |     5 |
| Mailers              |    2618 |    1940 |      10 |     270 |  27 |     5 |
| Channels             |     153 |     107 |       4 |      12 |   3 |     6 |
| Views                |    1048 |     821 |       0 |       0 |   0 |     0 |
| JavaScripts          |  135547 |  100696 |       0 |     988 |   0 |    99 |
| Stylesheets          |   41272 |   33060 |       0 |       0 |   0 |     0 |
| Libraries            |  264588 |  194114 |    3774 |   20049 |   5 |     7 |
| Bin specs            |    1049 |     840 |       0 |       0 |   0 |     0 |
| Channel specs        |     246 |     184 |       0 |       0 |   0 |     0 |
| Command specs        |     606 |     467 |       0 |       0 |   0 |     0 |
| Component specs      |    3263 |    2545 |      13 |      41 |   3 |    60 |
| Config specs         |    1108 |     893 |       0 |       2 |   0 |   444 |
| Contract specs       |    1799 |    1538 |       1 |      17 |  17 |    88 |
| Controller specs     |   64685 |   49328 |       1 |     372 | 372 |   130 |
| Db specs             |     887 |     674 |       0 |      16 |   0 |    40 |
| Dependency specs     |      26 |      20 |       0 |       0 |   0 |     0 |
| Dot_gitlab_ci specs  |     323 |     255 |       0 |       0 |   0 |     0 |
| Experiment specs     |     281 |     204 |       0 |       0 |   0 |     0 |
| Feature specs        |   94920 |   71198 |       0 |     533 |   0 |   131 |
| Finder specs         |   23702 |   17931 |       0 |      35 |   0 |   510 |
| Graphql specs        |   35688 |   26984 |       0 |     194 |   0 |   137 |
| Haml_lint specs      |     228 |     161 |       0 |       0 |   0 |     0 |
| Helper specs         |   29285 |   23092 |       0 |      52 |   0 |   442 |
| Initializer specs    |    4133 |    3106 |       0 |      33 |   0 |    92 |
| Keep specs           |     617 |     483 |       3 |       9 |   3 |    51 |
| Lib specs            |  361707 |  281858 |      18 |    1300 |  72 |   214 |
| Mailer specs         |    5158 |    3998 |       0 |      10 |   0 |   397 |
| Metrics_server specs |     260 |     191 |       0 |       0 |   0 |     0 |
| Migration specs      |    8842 |    6937 |       0 |      26 |   0 |   264 |
| Model specs          |  175491 |  134295 |       4 |     292 |  73 |   457 |
| Policy specs         |   15145 |   11494 |       0 |      22 |   0 |   520 |
| Presenter specs      |    9060 |    6902 |       0 |       8 |   0 |   860 |
| Rack_server specs    |      82 |      60 |       0 |       2 |   0 |    28 |
| Request specs        |  160588 |  124605 |       0 |     516 |   0 |   239 |
| Routing specs        |    2530 |    1856 |       0 |       3 |   0 |   616 |
| Rubocop specs        |   15448 |   12808 |     351 |     320 |   0 |    38 |
| Script specs         |    6026 |    4763 |       0 |      19 |   0 |   248 |
| Serializer specs     |   13315 |   10330 |       0 |       9 |   0 |  1145 |
| Service specs        |  159654 |  123195 |       2 |     396 | 198 |   309 |
| Sidekiq specs        |      21 |      17 |       0 |       0 |   0 |     0 |
| Sidekiq_cluster specs |     130 |     101 |       0 |       0 |   0 |     0 |
| Spam specs           |      31 |      25 |       0 |       0 |   0 |     0 |
| Support_spec specs   |    2832 |    2204 |       0 |      29 |   0 |    74 |
| Task specs           |    7812 |    5969 |       0 |      30 |   0 |   196 |
| Tooling specs        |   10200 |    8048 |       4 |      17 |   4 |   471 |
| Uploader specs       |    4069 |    3100 |       1 |      10 |  10 |   308 |
| Validator specs      |    2070 |    1471 |       0 |       8 |   0 |   181 |
| View specs           |    8360 |    6205 |       0 |      23 |   0 |   267 |
| Worker specs         |   29883 |   22522 |       0 |      90 |   0 |   248 |
| ViewComponents       |    1267 |     942 |      26 |      95 |   3 |     7 |
+----------------------+---------+---------+---------+---------+-----+-------+
| Total                | 1848246 | 1406746 |    5336 |   38958 |   7 |    34 |
+----------------------+---------+---------+---------+---------+-----+-------+
  Code LOC: 433889     Test LOC: 972857     Code to Test Ratio: 1:2.2

Mastodon

Controller SpecもRequest Specがあるのが特徴。
このくらいのコード量のプロジェクトが一番参考になるのかなーと思ったりしています。
https://joinmastodon.org/ja

rake stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name                 |  Lines |    LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers          |  12376 |   9274 |     253 |    1538 |   6 |     4 |
| Helpers              |   1962 |   1581 |       0 |     186 |   0 |     6 |
| Models               |  13419 |   8917 |     178 |    1175 |   6 |     5 |
| Mailers              |    424 |    313 |       4 |      42 |  10 |     5 |
| Views                |    377 |    250 |       0 |       0 |   0 |     0 |
| JavaScript           |  34559 |  28504 |       0 |     443 |   0 |    62 |
| Libraries            |   7670 |   5704 |      99 |     307 |   3 |    16 |
| Chewy specs          |    124 |    100 |       0 |       4 |   0 |    23 |
| Config specs         |    134 |     95 |       0 |       6 |   0 |    13 |
| Controller specs     |  10493 |   8022 |       0 |      52 |   0 |   152 |
| Fabrication specs    |     14 |     10 |       0 |       0 |   0 |     0 |
| Feature specs        |    670 |    462 |       0 |      24 |   0 |    17 |
| Generator specs      |     27 |     20 |       0 |       0 |   0 |     0 |
| Helper specs         |   1424 |   1112 |       0 |      17 |   0 |    63 |
| Lib specs            |  12260 |   9620 |       0 |      98 |   0 |    96 |
| Locale specs         |     35 |     28 |       0 |       0 |   0 |     0 |
| Mailer specs         |    709 |    538 |       3 |      31 |  10 |    15 |
| Model specs          |   9607 |   7468 |       0 |      18 |   0 |   412 |
| Policy specs         |   1256 |   1000 |       0 |       0 |   0 |     0 |
| Presenter specs      |    442 |    356 |       0 |       0 |   0 |     0 |
| Request specs        |  12603 |   9532 |       0 |      60 |   0 |   156 |
| Routing specs        |    207 |    161 |       0 |       0 |   0 |     0 |
| Search specs         |    104 |     82 |       0 |       0 |   0 |     0 |
| Serializer specs     |    280 |    209 |       0 |       0 |   0 |     0 |
| Service specs        |   8368 |   6625 |       0 |      45 |   0 |   145 |
| System specs         |    342 |    214 |       0 |       2 |   0 |   105 |
| Validator specs      |    955 |    738 |       0 |       9 |   0 |    80 |
| View specs           |     63 |     47 |       0 |       1 |   0 |    45 |
| Worker specs         |   2324 |   1718 |       0 |       6 |   0 |   284 |
+----------------------+--------+--------+---------+---------+-----+-------+
| Total                | 133228 | 102700 |     537 |    4064 |   7 |    23 |
+----------------------+--------+--------+---------+---------+-----+-------+
  Code LOC: 54543     Test LOC: 48157     Code to Test Ratio: 1:0.9

Forem

一時期阿部寛のホームページと比較しても遜色ないレスポンススピードで一斉を風靡したdev.toのOSSバージョン。
コードの内容も参考になることが多いプロジェクトではないでしょうか。
https://dev.to/

rake stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name                 |  Lines |    LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers          |  11443 |   8984 |     171 |     895 |   5 |     8 |
| Helpers              |   1339 |   1002 |       0 |     148 |   0 |     4 |
| Models               |   9189 |   6382 |     117 |     705 |   6 |     7 |
| Mailers              |    324 |    251 |       5 |      30 |   6 |     6 |
| Views                |  22462 |  20727 |       0 |       0 |   0 |     0 |
| JavaScripts          |   5710 |   4158 |       0 |     163 |   0 |    23 |
| Stylesheets          |  17914 |  15221 |       0 |       0 |   0 |     0 |
| JavaScript           |  23342 |  16554 |       0 |     393 |   0 |    40 |
| Libraries            |   2803 |   2387 |     148 |     170 |   1 |    12 |
| Controller specs     |    110 |     90 |       0 |       0 |   0 |     0 |
| Decorator specs      |   1318 |   1112 |       0 |       1 |   0 |  1110 |
| Form specs           |     70 |     59 |       0 |       0 |   0 |     0 |
| Generator specs      |      5 |      4 |       0 |       0 |   0 |     0 |
| Helper specs         |   1326 |   1076 |       0 |       1 |   0 |  1074 |
| Initializer specs    |    293 |    244 |       0 |       1 |   0 |   242 |
| Lib specs            |   2510 |   2011 |       2 |      10 |   5 |   199 |
| Liquid_tag specs     |   3473 |   2854 |       0 |      59 |   0 |    46 |
| Mailer specs         |    782 |    616 |       5 |      24 |   4 |    23 |
| Model specs          |  12469 |   9936 |       1 |       7 |   7 |  1417 |
| Policy specs         |   1473 |   1076 |       0 |       1 |   0 |  1074 |
| Query specs          |   1696 |   1318 |       0 |       2 |   0 |   657 |
| Refinement specs     |     10 |      9 |       0 |       0 |   0 |     0 |
| Request specs        |  31784 |  25674 |       1 |      81 |  81 |   314 |
| Routing specs        |    152 |    124 |       0 |       0 |   0 |     0 |
| Sanitizer specs      |     66 |     58 |       0 |       0 |   0 |     0 |
| Serializer specs     |    264 |    218 |       0 |       0 |   0 |     0 |
| Service specs        |  16923 |  13639 |       0 |      54 |   0 |   250 |
| System specs         |   6097 |   4880 |       0 |      24 |   0 |   201 |
| Task specs           |     78 |     59 |       0 |       0 |   0 |     0 |
| Uploader specs       |    335 |    264 |       0 |       0 |   0 |     0 |
| Validator specs      |    200 |    149 |       0 |       6 |   0 |    22 |
| View_object specs    |     87 |     68 |       0 |       0 |   0 |     0 |
| View specs           |    404 |    324 |       0 |       1 |   0 |   322 |
| Worker specs         |   3242 |   2596 |       0 |       4 |   0 |   647 |
+----------------------+--------+--------+---------+---------+-----+-------+
| Total                | 179693 | 144124 |     450 |    2780 |   6 |    49 |
+----------------------+--------+--------+---------+---------+-----+-------+
  Code LOC: 75666     Test LOC: 68458     Code to Test Ratio: 1:0.9

Redmine

老舗のプロジェクト管理ツール
テストについてはあまり行き届いておらず、ModelのテストよりはIntegration testsやSystem testsで全体的な品質をカバーしていそうです。
https://www.redmine.org/

rake stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name                 |  Lines |    LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers          |   8881 |   6634 |      56 |     536 |   9 |    10 |
| Helpers              |   6734 |   4942 |       1 |     396 | 396 |    10 |
| Jobs                 |    115 |     90 |       3 |       9 |   3 |     8 |
| Models               |  19688 |  14245 |     106 |    1501 |  14 |     7 |
| Views                |  29003 |  24546 |       0 |       0 |   0 |     0 |
| JavaScripts          |   6646 |   5151 |       0 |     447 |   0 |     9 |
| Stylesheets          |   3719 |   3080 |       0 |       0 |   0 |     0 |
| Libraries            |  21174 |  14795 |     154 |    1212 |   7 |    10 |
| Controller tests     |      0 |      0 |       0 |       0 |   0 |     0 |
| Helper tests         |   4198 |   3263 |      21 |     286 |  13 |     9 |
| Model tests          |      0 |      0 |       0 |       0 |   0 |     0 |
| Mailer tests         |      0 |      0 |       0 |       0 |   0 |     0 |
| Integration tests    |  10555 |   7406 |     103 |     586 |   5 |    10 |
| System tests         |   1591 |   1071 |      11 |      69 |   6 |    13 |
+----------------------+--------+--------+---------+---------+-----+-------+
| Total                | 112304 |  85223 |     455 |    5042 |  11 |    14 |
+----------------------+--------+--------+---------+---------+-----+-------+
  Code LOC: 73483     Test LOC: 11740     Code to Test Ratio: 1:0.2

OSSではないRailsアプリケーション

Campfire(once)

once.comにある、Campfireも私は課金して購入したので、rake statsの確認が可能でした。
かなりModelやControllerについては実装量が少ないことがわかります。
DHHや37signalsの哲学が入っている「作品」だと思うので、もしよければ購入してみてください。

https://once.com/campfire

rake stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name                 |  Lines |    LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers          |    932 |    748 |      28 |     144 |   5 |     3 |
| Helpers              |    551 |    481 |       2 |      67 |  33 |     5 |
| Jobs                 |     12 |      7 |       2 |       1 |   0 |     5 |
| Models               |    961 |    765 |      26 |     121 |   4 |     4 |
| Channels             |     89 |     76 |       7 |      13 |   1 |     3 |
| Views                |   1891 |   1656 |       0 |       3 |   0 |   550 |
| Stylesheets          |   2960 |   2412 |       0 |       0 |   0 |     0 |
| JavaScript           |   3570 |   2849 |       0 |      44 |   0 |    62 |
| Libraries            |    352 |    297 |      13 |      38 |   2 |     5 |
| Controller tests     |    932 |    726 |      24 |      94 |   3 |     5 |
| Helper tests         |     32 |     26 |       1 |       4 |   4 |     4 |
| Model tests          |    630 |    499 |      19 |      71 |   3 |     5 |
| Channel tests        |     72 |     52 |       2 |       9 |   4 |     3 |
| System tests         |    194 |    156 |       3 |      11 |   3 |    12 |
+----------------------+--------+--------+---------+---------+-----+-------+
| Total                |  13178 |  10750 |     127 |     620 |   4 |    15 |
+----------------------+--------+--------+---------+---------+-----+-------+
  Code LOC: 9291     Test LOC: 1459     Code to Test Ratio: 1:0.2

OSIRO(弊社プロダクト

最後に弊社のプロダクトであるオンラインコミュニティプラットフォームのOSIROについても赤裸々にrake statsを公開しておきます。執筆時点でエンジニアは6名で開発しています。
他のOSSプロジェクトに比べると規模の割に実装が多いような感じがしますね。
デットコードなども多いかもしれないですが、それでもそこまで減ることはないのかなと思っています。

rake stats
+----------------------+--------+--------+---------+---------+-----+-------+
| Name                 |  Lines |    LOC | Classes | Methods | M/C | LOC/M |
+----------------------+--------+--------+---------+---------+-----+-------+
| Controllers          |  29008 |  23925 |     536 |    2220 |   4 |     8 |
| Helpers              |   1880 |   1665 |       1 |     127 | 127 |    11 |
| Jobs                 |    288 |    249 |      28 |      29 |   1 |     6 |
| Models               |  67561 |  56300 |     999 |    6047 |   6 |     7 |
| Mailers              |   1992 |   1692 |      42 |     156 |   3 |     8 |
| Views                |   3981 |   3534 |       0 |       0 |   0 |     0 |
| JavaScripts          |    264 |    160 |       0 |      11 |   0 |    12 |
| Stylesheets          |  43786 |  39214 |       0 |       0 |   0 |     0 |
| Libraries            |   5525 |   4894 |     208 |     264 |   1 |    16 |
| Exception specs      |     45 |     38 |       0 |       0 |   0 |     0 |
| Feature specs        |   4807 |   3880 |       0 |       0 |   0 |     0 |
| Helper specs         |    287 |    242 |       0 |       0 |   0 |     0 |
| Integration specs    |    697 |    589 |       0 |       0 |   0 |     0 |
| Lib specs            |   2295 |   1945 |       0 |       0 |   0 |     0 |
| Mailer specs         |   4938 |   4446 |      11 |      32 |   2 |   136 |
| Model specs          |  73084 |  62716 |       3 |       5 |   1 | 12541 |
| Request specs        |  46279 |  40369 |       4 |      12 |   3 |  3362 |
| Service specs        |  19773 |  16979 |       0 |       0 |   0 |     0 |
| Task specs           |   2919 |   2483 |       0 |       0 |   0 |     0 |
| Util specs           |    128 |    104 |       0 |       0 |   0 |     0 |
| Validator specs      |    193 |    148 |       2 |       2 |   1 |    72 |
| Worker specs         |   1432 |   1234 |       0 |       0 |   0 |     0 |
| Services             |  13356 |  11302 |     198 |     814 |   4 |    11 |
+----------------------+--------+--------+---------+---------+-----+-------+
| Total                | 324518 | 278108 |    2032 |    9719 |   4 |    26 |
+----------------------+--------+--------+---------+---------+-----+-------+
  Code LOC: 142935     Test LOC: 135173     Code to Test Ratio: 1:0.9

最後に

ということで、エンジニア採用強化中で、まだまだ改善しなければいけないことだったり、
弊プロダクトの開発を一緒に行ってくれるエンジニアを募集中しています。

OSIRO テックブログ

Discussion