The AI-Native Rails App: What a 2025 Architecture Looks Like

Introduction

For the first time in decades of building products, I’m seeing a shift that feels bigger than mobile or cloud.
AI-native architecture isn’t “AI added into the app” it’s the app shaped around AI from day one.

In this new world:

  • Rails is no longer the main intelligence layer
  • Rails becomes the orchestrator
  • The AI systems do the thinking
  • The Rails app enforces structure, rules, and grounding

And honestly? Rails has never felt more relevant than in 2025.

In this post, I’m breaking down exactly what an AI-native Rails architecture looks like today, why it matters, and how to build it with real, founder-level examples from practical product work.

1. AI-Native Rails vs. AI-Powered Rails

Many apps today use AI like this:

User enters text → you send it to OpenAI → you show the result

That’s not AI-native.
That’s “LLM glued onto a CRUD app.”

AI-native means:

  • Your DB supports vector search
  • Your UI expects streaming
  • Your workflows assume LLM latency
  • Your logic expects probabilistic answers
  • Your system orchestrates multi-step reasoning
  • Your workers coordinate long-running tasks
  • Your app is built around contextual knowledge, not just forms
A 2025 AI-native Rails stack looks like this:
  • Rails 7/8
  • Hotwire (Turbo + Stimulus)
  • Sidekiq or Solid Queue
  • Postgres with PgVector
  • OpenAI, Anthropic, or Groq APIs
  • Langchain.rb for tooling and structure
  • ActionCable for token-by-token streaming
  • Comprehensive logging and observability

This is the difference between a toy and a business.

2. Rails as the AI Orchestrator

AI-native architecture can be summarized in one sentence:

Rails handles the constraints, AI handles the uncertainty.

Rails does:

  • validation
  • data retrieval
  • vector search
  • chain orchestration
  • rule enforcement
  • tool routing
  • background workflows
  • streaming to UI
  • cost tracking

The AI does:

  • reasoning
  • summarization
  • problem-solving
  • planning
  • generating drafts
  • interpreting ambiguous input

In an AI-native system:

Rails is the conductor. The AI is the orchestra.

3. Real Example: AI Customer Support for Ecommerce

Most ecommerce AI support systems are fragile:

  • they hallucinate answers
  • they guess policies
  • they misquote data
  • they forget context

An AI-native Rails solution works very differently.

Step 1: User submits a question

A Turbo Frame or Turbo Stream posts to:

POST /support_queries

Rails saves:

  • user
  • question
  • metadata

Step 2: Rails triggers two workers

(1) EmbeddingJob
– Create embeddings via OpenAI
– Save vector into PgVector column

(2) AnswerGenerationJob
– Perform similarity search on:

  1. product catalog
  2. order history
  3. return policies
  4. previous chats
  5. FAQ rules
    – Pass retrieved context into LLM
    – Validate JSON output
    – Store reasoning steps (optional)

Step 3: Stream the answer

ActionCable + Turbo Streams push tokens as they arrive.

broadcast_append_to "support_chat_#{id}"Code language: JavaScript (javascript)

The user sees the answer appear live, like a human typing.

Why this architecture matters for founders

  • Accuracy skyrockets with grounding
  • Cost drops because vector search reduces tokens
  • Hallucinations fall due to enforced structure
  • You can audit the exact context used
  • UX improves dramatically with streaming
  • Support cost decreases 50–70% in real deployments

This isn’t AI chat inside Rails.

This is AI replacing Tier-1 support, with Rails as the backbone of the system.

4. Example: Founder Tools for Strategy, Decks, and Roadmaps

Imagine building a platform where founders upload:

  • pitch decks
  • PDFs
  • investor emails
  • spreadsheets
  • competitor research
  • user feedback
  • product specs

Old SaaS approach:
You let GPT speculate.

AI-native approach:
You let GPT reason using real company documents.

How it works

Step 1: Upload documents

Rails converts PDFs → text → chunks → embeddings.

Step 2: Store a knowledge graph

PgVector stores embeddings.
Metadata connects insights.

Step 3: Rails defines structure

Rails enforces:

  • schemas
  • output formats
  • business rules
  • agent constraints
  • allowed tools
  • validation filters

Step 4: Langchain.rb orchestrates the reasoning

But Rails sets the boundaries.
The AI stays inside the rails (pun intended).

Step 5: Turbo Streams show ongoing progress

Founders see:

  • “Extracting insights…”
  • “Analyzing competitors…”
  • “Summarizing risks…”
  • “Drafting roadmap…”

This builds trust and increases perceived value.

5. Technical Breakdown: What You Need to Build

Below is the exact architecture I recommend.

1. Rails + Hotwire Frontend

Turbo Streams = real-time AI experience.

  • Streams for token output
  • Frames for async updates
  • No need for React overhead

2. PgVector for AI Memory

Install extension + migration.

Example schema:

create_table :documents do |t|
  t.text :content
  t.vector :embedding, limit: 1536
  t.timestamps
end
Code language: JavaScript (javascript)

Vectors become queryable like any column.

3. Sidekiq or Solid Queue for AI Orchestration

LLM calls must never run in controllers.

Recommended jobs:

  • EmbeddingJob
  • ChunkingJob
  • RetrievalJob
  • LLMQueryJob
  • GroundedAnswerJob
  • AgentWorkflowJob

4. AI Services Layer

Lightweight Ruby service objects.

Embedding example:

class Embeddings::Create
  def call(text)
    OpenAI::Client.new.embeddings(
      model: "text-embedding-3-large",
      input: text
    )["data"][0]["embedding"]
  end
endCode language: CSS (css)

5. Retrieval Layer

Document.order(Arel.sql("embedding <-> '#{embedding}' ASC")).limit(5)Code language: HTML, XML (xml)

Grounding prevents hallucinations and cuts costs.

6. Streaming with ActionCable

Token streaming UX looks magical and retains users.

7. Observability Layer (Non-Optional)

Track:

  • prompts
  • model
  • cost
  • context chunks
  • errors
  • retries
  • latency

AI systems break differently than traditional code.
Logging is survival.


6. How To Start Building This (Exact Steps)

Here’s the fast-track setup:

Step 1: Enable PgVector

Install and migrate.

Step 2: Build an Embedding Service

Clean, testable, pure Ruby.

Step 3: Add Worker Pipeline

One worker per step.
No logic inside controllers.

Step 4: Create Retrieval Functions

Structured context retrieval before every LLM call.

Step 5: Build Token Streaming

Turbo Streams + ActionCable.

Step 6: Add Prompt Templates & A/B Testing

Prompt engineering is your new growth lever.

7. Why Rails Wins the AI Era

AI products are:

  • async
  • slow
  • streaming-heavy
  • stateful
  • data-driven
  • orchestration heavy
  • context dependent

Rails was made for this style of work.

Python builds models.
Rails builds businesses.

We are entering an era where:

Rails becomes the best framework in the world for shipping AI-powered products fast.

And I’m betting on it again like I did 15 years ago but with even more conviction.

Closing Thoughts

Your product is no longer a set of forms.
In the AI era, your product is:

  • memory
  • context
  • retrieval
  • reasoning
  • workflows
  • streaming interfaces
  • orchestration

Rails is the perfect orchestrator for all of it.

Why “Lines of Code” Is the Wrong Way to Measure AI Productivity in Software Development

Last week, I had a conversation with another CTO that got me thinking about how we measure productivity in the age of AI-assisted software development.

Here’s how it went:

CTO: Right now, about 70% of our software output is generated by AI.
Me: Interesting. How are you measuring that?
CTO: By looking at the proportion of code that AI tools contribute during check-ins.
Me: But what if the AI produces ten times more code than a human would to solve the same problem? Doesn’t that risk adding unnecessary complexity and future technical debt?

That short exchange captures a much bigger problem: we are still in the earliest innings of understanding how AI fits into the software development lifecycle (SDLC). And one thing is already clear, measuring lines of code is not the way forward.


The Myth of Lines of Code as a Metric

The idea that “more lines of code = more productivity” has always been flawed. Good engineering has never been about who can write the most code. It’s about solving problems in the most effective and maintainable way possible.

A senior engineer might solve a business-critical feature in 20 lines of clean, tested code, while a less experienced developer or now, an AI might churn out 200 lines to accomplish the same thing. On paper, the latter looks “more productive,” but in practice, they’ve just created more surface area for bugs, maintenance, and future refactoring.

When AI is added into the mix, this risk multiplies. Large language models are excellent at producing code, but quantity is a misleading signal. We could easily end up with a lot of syntactically correct but architecturally messy software.


Why AI-Generated Code Can Inflate the Wrong Numbers

Imagine this scenario:

Human developer approach

  • Implements a payment validation service in 50 lines.
  • Uses existing abstractions, adds unit tests, and ensures long-term maintainability.

vs AI-generated approach

  • Produces a 500-line solution with redundant logic, overly generic abstractions, and unnecessary boilerplate.
  • Works today, but in 3 months, another engineer spends days cleaning it up.

If you measure productivity by “lines of code checked in,” the AI looks 10x more productive. But if you measure by long-term cost of ownership, the AI just created technical debt.

The irony is that AI often defaults to verbosity. It tries to be “helpful” by filling in every possible branch, every possible configuration, every possible error case. That’s useful in some contexts, but often it leads to bloat instead of clarity.


Better Metrics for AI-Assisted Development

If we agree that lines of code isn’t the answer, what should we be looking at?

Here are a few ideas:

Cycle time to value

  • How quickly can a feature go from idea → production → value delivered to the business?
  • If AI speeds this up without adding long-term drag, that’s true productivity.

Code quality and maintainability

  • Static analysis scores, cyclomatic complexity, duplication, and readability.
  • AI should be measured on whether it improves or degrades these metrics.

Bug rate and rework cost

  • How often do AI-generated contributions introduce regressions?
  • How much effort do humans spend debugging or rewriting AI code?

Developer experience

  • Are engineers spending less time on repetitive boilerplate?
  • Do they feel empowered to focus on architecture, problem-solving, and innovation?

Business outcomes

  • Does AI accelerate delivery of meaningful features, reduce time-to-market, and improve customer satisfaction?
  • Or does it just fill up the repo with more stuff to manage?

    Where This Leaves Us

    We are only at the beginning of figuring out how AI fits into modern software development. There will be new metrics, new practices, and new patterns of collaboration between humans and machines.

    But one thing is certain: lines of code is the wrong measure of productivity.

    In fact, if you see your AI adoption leading to more lines of code, you should pause and ask:

    • Is this actually solving problems more effectively?
    • Or are we just accumulating more technical debt at machine speed?

    The future of engineering with AI will belong to those who focus on outcomes, maintainability, and business value not vanity metrics.


    Conclusion

    AI is not going to replace developers; it’s going to reshape what productivity looks like. The teams that succeed will be the ones that look beyond shallow metrics and focus on sustainable velocity.

    The next time someone tells you their AI is producing 70% of the code, ask them:

    • 70% of what?
    • Is that 70% value, or 70% debt?

    Because in software, less is often more.

    May 1st, Workers’ Day: Reflecting on the Future of Developers in the Age of AI

    Every May 1st, we celebrate Workers’ Day a moment to recognize the hard work, progress, and dignity of people across every profession. Traditionally, it’s a day to honor laborers, craftsmen, and knowledge workers alike.

    Today, in 2025, it’s worth asking: What does Workers’ Day mean for developers, engineers, and tech builders when AI is rewriting the rules of work?

    Software development once a purely manual craft is being transformed. AI coding assistants, automated testing, and AI-driven architecture design are fundamentally reshaping what “developer work” looks like.

    This shift is both exciting and unsettling. And on a day meant to honor workers, it’s important to pause, reflect, and imagine the future of our profession.


    Developers and the Changing Nature of Work

    Writing software has historically been seen as highly skilled, highly manual labor an exercise in translating human logic and creativity into machine instructions. It’s an intellectual craft.

    But the arrival of advanced AI tools like GitHub Copilot, ChatGPT, and autonomous coding agents is shifting where the true value lies:

    • Repetitive coding is being automated.
    • Simple application patterns are being commoditized.
    • Technical excellence is being augmented and sometimes replaced by strategic and creative excellence.

    Just as factory workers once faced automation during the industrial revolutions, developers today are facing an “intellectual automation” wave. The tasks that defined junior and even mid-level engineering roles are changing fast.


    AI Is Not Eliminating Developers. But It’s Redefining Them

    There’s a common fear that AI will “replace” developers.

    That’s not exactly what’s happening.

    Instead, AI is redefining the developer’s role:

    • From a pure code generator → to a system designer and critical thinker.
    • From solving known problems → to exploring unknown problems.
    • From typing faster → to asking better questions.

    The core of great software development will become less about how many lines of code you can write, and more about:

    • How clearly you understand the problem.
    • How creatively you design the solution.
    • How effectively you validate assumptions with real users.

    In short: technical execution is being democratized, but insight, creativity, and judgment are becoming even more valuable.


    Workers’ Rights and Respect in a Post-AI World

    Workers’ Day isn’t just about jobs, it’s about dignity, fairness, and the value of human effort.

    As AI reshapes engineering, companies, leaders, and communities must ensure that:

    • Developers are given opportunities to reskill and evolve.
    • Workplaces value critical thinking and creativity over brute-force output.
    • Workers are recognized for their judgment, leadership, and empathy, not just their typing speed.

    The dignity of developer work must evolve but it must not disappear.

    The risk is that companies, chasing efficiency, might treat developers like “AI supervisors” or “prompt engineers” only undervaluing the strategic, human essence of great engineering work.

    This May 1st, we should celebrate not just what developers do but how they think, imagine, and create.


    The Future of Developer Work: What Matters Now

    So, if you’re a developer, or leading a tech team, what skills and mindsets will matter most in the future?

    1. Product Thinking
    Understanding user needs, business goals, and the “why” behind the “what” will be essential.

    2. Critical Reasoning
    Knowing when AI-generated code is wrong, incomplete, or misaligned with real-world requirements.

    3. Creativity and Innovation
    Thinking beyond what’s obvious. AI can suggest patterns, but it can’t invent bold new paradigms yet.

    4. Collaboration and Empathy
    Working with designers, PMs, stakeholders, and users will become even more central.

    5. Strategic Use of AI
    Knowing how to use AI, when to trust it, and when human judgment must take over.


    A New Kind of Craftsmanship

    In many ways, the evolution we’re living through isn’t the end of craftsmanship in software, it’s a renaissance.

    The tools have changed. The basic tasks have changed. But the core spirit of the developer the builder, the solver, the creator remains vital.

    If anything, AI makes the human parts of engineering even more valuable:

    • Vision.
    • Judgement.
    • Ethical thinking.
    • Originality.
    • Connection to human needs.

    That’s worth celebrating this Workers’ Day and fighting for in the years ahead.


    Final Thoughts: Building the Future Intentionally

    This May 1st, let’s honor developers not for how fast they can code but for how thoughtfully they can shape the future.

    Let’s champion workplaces that invest in human skills, not just AI tools.

    And let’s remember that while technology evolves, the heart of work the pursuit of meaning, the quest to make things better remains uniquely, beautifully human.


    Need help preparing your tech team for the AI era?

    I help companies and teams rethink their product strategies, evolve their engineering practices, and align AI innovation with real-world user needs.

    With 20+ years of experience across tech, fintech, and startup ecosystems, I can help your organization:

    • Embrace AI smartly and strategically
    • Foster product thinking across engineering
    • Future-proof your development practices

    📩 Contact me here or visit ivanturkovic.com to learn more.

    Let’s build a smarter, more human-centered future together.

    Extending Javascript objects with a help of AngularJS extend method

    Multiple ways of extending javascript objects

    /**
     * One-way reference from subclass to superclass (instance)
     * Most of the time this is what you want. It should be done
     * before adding other methods to Subclass.
     */
    ChildClass.prototype = new SuperClass();
     
    /**
     * Two-way reference
     * Superclass will also get any Subclass methods added later.
     */
    ChildClass.prototype = SuperClass.prototype;
     
    /**
     * Cloning behavior
     * This does not setup a reference, so instanceof will not work.
     */
    angular.extend(ChildClass.prototype, SuperClass.prototype);
     
    /**
     * Enhancing a single instance
     * This could be used to implement the decorator pattern.
     */
    angular.extend(subClassInstance, SuperClass.prototype);

    Be that likable person

    Become genuinely interested in other people.

    Smile.

    Remember that a person’s name is to that person the sweetest and most important sound in any language.

    Be a good listener. Encourage others to talk about themselves.

    Talk in terms of the other person’s interests.

    Make the other person feel important and do it sincerely.

    Smile, smile, smile 🙂

    AngularJS directive multiple element

    How to get AngularJS directive multiple element

    You probably know there exists opening ng-repeat-start and finishing directive ng-repeat-end like:

    <ul>
     <li ng-repeat-start="user in users">
       {{user.firstName}}
     </li>
     <li ng-repeat-end>
       {{user.firstName}}
     </li>
    </ul>

    You would think it is a specially made directive that works that way but actually it is not. It is part of any directive so you can use it inside your too. When you create new directory and inside you factory function you need to return an object with multiElement options set to true. This way it will behave same as ngRepeat directive over multiple non nested fields. Small excerpt from ngRepeat.js file denoting this:

    var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
      ...
      return {
        restrict: 'A',
        <strong>multiElement: true,</strong>
        transclude: 'element',
        priority: 1000,
        terminal: true,
        ...
       }
    }];

    From native angularJS directive there are few more directives that support multi element spanning. They are ngIf, ngShow, ngHide and ngSwitch. So by adding multiElement to your custom directive you can make to transclude over angularjs directive multiple elements at the same time. This also comes handy because you can do nesting of multiple elements if they are contained inside another one.

    Conquering Fear

    What really keeps you from living your dreams?

    What problem is most dominant in peoples lives?

    The answer is: FEAR!

    People live every day in fear. Fear of losing their wealth, fear of losing their loved ones, fear of making the wrong decisions, fear of being themselves, fear of growing up, fear of making a commitment. The list goes on and on.

    The leading cause of people not fulfilling their dreams is NOT the fear of failure – itís the fear of success! The fear of actually accomplishing what they set out to do. The fear of living life to the fullest may have paralyzed you. This will cause you to never really try in your business, or if you do try, to sabotage your efforts so you never have to face your fear of success.

    Most people live their lives in the grip of this fear and they arenít even aware that it has control over them! The fear is the one thing that can turn your dreams of financial freedom, loving relationships, and a fulfilling and significant life into a pattern of habits including procrastination, self-sabotage and other bad habits.

    Fear is the dominate problem in your life today. The two questions you need to answer to conquer your fear are:

    Which fear has the most control over your behavior? Is it the fear of failure, the fear of rejection, the fear of success, or is it all of them?

    How do I interrupt the bad habits that I have developed as a means of protection from this fear? How do I interrupt the programming I have within me?

    These are the two most significant questions when it comes to overcoming your fears. If you can answer these two questions, your life will forever change!

    The reality of fear is that it is human and is a part of life. Itís not going to go away. Some fear is even healthy! It is a gift given to you to keep you safe and bring you closer to your creator.

    Every person is born with three instinctive fears. These are: fear of falling, fear of loud noises, and fear of abandonment. These three fears were given to you to help you monitor what is going on around you. Think about it; it is fear that gives you the adrenaline rush that makes you escape from a situation that is really, truly unsafe. It also gives you the same rush that causes you to fight to win.

    Faith is born in fear. God knew in His infinite wisdom that fear is what would drive His people back to Him. Although sometimes it is only in times of extreme fear that we look to God and choose Him. Take a look at your own life and think about the times you looked to God for His power and wisdom. Those were probably times of extreme fear. True faith is born from fear!

    So what caused the gift of fear to be the number one problem in society today? Why do people let fear control their actions, beliefs and lives? The answer is the difference between reacting to fear and acting in fear. It has everything to do with your belief system.

    Children typically react instinctively to fear, which is appropriate behavior at this age. Most adults don’t make the distinction between reacting to fear, as when they were a child, and acting with their intellect when dealing with fear.

    People react instinctively to fear by either denying it or running away from it. They miss the power that comes from acting with their intellect, never allowing the fear to become the gift it was intended to be. Learn to act with your intellect by exposing your true fears and the beliefs they represent and free yourself so you can move on with all you are meant to do, have and become!

     

    Be A Leader Not A Follower

    Most people in life are happy to follow the lead of other people, to sit on the fence in a debate or have the attitude of hiding at the back of the class. The most successful people are leaders and make things happen for themselves by taking a positive attitude and through working very hard to reach their goals. We are all able to become leaders and this article may help you to achieve this status.

    I grew up as a very nervous person, who had very little self-confidence and who was very shy. I was not happy being this way and often felt jealous of other people who were happy to speak up and take control of tasks and situations. I wanted to be one of these leaders and not the follower that I certainly had become.

    In my early twenties, I decided that the time had arrived to make a series of life changing decisions. I was determined to have a happy and successful life and was aware that I needed to change my whole attitude and approach to life.

    I was not happy at where I worked and joined an employment agency in an attempt to find alternative employment. In the reception area of the agency, I started speaking to a man who was also their hoping to find a different job. His name was Mark and we got on well and wished each other the best of luck in our quest to find work. We even exchanged phone numbers and vowed to keep each other up to date with our progress.

    I was then interviewed by a man who explained his plan to help me to find this new role of work. He was very bright, clever and positive and had many interesting ideas. He seemed very confident that I would soon be employed for a different company more suited to the skills which I had.

    At one stage of the meeting he described the scenario of a group interview. He suggested that we may be ushered into a large room with a big table. As we sat down there would be a sheet of paper asking the group to debate a particular subject. He stated that all of the people in the room would be in the same position, all looking for work, all nervous, however that in that room I could be whoever I wanted to be. He said that I needed to stand up and take the lead by stating that I would act as chairman and that if anyone had a comment that they wanted to make, that they could raise their hand. If I did this I would show my prospective employer that I was a leader.

    I went home and thought about this and did not believe I had it in me to act in the way that he wanted me to, as I was not a leader. Later that evening Mark phoned and all he was talking about was the group interview scenario. He also stated that there was no way that he would be able to stand up either in the way that had been described.

    I did not have to ever attend a group interview, but Mark did. He surprised himself by carrying out the advice and stated that after he had said his initial statement about being the chairman, that he had never felt so powerful and in control. For the rest of the day other members of the group had been regularly asking him questions as if he was some sort of team leader. He was very proud of himself and I am happy to report that he was successful at that interview and is very happy in his new position.

    He has also taken the success and learning experience into his social life and states that he has never had a higher self-esteem. I am very pleased for him as he is a genuine person who works very hard. He is also one of only a few friends that I can honestly say that I trust.

    I have taken inspiration from Mark and have entered into a career of helping people who stutter, to achieve fluency. This is something which I really enjoy and which gives me a large amount of job satisfaction. I am also far more confident than I ever have been and have at last found happiness.

    In conclusion we all have it in us to be a leader. We need to be brave and determined to take control and remember that all we can do in life is to try our best. We are only sure about living one life, so lets be happy and not accept second best. Be a leader in life, not a follower.